diff options
-rw-r--r-- | src/c.cpp | 4 | ||||
-rw-r--r-- | src/compile.cpp | 10 | ||||
-rw-r--r-- | src/constrain.cpp | 10 | ||||
-rw-r--r-- | src/cps.cpp | 2 | ||||
-rw-r--r-- | src/expand.cpp | 4 | ||||
-rw-r--r-- | src/lift.cpp | 18 | ||||
-rw-r--r-- | src/llvm.cpp | 6 | ||||
-rw-r--r-- | src/resp.cpp | 4 | ||||
-rw-r--r-- | src/resp.hpp | 22 | ||||
-rw-r--r-- | src/simplify.cpp | 4 |
10 files changed, 38 insertions, 46 deletions
@@ -107,7 +107,7 @@ CEngine::llType(const AST* t) *ret += ")"; return ret; - } else if (AType::is_expr(t) && isupper(t->as_tuple()->head()->str()[0])) { + } else if (AType::is_expr(t) && isupper(t->as_tuple()->fst()->str()[0])) { Type* ret = new Type("struct { void* me; "); for (ATuple::const_iterator i = t->as_tuple()->iter_at(1); i != t->as_tuple()->end(); ++i) { const Type* lt = llType(*i); @@ -271,7 +271,7 @@ CEngine::compilePrimitive(CEnv& cenv, const ATuple* prim) Value* a = llVal(resp_compile(cenv, *i++)); Value* b = llVal(resp_compile(cenv, *i++)); - const string n = prim->head()->to_symbol()->str(); + const string n = prim->fst()->to_symbol()->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 756e90d..1de8a78 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -53,13 +53,13 @@ compile_literal_symbol(CEnv& cenv, const ASymbol* sym) throw() static CVal compile_type(CEnv& cenv, const AST* type) throw() { - return compile_literal_symbol(cenv, type->as_tuple()->head()->as_symbol()); + return compile_literal_symbol(cenv, type->as_tuple()->fst()->as_symbol()); } static CVal compile_cons(CEnv& cenv, const ATuple* cons) throw() { - ATuple* type = new ATuple(cons->head()->as_symbol(), NULL, Cursor()); + ATuple* type = new ATuple(cons->fst()->as_symbol(), NULL, Cursor()); List tlist(type); vector<CVal> fields; for (ATuple::const_iterator i = cons->iter_at(1); i != cons->end(); ++i) { @@ -161,7 +161,7 @@ compile_quote(CEnv& cenv, const ATuple* quote) throw() static CVal compile_call(CEnv& cenv, const ATuple* call) throw() { - CFunc f = resp_compile(cenv, call->head()); + CFunc f = resp_compile(cenv, call->fst()); if (!f) f = cenv.currentFn; // Recursive call (callee defined as a stub) @@ -170,7 +170,7 @@ compile_call(CEnv& cenv, const ATuple* call) throw() for (ATuple::const_iterator e = call->iter_at(1); e != call->end(); ++e) args.push_back(resp_compile(cenv, *e)); - return cenv.engine()->compileCall(cenv, f, cenv.type(call->head())->as_tuple(), args); + return cenv.engine()->compileCall(cenv, f, cenv.type(call->fst())->as_tuple(), args); } CVal @@ -193,7 +193,7 @@ resp_compile(CEnv& cenv, const AST* ast) throw() case T_TUPLE: { const ATuple* const call = ast->as_tuple(); - const ASymbol* const sym = call->head()->to_symbol(); + const ASymbol* const sym = call->fst()->to_symbol(); const std::string form = sym ? sym->sym() : ""; if (is_primitive(cenv.penv, call)) return cenv.engine()->compilePrimitive(cenv, ast->as_tuple()); diff --git a/src/constrain.cpp b/src/constrain.cpp index f65ad8f..7530f01 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -52,7 +52,7 @@ constrain_cons(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) THROW_IF(!consTRef, call->loc, (format("call to undefined constructor `%1%'") % sym->sym()).str()); const AST* consT = *consTRef; - type = new ATuple(consT->as_tuple()->head(), 0, call->loc); + type = new ATuple(consT->as_tuple()->fst(), 0, call->loc); } c.constrain(tenv, call, type); } @@ -246,7 +246,7 @@ constrain_match(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) const AST* consT = *tenv.ref(name); if (!matcheeT) { - const AST* headT = consT->as_tuple()->head(); + const AST* headT = consT->as_tuple()->fst(); matcheeT = new ATuple(headT, 0, call->loc); } @@ -273,7 +273,7 @@ constrain_quote(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) static void constrain_call(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { - const AST* const head = call->head(); + const AST* const head = call->fst(); for (ATuple::const_iterator i = call->begin(); i != call->end(); ++i) resp_constrain(tenv, c, *i); @@ -300,7 +300,7 @@ constrain_call(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) static void constrain_primitive(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { - const string n = call->head()->to_symbol()->str(); + const string n = call->fst()->to_symbol()->str(); enum { ARITHMETIC, BINARY, LOGICAL, COMPARISON } type; if (n == "+" || n == "-" || n == "*" || n == "/") type = ARITHMETIC; @@ -356,7 +356,7 @@ constrain_primitive(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) static void constrain_list(TEnv& tenv, Constraints& c, const ATuple* tup) throw(Error) { - const ASymbol* const sym = tup->head()->to_symbol(); + const ASymbol* const sym = tup->fst()->to_symbol(); if (!sym) { constrain_call(tenv, c, tup); return; diff --git a/src/cps.cpp b/src/cps.cpp index 3c4f38d..88ab425 100644 --- a/src/cps.cpp +++ b/src/cps.cpp @@ -103,7 +103,7 @@ cps_tuple(TEnv& tenv, AST* cont) const fn->push_back(call->(tenv, cont)); return (*firstFnIter)->(tenv, firstFn); } else { - assert(head()->value()); + assert(fst()->value()); ATuple* ret = tup(loc, 0); FOREACHP(const_iterator, i, this) ret->push_back((*i)); diff --git a/src/expand.cpp b/src/expand.cpp index f0fed33..d10b64d 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -77,8 +77,8 @@ expand_def(PEnv& penv, const AST* exp, void* arg) fnExp.head->loc = body->loc; List ret; - ret.push_back(tup->head()); - ret.push_back(pat->head()); + ret.push_back(tup->fst()); + ret.push_back(pat->fst()); ret.push_back(fnExp.head); ret.head->loc = exp->loc; diff --git a/src/lift.cpp b/src/lift.cpp index 1991eb5..799c1e7 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -60,7 +60,7 @@ lift_dot(CEnv& cenv, Code& code, const ATuple* dot) throw() { const ALiteral<int32_t>* index = (ALiteral<int32_t>*)(dot->list_ref(2)); List copy; - copy.push_back(dot->head()); + copy.push_back(dot->fst()); copy.push_back(resp_lift(cenv, code, dot->list_ref(1))); copy.push_back(new ALiteral<int32_t>(T_INT32, index->val + 1, Cursor())); // skip RTTI cenv.setTypeSameAs(copy, dot); @@ -79,7 +79,7 @@ lift_def(CEnv& cenv, Code& code, const ATuple* def) throw() assert(def->list_ref(1)->to_symbol()); List copy; - copy.push_back(def->head()); + copy.push_back(def->fst()); copy.push_back(resp_lift(cenv, code, def->list_ref(1))); for (ATuple::const_iterator t = def->iter_at(2); t != def->end(); ++t) copy.push_back(resp_lift(cenv, code, *t)); @@ -100,7 +100,7 @@ static const AST* lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() { List impl; - impl.push_back(fn->head()); + impl.push_back(fn->fst()); const string fnName = cenv.name(fn); const string implNameStr = (fnName != "") @@ -165,7 +165,7 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() implProtT.push_front(tupT); - implT.push_back(type->head()); + implT.push_back(type->fst()); implT.push_back(implProtT.head); implT.push_back(implRetT); @@ -193,7 +193,7 @@ lift_call(CEnv& cenv, Code& code, const ATuple* call) throw() copy.head->loc = call->loc; - const ASymbol* sym = call->head()->to_symbol(); + const ASymbol* sym = call->fst()->to_symbol(); if (sym && !cenv.liftStack.empty() && sym->sym() == cenv.name(cenv.liftStack.top().fn)) { /* Recursive call to innermost function, call implementation directly, * reusing the current "_me" closure parameter (no cons or .). @@ -216,9 +216,9 @@ lift_call(CEnv& cenv, Code& code, const ATuple* call) throw() } else { // Call to a closure, prepend code to access implementation function ATuple* getFn = tup(call->loc, cenv.penv.sym("."), - copy.head->head(), + copy.head->fst(), new ALiteral<int32_t>(T_INT32, 1, Cursor()), NULL); - const ATuple* calleeT = cenv.type(copy.head->head())->as_tuple(); + const ATuple* calleeT = cenv.type(copy.head->fst())->as_tuple(); assert(**calleeT->begin() == *cenv.tenv.Tup); const ATuple* implT = calleeT->list_ref(1)->as_tuple(); copy.push_front(getFn); @@ -233,7 +233,7 @@ static const AST* lift_args(CEnv& cenv, Code& code, const ATuple* call) throw() { List copy; - copy.push_back(call->head()); + copy.push_back(call->fst()); // Lift all arguments for (ATuple::const_iterator i = call->iter_at(1); i != call->end(); ++i) @@ -253,7 +253,7 @@ resp_lift(CEnv& cenv, Code& code, const AST* ast) throw() const ATuple* const call = ast->to_tuple(); if (call) { - const ASymbol* const sym = call->head()->to_symbol(); + const ASymbol* const sym = call->fst()->to_symbol(); const std::string form = sym ? sym->sym() : ""; if (is_primitive(cenv.penv, call)) return lift_args(cenv, code, call); diff --git a/src/llvm.cpp b/src/llvm.cpp index cb2d6c1..3f48dec 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -157,7 +157,7 @@ LLVMEngine::llType(const AST* t) } return PointerType::get(FunctionType::get(llType(retT), cprot, false), 0); - } else if (AType::is_expr(t) && isupper(t->as_tuple()->head()->str()[0])) { + } else if (AType::is_expr(t) && isupper(t->as_tuple()->fst()->str()[0])) { vector<const Type*> ctypes; ctypes.push_back(PointerType::get(Type::getInt8Ty(context), NULL)); // RTTI for (ATuple::const_iterator i = t->as_tuple()->iter_at(1); i != t->as_tuple()->end(); ++i) { @@ -184,7 +184,7 @@ LLVMEngine::compileCall(CEnv& cenv, CFunc f, const ATuple* funcT, const vector<C { vector<Value*> llArgs(*reinterpret_cast<const vector<Value*>*>(&args)); Value* closure = builder.CreateBitCast(llArgs[0], - llType(funcT->prot()->head()), + llType(funcT->prot()->fst()), cenv.penv.gensymstr("you")); llArgs[0] = closure; return builder.CreateCall(llFunc(f), llArgs.begin(), llArgs.end()); @@ -372,7 +372,7 @@ LLVMEngine::compilePrimitive(CEnv& cenv, const ATuple* prim) bool isFloat = cenv.type(prim)->str() == "Float"; Value* a = llVal(resp_compile(cenv, *i++)); Value* b = llVal(resp_compile(cenv, *i++)); - const string n = prim->head()->to_symbol()->str(); + const string n = prim->fst()->to_symbol()->str(); // Binary arithmetic operations Instruction::BinaryOps op = (Instruction::BinaryOps)0; diff --git a/src/resp.cpp b/src/resp.cpp index 9834013..b264850 100644 --- a/src/resp.cpp +++ b/src/resp.cpp @@ -40,7 +40,7 @@ is_form(const AST* ast, const std::string& form) if (!call) return false; - const ASymbol* const sym = call->head()->to_symbol(); + const ASymbol* const sym = call->fst()->to_symbol(); if (!sym) return false; @@ -54,7 +54,7 @@ is_primitive(const PEnv& penv, const AST* ast) if (!call) return false; - const ASymbol* const sym = call->head()->to_symbol(); + const ASymbol* const sym = call->fst()->to_symbol(); if (!sym) return false; diff --git a/src/resp.hpp b/src/resp.hpp index 3c949a0..acf7725 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -205,9 +205,9 @@ struct ATuple : public AST { ATuple(const AST* fst, const ATuple* rst, Cursor c=Cursor()) : AST(T_TUPLE, c), _fst(fst), _rst(rst) {} - const AST* head() const { return _fst; } - const AST* last() const { return _rst; } - bool empty() const { return _fst == 0 && _rst ==0; } + const AST* fst() const { return _fst; } + const ATuple* rst() const { return _rst; } + bool empty() const { return _fst == 0 && _rst ==0; } size_t list_len() const { size_t ret = 0; @@ -232,22 +232,14 @@ struct ATuple : public AST { void last(ATuple* ast) { _rst = ast; } struct const_iterator { - explicit const_iterator(const ATuple* n) : node(n) {} - inline void increment() { - if (node->last()) - node = node->last()->as_tuple(); - else - node = NULL; - } + explicit inline const_iterator(const ATuple* n) : node(n) {} inline const_iterator& operator++() { - assert(node); - increment(); + node = node->rst(); return *this; } inline const_iterator operator++(int) { - assert(node); const const_iterator ret(node); - increment(); + node = node->rst(); return ret; } inline bool operator==(const const_iterator& i) const { @@ -256,7 +248,7 @@ struct ATuple : public AST { inline bool operator!=(const const_iterator& i) const { return !operator==(i); } - const AST* operator*() { return node->head(); } + inline const AST* operator*() { return node->fst(); } const ATuple* node; }; diff --git a/src/simplify.cpp b/src/simplify.cpp index 63b5fd6..0c839f7 100644 --- a/src/simplify.cpp +++ b/src/simplify.cpp @@ -74,7 +74,7 @@ simplify_match(CEnv& cenv, const ATuple* match) throw() const ATuple* pat = (*i++)->as_tuple(); const AST* body = *i++; - const ASymbol* consTag = cenv.penv.sym(pat->head()->str(), pat->head()->loc); + const ASymbol* consTag = cenv.penv.sym(pat->fst()->str(), pat->fst()->loc); const_cast<ASymbol*>(consTag)->tag(T_LITSYM); cenv.setType(consTag, cenv.tenv.named("Symbol")); @@ -166,7 +166,7 @@ resp_simplify(CEnv& cenv, const AST* ast) throw() if (!list) return ast; - const ASymbol* const sym = list->head()->to_symbol(); + const ASymbol* const sym = list->fst()->to_symbol(); const std::string form = sym ? sym->sym() : ""; if (form == "match") |