aboutsummaryrefslogtreecommitdiffstats
path: root/src/unify.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-02 06:16:29 +0000
committerDavid Robillard <d@drobilla.net>2010-12-02 06:16:29 +0000
commit563a807be78bfe12e5bfbb9ff0d6da44242696c4 (patch)
tree13cf7ce3b90d072d6e7106c7d2eb4da33209acb0 /src/unify.cpp
parent32ac40a9ef62d2109563e36fb7cd478426c3489f (diff)
downloadresp-563a807be78bfe12e5bfbb9ff0d6da44242696c4.tar.gz
resp-563a807be78bfe12e5bfbb9ff0d6da44242696c4.tar.bz2
resp-563a807be78bfe12e5bfbb9ff0d6da44242696c4.zip
Represent code as list structure (i.e. traditional LISP lists built from pairs), rather than tuple structure.
Remove unused/crufty depoly stage. Remove cps from AST interface (but keep cps.cpp code around for later). Improved command line interface for compilation stages (options -T -L -S). git-svn-id: http://svn.drobilla.net/resp/resp@277 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/unify.cpp')
-rw-r--r--src/unify.cpp46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/unify.cpp b/src/unify.cpp
index a4ea035..9165d49 100644
--- a/src/unify.cpp
+++ b/src/unify.cpp
@@ -31,19 +31,19 @@ TEnv::buildSubst(const AType* genericT, const AType& argsT)
Subst subst;
// Build substitution to apply to generic type
- const ATuple* genericProtT = (*(genericT->begin() + 1))->as<const ATuple*>();
+ const ATuple* genericProtT = genericT->list_ref(1)->as<const ATuple*>();
ATuple::const_iterator g = genericProtT->begin();
AType::const_iterator a = argsT.begin();
for (; a != argsT.end(); ++a, ++g) {
const AType* genericArgT = (*g)->to<const AType*>();
- AType* callArgT = (*a)->to<AType*>();
+ const AType* callArgT = (*a)->to<const AType*>();
if (callArgT->kind == AType::EXPR) {
assert(genericArgT->kind == AType::EXPR);
ATuple::const_iterator gi = genericArgT->begin();
ATuple::const_iterator ci = callArgT->begin();
for (; gi != genericArgT->end(); ++gi, ++ci) {
const AType* gT = (*gi)->to<const AType*>();
- AType* aT = (*ci)->to<AType*>();
+ const AType* aT = (*ci)->to<const AType*>();
if (gT && aT)
subst.add(gT, aT);
}
@@ -64,29 +64,27 @@ Constraints::constrain(TEnv& tenv, const AST* o, const AType* t)
push_back(Constraint(tenv.var(o), t));
}
-template<typename T, typename E>
-static const T*
-substitute(const T* tup, const E* from, const E* to)
+static const AType*
+substitute(const AType* tup, const AType* from, const AType* to)
{
if (!tup) return NULL;
- T* ret = new T(*tup);
- typename T::iterator ri = ret->begin();
- FOREACHP(typename T::const_iterator, i, tup) {
+ TList ret;
+ FOREACHP(AType::const_iterator, i, tup) {
if (**i == *from) {
- T* type = new T(*to);
+ AType* type = new AType(*to);
type->loc = (*i)->loc;
- *ri++ = type;
- } else if (static_cast<const E*>(*i) != static_cast<const E*>(to)) {
- const T* subTup = dynamic_cast<const T*>(*i);
- if (subTup)
- *ri++ = const_cast<E*>(substitute(subTup, from, to));
+ ret.push_back(type);
+ } else if (*i != to) {
+ const AType* elem = (*i)->as<const AType*>();
+ if (elem->kind == AType::EXPR)
+ ret.push_back(const_cast<AType*>(substitute(elem, from, to)));
else
- *ri++ = *i;
+ ret.push_back(const_cast<AType*>(elem));
} else {
- ++ri;
+ ret.push_back(const_cast<AType*>((*i)->as<const AType*>()));
}
}
- return ret;
+ return ret.head;
}
/// Compose two substitutions (TAPL 22.1.1)
@@ -114,14 +112,14 @@ Constraints::replace(const AType* s, const AType* t)
AType* type = new AType(*t);
type->loc = c->first->loc;
c->first = type;
- } else {
+ } else if (c->first->kind == AType::EXPR) {
c->first = substitute(c->first, s, t);
}
if (*c->second == *s) {
AType* type = new AType(*t);
type->loc = c->second->loc;
c->second = type;
- } else {
+ } else if (c->second->kind == AType::EXPR) {
c->second = substitute(c->second, s, t);
}
}
@@ -150,15 +148,15 @@ unify(const Constraints& constraints)
AType::const_iterator si = s->begin();
AType::const_iterator ti = t->begin();
for (; si != s->end() && ti != t->end(); ++si, ++ti) {
- AType* st = (*si)->as<AType*>();
- AType* tt = (*ti)->as<AType*>();
+ const AType* st = (*si)->as<const AType*>();
+ const AType* tt = (*ti)->as<const AType*>();
if (st->kind == AType::DOTS || tt->kind == AType::DOTS)
return unify(cp);
else
cp.push_back(Constraint(st, tt));
}
- if ( (si == s->end() && (ti == t->end() || (*ti)->as<AType*>()->kind == AType::DOTS))
- || (ti == t->end() && (*si)->as<AType*>()->kind == AType::DOTS))
+ if ( (si == s->end() && (ti == t->end() || (*ti)->as<const AType*>()->kind == AType::DOTS))
+ || (ti == t->end() && (*si)->as<const AType*>()->kind == AType::DOTS))
return unify(cp);
}
throw Error(s->loc,