cond use expBuilder()
This commit is contained in:
@@ -739,21 +739,21 @@ class Macros {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO use expBuilder()
|
|
||||||
// cond expands telescopically into a nested if expression
|
// cond expands telescopically into a nested if expression
|
||||||
static function cond(wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) {
|
static function cond(wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) {
|
||||||
wholeExp.checkNumArgs(1, null, "(cond [cases...])");
|
wholeExp.checkNumArgs(1, null, "(cond [cases...])");
|
||||||
|
var b = wholeExp.expBuilder();
|
||||||
return switch (exps[0].def) {
|
return switch (exps[0].def) {
|
||||||
case CallExp(condition, body):
|
case CallExp(condition, body):
|
||||||
CallExp(Symbol("if").withPosOf(wholeExp), [
|
b.call(b.symbol("if"), [
|
||||||
condition,
|
condition,
|
||||||
CallExp(Symbol("begin").withPosOf(wholeExp), body).withPosOf(wholeExp),
|
b.begin(body),
|
||||||
if (exps.length > 1) {
|
if (exps.length > 1) {
|
||||||
cond(CallExp(Symbol("cond").withPosOf(wholeExp), exps.slice(1)).withPosOf(wholeExp), exps.slice(1), k);
|
cond(b.call(b.symbol("cond"), exps.slice(1)), exps.slice(1), k);
|
||||||
} else {
|
} else {
|
||||||
Symbol("null").withPosOf(wholeExp);
|
b.symbol("null");
|
||||||
}
|
}
|
||||||
]).withPosOf(wholeExp);
|
]);
|
||||||
default:
|
default:
|
||||||
throw CompileError.fromExp(exps[0], 'top-level expression of (cond... ) must be a call list starting with a condition expression');
|
throw CompileError.fromExp(exps[0], 'top-level expression of (cond... ) must be a call list starting with a condition expression');
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user