rest of the special form macro expanders. Close #7

This commit is contained in:
2024-02-17 13:45:49 -07:00
parent efbd024c3f
commit 6c113ca1ee
2 changed files with 35 additions and 0 deletions

View File

@@ -725,6 +725,36 @@ class SpecialForms {
b.callSymbol("cast", newArgs);
};
map["try"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
var b = wholeExp.expBuilder();
var tryKissExp = args[0];
var catchKissExps = args.slice(1);
var newCatchExps = [
for (catchExp in catchKissExps) {
switch (catchExp.def) {
case CallExp({def:Symbol("catch")}, catchBlockArgs):
b.callSymbol("catch", [expandTypeAliases(catchBlockArgs[0])].concat(Lambda.map(catchBlockArgs.slice(1), macroExpand)));
default:
catchExp;
}
}
];
b.callSymbol("try", [macroExpand(tryKissExp)].concat(newCatchExps));
};
function identity(wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) {
return wholeExp;
}
map["import"] = identity;
map["importAs"] = identity;
map["importAll"] = identity;
map["using"] = identity;
map["extends"] = identity;
map["implements"] = identity;
return map;
}

View File

@@ -80,4 +80,9 @@
.content (cast (Stream.fromString "hey") Stream)
(Assert.equals normal "hey\n")
(Assert.equals expanded "hey\n"))
(makeExampleNoValues
(try (throw (Stream.fromString "error"))
(catch [:Stream s]
(print "as expected"))))
)