Fix exprCase for new macro expansion system

This commit is contained in:
2021-11-11 14:29:31 -07:00
parent 37b12052a6
commit 329d46f50b
2 changed files with 8 additions and 4 deletions

View File

@@ -402,6 +402,7 @@ class Helpers {
ReaderExpDef: ReaderExpDef
}
});
interp.variables.set("k", k.forMacroEval());
interp.variables.set("Macros", Macros);
for (name => value in k.macroVars) {
interp.variables.set(name, value);
@@ -431,8 +432,10 @@ class Helpers {
interp.variables.set("eval", innerRunAtCompileTimeDynamic);
interp.variables.set("Helpers", {
evalUnquotes: evalUnquotes.bind(_, innerRunAtCompileTime)
evalUnquotes: evalUnquotes.bind(_, innerRunAtCompileTime),
runAtCompileTime: innerRunAtCompileTime
});
interp.variables.set("__interp__", interp);
if (args != null) {
for (arg => value in args) {

View File

@@ -473,6 +473,7 @@ class Macros {
} catch (error:CompileError) {
throw error;
} catch (error:Dynamic) {
// TODO this could print the hscript, with some refactoring
throw CompileError.fromExp(wholeExp, 'Macro expansion error: $error');
};
};
@@ -932,7 +933,7 @@ class Macros {
throw CompileError.fromExp(wholeExp, 'expression ${toMatch.def.toString()} matches no pattern in exprCase');
};
return b.call(b.symbol("Macros.exprCase"), [b.str(functionKey), toMatch, b.symbol("k")]);
return b.call(b.symbol("Macros.exprCase"), [b.str(functionKey), toMatch, b.symbol("__interp__")]);
};
// Maybe the NEW wildest code in Kiss?
@@ -1043,8 +1044,8 @@ class Macros {
static var exprCaseFunctions:Map<String, ReaderExp->ReaderExp> = [];
public static function exprCase(id:String, toMatchValue:ReaderExp, k:KissState):ReaderExp {
return Helpers.runAtCompileTime(exprCaseFunctions[id](toMatchValue), k);
public static function exprCase(id:String, toMatchValue:ReaderExp, i:KissInterp):ReaderExp {
return i.variables["Helpers"].runAtCompileTime(exprCaseFunctions[id](toMatchValue));
}
static function matchExpr(pattern:ReaderExp, instance:ReaderExp):Bool {