aboutsummaryrefslogtreecommitdiffstats
path: root/ll.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'll.cpp')
-rw-r--r--ll.cpp26
1 files changed, 9 insertions, 17 deletions
diff --git a/ll.cpp b/ll.cpp
index b8b7c01..8bd14ac 100644
--- a/ll.cpp
+++ b/ll.cpp
@@ -703,15 +703,9 @@ compileFunction(CEnv& cenv, const std::string& name, ASTTuple& prot, const Type*
Value*
ASTSymbol::compile(CEnv& cenv)
{
- Value** v = cenv.vals.ref(this);
- if (v) return *v;
-
AST** c = cenv.code.ref(this);
- if (c) {
- Value* v = cenv.compile(*c);
- cenv.vals.def(this, v);
- return v;
- }
+ if (c)
+ return cenv.vals.def(this, cenv.compile(*c));
throw SyntaxError((string("Undefined symbol '") + cppstr + "'").c_str());
}
@@ -719,11 +713,11 @@ ASTSymbol::compile(CEnv& cenv)
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;
+ if (cenv.tenv.type(tup[2])->var)
+ throw CompileError("Closure with untyped body lifted");
for (size_t i = 0; i < prot->tup.size(); ++i)
if (cenv.tenv.type(prot->tup[i])->var)
- return;
+ throw CompileError("Closure with untyped parameter lifted");
assert(!func);
cenv.push();
@@ -799,15 +793,13 @@ ASTCall::compile(CEnv& cenv)
c = (val) ? dynamic_cast<ASTClosure*>(*val) : c;
}
- if (!c) throw CompileError("Call to non-closure");
- Value* v = cenv.compile(c);
- if (!v) throw CompileError("Callee failed to compile");
+ assert(c);
Function* f = dynamic_cast<Function*>(cenv.compile(c));
- if (!f) throw CompileError("Callee compiled to non-function");
+ if (!f) throw CompileError("Callee failed to compile");
- vector<Value*> params;
+ vector<Value*> params(tup.size() - 1);
for (size_t i = 1; i < tup.size(); ++i)
- params.push_back(cenv.compile(tup[i]));
+ params[i-1] = cenv.compile(tup[i]);
return cenv.builder.CreateCall(f, params.begin(), params.end(), "calltmp");
}