diff options
-rw-r--r-- | llvm.cpp | 7 | ||||
-rw-r--r-- | tuplr.hpp | 18 | ||||
-rw-r--r-- | typing.cpp | 24 |
3 files changed, 23 insertions, 26 deletions
@@ -73,9 +73,8 @@ CEngine::CEngine() { } -struct CEnvPimpl { - CEnvPimpl(CEngine& engine) - : module(engine.module), emp(module), opt(&emp) +struct CEnv::PImpl { + PImpl(CEngine& engine) : module(engine.module), emp(module), opt(&emp) { // Set up the optimizer pipeline: const TargetData* target = engine.engine->getTargetData(); @@ -93,7 +92,7 @@ struct CEnvPimpl { }; CEnv::CEnv(PEnv& p, TEnv& t, CEngine& e, ostream& os, ostream& es) - : engine(e), penv(p), tenv(t), symID(0), alloc(0), log(os, es), _pimpl(new CEnvPimpl(e)) + : engine(e), penv(p), tenv(t), symID(0), alloc(0), log(os, es), _pimpl(new PImpl(e)) { } @@ -406,10 +406,6 @@ struct Env : public list< map<K,V> > { * Typing (Prefix T for Type) * ***************************************************************************/ -struct TSubst : public map<AType*, AType*> { - TSubst(AType* s=0, AType* t=0) { if (s && t) insert(make_pair(s, t)); } -}; - /// Type-Time Environment struct TEnv : public Env<const AST*,AType*> { TEnv(PEnv& p) : penv(p), varID(1) {} @@ -417,6 +413,9 @@ struct TEnv : public Env<const AST*,AType*> { Constraint(AType* a, AType* b, Cursor c) : pair<AType*,AType*>(a, b), loc(c) {} Cursor loc; }; + struct Subst : public map<AType*, AType*> { + Subst(AType* s=0, AType* t=0) { if (s && t) insert(make_pair(s, t)); } + }; typedef list<Constraint> Constraints; AType* var(Cursor c=Cursor()) { return new AType(varID++, c); } AType* type(const AST* ast) { @@ -430,9 +429,9 @@ struct TEnv : public Env<const AST*,AType*> { assert(!dynamic_cast<const AType*>(o)); constraints.push_back(Constraint(type(o), t, o->loc)); } - void solve() { apply(unify(constraints)); } - void apply(const TSubst& substs); - static TSubst unify(const Constraints& c); + void solve() { apply(unify(constraints)); } + void apply(const Subst& substs); + static Subst unify(const Constraints& c); PEnv& penv; Constraints constraints; @@ -444,8 +443,6 @@ struct TEnv : public Env<const AST*,AType*> { * Code Generation * ***************************************************************************/ -struct CEnvPimpl; - /// Compile-Time Environment struct CEnv { CEnv(PEnv& p, TEnv& t, CEngine& e, ostream& os=std::cout, ostream& es=std::cerr); @@ -472,7 +469,8 @@ struct CEnv { Log log; private: - CEnvPimpl* _pimpl; + struct PImpl; ///< Private Implementation + PImpl* _pimpl; }; @@ -185,15 +185,15 @@ substitute(ATuple* tup, AST* from, AST* to) substitute(dynamic_cast<ATuple*>(tup->at(i)), from, to); } -TSubst -compose(const TSubst& delta, const TSubst& gamma) // TAPL 22.1.1 +TEnv::Subst +compose(const TEnv::Subst& delta, const TEnv::Subst& gamma) // TAPL 22.1.1 { - TSubst r; - for (TSubst::const_iterator g = gamma.begin(); g != gamma.end(); ++g) { - TSubst::const_iterator d = delta.find(g->second); + TEnv::Subst r; + for (TEnv::Subst::const_iterator g = gamma.begin(); g != gamma.end(); ++g) { + TEnv::Subst::const_iterator d = delta.find(g->second); r.insert(make_pair(g->first, ((d != delta.end()) ? d : g)->second)); } - for (TSubst::const_iterator d = delta.begin(); d != delta.end(); ++d) { + for (TEnv::Subst::const_iterator d = delta.begin(); d != delta.end(); ++d) { if (gamma.find(d->first) == gamma.end()) r.insert(*d); } @@ -213,10 +213,10 @@ substConstraints(TEnv::Constraints& constraints, AType* s, AType* t) } } -TSubst +TEnv::Subst TEnv::unify(const Constraints& constraints) // TAPL 22.4 { - if (constraints.empty()) return TSubst(); + if (constraints.empty()) return Subst(); AType* s = constraints.begin()->first; AType* t = constraints.begin()->second; Constraints cp = constraints; @@ -226,10 +226,10 @@ TEnv::unify(const Constraints& constraints) // TAPL 22.4 return unify(cp); } else if (s->var() && !t->contains(s)) { substConstraints(cp, s, t); - return compose(unify(cp), TSubst(s, t)); + return compose(unify(cp), Subst(s, t)); } else if (t->var() && !s->contains(t)) { substConstraints(cp, t, s); - return compose(unify(cp), TSubst(t, s)); + return compose(unify(cp), Subst(t, s)); } else if (s->kind == AType::EXPR && s->kind == t->kind && s->size() == t->size()) { for (size_t i = 0; i < s->size(); ++i) { AType* si = dynamic_cast<AType*>(s->at(i)); @@ -245,9 +245,9 @@ TEnv::unify(const Constraints& constraints) // TAPL 22.4 } void -TEnv::apply(const TSubst& substs) +TEnv::apply(const TEnv::Subst& substs) { - FOREACH(TSubst::const_iterator, s, substs) + FOREACH(Subst::const_iterator, s, substs) FOREACH(Frame::iterator, t, front()) if (*t->second == *s->first) t->second = s->second; |