diff options
author | David Robillard <d@drobilla.net> | 2010-08-22 20:20:38 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-08-22 20:20:38 +0000 |
commit | 8338b52abc0e5a1c0893526bde2d347f1891773e (patch) | |
tree | ffea8eedbb766ff08dd6b30636b9060232d1ebb8 /src/compile.cpp | |
parent | b4dba561084b7ce60a8b1cfdb4e3b9de87de8d35 (diff) | |
download | resp-8338b52abc0e5a1c0893526bde2d347f1891773e.tar.gz resp-8338b52abc0e5a1c0893526bde2d347f1891773e.tar.bz2 resp-8338b52abc0e5a1c0893526bde2d347f1891773e.zip |
Simplify Engine function compilation interface.
Removes duplicated code in various backends and reduces Engine code
knowledge of AFn specifics (which belongs in compile.cpp).
git-svn-id: http://svn.drobilla.net/resp/resp@268 ad02d1e2-f140-0410-9f75-f8b11f17cedd
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; |