diff options
author | David Robillard <d@drobilla.net> | 2009-10-16 03:20:22 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-10-16 03:20:22 +0000 |
commit | 195598d60fec7a9ea2096143d853fab8232b5138 (patch) | |
tree | a768c19d5b59db09df0b6ee52e2ee6e1fb8a0ba0 /src/tuplr.hpp | |
parent | c2d75892af2fdc6b9bf25365a15de5dc63bcc852 (diff) | |
download | resp-195598d60fec7a9ea2096143d853fab8232b5138.tar.gz resp-195598d60fec7a9ea2096143d853fab8232b5138.tar.bz2 resp-195598d60fec7a9ea2096143d853fab8232b5138.zip |
. operator for destructuring Tuples (cons).
git-svn-id: http://svn.drobilla.net/resp/tuplr@236 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/tuplr.hpp')
-rw-r--r-- | src/tuplr.hpp | 24 |
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) { |