diff options
author | David Robillard <d@drobilla.net> | 2012-12-15 21:48:21 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-12-15 21:48:21 +0000 |
commit | d3708205163f784343733661d9fa01ff14f8b751 (patch) | |
tree | a771a4956753c66cd2c8b7c5eb9f1e4a0b30834a /src/lift.cpp | |
parent | 10174ffc7ea08b7845dbe409a11811e820536468 (diff) | |
download | resp-d3708205163f784343733661d9fa01ff14f8b751.tar.gz resp-d3708205163f784343733661d9fa01ff14f8b751.tar.bz2 resp-d3708205163f784343733661d9fa01ff14f8b751.zip |
Write forward declarations for all types and functions for mutual and/or nested recursion.
git-svn-id: http://svn.drobilla.net/resp/trunk@440 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/lift.cpp')
-rw-r--r-- | src/lift.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/lift.cpp b/src/lift.cpp index 802130d..c6bcee9 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -82,7 +82,7 @@ lift_def(CEnv& cenv, Code& code, const ATuple* def) throw() assert(def->list_ref(1)->to_symbol()); List copy; copy.push_back(def->fst()); - copy.push_back(resp_lift(cenv, code, def->list_ref(1))); + copy.push_back(sym); for (ATuple::const_iterator t = def->iter_at(2); t != def->end(); ++t) copy.push_back(resp_lift(cenv, code, *t)); @@ -135,6 +135,14 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() implProtT.push_back(paramType); } + // Write function prototype first for mutual and/or nested recursion + List declProt(fn->loc, cenv.penv.sym("fn"), 0); + declProt.push_back(implProt); + List decl(fn->loc, cenv.penv.sym("prot"), cenv.penv.sym(implNameStr), 0); + decl.push_back(declProt); + code.push_back(decl); + cenv.setType(decl, cenv.penv.sym("Nothing")); + impl.push_back(implProt); // Lift body @@ -159,13 +167,13 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() List consT; List cons(fn->loc, cenv.penv.sym("Closure"), implName, NULL); - const CEnv::FreeVars& freeVars = cenv.liftStack.top(); + const CEnv::FreeVars freeVars = cenv.liftStack.top(); + cenv.liftStack.pop(); for (CEnv::FreeVars::const_iterator i = freeVars.begin(); i != freeVars.end(); ++i) { - cons.push_back(*i); + cons.push_back(resp_lift(cenv, code, *i)); tupT.push_back(cenv.type(*i)); consT.push_back(cenv.type(*i)); } - cenv.liftStack.pop(); // Prepend closure parameter type implProtT.push_front(tsym); @@ -183,6 +191,9 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() code.push_back(tdef); cenv.tenv.def(tsym, consT); + List tdecl(Cursor(), cenv.penv.sym("def-type"), tsym, 0); + code.push_front(tdecl); + code.push_back(def); // Set type of closure to type symbol @@ -192,7 +203,6 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() if (cenv.name(fn) != "") cenv.def(cenv.penv.sym(cenv.name(fn)), fn, consT, NULL); - return cons; } |