aboutsummaryrefslogtreecommitdiffstats
path: root/tuplr.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-03-05 22:27:44 +0000
committerDavid Robillard <d@drobilla.net>2009-03-05 22:27:44 +0000
commit832a7a2482c49478f684060583d23d2ef7355137 (patch)
treefe18a2b92e516112be94b02c5b442e5745ddc60e /tuplr.cpp
parentb6bc968944cde401be703371f75d3059cbccaae5 (diff)
downloadresp-832a7a2482c49478f684060583d23d2ef7355137.tar.gz
resp-832a7a2482c49478f684060583d23d2ef7355137.tar.bz2
resp-832a7a2482c49478f684060583d23d2ef7355137.zip
Shrink.
git-svn-id: http://svn.drobilla.net/resp/tuplr@50 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'tuplr.cpp')
-rw-r--r--tuplr.cpp30
1 files changed, 10 insertions, 20 deletions
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<string> argNames=vector<string>())
{
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<Value*> 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