diff options
author | David Robillard <d@drobilla.net> | 2010-04-13 02:28:56 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-04-13 02:28:56 +0000 |
commit | 8675beae4f7a8415fc2e88451da95dc068719194 (patch) | |
tree | 599de9b6730a14035a25f7d9e0467f96866185ed /src/compile.cpp | |
parent | 1f988f420ba3827941886962680f3e2ad6f01740 (diff) | |
download | resp-8675beae4f7a8415fc2e88451da95dc068719194.tar.gz resp-8675beae4f7a8415fc2e88451da95dc068719194.tar.bz2 resp-8675beae4f7a8415fc2e88451da95dc068719194.zip |
Restructure as a source translation based compiler.
Implement support for closures (via lambda lifting phase).
git-svn-id: http://svn.drobilla.net/resp/resp@254 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/compile.cpp')
-rw-r--r-- | src/compile.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/compile.cpp b/src/compile.cpp index 4f24994..ee92dbd 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -43,33 +43,29 @@ ASymbol::compile(CEnv& cenv) throw() CVal AFn::compile(CEnv& cenv) throw() { - return impls.find(cenv.type(this)); + const AType* type = cenv.type(this); + CFunc f = cenv.findImpl(this, type); + if (!f) { + f = cenv.engine()->compileFunction(cenv, this, type); + cenv.vals.def(cenv.penv.sym(name), f); + cenv.addImpl(this, f); + } + return f; } CVal ACall::compile(CEnv& cenv) throw() { - AFn* c = cenv.resolve(head())->to<AFn*>(); - - if (!c) return NULL; // Primitive - - AType protT(loc); - for (const_iterator i = begin() + 1; i != end(); ++i) - protT.push_back(cenv.type(*i)); - - AType fnT(loc); - fnT.push_back(cenv.tenv.Fn); - fnT.push_back(&protT); - fnT.push_back(cenv.type(this)); + CFunc f = (*begin())->compile(cenv); - CFunc f = c->impls.find(&fnT); - THROW_IF(!f, loc, (format("callee failed to compile for type %1%") % fnT.str()).str()); + if (!f) + f = cenv.currentFn; // Recursive call (callee defined as a stub) vector<CVal> args; for (const_iterator e = begin() + 1; e != end(); ++e) args.push_back((*e)->compile(cenv)); - return cenv.engine()->compileCall(cenv, f, args); + return cenv.engine()->compileCall(cenv, f, cenv.type(head()), args); } CVal @@ -83,7 +79,7 @@ ADef::compile(CEnv& cenv) throw() cenv.lock(this); } cenv.vals.def(sym(), val); - return val; + return NULL; } CVal |