aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ll.cpp104
1 files changed, 52 insertions, 52 deletions
diff --git a/ll.cpp b/ll.cpp
index 114bab8..b8b7c01 100644
--- a/ll.cpp
+++ b/ll.cpp
@@ -717,16 +717,50 @@ ASTSymbol::compile(CEnv& cenv)
}
void
-ASTDefinition::lift(CEnv& cenv)
+ASTClosure::lift(CEnv& cenv)
{
- cenv.code.def((ASTSymbol*)tup[1], tup[2]); // Define first for recursion
- tup[2]->lift(cenv);
+ // Can't lift a closure with variable types (lift later when called)
+ if (cenv.tenv.type(tup[2])->var) return;
+ for (size_t i = 0; i < prot->tup.size(); ++i)
+ if (cenv.tenv.type(prot->tup[i])->var)
+ return;
+
+ assert(!func);
+ cenv.push();
+
+ // Write function declaration
+ Function* f = compileFunction(cenv, cenv.gensym("_fn"), *prot, cenv.tenv.type(tup[2])->ctype);
+ BasicBlock* bb = BasicBlock::Create("entry", f);
+ cenv.builder.SetInsertPoint(bb);
+
+ // Bind argument values in CEnv
+ vector<Value*> args;
+ TupV::const_iterator p = prot->tup.begin();
+ for (Function::arg_iterator a = f->arg_begin(); a != f->arg_end(); ++a, ++p)
+ cenv.vals.def(dynamic_cast<ASTSymbol*>(*p), &*a);
+
+ // Write function body
+ try {
+ cenv.precompile(this, f); // Define our value first for recursion
+ Value* retVal = cenv.compile(tup[2]);
+ cenv.builder.CreateRet(retVal); // Finish function
+ verifyFunction(*f); // Validate generated code
+ cenv.fpm.run(*f); // Optimize function
+ func = f;
+ } catch (exception e) {
+ f->eraseFromParent(); // Error reading body, remove function
+ throw e;
+ }
+
+ assert(func);
+ cenv.pop();
}
Value*
-ASTDefinition::compile(CEnv& cenv)
+ASTClosure::compile(CEnv& cenv)
{
- return cenv.compile(tup[2]);
+ assert(func);
+ return func; // Function was already compiled in the lifting pass
}
void
@@ -778,6 +812,19 @@ ASTCall::compile(CEnv& cenv)
return cenv.builder.CreateCall(f, params.begin(), params.end(), "calltmp");
}
+void
+ASTDefinition::lift(CEnv& cenv)
+{
+ cenv.code.def((ASTSymbol*)tup[1], tup[2]); // Define first for recursion
+ tup[2]->lift(cenv);
+}
+
+Value*
+ASTDefinition::compile(CEnv& cenv)
+{
+ return cenv.compile(tup[2]);
+}
+
Value*
ASTIf::compile(CEnv& cenv)
{
@@ -815,53 +862,6 @@ ASTIf::compile(CEnv& cenv)
return pn;
}
-void
-ASTClosure::lift(CEnv& cenv)
-{
- // Can't lift a closure with variable types (lift later when called)
- if (cenv.tenv.type(tup[2])->var) return;
- for (size_t i = 0; i < prot->tup.size(); ++i)
- if (cenv.tenv.type(prot->tup[i])->var)
- return;
-
- assert(!func);
- cenv.push();
-
- // Write function declaration
- Function* f = compileFunction(cenv, cenv.gensym("_fn"), *prot, cenv.tenv.type(tup[2])->ctype);
- BasicBlock* bb = BasicBlock::Create("entry", f);
- cenv.builder.SetInsertPoint(bb);
-
- // Bind argument values in CEnv
- vector<Value*> args;
- TupV::const_iterator p = prot->tup.begin();
- for (Function::arg_iterator a = f->arg_begin(); a != f->arg_end(); ++a, ++p)
- cenv.vals.def(dynamic_cast<ASTSymbol*>(*p), &*a);
-
- // Write function body
- try {
- cenv.precompile(this, f); // Define our value first for recursion
- Value* retVal = cenv.compile(tup[2]);
- cenv.builder.CreateRet(retVal); // Finish function
- verifyFunction(*f); // Validate generated code
- cenv.fpm.run(*f); // Optimize function
- func = f;
- } catch (exception e) {
- f->eraseFromParent(); // Error reading body, remove function
- throw e;
- }
-
- assert(func);
- cenv.pop();
-}
-
-Value*
-ASTClosure::compile(CEnv& cenv)
-{
- assert(func);
- return func; // Function was already compiled in the lifting pass
-}
-
Value*
ASTPrimitive::compile(CEnv& cenv)
{