From edb174e9be7ebb9ba251f7b03526eaad01552cba Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 29 Oct 2021 22:10:17 -0400 Subject: [PATCH] loadFrom return a (begin) --- kiss/src/kiss/Kiss.hx | 10 +++++++++- kiss/src/kiss/Macros.hx | 11 +++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/kiss/src/kiss/Kiss.hx b/kiss/src/kiss/Kiss.hx index d37e5a90..4333b58a 100644 --- a/kiss/src/kiss/Kiss.hx +++ b/kiss/src/kiss/Kiss.hx @@ -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); diff --git a/kiss/src/kiss/Macros.hx b/kiss/src/kiss/Macros.hx index 84cd5451..89d004ea 100644 --- a/kiss/src/kiss/Macros.hx +++ b/kiss/src/kiss/Macros.hx @@ -35,17 +35,17 @@ class Macros { } macros["load"] = (wholeExp:ReaderExp, args:Array, k:KissState) -> { - wholeExp.checkNumArgs(1, 1, '(load "[file]")'); + wholeExp.checkNumArgs(1, 1, '(load "")'); 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, k:KissState) -> { - wholeExp.checkNumArgs(2, 2, '(loadFrom "[haxelib name]" "[file]")'); + wholeExp.checkNumArgs(2, 2, '(loadFrom "" "")'); 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) {