use expBuilder for awaitLet
This commit is contained in:
@@ -484,31 +484,33 @@ class Macros {
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO use expBuilder()
|
// TODO test this
|
||||||
function awaitLet(wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) {
|
function awaitLet(wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) {
|
||||||
wholeExp.checkNumArgs(2, null, "(awaitLet [[promise bindings...]] [body...])");
|
wholeExp.checkNumArgs(2, null, "(awaitLet [[promise bindings...]] [body...])");
|
||||||
var bindingList = exps[0].bindingList("awaitLet");
|
var bindingList = exps[0].bindingList("awaitLet");
|
||||||
var firstName = bindingList.shift();
|
var firstName = bindingList.shift();
|
||||||
var firstValue = bindingList.shift();
|
var firstValue = bindingList.shift();
|
||||||
return CallExp(FieldExp("then", firstValue).withPosOf(wholeExp), [
|
var b = wholeExp.expBuilder();
|
||||||
CallExp(Symbol("lambda").withPosOf(wholeExp), [
|
|
||||||
ListExp([firstName]).withPosOf(wholeExp),
|
return b.call(b.field("then", firstValue), [
|
||||||
|
b.call(b.symbol("lambda"), [
|
||||||
|
b.list([firstName]),
|
||||||
if (bindingList.length == 0) {
|
if (bindingList.length == 0) {
|
||||||
CallExp(Symbol("begin").withPosOf(wholeExp), exps.slice(1)).withPosOf(wholeExp);
|
b.call(b.symbol("begin"), exps.slice(1));
|
||||||
} else {
|
} else {
|
||||||
awaitLet(wholeExp, [ListExp(bindingList).withPosOf(wholeExp)].concat(exps.slice(1)), k);
|
awaitLet(wholeExp, [b.list(bindingList)].concat(exps.slice(1)), k);
|
||||||
}
|
}
|
||||||
]).withPosOf(wholeExp),
|
]),
|
||||||
// Handle rejections:
|
// Handle rejections:
|
||||||
CallExp(Symbol("lambda").withPosOf(wholeExp), [
|
b.call(b.symbol("lambda"), [
|
||||||
ListExp([Symbol("reason").withPosOf(wholeExp)]).withPosOf(wholeExp),
|
b.list([b.symbol("reason")]),
|
||||||
CallExp(Symbol("throw").withPosOf(wholeExp), [
|
b.call(b.symbol("throw"), [
|
||||||
// TODO generalize CompileError to KissError which will also handle runtime errors
|
// TODO generalize CompileError to KissError which will also handle runtime errors
|
||||||
// with the same source position format
|
// with the same source position format
|
||||||
StrExp("rejected promise").withPosOf(wholeExp)
|
b.str("rejected promise")
|
||||||
]).withPosOf(wholeExp)
|
])
|
||||||
]).withPosOf(wholeExp)
|
])
|
||||||
]).withPosOf(wholeExp);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
macros["awaitLet"] = awaitLet;
|
macros["awaitLet"] = awaitLet;
|
||||||
|
Reference in New Issue
Block a user