diff options
author | David Robillard <d@drobilla.net> | 2009-03-07 02:03:33 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-03-07 02:03:33 +0000 |
commit | 76a2dc8afc2e59e2927cacb7270e28943ec9841d (patch) | |
tree | 014c7f15ad4cb9609e9466271e0f23cf0555f345 | |
parent | d2c34198db88c8ffdf9a9352825a71c85a00c26e (diff) | |
download | resp-76a2dc8afc2e59e2927cacb7270e28943ec9841d.tar.gz resp-76a2dc8afc2e59e2927cacb7270e28943ec9841d.tar.bz2 resp-76a2dc8afc2e59e2927cacb7270e28943ec9841d.zip |
Fancy varargs AType constructor.
git-svn-id: http://svn.drobilla.net/resp/tuplr@69 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r-- | llvm.cpp | 6 | ||||
-rw-r--r-- | tuplr.hpp | 10 | ||||
-rw-r--r-- | typing.cpp | 28 |
3 files changed, 24 insertions, 20 deletions
@@ -409,9 +409,9 @@ AType* ASTConsCall::functionType(CEnv& cenv) { ASTTuple* protTypes = new ASTTuple(cenv.tenv.type(at(1)), cenv.tenv.type(at(2)), NULL); - AType* cellType = new AType(ASTTuple(cenv.penv.sym("Pair"), - cenv.tenv.type(at(1)), cenv.tenv.type(at(2)), NULL), Cursor()); - return new AType(ASTTuple(cenv.penv.sym("Fn"), protTypes, cellType, NULL), loc); + AType* cellType = new AType(loc, + cenv.penv.sym("Pair"), cenv.tenv.type(at(1)), cenv.tenv.type(at(2))); + return new AType(at(0)->loc, cenv.penv.sym("Fn"), protTypes, cellType, 0); } void @@ -136,9 +136,11 @@ 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, Cursor c) : AST(c), vector<AST*>(size) {} ASTTuple(AST* ast, ...) { + va_list args; va_start(args, ast); + init(ast, args); + } + void init(AST* ast, va_list args) { push_back(ast); - va_list args; - va_start(args, ast); for (AST* a = va_arg(args, AST*); a; a = va_arg(args, AST*)) push_back(a); va_end(args); @@ -178,6 +180,10 @@ struct AType : public ASTTuple { 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) {} + AType(Cursor c, AST* ast, ...) : ASTTuple(0, c) { + va_list args; va_start(args, ast); + init(ast, args); + } string str() const { switch (kind) { case VAR: return (format("?%1%") % id).str(); @@ -24,7 +24,7 @@ void ASTTuple::constrain(TEnv& tenv) const { - AType* t = new AType(ASTTuple(), loc); + AType* t = new AType(loc, 0); FOREACH(const_iterator, p, *this) { (*p)->constrain(tenv); t->push_back(tenv.type(*p)); @@ -39,8 +39,7 @@ ASTClosure::constrain(TEnv& tenv) const at(2)->constrain(tenv); AType* protT = tenv.type(at(1)); AType* bodyT = tenv.type(at(2)); - tenv.constrain(this, new AType(ASTTuple( - tenv.penv.sym("Fn"), protT, bodyT, 0), loc)); + tenv.constrain(this, new AType(loc, tenv.penv.sym("Fn"), protT, bodyT, 0)); } void @@ -49,11 +48,10 @@ ASTCall::constrain(TEnv& tenv) const FOREACH(const_iterator, p, *this) (*p)->constrain(tenv); AType* retT = tenv.type(this); - AType* argsT = new AType(ASTTuple(), loc); + AType* argsT = new AType(loc, 0); for (size_t i = 1; i < size(); ++i) argsT->push_back(tenv.type(at(i))); - tenv.constrain(at(0), new AType(ASTTuple( - tenv.penv.sym("Fn"), argsT, retT, NULL), loc)); + tenv.constrain(at(0), new AType(at(0)->loc, tenv.penv.sym("Fn"), argsT, retT, 0)); } void @@ -141,7 +139,7 @@ void ASTConsCall::constrain(TEnv& tenv) const { if (size() != 3) throw Error("`cons' requires exactly 2 arguments", loc); - AType* t = new AType(ASTTuple(tenv.penv.sym("Pair"), 0), loc); + AType* t = new AType(loc, tenv.penv.sym("Pair"), 0); for (size_t i = 1; i < size(); ++i) { at(i)->constrain(tenv); t->push_back(tenv.type(at(i))); @@ -154,10 +152,10 @@ ASTCarCall::constrain(TEnv& tenv) const { if (size() != 2) throw Error("`car' requires exactly 1 argument", loc); at(1)->constrain(tenv); - AType* ct = tenv.var(loc); - AType* tt = new AType(ASTTuple(tenv.penv.sym("Pair"), ct, tenv.var(), 0), loc); - tenv.constrain(at(1), tt); - tenv.constrain(this, ct); + AType* carT = tenv.var(loc); + AType* pairT = new AType(at(1)->loc, tenv.penv.sym("Pair"), carT, tenv.var(), 0); + tenv.constrain(at(1), pairT); + tenv.constrain(this, carT); } void @@ -165,10 +163,10 @@ ASTCdrCall::constrain(TEnv& tenv) const { if (size() != 2) throw Error("`cdr' requires exactly 1 argument", loc); at(1)->constrain(tenv); - AType* ct = tenv.var(loc); - AType* tt = new AType(ASTTuple(tenv.penv.sym("Pair"), tenv.var(), ct, 0), loc); - tenv.constrain(at(1), tt); - tenv.constrain(this, ct); + AType* cdrT = tenv.var(loc); + AType* pairT = new AType(at(1)->loc, tenv.penv.sym("Pair"), tenv.var(), cdrT, 0); + tenv.constrain(at(1), pairT); + tenv.constrain(this, cdrT); } |