diff options
Diffstat (limited to 'tuplr.hpp')
-rw-r--r-- | tuplr.hpp | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -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(); } |