aboutsummaryrefslogtreecommitdiffstats
path: root/src/compile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/compile.cpp')
-rw-r--r--src/compile.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/compile.cpp b/src/compile.cpp
index 282a7f0..647c7d5 100644
--- a/src/compile.cpp
+++ b/src/compile.cpp
@@ -36,17 +36,16 @@ compile_symbol(CEnv& cenv, const ASymbol* sym) throw()
static CVal
compile_fn(CEnv& cenv, const ATuple* fn) throw()
{
+ assert(!cenv.currentFn);
+
const AType* type = cenv.type(fn);
CFunc f = cenv.findImpl(fn, type);
if (f)
return f;
-
- // Write function declaration
- f = cenv.engine()->startFunction(cenv, cenv.name(fn), fn->prot(), type);
- // Create a new environment frame and bind argument values
- cenv.engine()->pushFunctionArgs(cenv, fn, type, f);
- assert(!cenv.currentFn);
+ // Write function declaration and push stack frame
+ f = cenv.engine()->startFunction(cenv, cenv.name(fn), fn->prot(), type);
+ cenv.engine()->pushFunctionArgs(cenv, fn->prot(), type, f);
cenv.currentFn = f;
// Write function body
@@ -54,11 +53,9 @@ compile_fn(CEnv& cenv, const ATuple* fn) throw()
for (ATuple::const_iterator i = fn->iter_at(2); i != fn->end(); ++i)
retVal = resp_compile(cenv, *i);
- // Write function conclusion
+ // Write function conclusion and pop stack frame
cenv.engine()->finishFunction(cenv, f, retVal);
-
- // Pop environment frame
- cenv.pop();
+ cenv.pop();
cenv.currentFn = NULL;
cenv.vals.def(cenv.penv.sym(cenv.name(fn)), f);
@@ -84,7 +81,7 @@ compile_type(CEnv& cenv, const AType* type) throw()
static CVal
compile_call(CEnv& cenv, const ATuple* call) throw()
{
- CFunc f = resp_compile(cenv, *call->begin());
+ CFunc f = resp_compile(cenv, call->head());
if (!f)
f = cenv.currentFn; // Recursive call (callee defined as a stub)