cast() special form

This commit is contained in:
2021-09-04 13:36:00 -06:00
parent c73e013bbc
commit a6ced87e9b

View File

@@ -370,6 +370,21 @@ class SpecialForms {
macro !$truthyExp;
};
map["cast"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
wholeExp.checkNumArgs(1, 2, '(cast <value> <optional type>)');
var e = k.convert(args[0]);
var t = null;
if (args.length > 1) {
switch (args[1].def) {
case Symbol(typePath):
t = Helpers.parseComplexType(typePath, args[1]);
default:
throw CompileError.fromExp(args[1], 'second argument to cast should be a type path symbol');
}
}
ECast(e, t).withMacroPosOf(wholeExp);
}
return map;
}