diff options
Diffstat (limited to 'src/cps.cpp')
-rw-r--r-- | src/cps.cpp | 58 |
1 files changed, 23 insertions, 35 deletions
diff --git a/src/cps.cpp b/src/cps.cpp index 3358089..a3ba720 100644 --- a/src/cps.cpp +++ b/src/cps.cpp @@ -26,15 +26,15 @@ #include "resp.hpp" /** (cps x cont) => (cont x) */ -AST* -AST::cps(TEnv& tenv, AST* cont) const +static const AST* +cps_value(TEnv& tenv, AST* cont) const { return tup<ATuple>(loc, cont, this, 0); } /** (cps (fn (a ...) body) cont) => (cont (fn (a ... k) (cps body k)) */ -AST* -AFn::cps(TEnv& tenv, AST* cont) const +static const AST* +cps_fn(TEnv& tenv, AST* cont) const { ATuple* copyProt = new ATuple(*prot()); ASymbol* contArg = tenv.penv.gensym("_k"); @@ -43,19 +43,19 @@ AFn::cps(TEnv& tenv, AST* cont) const const_iterator p = begin(); ++(++p); for (; p != end(); ++p) - copy->push_back((*p)->cps(tenv, contArg)); + copy->push_back((*p)->(tenv, contArg)); return tup<ATuple>(loc, cont, copy, 0); } -AST* -APrimitive::cps(TEnv& tenv, AST* cont) const +static const AST* +cps_primitive(TEnv& tenv, AST* cont) const { - return value() ? tup<ATuple>(loc, cont, this, 0) : ATuple::cps(tenv, cont); + return value() ? tup<ATuple>(loc, cont, this, 0) : ATuple::(tenv, cont); } /** (cps (f a b ...)) => (a (fn (x) (b (fn (y) ... (cont (f x y ...)) */ -AST* -ATuple::cps(TEnv& tenv, AST* cont) const +static const AST* +cps_tuple(TEnv& tenv, AST* cont) const { std::vector< std::pair<AFn*, AST*> > funcs; AFn* fn = NULL; @@ -84,7 +84,7 @@ ATuple::cps(TEnv& tenv, AST* cont) const } if (fn) - fn->push_back((*i)->cps(tenv, thisFn)); + fn->push_back((*i)->(tenv, thisFn)); funcs.push_back(make_pair(thisFn, arg)); fn = thisFn; @@ -100,8 +100,8 @@ ATuple::cps(TEnv& tenv, AST* cont) const call->push_back(funcs[i].second); assert(fn); - fn->push_back(call->cps(tenv, cont)); - return (*firstFnIter)->cps(tenv, firstFn); + fn->push_back(call->(tenv, cont)); + return (*firstFnIter)->(tenv, firstFn); } else { assert(head()->value()); ATuple* ret = tup<ATuple>(loc, 0); @@ -114,30 +114,18 @@ ATuple::cps(TEnv& tenv, AST* cont) const } /** (cps (def x y)) => (y (fn (x) (cont))) */ -AST* -ADef::cps(TEnv& tenv, AST* cont) const +static const AST* +cps_def(TEnv& tenv, AST* cont) const { - AST* val = body()->cps(tenv, cont); + AST* val = body()->(tenv, cont); ATuple* valCall = val->to_tuple(); ATuple::iterator i = valCall->begin(); return tup<ADef>(loc, tenv.penv.sym("def"), sym(), *++i, 0); } -AST* -ADefType::cps(TEnv& tenv, AST* cont) const -{ - return new ADefType(*this); -} - -AST* -AMatch::cps(TEnv& tenv, AST* cont) const -{ - return new AMatch(*this); -} - /** (cps (if c t ... e)) => */ -AST* -AIf::cps(TEnv& tenv, AST* cont) const +static const AST* +cps_iff(TEnv& tenv, AST* cont) const { ASymbol* argSym = tenv.penv.gensym("c"); const_iterator i = begin(); @@ -146,14 +134,14 @@ AIf::cps(TEnv& tenv, AST* cont) const AST* next = *++i; if (cond->value()) { return tup<AIf>(loc, tenv.penv.sym("if"), cond, - exp->cps(tenv, cont), - next->cps(tenv, cont), 0); + exp->(tenv, cont), + next->(tenv, cont), 0); } else { AFn* contFn = tup<AFn>(loc, tenv.penv.sym("fn"), tup<ATuple>(cond->loc, argSym, tenv.penv.gensym("_k"), 0), tup<AIf>(loc, tenv.penv.sym("if"), argSym, - exp->cps(tenv, cont), - next->cps(tenv, cont), 0)); - return cond->cps(tenv, contFn); + exp->(tenv, cont), + next->(tenv, cont), 0)); + return cond->(tenv, contFn); } } |