diff options
author | David Robillard <d@drobilla.net> | 2011-05-15 20:15:27 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-05-15 20:15:27 +0000 |
commit | 8cbb1c710d6c8877dfc2871dc3f068b52598a884 (patch) | |
tree | e1a7b157be12dbaafc8baee861407242595d0e4f /src/compile.cpp | |
parent | ec6bd7cded43bfd3ba1491c8ec08eb1975334e4e (diff) | |
download | resp-8cbb1c710d6c8877dfc2871dc3f068b52598a884.tar.gz resp-8cbb1c710d6c8877dfc2871dc3f068b52598a884.tar.bz2 resp-8cbb1c710d6c8877dfc2871dc3f068b52598a884.zip |
Generate code entirely via emitting flat IR (don't special case main/repl).
git-svn-id: http://svn.drobilla.net/resp/trunk@427 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/compile.cpp')
-rw-r--r-- | src/compile.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/compile.cpp b/src/compile.cpp index e8baed3..f84d789 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -33,7 +33,8 @@ compile_symbol(CEnv& cenv, const ASymbol* sym) throw() return NULL; if (cenv.repl && cenv.vals.topLevel(sym) && !is_form(cenv.type(sym), "Fn")) { - return cenv.engine()->compileGlobalGet(cenv, sym->sym(), *cenv.vals.ref(sym)); + CVal val = cenv.globals[sym->sym()]; + return cenv.engine()->compileGlobalGet(cenv, sym->sym(), val); } else { return *cenv.vals.ref(sym); } @@ -93,6 +94,7 @@ compile_def(CEnv& cenv, const ATuple* def) throw() if (cenv.repl && cenv.vals.topLevel(sym) && !is_form(cenv.type(sym), "Fn")) { CVal global = cenv.engine()->compileGlobalSet( cenv, sym->sym(), val, cenv.type(body)); + cenv.globals.insert(make_pair(sym->sym(), global)); cenv.def(sym, body, cenv.type(body), global); } else { cenv.def(sym, body, cenv.type(body), val); @@ -159,10 +161,7 @@ compile_fn_start(CEnv& cenv, const ATuple* call) throw() const ATuple* type = cenv.type(name)->as_tuple(); const ATuple* args = call->rst()->rst(); - CFunc func = cenv.engine()->startFn(cenv, name->sym(), args, type); - cenv.def(name, NULL, type, func); - - cenv.engine()->pushFnArgs(cenv, args, type, func); + cenv.engine()->startFn(cenv, name->sym(), args, type); return NULL; } @@ -170,8 +169,13 @@ compile_fn_start(CEnv& cenv, const ATuple* call) throw() static CVal compile_fn_end(CEnv& cenv, const ATuple* call) throw() { - const AST* retT = cenv.type(call->frst())->as_tuple()->frrst(); - cenv.engine()->finishFn(cenv, resp_compile(cenv, call->frrst()), retT); + const AST* ret = (call->list_len() > 2) ? call->frrst() : NULL; + const AST* retT = (ret) + ? cenv.type(call->frst())->as_tuple()->frrst() + : cenv.penv.sym("Nothing"); + + cenv.engine()->finishFn(cenv, resp_compile(cenv, ret), retT); + cenv.pop(); return NULL; } |