aboutsummaryrefslogtreecommitdiffstats
path: root/src/simplify.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-12-14 05:29:49 +0000
committerDavid Robillard <d@drobilla.net>2012-12-14 05:29:49 +0000
commit32c1b78fc9bdadd1dd40ed390941b2a6fea39435 (patch)
treec02e3da8138d29ee060bd5bf584812bd9ad4ca5f /src/simplify.cpp
parent60cb2bb1a12a1393abdc0d82b40ea0feabe3a74d (diff)
downloadresp-32c1b78fc9bdadd1dd40ed390941b2a6fea39435.tar.gz
resp-32c1b78fc9bdadd1dd40ed390941b2a6fea39435.tar.bz2
resp-32c1b78fc9bdadd1dd40ed390941b2a6fea39435.zip
Real implementation of algebraic data types, and parametric types.
git-svn-id: http://svn.drobilla.net/resp/trunk@434 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/simplify.cpp')
-rw-r--r--src/simplify.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/simplify.cpp b/src/simplify.cpp
index 2085ad9..e081bf7 100644
--- a/src/simplify.cpp
+++ b/src/simplify.cpp
@@ -78,7 +78,8 @@ simplify_match(CEnv& cenv, const ATuple* match) throw()
const_cast<ASymbol*>(consTag)->tag(T_LITSYM);
cenv.setType(consTag, cenv.tenv.named("Symbol"));
- const ATuple* texp = cenv.tenv.named(consTag->sym())->as_tuple();
+ const TEnv::Constructor& constructor = cenv.tenv.tags.find(consTag->str())->second;
+ const ATuple* texp = constructor.expr->as_tuple();
// Append condition for this case
List cond(Cursor(), cenv.penv.sym("="), tsym, consTag, 0);
@@ -87,7 +88,7 @@ simplify_match(CEnv& cenv, const ATuple* match) throw()
// If constructor has no variables, append body and continue
// (don't generate pointless fn)
- if (texp->list_len() == 2) {
+ if (texp->list_len() == 1) {
copyIf.push_back(body);
continue;
}
@@ -95,11 +96,11 @@ simplify_match(CEnv& cenv, const ATuple* match) throw()
// Build fn for the body of this case
const ASymbol* osym = cenv.penv.gensym("__obj");
const ATuple* prot = new ATuple(osym, 0, Cursor());
- const ATuple* protT = new ATuple(texp->rst(), 0, Cursor());
+ const ATuple* protT = new ATuple(texp, 0, Cursor());
List fn(Cursor(), cenv.penv.sym("fn"), prot, 0);
int idx = 0;
- ATuple::const_iterator ti = texp->iter_at(2);
+ ATuple::const_iterator ti = texp->iter_at(1);
for (ATuple::const_iterator j = pat->iter_at(1); j != pat->end(); ++j, ++ti, ++idx) {
const AST* index = new ALiteral<int32_t>(T_INT32, idx, Cursor());
const AST* dot = tup(Cursor(), cenv.penv.sym("."), osym, index, 0);
@@ -186,7 +187,7 @@ simplify_list_elem(CEnv& cenv, const ATuple* node, const AST* type)
const AST* const rst = simplify_list_elem(cenv, node->rst(), type);
assert(node->fst());
assert(rst);
- List cons(node->loc, cenv.tenv.List, fst, rst, 0);
+ List cons(node->loc, cenv.tenv.Tup, fst, rst, 0);
cenv.setType(fst, tup(Cursor(), cenv.penv.sym("Expr"), 0));
cenv.setType(cons, type);
return cons;
@@ -203,7 +204,7 @@ simplify_quote(CEnv& cenv, const ATuple* call) throw()
// Lists are transformed into nested conses
const ATuple* const list = call->frst()->as_tuple();
return simplify_list_elem(cenv, list,
- tup(Cursor(), cenv.tenv.List, cenv.penv.sym("Expr"), 0));
+ tup(Cursor(), cenv.tenv.Tup, cenv.penv.sym("Expr"), 0));
}
default:
// Other literals (e.g. numbers, strings) are self-evaluating, so the