diff options
Diffstat (limited to 'src/lift.cpp')
-rw-r--r-- | src/lift.cpp | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/lift.cpp b/src/lift.cpp index aea8b0d..c24832f 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -40,7 +40,7 @@ lift_symbol(CEnv& cenv, Code& code, ASymbol* sym) throw() const int32_t index = cenv.liftStack.top().index(sym); // Replace symbol with code to access free variable from closure - return tup<ADot>(sym->loc, cenv.penv.sym("."), + return tup<ACall>(sym->loc, cenv.penv.sym("."), cenv.penv.sym("_me"), new ALiteral<int32_t>(index, Cursor()), NULL); @@ -97,13 +97,13 @@ lift_fn(CEnv& cenv, Code& code, AFn* fn) throw() // Create definition for implementation fn ASymbol* implName = cenv.penv.sym(impl->name); - ADef* def = tup<ADef>(fn->loc, cenv.penv.sym("def"), implName, impl, NULL); + ACall* def = tup<ACall>(fn->loc, cenv.penv.sym("def"), implName, impl, NULL); code.push_back(def); AType* implT = new AType(*type); // Type of the implementation function TList tupT(fn->loc, cenv.tenv.Tup, cenv.tenv.var(), NULL); TList consT(fn->loc, cenv.tenv.Tup, implT, NULL); - List<ACons, AST> cons(fn->loc, cenv.penv.sym("Closure"), implName, NULL); + List<ACall, AST> cons(fn->loc, cenv.penv.sym("Closure"), implName, NULL); implT->list_ref(1) = implProtT; @@ -155,14 +155,14 @@ lift_call(CEnv& cenv, Code& code, ACall* call) throw() * closure as the first parameter: * (_impl (Fn _impl ...) ...) */ - ACons* closure = copy.head->list_ref(0)->as<ACons*>(); + ATuple* closure = copy.head->list_ref(0)->as<ATuple*>(); ASymbol* implSym = closure->list_ref(1)->as<ASymbol*>(); const AType* implT = cenv.type(cenv.resolve(implSym)); copy.push_front(implSym); copyT = implT->list_ref(2)->as<const AType*>(); } else { // Call to a closure, prepend code to access implementation function - ADot* getFn = tup<ADot>(call->loc, cenv.penv.sym("."), + ACall* getFn = tup<ACall>(call->loc, cenv.penv.sym("."), copy.head->head(), new ALiteral<int32_t>(0, Cursor()), NULL); const AType* calleeT = cenv.type(copy.head->head()); @@ -189,10 +189,10 @@ lift_def(CEnv& cenv, Code& code, ACall* def) throw() c->name = sym->str(); assert(def->list_ref(1)->to<const ASymbol*>()); - List<ADef, AST> copy; + List<ACall, AST> copy; copy.push_back(def->head()); copy.push_back(resp_lift(cenv, code, def->list_ref(1))); - for (ADef::iterator t = def->iter_at(2); t != def->end(); ++t) + for (ATuple::iterator t = def->iter_at(2); t != def->end(); ++t) copy.push_back(resp_lift(cenv, code, *t)); cenv.setTypeSameAs(copy, def); @@ -207,11 +207,10 @@ lift_def(CEnv& cenv, Code& code, ACall* def) throw() return copy; } -template<typename T> static AST* lift_builtin_call(CEnv& cenv, Code& code, ACall* call) throw() { - List<T, AST> copy; + List<ACall, AST> copy; copy.push_back(call->head()); // Lift all arguments @@ -233,29 +232,27 @@ resp_lift(CEnv& cenv, Code& code, AST* ast) throw() if (fn) return lift_fn(cenv, code, fn); - APrimitive* const prim = ast->to<APrimitive*>(); - if (prim) - return lift_builtin_call<APrimitive>(cenv, code, prim); - ACall* const call = ast->to<ACall*>(); if (call) { const ASymbol* const sym = call->head()->to<const ASymbol*>(); const std::string form = sym ? sym->cppstr : ""; - if (form == "def") + if (is_primitive(cenv.penv, call)) + return lift_builtin_call(cenv, code, call); + else if (form == "def") return lift_def(cenv, code, call); else if (form == "if") - return lift_builtin_call<AIf>(cenv, code, call); + return lift_builtin_call(cenv, code, call); else if (form == "cons" || isupper(form[0])) - return lift_builtin_call<ACons>(cenv, code, call); + return lift_builtin_call(cenv, code, call); else if (form == ".") - return lift_builtin_call<ADot>(cenv, code, call); + return lift_builtin_call(cenv, code, call); else if (form == "quote") - return lift_builtin_call<AQuote>(cenv, code, call); + return lift_builtin_call(cenv, code, call); else if (form == "match" || form == "def-type") return call; // FIXME else return lift_call(cenv, code, call); } - + return ast; } |