separate forHScript() and forMacroEval()
This commit is contained in:
@@ -374,7 +374,7 @@ class Helpers {
|
|||||||
|
|
||||||
static var parser = new Parser();
|
static var parser = new Parser();
|
||||||
static function compileTimeHScript(exp:ReaderExp, k:KissState) {
|
static function compileTimeHScript(exp:ReaderExp, k:KissState) {
|
||||||
var hscriptExp = mapForInterp(k.forHScript().convert(exp));
|
var hscriptExp = mapForInterp(k.forMacroEval().convert(exp));
|
||||||
var code = hscriptExp.toString(); // tink_macro to the rescue
|
var code = hscriptExp.toString(); // tink_macro to the rescue
|
||||||
#if macrotest
|
#if macrotest
|
||||||
Prelude.print("Compile-time hscript: " + code);
|
Prelude.print("Compile-time hscript: " + code);
|
||||||
|
@@ -14,6 +14,7 @@ import kiss.Macros;
|
|||||||
import kiss.CompileError;
|
import kiss.CompileError;
|
||||||
import kiss.cloner.Cloner;
|
import kiss.cloner.Cloner;
|
||||||
|
|
||||||
|
using kiss.Kiss;
|
||||||
using kiss.Helpers;
|
using kiss.Helpers;
|
||||||
using kiss.Reader;
|
using kiss.Reader;
|
||||||
using tink.MacroApi;
|
using tink.MacroApi;
|
||||||
@@ -372,24 +373,34 @@ class Kiss {
|
|||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return an identical Kiss State, but without type annotations or wrapping list expressions as kiss.List constructor calls.
|
static function disableMacro(copy:KissState, m:String, reason:String) {
|
||||||
public static function forHScript(k:KissState):KissState {
|
|
||||||
var copy = new Cloner().clone(k);
|
|
||||||
copy.hscript = true;
|
|
||||||
|
|
||||||
// disallow macros that will error when run in hscript:
|
|
||||||
function disableMacro(m:String, reason:String) {
|
|
||||||
copy.macros[m] = (wholeExp:ReaderExp, exps, k) -> {
|
copy.macros[m] = (wholeExp:ReaderExp, exps, k) -> {
|
||||||
var b = wholeExp.expBuilder();
|
var b = wholeExp.expBuilder();
|
||||||
b.callSymbol("throw", [b.str('$m is unavailable in macros because $reason')]);
|
b.callSymbol("throw", [b.str('$m is unavailable in macros because $reason')]);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
disableMacro("set", "you don't want your macros to be stateful");
|
// Return an identical Kiss State, but without type annotations or wrapping list expressions as kiss.List constructor calls.
|
||||||
disableMacro("ifLet", "hscript doesn't support pattern-matching");
|
public static function forHScript(k:KissState):KissState {
|
||||||
disableMacro("whenLet", "hscript doesn't support pattern-matching");
|
var copy = new Cloner().clone(k);
|
||||||
disableMacro("unlessLet", "hscript doesn't support pattern-matching");
|
copy.hscript = true;
|
||||||
|
|
||||||
|
// disallow macros that will error when run in hscript:
|
||||||
|
disableMacro(copy, "ifLet", "hscript doesn't support pattern-matching");
|
||||||
|
disableMacro(copy, "whenLet", "hscript doesn't support pattern-matching");
|
||||||
|
disableMacro(copy, "unlessLet", "hscript doesn't support pattern-matching");
|
||||||
|
|
||||||
|
copy.macros["cast"] = (wholeExp:ReaderExp, exps, k) -> {
|
||||||
|
exps[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function forMacroEval(k:KissState): KissState {
|
||||||
|
var copy = k.forHScript();
|
||||||
|
// Disable macros that will cause problems in macro evaluation:
|
||||||
|
disableMacro(copy, "set", "you don't want your macros to be stateful");
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@ import kiss.Reader;
|
|||||||
import kiss.Stream;
|
import kiss.Stream;
|
||||||
|
|
||||||
using tink.MacroApi;
|
using tink.MacroApi;
|
||||||
|
using kiss.Kiss;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
import haxe.Json;
|
import haxe.Json;
|
||||||
@@ -132,7 +133,9 @@ class Main {
|
|||||||
var k = Kiss.defaultKissState();
|
var k = Kiss.defaultKissState();
|
||||||
k.wrapListExps = false;
|
k.wrapListExps = false;
|
||||||
var pretty = args.indexOf("--pretty") != -1;
|
var pretty = args.indexOf("--pretty") != -1;
|
||||||
k.hscript = args.indexOf("--hscript") != -1;
|
|
||||||
|
if (args.indexOf("--hscript") != -1)
|
||||||
|
k = k.forHScript();
|
||||||
|
|
||||||
function print(s:String) {
|
function print(s:String) {
|
||||||
if (!pretty)
|
if (!pretty)
|
||||||
|
Reference in New Issue
Block a user