aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-05-14 06:51:51 +0000
committerDavid Robillard <d@drobilla.net>2011-05-14 06:51:51 +0000
commit6cbeccf2ca0df91e5b71ccdbfcf412535f0c1179 (patch)
tree2df6d87917144977b63b5a7d1762b724b1832bab
parentb4745f2217a735b3b5ea2a163f79a90f1457a59f (diff)
downloadresp-6cbeccf2ca0df91e5b71ccdbfcf412535f0c1179.tar.gz
resp-6cbeccf2ca0df91e5b71ccdbfcf412535f0c1179.tar.bz2
resp-6cbeccf2ca0df91e5b71ccdbfcf412535f0c1179.zip
Use recursive types in IR rather than fugly __REC kludge.
git-svn-id: http://svn.drobilla.net/resp/trunk@420 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r--src/lift.cpp13
-rw-r--r--src/llvm.cpp10
2 files changed, 9 insertions, 14 deletions
diff --git a/src/lift.cpp b/src/lift.cpp
index 2d26ace..518fc4f 100644
--- a/src/lift.cpp
+++ b/src/lift.cpp
@@ -99,17 +99,6 @@ lift_def(CEnv& cenv, Code& code, const ATuple* def) throw()
}
static const AST*
-lift_def_type(CEnv& cenv, Code& code, const ATuple* def) throw()
-{
- const ASymbol* sym = def->frst()->to_symbol();
- if (!sym)
- return def;
-
- const AST* type = def->frrst()->as_tuple()->replace(sym, cenv.penv.sym("__REC"));
- return tup(def->loc, def->fst(), sym, type, 0);
-}
-
-static const AST*
lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw()
{
List impl;
@@ -289,7 +278,7 @@ resp_lift(CEnv& cenv, Code& code, const AST* ast) throw()
else if (form == "def")
return lift_def(cenv, code, call);
else if (form == "def-type")
- return lift_def_type(cenv, code, call);
+ return call;
else if (form == "do")
return lift_args(cenv, code, call);
else if (form == "fn")
diff --git a/src/llvm.cpp b/src/llvm.cpp
index 68a2a83..a0b635b 100644
--- a/src/llvm.cpp
+++ b/src/llvm.cpp
@@ -121,6 +121,7 @@ private:
CType objectT;
PATypeHolder* opaqueT;
+ std::string opaqueName;
typedef std::map<const std::string, const Type*> CTypes;
CTypes compiledTypes;
@@ -186,7 +187,10 @@ LLVMEngine::llType(const AST* t, const char* name)
if (sym == "String") return PointerType::get(Type::getInt8Ty(context), 0);
if (sym == "Symbol") return PointerType::get(Type::getInt8Ty(context), 0);
if (sym == "Expr") return PointerType::get(Type::getInt8Ty(context), 0);
- if (sym == "__REC") { if (!opaqueT) throw; return *opaqueT;}
+ if (sym == opaqueName) {
+ THROW_IF(!opaqueT, t->loc, "Broken recursive type");
+ return *opaqueT;
+ }
CTypes::const_iterator i = compiledTypes.find(sym);
if (i != compiledTypes.end())
@@ -199,7 +203,8 @@ LLVMEngine::llType(const AST* t, const char* name)
// Define opaque type to stand for name in recursive type body
if (name) {
THROW_IF(opaqueT, t->loc, "Nested recursive types");
- opaqueT = new PATypeHolder(OpaqueType::get(context));
+ opaqueT = new PATypeHolder(OpaqueType::get(context));
+ opaqueName = name;
}
const Type* ret;
@@ -247,6 +252,7 @@ LLVMEngine::llType(const AST* t, const char* name)
((OpaqueType*)opaqueT->get())->refineAbstractTypeTo(ptrT);
ptrT = cast<PointerType>(opaqueT->get()); // update potentially invalidated type
opaqueT = NULL;
+ opaqueName = "";
module->addTypeName(name, retT.get());
}