From 32c1b78fc9bdadd1dd40ed390941b2a6fea39435 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 14 Dec 2012 05:29:49 +0000 Subject: Real implementation of algebraic data types, and parametric types. git-svn-id: http://svn.drobilla.net/resp/trunk@434 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/simplify.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/simplify.cpp') 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(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(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 -- cgit v1.2.1