From 832a7a2482c49478f684060583d23d2ef7355137 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 5 Mar 2009 22:27:44 +0000 Subject: Shrink. git-svn-id: http://svn.drobilla.net/resp/tuplr@50 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- tuplr.cpp | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'tuplr.cpp') diff --git a/tuplr.cpp b/tuplr.cpp index 4403922..fc7b36c 100644 --- a/tuplr.cpp +++ b/tuplr.cpp @@ -770,7 +770,7 @@ LITERAL(float, "Float", ConstantFP::get(Type::FloatTy, val)) LITERAL(bool, "Bool", ConstantInt::get(Type::Int1Ty, val, false)) static Function* -compileFunction(CEnv& cenv, const std::string& name, const Type* retT, ASTTuple& prot, +compileFunction(CEnv& cenv, const std::string& name, const Type* retT, const ASTTuple& prot, const vector argNames=vector()) { Function::LinkageTypes linkage = Function::ExternalLinkage; @@ -799,6 +799,9 @@ compileFunction(CEnv& cenv, const std::string& name, const Type* retT, ASTTuple& else for (size_t i = 0; i != prot.size(); ++a, ++i) a->setName(prot.at(i)->str()); + + BasicBlock* bb = BasicBlock::Create("entry", f); + cenv.builder.SetInsertPoint(bb); return f; } @@ -828,8 +831,6 @@ ASTClosure::lift(CEnv& cenv) // Write function declaration string name = this->name == "" ? cenv.gensym("_fn") : this->name; Function* f = compileFunction(cenv, name, cenv.tenv.type(at(2))->type(), *prot()); - BasicBlock* bb = BasicBlock::Create("entry", f); - cenv.builder.SetInsertPoint(bb); // Bind argument values in CEnv vector args; @@ -1042,8 +1043,6 @@ ASTConsCall::lift(CEnv& cenv) argNames.push_back("car"); argNames.push_back("cdr"); Function* func = compileFunction(cenv, cenv.gensym("cons"), pT, *prot, argNames); - BasicBlock* bb = BasicBlock::Create("entry", func); - cenv.builder.SetInsertPoint(bb); Value* mem = cenv.builder.CreateCall(cenv.alloc, ConstantInt::get(Type::Int32Ty, sz), "mem"); Value* cell = cenv.builder.CreateBitCast(mem, pT, "cell"); @@ -1133,18 +1132,12 @@ eval(CEnv& cenv, ExecutionEngine* engine, const string& name, istream& is) } if (!resultType || resultType->var()) throw Error("body is undefined/untyped", cursor); + + const Type* ctype = resultType->type(); + if (!ctype) throw Error("body has no system type", cursor); // Create function for top-level of program - ASTTuple prot; - const Type* ctype = resultType->type(); - if (!ctype) { - err << "program body has non-compilable type" << endl; - return 2; - } - assert(ctype); - Function* f = compileFunction(cenv, cenv.gensym("input"), ctype, prot); - BasicBlock* bb = BasicBlock::Create("entry", f); - cenv.builder.SetInsertPoint(bb); + Function* f = compileFunction(cenv, cenv.gensym("input"), ctype, ASTTuple()); // Compile all expressions into it Value* val = NULL; @@ -1189,11 +1182,8 @@ repl(CEnv& cenv, ExecutionEngine* engine) body->lift(cenv); if (bodyT->type()) { - // Create anonymous function to insert code into. - ASTTuple* prot = new ASTTuple(); - Function* f = compileFunction(cenv, cenv.gensym("_repl"), bodyT->type(), *prot); - BasicBlock* bb = BasicBlock::Create("entry", f); - cenv.builder.SetInsertPoint(bb); + // Create anonymous function to insert code into + Function* f = compileFunction(cenv, cenv.gensym("_repl"), bodyT->type(), ASTTuple()); try { Value* retVal = cenv.compile(body); cenv.builder.CreateRet(retVal); // Finish function -- cgit v1.2.1