This commit is contained in:
Reece Wilson 2021-10-07 17:28:16 +01:00
parent 4812a825db
commit fc94167ae7

View File

@ -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,20 +56,25 @@ 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 {
ignoreListFirst[`AU_FE_0_FIRST${suffix}`] = true
return
}
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) {
@ -82,7 +90,7 @@ forN(subn, function(subN) {
var I2 = i + 1
if (i < subN) {
ignoreList2[`AU_FE_${i}_FIRST${suffix}`] = true
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`
@ -90,19 +98,18 @@ forN(subn, function(subN) {
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, prefix, ${X}, ...) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(prefix, __VA_ARGS__))\n`
}
} else {
ignoreList2[`AU_FE_${I2}_FIRST${suffix}`] = true
}
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(", ")
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__))`