aboutsummaryrefslogtreecommitdiffstats
path: root/src/tuplr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tuplr.hpp')
-rw-r--r--src/tuplr.hpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/tuplr.hpp b/src/tuplr.hpp
index 31585d2..18e8830 100644
--- a/src/tuplr.hpp
+++ b/src/tuplr.hpp
@@ -440,6 +440,13 @@ struct ACons : public ACall {
CVal compile(CEnv& cenv);
};
+struct ADot : public ACall {
+ ADot(const ATuple* exp) : ACall(exp) {}
+ void constrain(TEnv& tenv, Constraints& c) const;
+ void lift(CEnv& cenv);
+ CVal compile(CEnv& cenv);
+};
+
/// Primitive (builtin arithmetic function), e.g. "(+ 2 3)"
struct APrimitive : public ACall {
APrimitive(const ATuple* exp) : ACall(exp) {}
@@ -563,13 +570,19 @@ 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"))) {
+ Fn(new AType(penv.sym("Fn"))),
+ Tup(new AType(penv.sym("Tup"))),
+ ellipses(new AType(penv.sym("...")))
+ {
Object::pool.addRoot(Fn);
}
AType* fresh(const ASymbol* sym) {
return def(sym, new AType(sym->loc, varID++));
}
AType* var(const AST* ast=0) {
+ if (!ast)
+ return new AType(Cursor(), varID++);
+
const ASymbol* sym = ast->to<const ASymbol*>();
if (sym)
return *ref(sym);
@@ -578,11 +591,7 @@ struct TEnv : public Env<const ASymbol*, AType*> {
if (v != vars.end())
return v->second;
- AType* ret = new AType(ast ? ast->loc : Cursor(), varID++);
- if (ast)
- vars[ast] = ret;
-
- return ret;
+ return (vars[ast] = new AType(ast->loc, varID++));
}
AType* named(const string& name) {
return *ref(penv.sym(name));
@@ -597,6 +606,7 @@ struct TEnv : public Env<const ASymbol*, AType*> {
AType* Fn;
AType* Tup;
+ AType* ellipses;
};
Subst unify(const Constraints& c);
@@ -619,6 +629,7 @@ struct Engine {
virtual void eraseFunction(CEnv& cenv, CFunc f) = 0;
virtual CFunc compileFunction(CEnv& cenv, AFn* fn, const AType& argsT) = 0;
virtual CVal compileTup(CEnv& cenv, const AType* t, const vector<CVal>& f) = 0;
+ virtual CVal compileDot(CEnv& cenv, CVal tup, int32_t index) = 0;
virtual CVal compileLiteral(CEnv& cenv, AST* lit) = 0;
virtual CVal compileCall(CEnv& cenv, CFunc f, const vector<CVal>& args) = 0;
virtual CVal compilePrimitive(CEnv& cenv, APrimitive* prim) = 0;
@@ -649,6 +660,7 @@ struct CEnv {
ASymbol* sym = ast->to<ASymbol*>();
if (sym)
return *tenv.ref(sym);
+ assert(tenv.vars[ast]);
return tsubst.apply(subst.apply(tenv.vars[ast]))->to<AType*>();
}
void def(const ASymbol* sym, AST* c, AType* t, CVal v) {