loadFrom return a (begin)
This commit is contained in:
@@ -217,6 +217,7 @@ class Kiss {
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
// readerExpToHaxeExpr must be called to process readermacro, alias, and macro definitions
|
// readerExpToHaxeExpr must be called to process readermacro, alias, and macro definitions
|
||||||
|
macroUsed = false;
|
||||||
var expr = readerExpToHaxeExpr(nextExp, k);
|
var expr = readerExpToHaxeExpr(nextExp, k);
|
||||||
|
|
||||||
// exps in the loaded file that actually become haxe expressions can be inserted into the
|
// exps in the loaded file that actually become haxe expressions can be inserted into the
|
||||||
@@ -242,7 +243,11 @@ class Kiss {
|
|||||||
loadedExps.push(nextExp);
|
loadedExps.push(nextExp);
|
||||||
} else if (!isEmpty(expr)) {
|
} else if (!isEmpty(expr)) {
|
||||||
// don't double-compile macros:
|
// 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;
|
return k.fieldList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static var macroUsed = false;
|
||||||
|
|
||||||
public static function readerExpToHaxeExpr(exp:ReaderExp, k:KissState):Expr {
|
public static function readerExpToHaxeExpr(exp:ReaderExp, k:KissState):Expr {
|
||||||
var macros = k.macros;
|
var macros = k.macros;
|
||||||
var fieldForms = k.fieldForms;
|
var fieldForms = k.fieldForms;
|
||||||
@@ -307,6 +314,7 @@ class Kiss {
|
|||||||
k.fieldDict[field.name] = field;
|
k.fieldDict[field.name] = field;
|
||||||
none; // Field forms are no-ops
|
none; // Field forms are no-ops
|
||||||
case CallExp({pos: _, def: Symbol(mac)}, args) if (macros.exists(mac)):
|
case CallExp({pos: _, def: Symbol(mac)}, args) if (macros.exists(mac)):
|
||||||
|
macroUsed = true;
|
||||||
var expanded = macros[mac](exp, args, k);
|
var expanded = macros[mac](exp, args, k);
|
||||||
if (expanded != null) {
|
if (expanded != null) {
|
||||||
convert(expanded);
|
convert(expanded);
|
||||||
|
@@ -35,17 +35,17 @@ class Macros {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macros["load"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
|
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) {
|
switch (args[0].def) {
|
||||||
case StrExp(otherKissFile):
|
case StrExp(otherKissFile):
|
||||||
return Kiss.load(otherKissFile, k);
|
Kiss.load(otherKissFile, k);
|
||||||
default:
|
default:
|
||||||
throw CompileError.fromExp(args[0], "only argument to load should be a string literal of a .kiss file path");
|
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) -> {
|
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) {
|
var libPath = switch (args[0].def) {
|
||||||
case StrExp(libName):
|
case StrExp(libName):
|
||||||
@@ -58,8 +58,7 @@ class Macros {
|
|||||||
Kiss.load(otherKissFile, k, libPath);
|
Kiss.load(otherKissFile, k, libPath);
|
||||||
default:
|
default:
|
||||||
throw CompileError.fromExp(args[1], "second argument to loadFrom should be a string literal of a .kiss file path");
|
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) {
|
function destructiveVersion(op:String, assignOp:String) {
|
||||||
|
Reference in New Issue
Block a user