diff options
Diffstat (limited to 'src/compile.cpp')
-rw-r--r-- | src/compile.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/compile.cpp b/src/compile.cpp index 65721fc..4d8e98d 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -133,6 +133,24 @@ compile_dot(CEnv& cenv, const ATuple* dot) throw() return cenv.engine()->compileDot(cenv, tupVal, index->val); } +static CVal +compile_if(CEnv& cenv, const ATuple* aif) throw() +{ + IfState state = cenv.engine()->compileIfStart(cenv); + for (ATuple::const_iterator i = aif->iter_at(1); ; ++i) { + ATuple::const_iterator next = i; + if (++next == aif->end()) + break; + + cenv.engine()->compileIfBranch(cenv, state, resp_compile(cenv, *i), *next); + + i = next; // jump 2 each iteration (to the next predicate) + } + + CVal elseV = resp_compile(cenv, aif->list_last()); + return cenv.engine()->compileIfEnd(cenv, state, elseV, cenv.type(aif)); +} + CVal resp_compile(CEnv& cenv, const AST* ast) throw() { @@ -161,7 +179,7 @@ resp_compile(CEnv& cenv, const AST* ast) throw() else if (form == "def") return compile_def(cenv, call); else if (form == "if") - return cenv.engine()->compileIf(cenv, call); + return compile_if(cenv, call); else if (form == "cons" || isupper(form[0])) return compile_cons(cenv, call); else if (form == ".") |