diff options
-rw-r--r-- | src/c.cpp | 12 | ||||
-rw-r--r-- | src/compile.cpp | 2 | ||||
-rw-r--r-- | src/cps.cpp | 2 | ||||
-rw-r--r-- | src/lift.cpp | 6 | ||||
-rw-r--r-- | src/llvm.cpp | 12 | ||||
-rw-r--r-- | src/parse.cpp | 2 | ||||
-rw-r--r-- | src/pprint.cpp | 8 | ||||
-rw-r--r-- | src/repl.cpp | 2 | ||||
-rw-r--r-- | src/tuplr.hpp | 7 |
9 files changed, 27 insertions, 26 deletions
@@ -43,12 +43,12 @@ static const Type* llType(const AType* t) { if (t->kind == AType::PRIM) { - if (t->at(0)->str() == "Nothing") return new string("void"); - if (t->at(0)->str() == "Bool") return new string("bool"); - if (t->at(0)->str() == "Int") return new string("int"); - if (t->at(0)->str() == "Float") return new string("float"); + if (t->head()->str() == "Nothing") return new string("void"); + if (t->head()->str() == "Bool") return new string("bool"); + if (t->head()->str() == "Int") return new string("int"); + if (t->head()->str() == "Float") return new string("float"); throw Error(t->loc, string("Unknown primitive type `") + t->str() + "'"); - } else if (t->kind == AType::EXPR && t->at(0)->str() == "Fn") { + } else if (t->kind == AType::EXPR && t->head()->str() == "Fn") { const AType* retT = t->at(2)->as<const AType*>(); if (!llType(retT)) return NULL; @@ -264,7 +264,7 @@ CEngine::compilePrimitive(CEnv& cenv, APrimitive* prim) CEngine* engine = reinterpret_cast<CEngine*>(cenv.engine()); Value* a = llVal(prim->at(1)->compile(cenv)); Value* b = llVal(prim->at(2)->compile(cenv)); - const string n = prim->at(0)->to<ASymbol*>()->str(); + const string n = prim->head()->to<ASymbol*>()->str(); string op = n; // Convert operator to C operator if they don't match diff --git a/src/compile.cpp b/src/compile.cpp index 2b16a78..e8e06b8 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -46,7 +46,7 @@ AFn::compile(CEnv& cenv) CVal ACall::compile(CEnv& cenv) { - AFn* c = cenv.resolve(at(0))->to<AFn*>(); + AFn* c = cenv.resolve(head())->to<AFn*>(); if (!c) return NULL; // Primitive diff --git a/src/cps.cpp b/src/cps.cpp index b8b6b62..eb44fd9 100644 --- a/src/cps.cpp +++ b/src/cps.cpp @@ -97,7 +97,7 @@ ACall::cps(TEnv& tenv, AST* cont) fn->push_back(call->cps(tenv, cont)); return at(firstFn)->cps(tenv, funcs[firstFn].first); } else { - assert(at(0)->value()); + assert(head()->value()); ACall* ret = tup<ACall>(loc, 0); FOREACH(iterator, i, *this) ret->push_back((*i)); diff --git a/src/lift.cpp b/src/lift.cpp index 3f0e1bf..f5fe607 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -47,7 +47,7 @@ AFn::lift(CEnv& cenv) void ACall::lift(CEnv& cenv) { - AFn* c = cenv.resolve(at(0))->to<AFn*>(); + AFn* c = cenv.resolve(head())->to<AFn*>(); AType argsT(loc); // Lift arguments @@ -59,9 +59,9 @@ ACall::lift(CEnv& cenv) if (!c) return; // Primitive if (c->prot()->size() < size() - 1) - throw Error(loc, (format("too many arguments to function `%1%'") % at(0)->str()).str()); + throw Error(loc, (format("too many arguments to function `%1%'") % head()->str()).str()); if (c->prot()->size() > size() - 1) - throw Error(loc, (format("too few arguments to function `%1%'") % at(0)->str()).str()); + throw Error(loc, (format("too few arguments to function `%1%'") % head()->str()).str()); cenv.engine()->compileFunction(cenv, c, argsT); // Lift called closure } diff --git a/src/llvm.cpp b/src/llvm.cpp index 1b01e4d..30927d4 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -46,12 +46,12 @@ static const Type* llType(const AType* t) { if (t->kind == AType::PRIM) { - if (t->at(0)->str() == "Nothing") return Type::VoidTy; - if (t->at(0)->str() == "Bool") return Type::Int1Ty; - if (t->at(0)->str() == "Int") return Type::Int32Ty; - if (t->at(0)->str() == "Float") return Type::FloatTy; + if (t->head()->str() == "Nothing") return Type::VoidTy; + if (t->head()->str() == "Bool") return Type::Int1Ty; + if (t->head()->str() == "Int") return Type::Int32Ty; + if (t->head()->str() == "Float") return Type::FloatTy; throw Error(t->loc, string("Unknown primitive type `") + t->str() + "'"); - } else if (t->kind == AType::EXPR && t->at(0)->str() == "Fn") { + } else if (t->kind == AType::EXPR && t->head()->str() == "Fn") { const AType* retT = t->at(2)->as<const AType*>(); if (!llType(retT)) return NULL; @@ -339,7 +339,7 @@ LLVMEngine::compilePrimitive(CEnv& cenv, APrimitive* prim) Value* a = llVal(prim->at(1)->compile(cenv)); Value* b = llVal(prim->at(2)->compile(cenv)); bool isFloat = cenv.type(prim->at(1))->str() == "Float"; - const string n = prim->at(0)->to<ASymbol*>()->str(); + const string n = prim->head()->to<ASymbol*>()->str(); // Binary arithmetic operations Instruction::BinaryOps op = (Instruction::BinaryOps)0; diff --git a/src/parse.cpp b/src/parse.cpp index c7209aa..6271cad 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -40,7 +40,7 @@ macDef(PEnv& penv, const AST* exp) return const_cast<AST*>(exp); } else { const ATuple* pat = name->to<const ATuple*>(); - name = pat->at(0); + name = pat->head(); // (def (f x) y) => (def f (fn (x) y)) ATuple* argsExp = new ATuple(exp->loc); ATuple::const_iterator j = pat->begin(); diff --git a/src/pprint.cpp b/src/pprint.cpp index ddbd403..1632f02 100644 --- a/src/pprint.cpp +++ b/src/pprint.cpp @@ -48,7 +48,7 @@ operator<<(ostream& out, const AST* ast) if (type) { switch (type->kind) { case AType::VAR: return out << "?" << type->id; - case AType::PRIM: return out << type->at(0); + case AType::PRIM: return out << type->head(); case AType::EXPR: break; // will catch Tuple case below } } @@ -69,10 +69,10 @@ pprint_internal(ostream& out, const AST* ast, unsigned indent) { const ATuple* tup = ast->to<const ATuple*>(); if (tup && tup->size() > 0) { - const string head = tup->at(0)->str(); - const ASymbol* headSym = tup->at(0)->to<const ASymbol*>(); + const string head = tup->head()->str(); + const ASymbol* headSym = tup->head()->to<const ASymbol*>(); out << "("; - pprint_internal(out, tup->at(0), indent); + pprint_internal(out, tup->head(), indent); unsigned child_indent = indent; if (tup->size() > 1) { out << " "; diff --git a/src/repl.cpp b/src/repl.cpp index 96f30c3..a94e51c 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -64,7 +64,7 @@ callPrintCollect(CEnv& cenv, CFunc f, AST* result, AType* resultT, bool execute) cenv.out << cenv.engine()->call(cenv, f, resultT); // Print type (if applicable) - if (resultT->at(0)->to<const ASymbol*>()->cppstr != "Nothing") + if (resultT->head()->to<const ASymbol*>()->cppstr != "Nothing") cenv.out << " : " << resultT << endl; Object::pool.collect(Object::pool.roots()); diff --git a/src/tuplr.hpp b/src/tuplr.hpp index 02d79af..7494cdb 100644 --- a/src/tuplr.hpp +++ b/src/tuplr.hpp @@ -242,6 +242,7 @@ struct ATuple : public AST { _vec = newvec; } const AST* head() const { assert(_len > 0); return _vec[0]; } + AST* head() { assert(_len > 0); return _vec[0]; } const AST* at(size_t i) const { assert(i < _len); return _vec[i]; } AST*& at(size_t i) { assert(i < _len); return _vec[i]; } size_t size() const { return _len; } @@ -290,7 +291,7 @@ struct AType : public ATuple { bool concrete() const { switch (kind) { case VAR: return false; - case PRIM: return at(0)->str() != "Nothing"; + case PRIM: return head()->str() != "Nothing"; case EXPR: FOREACH(const_iterator, t, *this) { AType* kid = (*t)->to<AType*>(); @@ -307,7 +308,7 @@ struct AType : public ATuple { else switch (kind) { case VAR: return id == rt->id; - case PRIM: return at(0)->str() == rt->at(0)->str(); + case PRIM: return head()->str() == rt->head()->str(); case EXPR: return ATuple::operator==(rhs); } return false; // never reached @@ -398,7 +399,7 @@ struct ADef : public ACall { if (!sym) { const ATuple* tup = at(1)->to<const ATuple*>(); if (tup && !tup->empty()) - return tup->at(0)->to<const ASymbol*>(); + return tup->head()->to<const ASymbol*>(); } return sym; } |