aboutsummaryrefslogtreecommitdiffstats
path: root/src/simplify.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-12-15 07:06:22 +0000
committerDavid Robillard <d@drobilla.net>2012-12-15 07:06:22 +0000
commit10174ffc7ea08b7845dbe409a11811e820536468 (patch)
treec74187d11b7f35c739045e7000d2fa505ac9499a /src/simplify.cpp
parent8148e755d3f587e6c212ba90efc151ea07de2703 (diff)
downloadresp-10174ffc7ea08b7845dbe409a11811e820536468.tar.gz
resp-10174ffc7ea08b7845dbe409a11811e820536468.tar.bz2
resp-10174ffc7ea08b7845dbe409a11811e820536468.zip
Compile constructors as LLVM struct types.
Use LLVM type names instead of hyper verbose literal types in more places in general. More work on quoting. git-svn-id: http://svn.drobilla.net/resp/trunk@439 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/simplify.cpp')
-rw-r--r--src/simplify.cpp36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/simplify.cpp b/src/simplify.cpp
index 921c6e6..d8d23f2 100644
--- a/src/simplify.cpp
+++ b/src/simplify.cpp
@@ -173,6 +173,9 @@ simplify_let(CEnv& cenv, Code& code, const ATuple* call) throw()
}
static inline const AST*
+quote(CEnv& cenv, const AST* ast);
+
+static inline const AST*
simplify_list_elem(CEnv& cenv, const ATuple* node, const AST* type)
{
if (!node) {
@@ -187,30 +190,29 @@ 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.Tup, fst, rst, 0);
- cenv.setType(fst, tup(Cursor(), cenv.penv.sym("Expr"), 0));
+ List cons(node->loc, cenv.tenv.List, fst, rst, 0);
+ cenv.setType(fst, tup(Cursor(), cenv.tenv.Expr, 0));
cenv.setType(cons, type);
return cons;
}
+static inline const AST*
+quote(CEnv& cenv, const AST* ast)
+{
+ if (ast->tag() == T_TUPLE) {
+ const ATuple* const list = ast->as_tuple();
+ return simplify_list_elem(cenv, list, tup(Cursor(), cenv.tenv.Expr, 0));
+ } else {
+ const AST* cons = tup(Cursor(), cenv.type(ast), ast, 0);
+ cenv.setType(cons, tup(Cursor(), cenv.tenv.Expr, 0));
+ return cons;
+ }
+}
+
static const AST*
simplify_quote(CEnv& cenv, Code& code, const ATuple* call) throw()
{
- switch (call->frst()->tag()) {
- case T_SYMBOL:
- // Symbols remain quoted so they are not interpreted as variables
- return call;
- case T_TUPLE: {
- // Lists are transformed into nested conses
- const ATuple* const list = call->frst()->as_tuple();
- return simplify_list_elem(cenv, list,
- tup(Cursor(), cenv.tenv.Tup, cenv.penv.sym("Expr"), 0));
- }
- default:
- // Other literals (e.g. numbers, strings) are self-evaluating, so the
- // quote can be removed, e.g. (quote 3) => 3
- return call->frst();
- }
+ return quote(cenv, call->frst());
}
const AST*