Decomissioning macro functions
This commit is contained in:
@@ -180,33 +180,6 @@ class Macros {
|
||||
]).withPosOf(wholeExp);
|
||||
};
|
||||
|
||||
// Under the hood, (defmacrofun ...) defines a runtime function that accepts Quote arguments and a special form that quotes the arguments to macrofun calls
|
||||
macros["defmacrofun"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
wholeExp.checkNumArgs(3, null, "(defmacrofun [name] [args] [body...])");
|
||||
var macroName = switch (exps[0].def) {
|
||||
case Symbol(name): name;
|
||||
default: throw CompileError.fromExp(exps[0], 'first argument for defmacrofun should be a symbol for the macro name');
|
||||
};
|
||||
var macroNumArgs = switch (exps[1].def) {
|
||||
case ListExp(argNames): argNames.length;
|
||||
default: throw CompileError.fromExp(exps[1], 'second argument of defmacrofun should be a list of argument names');
|
||||
};
|
||||
k.specialForms[macroName] = (wholeExp:ReaderExp, callArgs:Array<ReaderExp>, convert) -> {
|
||||
// Macro functions don't need to check their argument numbers
|
||||
// because macro function calls expand to function calls that the Haxe compiler will check
|
||||
ECall(Context.parse('${k.className}.${macroName}', wholeExp.macroPos()), [
|
||||
for (callArg in callArgs)
|
||||
EFunction(FArrow, {
|
||||
args: [],
|
||||
ret: null,
|
||||
expr: EReturn(k.convert(callArg)).withMacroPosOf(wholeExp)
|
||||
}).withMacroPosOf(wholeExp)
|
||||
]).withMacroPosOf(wholeExp);
|
||||
};
|
||||
|
||||
CallExp(Symbol("defun").withPosOf(wholeExp), exps).withPosOf(wholeExp);
|
||||
}
|
||||
|
||||
macros["defreadermacro"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
wholeExp.checkNumArgs(3, 3, '(defreadermacro ["[startingString]" or [startingStrings...]] [[streamArgName]] [RawHaxe])');
|
||||
|
||||
|
@@ -53,8 +53,6 @@ class Reader {
|
||||
};
|
||||
readTable["#|"] = (stream) -> RawHaxe(stream.expect("closing |#", () -> stream.takeUntilAndDrop("|#")));
|
||||
// For defmacrofuns, unquoting with , is syntactic sugar for calling a Quote (Void->T)
|
||||
readTable[","] = (stream) -> CallExp(assertRead(stream, readTable), []);
|
||||
// If/when proper defmacro is added, reading every Unquote directly as a CallExp won't work anymore
|
||||
|
||||
readTable[":"] = (stream) -> TypedExp(nextToken(stream, "a type path"), assertRead(stream, readTable));
|
||||
|
||||
|
@@ -112,15 +112,6 @@ class BasicTestCase extends Test {
|
||||
_testIf();
|
||||
}
|
||||
|
||||
function testMacros() {
|
||||
Assert.equals(7, BasicTestCase.incrementTwice(5));
|
||||
|
||||
var seasonsGreetings = "ho ";
|
||||
Assert.equals("ho ho ho ", BasicTestCase.doTwiceString(() -> {
|
||||
seasonsGreetings += "ho ";
|
||||
}));
|
||||
}
|
||||
|
||||
// TODO to really test typed variable definitions, check for compilation failure on a bad example
|
||||
function testTypedDefvar() {
|
||||
Assert.equals(8, BasicTestCase.myInt);
|
||||
|
@@ -92,18 +92,6 @@
|
||||
|
||||
(defvar :Int myInt 8)
|
||||
|
||||
(defmacrofun doTwiceInt [intOp]
|
||||
,intOp
|
||||
,intOp)
|
||||
|
||||
// I think this causes doTwiceInt's runtime function to be typed as requiring Quote<Int> and returning Int
|
||||
(defun :Int incrementTwice [:Int val]
|
||||
(doTwiceInt ++val))
|
||||
|
||||
(defmacrofun doTwiceString [stringOp]
|
||||
,stringOp
|
||||
,stringOp)
|
||||
|
||||
(defun myTryCatch [:Any e]
|
||||
(try
|
||||
(throw e)
|
||||
|
Reference in New Issue
Block a user