diff options
author | David Robillard <d@drobilla.net> | 2010-12-08 19:07:09 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-08 19:07:09 +0000 |
commit | d02fe43f0f6e50f8f22321aa0080283ee2ecc9fc (patch) | |
tree | 2a2007137d19221a541e97764dc3adef054f6581 /src/resp.hpp | |
parent | 583a2d9d2397ff174b16d7df377f16c1df6fe875 (diff) | |
download | resp-d02fe43f0f6e50f8f22321aa0080283ee2ecc9fc.tar.gz resp-d02fe43f0f6e50f8f22321aa0080283ee2ecc9fc.tar.bz2 resp-d02fe43f0f6e50f8f22321aa0080283ee2ecc9fc.zip |
Clean up function compilation stuff.
Add some utilities to for using named types.
git-svn-id: http://svn.drobilla.net/resp/resp@313 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/resp.hpp')
-rw-r--r-- | src/resp.hpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/resp.hpp b/src/resp.hpp index 3cccd30..7c88be4 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -647,6 +647,8 @@ struct TEnv : public Env<const ASymbol*, const AType*> { TEnv(PEnv& p) : penv(p) , varID(1) + , Closure(new AType(penv.sym("Closure"), AType::NAME)) + , Dots(new AType(Cursor(), AType::DOTS)) , Fn(new AType(penv.sym("Fn"), AType::PRIM)) , Tup(new AType(penv.sym("Tup"), AType::NAME)) , U(new AType(penv.sym("U"), AType::PRIM)) @@ -678,6 +680,8 @@ struct TEnv : public Env<const ASymbol*, const AType*> { PEnv& penv; unsigned varID; + AType* Closure; + AType* Dots; AType* Fn; AType* Tup; AType* U; @@ -701,9 +705,9 @@ struct Engine { const std::string& name, const ATuple* args, const AType* type) = 0; - - virtual void pushFunctionArgs(CEnv& cenv, const ATuple* fn, const AType* type, CFunc f) = 0; - + + virtual void pushFunctionArgs(CEnv& cenv, const ATuple* prot, const AType* type, CFunc f) = 0; + virtual void finishFunction(CEnv& cenv, CFunc f, CVal ret) = 0; virtual void eraseFunction(CEnv& cenv, CFunc f) = 0; virtual CVal compileCons(CEnv& cenv, const AType* t, CVal rtti, ValVec& f) = 0; @@ -742,7 +746,12 @@ struct CEnv { if (type(ast)) Object::pool.addRoot(type(ast)); } - const AType* type(const AST* ast, const Subst& subst = Subst()) const { + const AType* resolveType(const AType* type) const { + if (type->kind == AType::NAME) + return tenv.named(type->head()->to_symbol()->cppstr); + return type; + } + const AType* type(const AST* ast, const Subst& subst = Subst(), bool resolve=true) const { const AType* ret = NULL; const ASymbol* sym = ast->to_symbol(); if (sym) { @@ -753,8 +762,10 @@ struct CEnv { if (!ret) ret = tenv.vars[ast]; if (ret) - return tsubst.apply(subst.apply(ret))->to_type(); - return NULL; + ret = tsubst.apply(subst.apply(ret))->to_type(); + if (resolve && ret) + ret = this->resolveType(ret); + return ret; } void def(const ASymbol* sym, const AST* c, const AType* t, CVal v) { code.def(sym, c); @@ -766,7 +777,8 @@ struct CEnv { const AST** rec = code.ref(sym); return rec ? *rec : ast; } - void setType(AST* ast, const AType* type) { + void setType(const AST* ast, const AType* type) { + assert(!ast->to_symbol()); const AType* tvar = tenv.var(); tenv.vars.insert(make_pair(ast, tvar)); tsubst.add(tvar, type); |