aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/constrain.cpp2
-rw-r--r--src/tuplr.hpp17
-rw-r--r--src/unify.cpp13
-rwxr-xr-xtest.sh4
-rw-r--r--test/tup.tpr4
5 files changed, 23 insertions, 17 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp
index 36a82d1..d419036 100644
--- a/src/constrain.cpp
+++ b/src/constrain.cpp
@@ -201,7 +201,7 @@ ADot::constrain(TEnv& tenv, Constraints& c) const
for (int i = 0; i < idx->val; ++i)
objT->push_back(tenv.var());
objT->push_back(retT);
- objT->push_back(tenv.ellipses);
+ objT->push_back(new AType(obj->loc, AType::DOTS));
c.constrain(tenv, obj, objT);
}
diff --git a/src/tuplr.hpp b/src/tuplr.hpp
index 18e8830..9a87c37 100644
--- a/src/tuplr.hpp
+++ b/src/tuplr.hpp
@@ -296,9 +296,10 @@ private:
/// Type Expression, e.g. "Int", "(Fn (Int Int) Float)"
struct AType : public ATuple {
+ enum Kind { VAR, PRIM, EXPR, DOTS };
AType(ASymbol* s) : ATuple(s->loc), kind(PRIM), id(0) { push_back(s); }
AType(Cursor c, unsigned i) : ATuple(c), kind(VAR), id(i) {}
- AType(Cursor c) : ATuple(c), kind(EXPR), id(0) {}
+ 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) {}
CVal compile(CEnv& cenv) { return NULL; }
@@ -329,8 +330,8 @@ struct AType : public ATuple {
}
return false; // never reached
}
- enum { VAR, PRIM, EXPR } kind;
- unsigned id;
+ Kind kind;
+ unsigned id;
};
/// Type substitution
@@ -569,10 +570,11 @@ inline ostream& operator<<(ostream& out, const Constraints& c) {
/// Type-Time Environment
struct TEnv : public Env<const ASymbol*, AType*> {
- TEnv(PEnv& p) : penv(p), varID(1),
- Fn(new AType(penv.sym("Fn"))),
- Tup(new AType(penv.sym("Tup"))),
- ellipses(new AType(penv.sym("...")))
+ TEnv(PEnv& p)
+ : penv(p)
+ , varID(1)
+ , Fn(new AType(penv.sym("Fn")))
+ , Tup(new AType(penv.sym("Tup")))
{
Object::pool.addRoot(Fn);
}
@@ -606,7 +608,6 @@ struct TEnv : public Env<const ASymbol*, AType*> {
AType* Fn;
AType* Tup;
- AType* ellipses;
};
Subst unify(const Constraints& c);
diff --git a/src/unify.cpp b/src/unify.cpp
index 1cecfb5..278f3a5 100644
--- a/src/unify.cpp
+++ b/src/unify.cpp
@@ -129,15 +129,16 @@ unify(const Constraints& constraints)
AType::iterator si = s->begin() + 1;
AType::iterator ti = t->begin() + 1;
for (; si != s->end() && ti != t->end(); ++si, ++ti) {
- if ((*si)->str() == "..." || (*ti)->str() == "...")
+ AType* st = (*si)->as<AType*>();
+ AType* tt = (*ti)->as<AType*>();
+ if (st->kind == AType::DOTS || tt->kind == AType::DOTS)
return unify(cp);
- AType* st = (*si)->to<AType*>();
- AType* tt = (*ti)->to<AType*>();
- assert(st && tt);
- cp.push_back(Constraint(st, tt, st->loc));
+ else
+ cp.push_back(Constraint(st, tt, st->loc));
}
if (si == s->end() && ti == t->end()
- || (*ti)->str() == "..." || (*si)->str() == "...")
+ || (*ti)->as<AType*>()->kind == AType::DOTS
+ || (*si)->as<AType*>()->kind == AType::DOTS)
return unify(cp);
}
throw Error(s->loc ? s->loc : t->loc,
diff --git a/test.sh b/test.sh
index 13d2b00..d7e4043 100755
--- a/test.sh
+++ b/test.sh
@@ -16,6 +16,6 @@ run() {
run './test/ack.tpr' '8189 : Int'
run './test/def.tpr' '3 : Int'
run './test/fac.tpr' '720 : Int'
-run './test/poly.tpr' '#t : Bool'
+run './test/poly.tpr' '#t : Bool'
run './test/nest.tpr' '6 : Int'
-run './test/tup.tpr' '3 : Int'
+run './test/tup.tpr' '5 : Int'
diff --git a/test/tup.tpr b/test/tup.tpr
index ac32387..17d59cb 100644
--- a/test/tup.tpr
+++ b/test/tup.tpr
@@ -1,2 +1,6 @@
(def t (cons 1 2 3 4 5))
+(. t 0)
+(. t 1)
(. t 2)
+(. t 3)
+(. t 4)