[+] Add new type, _THAT

This commit is contained in:
Reece Wilson 2021-10-28 21:12:39 +01:00
parent 917ad238b9
commit 17a19fd90d
2 changed files with 387 additions and 30 deletions

File diff suppressed because it is too large Load Diff

View File

@ -49,12 +49,12 @@ forN(kMaxPairedElements, function(nElements) {
var nElementsMulNCapped = Math.min(kMacroParamLimit - 3, kWantMaxSupportedElements * nElements) var nElementsMulNCapped = Math.min(kMacroParamLimit - 3, kWantMaxSupportedElements * nElements)
var ignoreList = {} var ignoreList = {}
var ignoreListFirst = {}
forN(nElementsMulNCapped, function(i) { forN(nElementsMulNCapped, function(i) {
if (i == 0) { if (i == 0) {
textBuffer += `#define AU_FE_0${suffix}(expandable) \n` textBuffer += `#define AU_FE_0${suffix}(expandable) \n`
ignoreListFirst[`AU_FE_0_FIRST${suffix}`] = true ignoreList[`AU_FE_0_FIRST${suffix}`] = true
ignoreList[`AU_FE_0_THAT${suffix}`] = true
return return
} }
@ -73,7 +73,7 @@ forN(kMaxPairedElements, function(nElements) {
} else if (i % nElements == 0) { } else if (i % nElements == 0) {
if (i == nElements) { if (i == nElements) {
// Edge case: the last element does not accept any parameters // Edge case: the last element does not accept any parameters
textBuffer += `#define AU_FE_${i}${suffix}(expandable, ${X}) expandable(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(expandable))\n` textBuffer += `#define AU_FE_${i}${suffix}(expandable, ${X}) expandable(${X})\n`
} else { } else {
textBuffer += `#define AU_FE_${i}${suffix}(expandable, ${X}, ...) expandable(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(expandable, __VA_ARGS__))\n` textBuffer += `#define AU_FE_${i}${suffix}(expandable, ${X}, ...) expandable(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(expandable, __VA_ARGS__))\n`
} }
@ -81,21 +81,37 @@ forN(kMaxPairedElements, function(nElements) {
ignoreList[`AU_FE_${i}${suffix}`] = true ignoreList[`AU_FE_${i}${suffix}`] = true
} }
// Similar to above
var I2 = i + 1 var I2 = i + 1
// Similar to above
if (i < nElements) {
ignoreList[`AU_FE_${i}_THAT${suffix}`] = true
} else if (i % nElements == 0) {
var offByOne = iM1Translated + 1
if (i == nElements) {
// Edge case: the last element does not accept any parameters
ignoreList[`AU_FE_${I2}_THAT${suffix}`] = true // ? dont question it
textBuffer += `#define AU_FE_${I2}_THAT${suffix}(expandable, ctx, ${X}) expandable(ctx, ${X})\n`
} else {
textBuffer += `#define AU_FE_${I2}_THAT${suffix}(expandable, ctx, ${X}, ...) expandable(ctx, ${X}) AU_FE_EXPAND(AU_FE_${offByOne}_THAT${suffix}(expandable, ctx, __VA_ARGS__))\n`
}
} else {
ignoreList[`AU_FE_${I2}_THAT${suffix}`] = true
}
if (i == 1) { if (i == 1) {
textBuffer += `#define AU_FE_${i}_FIRST${suffix}(first, second) \n` textBuffer += `#define AU_FE_${i}_FIRST${suffix}(first, second) \n`
} else if (i < nElements) { } else if (i < nElements) {
ignoreListFirst[`AU_FE_${i}_FIRST${suffix}`] = true ignoreList[`AU_FE_${i}_FIRST${suffix}`] = true
} else if ((i % (nElements) == 0)) { } else if ((i % (nElements) == 0)) {
if (i == nElements) { if (i == nElements) {
ignoreListFirst[`AU_FE_${i}_FIRST${suffix}`] = true // ? dont question it ignoreList[`AU_FE_${i}_FIRST${suffix}`] = true // ? dont question it
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, second, ${X}) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(second))\n` textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, second, ${X}) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(second))\n`
} else { } else {
textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, second, ${X}, ...) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(second, __VA_ARGS__))\n` textBuffer += `#define AU_FE_${I2}_FIRST${suffix}(first, second, ${X}, ...) first(${X}) AU_FE_EXPAND(AU_FE_${iM1Translated}${suffix}(second, __VA_ARGS__))\n`
} }
} else { } else {
ignoreListFirst[`AU_FE_${I2}_FIRST${suffix}`] = true ignoreList[`AU_FE_${I2}_FIRST${suffix}`] = true
} }
}) })
@ -106,14 +122,17 @@ forN(kMaxPairedElements, function(nElements) {
// Stringify the parameter portion of the prototype // Stringify the parameter portion of the prototype
var params = formatNParamPatternReverseSuffix(nElementsMulNCapped, "AU_FE_", suffix) var params = formatNParamPatternReverseSuffix(nElementsMulNCapped, "AU_FE_", suffix)
var params2 = formatNParamPatternReverseSuffix(nElementsMulNCapped, "AU_FE_", "_FIRST" + suffix) var params2 = formatNParamPatternReverseSuffix(nElementsMulNCapped, "AU_FE_", "_FIRST" + suffix)
var params3 = formatNParamPatternReverseSuffix(nElementsMulNCapped, "AU_FE_", "_THAT" + suffix)
// Replace missing macro paramaters with the AU_FE_ERROR macro // Replace missing macro paramaters with the AU_FE_ERROR macro
params = params.split(", ").map((str) => { return ignoreList[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(", ") params2 = params2.split(", ").map((str) => { return ignoreList[str] ? "AU_FE_ERROR" : str}).join(", ")
params3 = params3.split(", ").map((str) => { return ignoreList[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__))`
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__))\n`
textBuffer += `#define AU_FOR_EACH_THAT${suffix}(action, ...) AU_FE_EXPAND(AU_GET_MACRO${suffix}(_whydoweneedthis, __VA_ARGS__, ${params3})(action,__VA_ARGS__))\n`
textBuffer += "\n\n" textBuffer += "\n\n"
}) })