aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm.cpp6
-rw-r--r--tuplr.hpp10
-rw-r--r--typing.cpp28
3 files changed, 24 insertions, 20 deletions
diff --git a/llvm.cpp b/llvm.cpp
index 1717160..4db9a2a 100644
--- a/llvm.cpp
+++ b/llvm.cpp
@@ -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
diff --git a/tuplr.hpp b/tuplr.hpp
index 54f48b2..a906743 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -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();
diff --git a/typing.cpp b/typing.cpp
index 5e419fd..872462a 100644
--- a/typing.cpp
+++ b/typing.cpp
@@ -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);
}