From d3bebf39b6992814207643c238c47c3e3ceddefe Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 3 Jul 2009 22:17:56 +0000 Subject: Improved const correctness. Use iterators over indices (towards non-vector ATuple). git-svn-id: http://svn.drobilla.net/resp/tuplr@176 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/cps.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/cps.cpp') diff --git a/src/cps.cpp b/src/cps.cpp index 9d80170..75b771f 100644 --- a/src/cps.cpp +++ b/src/cps.cpp @@ -29,7 +29,7 @@ AST::cps(TEnv& tenv, AST* cont) return tup(loc, cont, this, 0); } -/** (cps (fn (a ...) body) cont) => (cont (fn (a ... k) (cps body k))*/ +/** (cps (fn (a ...) body) cont) => (cont (fn (a ... k) (cps body k)) */ AST* AFn::cps(TEnv& tenv, AST* cont) { @@ -63,25 +63,27 @@ ACall::cps(TEnv& tenv, AST* cont) // 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; - for (size_t i = 0; i < size(); ++i) { - if (!at(i)->to()) { - funcs.push_back(make_pair((AFn*)NULL, at(i))); + ssize_t index = 0; + FOREACH(iterator, i, *this) { + if (!(*i)->to()) { + funcs.push_back(make_pair((AFn*)NULL, (*i))); } else { arg = tenv.penv.gensym("a"); if (firstFn == -1) - firstFn = i; + firstFn = index; AFn* thisFn = tup(loc, tenv.penv.sym("fn"), - tup(at(i)->loc, arg, 0), + tup((*i)->loc, arg, 0), 0); if (fn) - fn->push_back(at(i)->cps(tenv, thisFn)); + fn->push_back((*i)->cps(tenv, thisFn)); funcs.push_back(make_pair(thisFn, arg)); fn = thisFn; } + ++index; } if (firstFn != -1) { @@ -97,8 +99,8 @@ ACall::cps(TEnv& tenv, AST* cont) } else { assert(at(0)->value()); ACall* ret = tup(loc, 0); - for (size_t i = 0; i < size(); ++i) - ret->push_back(at(i)); + FOREACH(iterator, i, *this) + ret->push_back((*i)); if (!to()) ret->push_back(cont); return ret; -- cgit v1.2.1