loadFrom return a (begin)

This commit is contained in:
2021-10-29 22:10:17 -04:00
parent 432473ff76
commit 1d4a294781
2 changed files with 14 additions and 7 deletions

View File

@@ -217,6 +217,7 @@ class Kiss {
#end
// readerExpToHaxeExpr must be called to process readermacro, alias, and macro definitions
macroUsed = false;
var expr = readerExpToHaxeExpr(nextExp, k);
// exps in the loaded file that actually become haxe expressions can be inserted into the
@@ -242,7 +243,11 @@ class Kiss {
loadedExps.push(nextExp);
} else if (!isEmpty(expr)) {
// don't double-compile macros:
loadedExps.push(RawHaxe(expr.toString()).withPosOf(nextExp));
if (macroUsed) {
loadedExps.push(RawHaxe(expr.toString()).withPosOf(nextExp));
} else {
loadedExps.push(nextExp);
}
}
});
@@ -276,6 +281,8 @@ class Kiss {
return k.fieldList;
}
static var macroUsed = false;
public static function readerExpToHaxeExpr(exp:ReaderExp, k:KissState):Expr {
var macros = k.macros;
var fieldForms = k.fieldForms;
@@ -307,6 +314,7 @@ class Kiss {
k.fieldDict[field.name] = field;
none; // Field forms are no-ops
case CallExp({pos: _, def: Symbol(mac)}, args) if (macros.exists(mac)):
macroUsed = true;
var expanded = macros[mac](exp, args, k);
if (expanded != null) {
convert(expanded);

View File

@@ -35,17 +35,17 @@ class Macros {
}
macros["load"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(1, 1, '(load "[file]")');
wholeExp.checkNumArgs(1, 1, '(load "<file.kiss>")');
switch (args[0].def) {
case StrExp(otherKissFile):
return Kiss.load(otherKissFile, k);
Kiss.load(otherKissFile, k);
default:
throw CompileError.fromExp(args[0], "only argument to load should be a string literal of a .kiss file path");
}
};
};
macros["loadFrom"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(2, 2, '(loadFrom "[haxelib name]" "[file]")');
wholeExp.checkNumArgs(2, 2, '(loadFrom "<haxelib name>" "<file.kiss>")');
var libPath = switch (args[0].def) {
case StrExp(libName):
@@ -58,8 +58,7 @@ class Macros {
Kiss.load(otherKissFile, k, libPath);
default:
throw CompileError.fromExp(args[1], "second argument to loadFrom should be a string literal of a .kiss file path");
}
null;
};
};
function destructiveVersion(op:String, assignOp:String) {