aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-03-05 07:22:32 +0000
committerDavid Robillard <d@drobilla.net>2009-03-05 07:22:32 +0000
commit3877bf43aa958817812759d8973ccc4a8523a88a (patch)
tree9b3a42ea60639411f8564294bf17eabc344be064
parent54bb98ea98aea60ef951ab73987128a78f5cd9aa (diff)
downloadresp-3877bf43aa958817812759d8973ccc4a8523a88a.tar.gz
resp-3877bf43aa958817812759d8973ccc4a8523a88a.tar.bz2
resp-3877bf43aa958817812759d8973ccc4a8523a88a.zip
Don't lift variable typed closures (but don't die).
Add some test programs. git-svn-id: http://svn.drobilla.net/resp/tuplr@42 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r--ack.tpr7
-rw-r--r--fac.tpr5
-rw-r--r--list.tpr3
-rw-r--r--tuplr.cpp14
4 files changed, 21 insertions, 8 deletions
diff --git a/ack.tpr b/ack.tpr
new file mode 100644
index 0000000..c5796bb
--- /dev/null
+++ b/ack.tpr
@@ -0,0 +1,7 @@
+(def ack (fn (m n)
+ (if (= 0 m) (+ n 1)
+ (= 0 n) (ack (- m 1) 1)
+ (ack (- m 1) (ack m (- n 1))))))
+
+(ack 3 10)
+
diff --git a/fac.tpr b/fac.tpr
new file mode 100644
index 0000000..a696ff7
--- /dev/null
+++ b/fac.tpr
@@ -0,0 +1,5 @@
+(def fac (fn (n)
+ (if (= 0 n) 1
+ (* n (fac (- n 1))))))
+
+(fac 5)
diff --git a/list.tpr b/list.tpr
new file mode 100644
index 0000000..947fe97
--- /dev/null
+++ b/list.tpr
@@ -0,0 +1,3 @@
+(def l (cons 1 (cons 2 (cons 3 4))))
+
+(car (cdr (cdr l)))
diff --git a/tuplr.cpp b/tuplr.cpp
index 31a83e5..6bea056 100644
--- a/tuplr.cpp
+++ b/tuplr.cpp
@@ -811,12 +811,10 @@ ASTSymbol::compile(CEnv& cenv)
void
ASTClosure::lift(CEnv& cenv)
{
- if (cenv.tenv.type(at(2))->var)
- throw Error("Closure with untyped body lifted");
- for (size_t i = 0; i < prot->size(); ++i)
- if (cenv.tenv.type(prot->at(i))->var)
- throw Error("Closure with untyped parameter lifted");
-
+ if (cenv.tenv.type(at(2))->var || !cenv.tenv.type(prot)->concrete()) {
+ std::cerr << "Closure has variable type, not lifting" << endl;
+ return;
+ }
assert(!func);
cenv.push();
@@ -851,8 +849,7 @@ ASTClosure::lift(CEnv& cenv)
Value*
ASTClosure::compile(CEnv& cenv)
{
- assert(func);
- return func; // Function was already compiled in the lifting pass
+ return func;
}
void
@@ -1139,6 +1136,7 @@ eval(CEnv& cenv, ExecutionEngine* engine, const string& name, istream& is)
// Create function for top-level of program
ASTTuple prot;
const Type* ctype = resultType->type();
+ assert(ctype);
Function* f = compileFunction(cenv, cenv.gensym("input"), ctype, prot);
BasicBlock* bb = BasicBlock::Create("entry", f);
cenv.builder.SetInsertPoint(bb);