fix stateChanged check in AsyncEmbeddedScript

This commit is contained in:
2023-07-17 14:17:04 -06:00
parent e7cb9319c5
commit d9f8f5dd47
2 changed files with 4 additions and 2 deletions

View File

@@ -304,6 +304,7 @@ class AsyncEmbeddedScript {
} }
nextExp = Kiss.macroExpand(nextExp, k); nextExp = Kiss.macroExpand(nextExp, k);
var stateChanged = k.stateChanged;
// Allow packing multiple commands into one exp with a (commands <...>) statement // Allow packing multiple commands into one exp with a (commands <...>) statement
switch (nextExp.def) { switch (nextExp.def) {
@@ -327,8 +328,8 @@ class AsyncEmbeddedScript {
var c = macro function(self, cc) { var c = macro function(self, cc) {
$expr; $expr;
}; };
// If the expression didn't add any fields, it can be cached // If the expression didn't change the KissState when macroExpanding, it can be cached
if (k.fieldList.length == fieldCount) if (!stateChanged)
cache[cacheKey] = expr.toString(); cache[cacheKey] = expr.toString();
commandList.push(c.expr.withMacroPosOf(nextExp)); commandList.push(c.expr.withMacroPosOf(nextExp));

View File

@@ -1081,6 +1081,7 @@ class Macros {
k.collectedBlocks[blockName] = []; k.collectedBlocks[blockName] = [];
// TODO some assertion that the coder hasn't defined over another macro (also should apply to defMacro) // TODO some assertion that the coder hasn't defined over another macro (also should apply to defMacro)
macros[blockName] = (wholeExp:ReaderExp, innerExps:Array<ReaderExp>, k:KissState) -> { macros[blockName] = (wholeExp:ReaderExp, innerExps:Array<ReaderExp>, k:KissState) -> {
k.stateChanged = true;
k.collectedBlocks[blockName] = k.collectedBlocks[blockName].concat(innerExps); k.collectedBlocks[blockName] = k.collectedBlocks[blockName].concat(innerExps);
if (exps.length > 1) exps[1] else null; if (exps.length > 1) exps[1] else null;
}; };