From 3bed7f70fb2793cf7ba82473526ac1ac97de1973 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 13 Oct 2009 20:54:01 +0000 Subject: liftCall -> compileFunction. git-svn-id: http://svn.drobilla.net/resp/tuplr@208 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/c.cpp | 14 ++++++++------ src/lift.cpp | 4 ++-- src/llvm.cpp | 14 ++++++++------ src/tuplr.hpp | 16 ++++++++-------- 4 files changed, 26 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/c.cpp b/src/c.cpp index ca35068..7f7337d 100644 --- a/src/c.cpp +++ b/src/c.cpp @@ -130,7 +130,7 @@ struct CEngine : public Engine { return varname; } - void liftCall(CEnv& cenv, AFn* fn, const AType& argsT); + CFunction compileFunction(CEnv& cenv, AFn* fn, const AType& argsT); CValue compileLiteral(CEnv& cenv, AST* lit); CValue compilePrimitive(CEnv& cenv, APrimitive* prim); @@ -164,8 +164,8 @@ CEngine::compileLiteral(CEnv& cenv, AST* lit) return new Value(lit->str()); } -void -CEngine::liftCall(CEnv& cenv, AFn* fn, const AType& argsT) +CFunction +CEngine::compileFunction(CEnv& cenv, AFn* fn, const AType& argsT) { TEnv::GenericTypes::const_iterator gt = cenv.tenv.genericTypes.find(fn); assert(gt != cenv.tenv.genericTypes.end()); @@ -184,8 +184,9 @@ CEngine::liftCall(CEnv& cenv, AFn* fn, const AType& argsT) string("call has non-concrete type %1%\n") + thisType->str()); Object::pool.addRoot(thisType); - if (fn->impls.find(thisType)) - return; + CFunction f = fn->impls.find(thisType); + if (f) + return f; ATuple* protT = thisType->at(1)->as(); @@ -195,7 +196,7 @@ CEngine::liftCall(CEnv& cenv, AFn* fn, const AType& argsT) // Write function declaration const string name = (fn->name == "") ? cenv.penv.gensymstr("_fn") : fn->name; - Function* f = llFunc(cenv.engine()->startFunction(cenv, name, + f = llFunc(cenv.engine()->startFunction(cenv, name, thisType->at(thisType->size()-1)->to(), *protT, argNames)); @@ -229,6 +230,7 @@ CEngine::liftCall(CEnv& cenv, AFn* fn, const AType& argsT) } cenv.tsubst = oldSubst; cenv.pop(); + return f; } CValue diff --git a/src/lift.cpp b/src/lift.cpp index d97e541..83c0491 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -41,7 +41,7 @@ AFn::lift(CEnv& cenv) return; AType* protT = type->at(1)->as(); - cenv.engine()->liftCall(cenv, this, *protT); + cenv.engine()->compileFunction(cenv, this, *protT); } void @@ -63,7 +63,7 @@ ACall::lift(CEnv& cenv) if (c->prot()->size() > size() - 1) throw Error(loc, (format("too few arguments to function `%1%'") % at(0)->str()).str()); - cenv.engine()->liftCall(cenv, c, argsT); // Lift called closure + cenv.engine()->compileFunction(cenv, c, argsT); // Lift called closure } void diff --git a/src/llvm.cpp b/src/llvm.cpp index 9e519a7..c798d24 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -154,7 +154,7 @@ struct LLVMEngine : public Engine { return builder.CreateCall(llFunc(f), llArgs.begin(), llArgs.end()); } - void liftCall(CEnv& cenv, AFn* fn, const AType& argsT); + CFunction compileFunction(CEnv& cenv, AFn* fn, const AType& argsT); CValue compileLiteral(CEnv& cenv, AST* lit); CValue compilePrimitive(CEnv& cenv, APrimitive* prim); @@ -219,8 +219,8 @@ LLVMEngine::compileLiteral(CEnv& cenv, AST* lit) throw Error(lit->loc, "Unknown literal type"); } -void -LLVMEngine::liftCall(CEnv& cenv, AFn* fn, const AType& argsT) +CFunction +LLVMEngine::compileFunction(CEnv& cenv, AFn* fn, const AType& argsT) { TEnv::GenericTypes::const_iterator gt = cenv.tenv.genericTypes.find(fn); assert(gt != cenv.tenv.genericTypes.end()); @@ -239,8 +239,9 @@ LLVMEngine::liftCall(CEnv& cenv, AFn* fn, const AType& argsT) string("call has non-concrete type %1%\n") + thisType->str()); Object::pool.addRoot(thisType); - if (fn->impls.find(thisType)) - return; + Function* f = (Function*)fn->impls.find(thisType); + if (f) + return f; ATuple* protT = thisType->at(1)->as(); @@ -250,7 +251,7 @@ LLVMEngine::liftCall(CEnv& cenv, AFn* fn, const AType& argsT) // Write function declaration const string name = (fn->name == "") ? cenv.penv.gensymstr("_fn") : fn->name; - Function* f = llFunc(cenv.engine()->startFunction(cenv, name, + f = llFunc(cenv.engine()->startFunction(cenv, name, thisType->at(thisType->size()-1)->to(), *protT, argNames)); @@ -327,6 +328,7 @@ LLVMEngine::liftCall(CEnv& cenv, AFn* fn, const AType& argsT) } cenv.tsubst = oldSubst; cenv.pop(); + return f; } CValue diff --git a/src/tuplr.hpp b/src/tuplr.hpp index a76f039..2814578 100644 --- a/src/tuplr.hpp +++ b/src/tuplr.hpp @@ -627,14 +627,14 @@ struct Engine { const ATuple& argsT, const vector argNames=vector()) = 0; - virtual void finishFunction(CEnv& cenv, CFunction f, const AType* retT, CValue ret) = 0; - virtual void eraseFunction(CEnv& cenv, CFunction f) = 0; - virtual void liftCall(CEnv& cenv, AFn* fn, const AType& argsT) = 0; - virtual CValue compileLiteral(CEnv& cenv, AST* lit) = 0; - virtual CValue compileCall(CEnv& cenv, CFunction f, const vector& args) = 0; - virtual CValue compilePrimitive(CEnv& cenv, APrimitive* prim) = 0; - virtual CValue compileIf(CEnv& cenv, AIf* aif) = 0; - virtual void writeModule(CEnv& cenv, std::ostream& os) = 0; + virtual void finishFunction(CEnv& cenv, CFunction f, const AType* retT, CValue ret) = 0; + virtual void eraseFunction(CEnv& cenv, CFunction f) = 0; + virtual CFunction compileFunction(CEnv& cenv, AFn* fn, const AType& argsT) = 0; + virtual CValue compileLiteral(CEnv& cenv, AST* lit) = 0; + virtual CValue compileCall(CEnv& cenv, CFunction f, const vector& args) = 0; + virtual CValue compilePrimitive(CEnv& cenv, APrimitive* prim) = 0; + virtual CValue compileIf(CEnv& cenv, AIf* aif) = 0; + virtual void writeModule(CEnv& cenv, std::ostream& os) = 0; virtual const string call(CEnv& cenv, CFunction f, AType* retT) = 0; }; -- cgit v1.2.1