diff options
Diffstat (limited to 'src/simplify.cpp')
-rw-r--r-- | src/simplify.cpp | 36 |
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* |