diff options
Diffstat (limited to 'cps.cpp')
-rw-r--r-- | cps.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -59,6 +59,9 @@ ACall::cps(TEnv& tenv, AST* cont) ASymbol* arg = NULL; // Make a continuation for each element (operator and arguments) + // Argument evaluation continuations are not themselves in CPS. + // Each makes a tail call to the next, and the last makes a tail + // call to the continuation of this call ssize_t firstFn = -1; ssize_t lastFn = -1; for (size_t i = 0; i < size(); ++i) { @@ -71,7 +74,7 @@ ACall::cps(TEnv& tenv, AST* cont) firstFn = i; AFn* thisFn = tup<AFn>(loc, tenv.penv.sym("fn"), - tup<ATuple>(at(i)->loc, arg, tenv.penv.gensym("_k"), 0), + tup<ATuple>(at(i)->loc, arg, 0), 0); if (lastFn != -1) @@ -84,18 +87,14 @@ ACall::cps(TEnv& tenv, AST* cont) } if (firstFn != -1) { - // Call our callee in the last argument's evaluation function + // Call this call's callee in the last argument evaluator ACall* call = tup<ACall>(loc, 0); assert(funcs.size() == size()); for (size_t i = 0; i < funcs.size(); ++i) call->push_back(funcs[i].second); - if (!to<APrimitive*>()) - call->push_back(cont); - else - call = tup<ACall>(loc, cont, call, 0); assert(fn); - fn->push_back(call); + fn->push_back(call->cps(tenv, cont)); return at(firstFn)->cps(tenv, funcs[firstFn].first); } else { assert(at(0)->value()); |