Clean up
This commit is contained in:
parent
4812a825db
commit
fc94167ae7
91
forEach.js
91
forEach.js
@ -9,21 +9,24 @@ function forN(n, cb) {
|
||||
}
|
||||
}
|
||||
|
||||
function genArray(n) {
|
||||
return [...Array(n).keys()]
|
||||
}
|
||||
|
||||
function formatNJoin(n, start, join) {
|
||||
return start + [...Array(n).keys()].join(join)
|
||||
return start + genArray(n).join(join)
|
||||
}
|
||||
|
||||
function formatNJoinReverse(n, start, join) {
|
||||
return start + [...Array(n).keys()].reverse().join(join)
|
||||
return start + genArray(n).reverse().join(join)
|
||||
}
|
||||
|
||||
function formatNJoinReverseSuffix(n, start, join, suffix) {
|
||||
return start + [...Array(n).keys()].reverse().join(suffix + join) + suffix
|
||||
return start + genArray(n).reverse().join(suffix + join) + suffix
|
||||
}
|
||||
|
||||
|
||||
function formatNJoinReverse(n, start, join) {
|
||||
return start + [...Array(n).keys()].reverse().join(join)
|
||||
return start + genArray(n).reverse().join(join)
|
||||
}
|
||||
|
||||
function formatNParamPattern(n, join) {
|
||||
@ -53,56 +56,60 @@ textBuffer +=
|
||||
|
||||
forN(subn, function(subN) {
|
||||
if (!subN) return
|
||||
var suffix = subN != 1 ? "_" + (subN): ""
|
||||
var re = Math.min(kMacroParamLimit - 3, n * subN)
|
||||
var ignoreList = {}
|
||||
var ignoreList2 = {}
|
||||
|
||||
forN(re, function(i) {
|
||||
var suffix = subN != 1 ? "_" + (subN): ""
|
||||
|
||||
var subNMulNCapped = Math.min(kMacroParamLimit - 3, n * subN)
|
||||
|
||||
var ignoreList = {}
|
||||
var ignoreListFirst = {}
|
||||
|
||||
forN(subNMulNCapped, function(i) {
|
||||
if (i == 0) {
|
||||
textBuffer += `#define AU_FE_0${suffix}(prefix) \n`
|
||||
ignoreList2[`AU_FE_0_FIRST${suffix}`] = true
|
||||
} else {
|
||||
var X = formatNParamPattern(subN, "X")
|
||||
var iM1 = i - 1
|
||||
var iM1Translated = i - subN
|
||||
var iM1Translated2 = (i - 1) - subN
|
||||
if (subN == 1) {
|
||||
textBuffer += `#define AU_FE_${i}${suffix}(prefix, ${X}, ...) prefix(${X}) AU_FE_EXPAND(AU_FE_${iM1}${suffix}(prefix, __VA_ARGS__))\n`
|
||||
} else if (i % subN == 0) {
|
||||
if (i == subN) {
|
||||
textBuffer += `#define AU_FE_${i}${suffix}(prefix, ${X}) prefix(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix))\n`
|
||||
} else {
|
||||
textBuffer += `#define AU_FE_${i}${suffix}(prefix, ${X}, ...) prefix(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix, __VA_ARGS__))\n`
|
||||
}
|
||||
|
||||
ignoreListFirst[`AU_FE_0_FIRST${suffix}`] = true
|
||||
return
|
||||
}
|
||||
|
||||
var X = formatNParamPattern(subN, "X")
|
||||
var iM1 = i - 1
|
||||
var iM1Translated = i - subN
|
||||
|
||||
if (subN == 1) {
|
||||
textBuffer += `#define AU_FE_${i}${suffix}(prefix, ${X}, ...) prefix(${X}) AU_FE_EXPAND(AU_FE_${iM1}${suffix}(prefix, __VA_ARGS__))\n`
|
||||
} else if (i % subN == 0) {
|
||||
if (i == subN) {
|
||||
textBuffer += `#define AU_FE_${i}${suffix}(prefix, ${X}) prefix(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix))\n`
|
||||
} else {
|
||||
ignoreList[`AU_FE_${i}${suffix}`] = true
|
||||
textBuffer += `#define AU_FE_${i}${suffix}(prefix, ${X}, ...) prefix(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix, __VA_ARGS__))\n`
|
||||
}
|
||||
|
||||
var I2 = i + 1
|
||||
if (i < subN) {
|
||||
ignoreList2[`AU_FE_${i}_FIRST${suffix}`] = true
|
||||
} else if ((i % (subN) == 0)) {
|
||||
if (i == subN) {
|
||||
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, prefix, ${X}) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix))\n`
|
||||
} else {
|
||||
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, prefix, ${X}, ...) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix, __VA_ARGS__))\n`
|
||||
}
|
||||
} else {
|
||||
ignoreList[`AU_FE_${i}${suffix}`] = true
|
||||
}
|
||||
|
||||
var I2 = i + 1
|
||||
if (i < subN) {
|
||||
ignoreListFirst[`AU_FE_${i}_FIRST${suffix}`] = true
|
||||
} else if ((i % (subN) == 0)) {
|
||||
if (i == subN) {
|
||||
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, prefix, ${X}) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix))\n`
|
||||
} else {
|
||||
ignoreList2[`AU_FE_${I2}_FIRST${suffix}`] = true
|
||||
}
|
||||
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, prefix, ${X}, ...) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix, __VA_ARGS__))\n`
|
||||
}
|
||||
} else {
|
||||
ignoreListFirst[`AU_FE_${I2}_FIRST${suffix}`] = true
|
||||
}
|
||||
})
|
||||
|
||||
var getMacroParams = formatNParamPattern(re, "_")
|
||||
var getMacroParams = formatNParamPattern(subNMulNCapped, "_")
|
||||
textBuffer += `#define AU_GET_MACRO${suffix}(${getMacroParams}, NAME,...) NAME\n`
|
||||
|
||||
var params = formatNParamPatternReverseSuffix(re, "AU_FE_", suffix)
|
||||
var params2 = formatNParamPatternReverseSuffix(re, "AU_FE_", "_FIRST" + suffix)
|
||||
var params = formatNParamPatternReverseSuffix(subNMulNCapped, "AU_FE_", suffix)
|
||||
var params2 = formatNParamPatternReverseSuffix(subNMulNCapped, "AU_FE_", "_FIRST" + suffix)
|
||||
|
||||
params = params.split(", ").map((str) => { return ignoreList[str] ? "AU_FE_ERROR" : str}).join(", ")
|
||||
params2 = params2.split(", ").map((str) => { return ignoreList2[str] ? "AU_FE_ERROR" : str}).join(", ")
|
||||
params = params.split(", ").map((str) => { return ignoreList[str] ? "AU_FE_ERROR" : str}).join(", ")
|
||||
params2 = params2.split(", ").map((str) => { return ignoreListFirst[str] ? "AU_FE_ERROR" : str}).join(", ")
|
||||
|
||||
textBuffer += `#define AU_FOR_EACH${suffix}(action, ...) AU_FE_EXPAND(AU_GET_MACRO${suffix}(_whydoweneedthis, __VA_ARGS__, ${params})(action,__VA_ARGS__))\n`
|
||||
textBuffer += `#define AU_FOR_EACH_FIRST${suffix}(action, ...) AU_FE_EXPAND(AU_GET_MACRO${suffix}(_whydoweneedthis, __VA_ARGS__, ${params2})(action,__VA_ARGS__))`
|
||||
|
Loading…
Reference in New Issue
Block a user