diff options
author | David Robillard <d@drobilla.net> | 2009-03-07 01:23:05 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-03-07 01:23:05 +0000 |
commit | 1865e80acca50f58cae41e8ed4e86a9c67e3a1ef (patch) | |
tree | 0ccc71383916b260bd8463d098b773407da2c463 /tuplr.hpp | |
parent | a7e747b45b0ff3f9e106182e6a357d0b261255a5 (diff) | |
download | resp-1865e80acca50f58cae41e8ed4e86a9c67e3a1ef.tar.gz resp-1865e80acca50f58cae41e8ed4e86a9c67e3a1ef.tar.bz2 resp-1865e80acca50f58cae41e8ed4e86a9c67e3a1ef.zip |
Typing improvements.
More location information.
git-svn-id: http://svn.drobilla.net/resp/tuplr@67 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'tuplr.hpp')
-rw-r--r-- | tuplr.hpp | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -134,7 +134,7 @@ private: /// Tuple (heterogeneous sequence of fixed length), e.g. "(a b c)" struct ASTTuple : public AST, public vector<AST*> { ASTTuple(const vector<AST*>& t=vector<AST*>(), Cursor c=Cursor()) : AST(c), vector<AST*>(t) {} - ASTTuple(size_t size) : vector<AST*>(size) {} + ASTTuple(size_t size, Cursor c) : AST(c), vector<AST*>(size) {} ASTTuple(AST* ast, ...) { push_back(ast); va_list args; @@ -175,9 +175,9 @@ struct ASTTuple : public AST, public vector<AST*> { /// Type Expression, e.g. "Int", "(Fn (Int Int) Float)" struct AType : public ASTTuple { - AType(unsigned i, Cursor c) : kind(VAR), id(i) {} - AType(ASTSymbol* s, Cursor c) : kind(PRIM), id(0) { push_back(s); } - AType(const ASTTuple& t, Cursor c) : ASTTuple(t), kind(EXPR), id(0) {} + AType(unsigned i, Cursor c=Cursor()) : ASTTuple(0, c), kind(VAR), id(i) {} + AType(ASTSymbol* s) : ASTTuple(0, s->loc), kind(PRIM), id(0) { push_back(s); } + AType(const ASTTuple& t, Cursor c) : ASTTuple(t, c), kind(EXPR), id(0) {} string str() const { switch (kind) { case VAR: return (format("?%1%") % id).str(); @@ -329,11 +329,12 @@ struct PEnv : private map<const string, ASTSymbol*> { static AST* parseExpression(PEnv& penv, const SExp& exp); static ASTTuple -pmap(PEnv& penv, const SExp::List& l) +pmap(PEnv& penv, const SExp& e) { - ASTTuple ret(l.size()); + assert(e.type == SExp::LIST); + ASTTuple ret(e.list.size(), e.loc); size_t n = 0; - FOREACH(SExp::List::const_iterator, i, l) + FOREACH(SExp::List::const_iterator, i, e.list) ret[n++] = parseExpression(penv, *i); return ret; } @@ -348,7 +349,7 @@ parseExpression(PEnv& penv, const SExp& exp) if (handler) // Dispatch to list parse function return handler->func(penv, exp, handler->arg); } - return new ASTCall(exp, pmap(penv, exp.list)); // Parse as regular call + return new ASTCall(exp, pmap(penv, exp)); // Parse as regular call } else if (isdigit(exp.atom[0])) { if (exp.atom.find('.') == string::npos) return new ASTLiteral<int32_t>(strtol(exp.atom.c_str(), NULL, 10), exp.loc); @@ -366,7 +367,7 @@ template<typename C> inline AST* parseCall(PEnv& penv, const SExp& exp, void* arg) { - return new C(exp, pmap(penv, exp.list)); + return new C(exp, pmap(penv, exp)); } template<typename T> @@ -381,7 +382,7 @@ parseFn(PEnv& penv, const SExp& exp, void* arg) { SExp::List::const_iterator a = exp.list.begin(); ++a; return new ASTClosure( - new ASTTuple(pmap(penv, a->list), (*a++).loc), + new ASTTuple(pmap(penv, *a), (*a++).loc), parseExpression(penv, *a++)); } @@ -428,7 +429,7 @@ struct TEnv : public Env<const AST*,AType*> { Cursor loc; }; typedef list<Constraint> Constraints; - AType* var(Cursor c) { return new AType(varID++, c); } + AType* var(Cursor c=Cursor()) { return new AType(varID++, c); } AType* type(const AST* ast) { AType** t = ref(ast); return t ? *t : def(ast, var(ast->loc)); @@ -461,7 +462,7 @@ struct CEnv { CEnv(PEnv& p, TEnv& t, CEngine& engine); ~CEnv(); - typedef Env<const AST*, AST*> Code; + typedef Env<const ASTSymbol*, AST*> Code; typedef Env<const AST*, CValue> Vals; string gensym(const char* s="_") { return (format("%s%d") % s % symID++).str(); } |