aboutsummaryrefslogtreecommitdiffstats
path: root/src/cps.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-07-03 22:17:56 +0000
committerDavid Robillard <d@drobilla.net>2009-07-03 22:17:56 +0000
commitd3bebf39b6992814207643c238c47c3e3ceddefe (patch)
tree18959e2c752b8787fccf6174efa13108b886f992 /src/cps.cpp
parent22dac3110718ed92672d22f0438034c7e1b77dfd (diff)
downloadresp-d3bebf39b6992814207643c238c47c3e3ceddefe.tar.gz
resp-d3bebf39b6992814207643c238c47c3e3ceddefe.tar.bz2
resp-d3bebf39b6992814207643c238c47c3e3ceddefe.zip
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
Diffstat (limited to 'src/cps.cpp')
-rw-r--r--src/cps.cpp20
1 files changed, 11 insertions, 9 deletions
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<ACall>(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<ATuple*>()) {
- funcs.push_back(make_pair((AFn*)NULL, at(i)));
+ ssize_t index = 0;
+ FOREACH(iterator, i, *this) {
+ if (!(*i)->to<ATuple*>()) {
+ funcs.push_back(make_pair((AFn*)NULL, (*i)));
} else {
arg = tenv.penv.gensym("a");
if (firstFn == -1)
- firstFn = i;
+ firstFn = index;
AFn* thisFn = tup<AFn>(loc, tenv.penv.sym("fn"),
- tup<ATuple>(at(i)->loc, arg, 0),
+ tup<ATuple>((*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<ACall>(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<APrimitive*>())
ret->push_back(cont);
return ret;