aboutsummaryrefslogtreecommitdiffstats
path: root/tuplr.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-06-28 03:06:22 +0000
committerDavid Robillard <d@drobilla.net>2009-06-28 03:06:22 +0000
commit87778a3526c38e0570a9462bf28ae87d38cf8ad1 (patch)
treeba8b3b95d398b889e6009c6cfa84e9990e7bc726 /tuplr.hpp
parent7ee03dcd4fa9bdbd94678f044133ba852c152532 (diff)
downloadresp-87778a3526c38e0570a9462bf28ae87d38cf8ad1.tar.gz
resp-87778a3526c38e0570a9462bf28ae87d38cf8ad1.tar.bz2
resp-87778a3526c38e0570a9462bf28ae87d38cf8ad1.zip
Fix type substitution.
git-svn-id: http://svn.drobilla.net/resp/tuplr@158 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'tuplr.hpp')
-rw-r--r--tuplr.hpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/tuplr.hpp b/tuplr.hpp
index 382b9d4..5275dfd 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -307,9 +307,6 @@ struct AType : public ATuple {
}
return true;
}
- bool operator<(const AType& rhs) const {
- return kind < rhs.kind || id < rhs.id;
- }
bool operator==(const AST& rhs) const {
const AType* rt = rhs.to<const AType*>();
if (!rt || kind != rt->kind)
@@ -326,14 +323,17 @@ struct AType : public ATuple {
unsigned id;
};
-struct typeLessThan {
- inline bool operator()(const AType* a, const AType* b) const { return *a < *b; }
-};
-
/// Type substitution
-struct Subst : public map<const AType*,AType*,typeLessThan> {
- Subst(AType* s=0, AType* t=0) { if (s && t) { assert(s != t); insert(make_pair(s, t)); } }
+struct Subst : public list< pair<const AType*,AType*> > {
+ Subst(AType* s=0, AType* t=0) { if (s && t) { assert(s != t); push_back(make_pair(s, t)); } }
static Subst compose(const Subst& delta, const Subst& gamma);
+ void add(const AType* from, AType* to) { push_back(make_pair(from, to)); }
+ const_iterator find(const AType* t) const {
+ for (const_iterator j = begin(); j != end(); ++j)
+ if (*j->first == *t)
+ return j;
+ return end();
+ }
AST* apply(AST* ast) const {
AType* in = ast->to<AType*>();
if (!in) return ast;
@@ -357,6 +357,12 @@ struct Subst : public map<const AType*,AType*,typeLessThan> {
}
};
+inline ostream& operator<<(ostream& out, const Subst& s) {
+ for (Subst::const_iterator i = s.begin(); i != s.end(); ++i)
+ out << i->first << " => " << i->second << endl;
+ return out;
+}
+
/// Fn (first-class function with captured lexical bindings)
struct AFn : public ATuple {
AFn(Cursor c, AST* ast, va_list args) : ATuple(c, ast, args) {}
@@ -598,8 +604,7 @@ struct CEnv {
~CEnv() { Object::pool.collect(GC::Roots()); }
- typedef Env<const ASymbol*, AST*> Code;
- typedef Env<const AST*, CValue> Vals;
+ typedef Env<const AST*, CValue> Vals;
Engine* engine() { return _engine; }
void push() { tenv.push(); vals.push(); }