From 7426c554dd639200a8541c66b376b9a7fab1ab07 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 15 Oct 2009 21:46:31 +0000 Subject: Type and const correct Subst::apply. git-svn-id: http://svn.drobilla.net/resp/tuplr@232 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/tuplr.hpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/tuplr.hpp') diff --git a/src/tuplr.hpp b/src/tuplr.hpp index 61e3f41..0390435 100644 --- a/src/tuplr.hpp +++ b/src/tuplr.hpp @@ -289,6 +289,7 @@ struct AType : public ATuple { AType(Cursor c, unsigned i) : ATuple(c), kind(VAR), id(i) {} AType(Cursor c) : ATuple(c), kind(EXPR), id(0) {} AType(Cursor c, AST* ast, va_list args) : ATuple(c, ast, args), kind(EXPR), id(0) {} + AType(const AType& copy) : ATuple(copy), kind(copy.kind), id(copy.id) {} CVal compile(CEnv& cenv) { return NULL; } const ATuple* prot() const { assert(kind == EXPR); return (*(begin() + 1))->to(); } ATuple* prot() { assert(kind == EXPR); return (*(begin() + 1))->to(); } @@ -332,24 +333,21 @@ struct Subst : public list< pair > { return j; return end(); } - AST* apply(AST* ast) const { - AType* in = ast->to(); - if (!in) return ast; + AType* apply(const AType* in) const { if (in->kind == AType::EXPR) { AType* out = tup(in->loc, NULL); - for (ATuple::iterator i = in->begin(); i != in->end(); ++i) - out->push_back(apply(*i)); + for (ATuple::const_iterator i = in->begin(); i != in->end(); ++i) + out->push_back(apply((*i)->as())); return out; } else { const_iterator i = find(in); if (i != end()) { - AST* out = i->second; - AType* outT = out->to(); - if (outT && outT->kind == AType::EXPR && !outT->concrete()) - out = apply(out); + AType* out = i->second->as(); + if (out->kind == AType::EXPR && !out->concrete()) + out = apply(out->as()); return out; } else { - return in; + return new AType(*in); } } } @@ -547,7 +545,9 @@ inline ostream& operator<<(ostream& out, const Constraints& c) { /// Type-Time Environment struct TEnv : public Env { - TEnv(PEnv& p) : penv(p), varID(1) {} + TEnv(PEnv& p) : penv(p), varID(1), Fn(new AType(penv.sym("Fn"))) { + Object::pool.addRoot(Fn); + } AType* fresh(const ASymbol* sym) { return def(sym, new AType(sym->loc, varID++)); } @@ -573,9 +573,11 @@ struct TEnv : public Env { typedef map Vars; - Vars vars; - PEnv& penv; - unsigned varID; + Vars vars; + PEnv& penv; + unsigned varID; + + AType* Fn; }; Subst unify(const Constraints& c); -- cgit v1.2.1