aboutsummaryrefslogtreecommitdiffstats
path: root/src/resp.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resp.hpp')
-rw-r--r--src/resp.hpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/resp.hpp b/src/resp.hpp
index f172548..1edf9e6 100644
--- a/src/resp.hpp
+++ b/src/resp.hpp
@@ -339,7 +339,7 @@ struct AType : public ATuple {
AType(Cursor c, unsigned i) : ATuple(c), kind(VAR), id(i) {}
AType(Cursor c, Kind k=EXPR) : ATuple(c), kind(k), 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) {}
+ AType(const AType& copy) : ATuple(copy), kind(copy.kind), id(copy.id) { }
CVal compile(CEnv& cenv) throw() { return NULL; }
const ATuple* prot() const { assert(kind == EXPR); return (*(begin() + 1))->to<const ATuple*>(); }
ATuple* prot() { assert(kind == EXPR); return (*(begin() + 1))->to<ATuple*>(); }
@@ -556,18 +556,17 @@ struct PEnv : private map<const string, ASymbol*> {
/// Type constraint
struct Constraint : public pair<const AType*,const AType*> {
- Constraint(const AType* a, const AType* b, Cursor c)
- : pair<const AType*, const AType*>(a, b), loc(c) {}
- Cursor loc;
+ Constraint(const AType* a, const AType* b)
+ : pair<const AType*, const AType*>(a, b) {}
};
/// Type substitution
struct Subst : public list<Constraint> {
Subst(const AType* s=0, const AType* t=0) {
- if (s && t) { assert(s != t); push_back(Constraint(s, t, t->loc)); }
+ if (s && t) { assert(s != t); push_back(Constraint(s, t)); }
}
static Subst compose(const Subst& delta, const Subst& gamma);
- void add(const AType* from, const AType* to) { push_back(Constraint(from, to, Cursor())); }
+ void add(const AType* from, const AType* to) { push_back(Constraint(from, to)); }
const_iterator find(const AType* t) const {
for (const_iterator j = begin(); j != end(); ++j)
if (*j->first == *t)
@@ -592,6 +591,14 @@ struct Subst : public list<Constraint> {
}
}
}
+ bool contains(const AType* type) const {
+ if (find(type) != end())
+ return true;
+ FOREACHP(const_iterator, j, this)
+ if (*j->second == *type || j->second->contains(type))
+ return true;
+ return false;
+ }
};
inline ostream& operator<<(ostream& out, const Subst& s) {
@@ -604,13 +611,12 @@ inline ostream& operator<<(ostream& out, const Subst& s) {
struct Constraints : public list<Constraint> {
Constraints() : list<Constraint>() {}
Constraints(const Subst& subst) : list<Constraint>() {
- FOREACH(Subst::const_iterator, i, subst) {
- push_back(Constraint(new AType(*i->first), new AType(*i->second), Cursor()));
- }
+ FOREACH(Subst::const_iterator, i, subst)
+ push_back(Constraint(new AType(*i->first), new AType(*i->second)));
}
Constraints(const_iterator begin, const_iterator end) : list<Constraint>(begin, end) {}
void constrain(TEnv& tenv, const AST* o, const AType* t);
- Constraints replace(const AType* s, const AType* t);
+ Constraints& replace(const AType* s, const AType* t);
};
inline ostream& operator<<(ostream& out, const Constraints& c) {
@@ -713,7 +719,11 @@ struct CEnv {
Engine* engine() { return _engine; }
void push() { code.push(); tenv.push(); vals.push(); }
void pop() { code.pop(); tenv.pop(); vals.pop(); }
- void lock(AST* ast) { Object::pool.addRoot(ast); Object::pool.addRoot(type(ast)); }
+ void lock(AST* ast) {
+ Object::pool.addRoot(ast);
+ if (type(ast))
+ Object::pool.addRoot(type(ast));
+ }
const AType* type(AST* ast, const Subst& subst = Subst()) const {
ASymbol* sym = ast->to<ASymbol*>();
if (sym) {