diff options
author | David Robillard <d@drobilla.net> | 2010-12-09 17:58:43 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-09 17:58:43 +0000 |
commit | acf13b1df559c6187d270ef7e31890201c191b12 (patch) | |
tree | 4a3d07f257efac1cd5ef51b21af2e55d4fd798b5 /src/compile.cpp | |
parent | d92de14f7d8354004edb14ed5658d5f434ce1e31 (diff) | |
download | resp-acf13b1df559c6187d270ef7e31890201c191b12.tar.gz resp-acf13b1df559c6187d270ef7e31890201c191b12.tar.bz2 resp-acf13b1df559c6187d270ef7e31890201c191b12.zip |
Add let form.
git-svn-id: http://svn.drobilla.net/resp/resp@328 ad02d1e2-f140-0410-9f75-f8b11f17cedd
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 |