From 454e8908d51d2bb8c83af69f69b2c72e9606967d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 15 Mar 2009 17:52:16 +0000 Subject: Fix functions with several expressions in their body. git-svn-id: http://svn.drobilla.net/resp/tuplr@108 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- llvm.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/llvm.cpp b/llvm.cpp index ef52b88..7786bf5 100644 --- a/llvm.cpp +++ b/llvm.cpp @@ -255,8 +255,9 @@ AClosure::liftCall(CEnv& cenv, const vector& argsT) // Define value first for recursion cenv.precompile(this, f); funcs.push_back(make_pair(thisType, f)); - - CValue retVal = cenv.compile(at(2)); + CValue retVal = NULL; + for (size_t i = 2; i < size(); ++i) + retVal = cenv.compile(at(i)); llengine(cenv)->builder.CreateRet(LLVal(retVal)); // Finish function cenv.optimise(LLFunc(f)); } catch (Error& e) { @@ -310,7 +311,7 @@ ACall::compile(CEnv& cenv) TEnv::GenericTypes::const_iterator gt = cenv.tenv.genericTypes.find(c); assert(gt != cenv.tenv.genericTypes.end()); const AType* polyT = gt->second; - AType* fnT = new AType(loc, cenv.penv.sym("Fn"), protT, polyT->at(2), 0); + AType* fnT = new AType(loc, cenv.penv.sym("Fn"), protT, polyT->at(polyT->size()-1), 0); Function* f = (Function*)c->funcs.find(fnT); if (!f) throw Error("callee failed to compile", loc); @@ -326,10 +327,10 @@ void ADefinition::lift(CEnv& cenv) { // Define stub first for recursion - cenv.def(at(1)->as(), at(2), cenv.type(at(2)), NULL); + cenv.def(sym(), at(2), cenv.type(at(2)), NULL); AClosure* c = at(2)->to(); if (c) - c->name = at(1)->str(); + c->name = sym()->str(); at(2)->lift(cenv); } @@ -337,9 +338,9 @@ CValue ADefinition::compile(CEnv& cenv) { // Define stub first for recursion - cenv.def(at(1)->as(), at(2), cenv.type(at(2)), NULL); - CValue val = cenv.compile(at(2)); - cenv.vals.def(at(1)->as(), val); + cenv.def(sym(), at(2), cenv.type(at(2)), NULL); + CValue val = cenv.compile(at(size() - 1)); + cenv.vals.def(sym(), val); return val; } -- cgit v1.2.1