diff options
Diffstat (limited to 'src/compile.cpp')
-rw-r--r-- | src/compile.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/compile.cpp b/src/compile.cpp index 66c3abe..f954b8e 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -67,7 +67,26 @@ AFn::compile(CEnv& cenv) const throw() if (f) return f; - f = cenv.engine()->compileFunction(cenv, this, type); + // Write function declaration + f = cenv.engine()->startFunction(cenv, name, prot(), type); + + // Create a new environment frame and bind argument values + cenv.engine()->pushFunctionArgs(cenv, this, type, f); + assert(!cenv.currentFn); + cenv.currentFn = f; + + // Write function body + CVal retVal = NULL; + for (AFn::const_iterator i = begin() + 2; i != end(); ++i) + retVal = (*i)->compile(cenv); + + // Write function conclusion + cenv.engine()->finishFunction(cenv, f, retVal); + + // Pop environment frame + cenv.pop(); + cenv.currentFn = NULL; + cenv.vals.def(cenv.penv.sym(name), f); cenv.addImpl(this, f); return f; |