aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-03-12 05:01:21 +0000
committerDavid Robillard <d@drobilla.net>2009-03-12 05:01:21 +0000
commit251232bc3bbf6d98f9f6f91352bdcceef3b102f0 (patch)
treebb3d1c65e672d0b9d933225a261337c44ebf2b7c
parent23978add2847c4ba1e8b2f5a63595fe1317ea992 (diff)
downloadresp-251232bc3bbf6d98f9f6f91352bdcceef3b102f0.tar.gz
resp-251232bc3bbf6d98f9f6f91352bdcceef3b102f0.tar.bz2
resp-251232bc3bbf6d98f9f6f91352bdcceef3b102f0.zip
Encapsulate more types.
git-svn-id: http://svn.drobilla.net/resp/tuplr@83 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r--llvm.cpp7
-rw-r--r--tuplr.hpp18
-rw-r--r--typing.cpp24
3 files changed, 23 insertions, 26 deletions
diff --git a/llvm.cpp b/llvm.cpp
index 8357f6d..4fcc5b6 100644
--- a/llvm.cpp
+++ b/llvm.cpp
@@ -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))
{
}
diff --git a/tuplr.hpp b/tuplr.hpp
index 16a9a75..cc0b086 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -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;
};
diff --git a/typing.cpp b/typing.cpp
index 80bc568..4e3fce5 100644
--- a/typing.cpp
+++ b/typing.cpp
@@ -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;