aboutsummaryrefslogtreecommitdiffstats
path: root/src/compile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/compile.cpp')
-rw-r--r--src/compile.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/compile.cpp b/src/compile.cpp
index f954b8e..e2d306a 100644
--- a/src/compile.cpp
+++ b/src/compile.cpp
@@ -130,21 +130,33 @@ AIf::compile(CEnv& cenv) const throw()
CVal
ACons::compile(CEnv& cenv) const throw()
{
- const AType* type = cenv.type(this);
- vector<CVal> fields;
- for (const_iterator i = begin() + 1; i != end(); ++i)
- fields.push_back((*i)->compile(cenv));
- return cenv.engine()->compileTup(cenv, type, fields);
+ return ATuple::compile(cenv);
}
CVal
ATuple::compile(CEnv& cenv) const throw()
{
- const AType* type = cenv.type(this);
+ AType* type = tup<AType>(loc, const_cast<ASymbol*>(head()->as<const ASymbol*>()), 0);
vector<CVal> fields;
- for (const_iterator i = begin(); i != end(); ++i)
+ for (const_iterator i = begin() + 1; i != end(); ++i) {
+ type->push_back(const_cast<AType*>(cenv.type(*i)));
fields.push_back((*i)->compile(cenv));
- return cenv.engine()->compileTup(cenv, type, fields);
+ }
+ return cenv.engine()->compileTup(cenv, type, type->compile(cenv), fields);
+}
+
+CVal
+AType::compile(CEnv& cenv) const throw()
+{
+ const ASymbol* sym = head()->as<const ASymbol*>();
+ CVal* existing = cenv.vals.ref(sym);
+ if (existing) {
+ return *existing;
+ } else {
+ CVal compiled = cenv.engine()->compileString(cenv, (string("__T_") + head()->str()).c_str());
+ cenv.vals.def(sym, compiled);
+ return compiled;
+ }
}
CVal
@@ -162,3 +174,9 @@ APrimitive::compile(CEnv& cenv) const throw()
{
return cenv.engine()->compilePrimitive(cenv, this);
}
+
+CVal
+AMatch::compile(CEnv& cenv) const throw()
+{
+ return cenv.engine()->compileMatch(cenv, this);
+}