diff options
-rw-r--r-- | src/c.cpp | 2 | ||||
-rw-r--r-- | src/compile.cpp | 7 | ||||
-rw-r--r-- | src/pprint.cpp | 2 | ||||
-rw-r--r-- | src/unify.cpp | 14 |
4 files changed, 11 insertions, 14 deletions
@@ -260,7 +260,7 @@ CEngine::compileIf(CEnv& cenv, AIf* aif) Value* elseV = llVal(aif->last()->compile(cenv)); out += (format("%s = %s;\n}\n") % *varname % *elseV).str(); - for (size_t i = 1; i < (aif->size() - 1) / 2; ++i) + for (size_t i = 1; i < idx / 2; ++i) out += "}"; return varname; diff --git a/src/compile.cpp b/src/compile.cpp index 9a7162f..3918617 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -62,10 +62,9 @@ ACall::compile(CEnv& cenv) CFunc f = c->impls.find(&fnT); THROW_IF(!f, loc, (format("callee failed to compile for type %1%") % fnT.str()).str()); - vector<CVal> args(size() - 1); - const_iterator e = begin() + 1; - for (size_t i = 0; i < args.size(); ++i) - args[i] = (*e++)->compile(cenv); + vector<CVal> args; + for (const_iterator e = begin() + 1; e != end(); ++e) + args.push_back((*e)->compile(cenv)); return cenv.engine()->compileCall(cenv, f, args); } diff --git a/src/pprint.cpp b/src/pprint.cpp index 3f2a5b8..78b13f4 100644 --- a/src/pprint.cpp +++ b/src/pprint.cpp @@ -72,7 +72,7 @@ void pprint_internal(ostream& out, const AST* ast, unsigned indent) { const ATuple* tup = ast->to<const ATuple*>(); - if (tup && tup->size() > 0) { + if (tup && !tup->empty()) { ATuple::const_iterator i = tup->begin() + 1; const string head = tup->head()->str(); const ASymbol* headSym = tup->head()->to<const ASymbol*>(); diff --git a/src/unify.cpp b/src/unify.cpp index 5284bea..92957c0 100644 --- a/src/unify.cpp +++ b/src/unify.cpp @@ -32,7 +32,6 @@ TEnv::buildSubst(AType* genericT, const AType& argsT) // Build substitution to apply to generic type const ATuple* genericProtT = (*(genericT->begin() + 1))->as<const ATuple*>(); - assert(argsT.size() == genericProtT->size()); ATuple::const_iterator g = genericProtT->begin(); AType::const_iterator a = argsT.begin(); for (; a != argsT.end(); ++a, ++g) { @@ -40,7 +39,6 @@ TEnv::buildSubst(AType* genericT, const AType& argsT) AType* callArgT = (*a)->to<AType*>(); if (callArgT->kind == AType::EXPR) { assert(genericArgT->kind == AType::EXPR); - assert(callArgT->size() == genericArgT->size()); ATuple::const_iterator gi = genericArgT->begin(); ATuple::const_iterator ci = callArgT->begin(); for (; gi != genericArgT->end(); ++gi, ++ci) { @@ -125,18 +123,18 @@ unify(const Constraints& constraints) } else if (t->kind == AType::VAR && !s->contains(t)) { cp.replace(t, s); return Subst::compose(unify(cp), Subst(t, s)); - } else if (s->kind == AType::EXPR && s->kind == t->kind && s->size() == t->size()) { + } else if (s->kind == AType::EXPR && t->kind == AType::EXPR) { AType::iterator si = s->begin() + 1; AType::iterator ti = t->begin() + 1; - for (; si != s->end(); ++si, ++ti) { + for (; si != s->end() && ti != t->end(); ++si, ++ti) { AType* st = (*si)->to<AType*>(); AType* tt = (*ti)->to<AType*>(); assert(st && tt); cp.push_back(Constraint(st, tt, st->loc)); } - return unify(cp); - } else { - throw Error(s->loc ? s->loc : t->loc, - (format("type is `%1%' but should be `%2%'") % s->str() % t->str()).str()); + if (si == s->end() && ti == t->end()) + return unify(cp); } + throw Error(s->loc ? s->loc : t->loc, + (format("type is `%1%' but should be `%2%'") % s->str() % t->str()).str()); } |