diff options
Diffstat (limited to 'src/compile.cpp')
-rw-r--r-- | src/compile.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/compile.cpp b/src/compile.cpp index a696836..2132c91 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -122,6 +122,28 @@ compile_if(CEnv& cenv, const ATuple* aif) throw() } static CVal +compile_let(CEnv& cenv, const ATuple* let) throw() +{ + const ATuple* vars = let->list_ref(1)->to_tuple(); + + cenv.push(); + + for (ATuple::const_iterator i = vars->begin(); i != vars->end();) { + const ASymbol* sym = (*i++)->to_symbol(); + const AST* val = (*i++); + cenv.def(sym, val, cenv.type(val), resp_compile(cenv, val)); + } + + CVal ret = NULL; + for (ATuple::const_iterator i = let->iter_at(2); i != let->end(); ++i) + ret = resp_compile(cenv, *i); + + cenv.pop(); + + return ret; +} + +static CVal compile_match(CEnv& cenv, const ATuple* match) throw() { IfState state = cenv.engine()->compileIfStart(cenv); @@ -208,6 +230,8 @@ resp_compile(CEnv& cenv, const AST* ast) throw() return compile_fn(cenv, call); else if (form == "if") return compile_if(cenv, call); + else if (form == "let") + return compile_let(cenv, call); else if (form == "match") return compile_match(cenv, call); else |