aboutsummaryrefslogtreecommitdiffstats
path: root/src/compile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/compile.cpp')
-rw-r--r--src/compile.cpp30
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