diff options
author | David Robillard <d@drobilla.net> | 2009-03-31 00:51:31 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-03-31 00:51:31 +0000 |
commit | 9dc74f15acec8daac019f21ec0834827a5c5fd51 (patch) | |
tree | 25c10e3b925c4ae124875621dff236d56c3efbb0 | |
parent | 14b989aaf2c11710cef316a3ba20a947777cca08 (diff) | |
download | resp-9dc74f15acec8daac019f21ec0834827a5c5fd51.tar.gz resp-9dc74f15acec8daac019f21ec0834827a5c5fd51.tar.bz2 resp-9dc74f15acec8daac019f21ec0834827a5c5fd51.zip |
Fix polymorphic functions (somewhat).
git-svn-id: http://svn.drobilla.net/resp/tuplr@112 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r-- | llvm.cpp | 10 | ||||
-rw-r--r-- | tuplr.hpp | 18 | ||||
-rw-r--r-- | typing.cpp | 2 |
3 files changed, 15 insertions, 15 deletions
@@ -220,7 +220,7 @@ AClosure::liftCall(CEnv& cenv, const vector<AType*>& argsT) assert(argsT.size() == prot()->size()); ATuple* genericProtT = genericType->at(1)->as<ATuple*>(); for (size_t i = 0; i < argsT.size(); ++i) - argsSubst[genericProtT->at(i)->to<AType*>()] = argsT.at(i)->to<AType*>(); + argsSubst[*genericProtT->at(i)->to<AType*>()] = argsT.at(i)->to<AType*>(); thisType = argsSubst.apply(genericType)->as<AType*>(); if (!thisType->concrete()) throw Error("unable to resolve concrete type for function", loc); @@ -310,11 +310,9 @@ ACall::compile(CEnv& cenv) TEnv::GenericTypes::const_iterator gt = cenv.tenv.genericTypes.find(c); assert(gt != cenv.tenv.genericTypes.end()); - const AType* polyT = gt->second; - AType* fnT = new AType(loc, cenv.penv.sym("Fn"), protT, polyT->at(polyT->size()-1), 0); - - Function* f = (Function*)c->funcs.find(fnT); - if (!f) throw Error("callee failed to compile", loc); + AType* fnT = new AType(loc, cenv.penv.sym("Fn"), protT, cenv.type(this), 0); + Function* f = (Function*)c->funcs.find(fnT); + if (!f) throw Error((format("callee failed to compile for type %1%") % fnT->str()).str(), loc); vector<Value*> params(size() - 1); for (size_t i = 1; i < size(); ++i) @@ -260,6 +260,9 @@ 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) @@ -431,8 +434,8 @@ inline ostream& operator<<(ostream& out, const Constraints& c) { return out; } -struct Subst : public map<const AType*,AType*> { - Subst(AType* s=0, AType* t=0) { if (s && t) { assert(s != t); insert(make_pair(s, t)); } } +struct Subst : public map<const AType,AType*> { + Subst(AType* s=0, AType* t=0) { if (s && t) { assert(s != t); insert(make_pair(*s, t)); } } static Subst compose(const Subst& delta, const Subst& gamma); AST* apply(AST* ast) const { AType* in = ast->to<AType*>(); @@ -443,13 +446,12 @@ struct Subst : public map<const AType*,AType*> { out->push_back(apply(in->at(i))); return out; } else { - Subst copy(*this); - iterator i; - while ((i = copy.find(in)) != copy.end()) { - in = i->second; - copy.erase(i); + const_iterator i = find(*in); + if (i != end()) { + return i->second; + } else { + return in; } - return in; } } }; @@ -283,7 +283,7 @@ Subst::compose(const Subst& delta, const Subst& gamma) // TAPL 22.1.1 { Subst r; for (Subst::const_iterator g = gamma.begin(); g != gamma.end(); ++g) { - Subst::const_iterator d = delta.find(g->second); + Subst::const_iterator d = delta.find(*g->second); r.insert(make_pair(g->first, ((d != delta.end()) ? d : g)->second)); } for (Subst::const_iterator d = delta.begin(); d != delta.end(); ++d) { |