From e59f6b218ffd75cf7970ea16ad8c66c4235d4b32 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 14 Oct 2009 01:40:27 +0000 Subject: Merge two loops to build parameter types. git-svn-id: http://svn.drobilla.net/resp/tuplr@218 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/constrain.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/constrain.cpp b/src/constrain.cpp index e5349d9..85f3c35 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -70,13 +70,18 @@ AFn::constrain(TEnv& tenv, Constraints& c) const TEnv::Frame frame; // Add parameters to environment frame - for (size_t i = 0; i < prot()->size(); ++i) { - const ASymbol* sym = prot()->at(i)->to(); - THROW_IF(!sym, prot()->at(i)->loc, "parameter name is not a symbol"); - THROW_IF(defs.count(sym) != 0, sym->loc, string("duplicate parameter `") + sym->str() + "'"); + AType* protT = tup(loc, NULL); + for (ATuple::const_iterator i = prot()->begin(); i != prot()->end(); ++i) { + const ASymbol* sym = (*i)->to(); + THROW_IF(!sym, (*i)->loc, "parameter name is not a symbol"); + THROW_IF(defs.count(sym) != 0, sym->loc, + (format("duplicate parameter `%1%'") % sym->str()).str()); defs.insert(sym); - frame.push_back(make_pair(sym, make_pair((AST*)NULL, (AType*)NULL))); + AType* tvar = tenv.fresh(sym); + frame.push_back(make_pair(sym, make_pair((AST*)(*i), tvar))); + protT->push_back(tvar); } + c.push_back(Constraint(tenv.var(at(1)), protT, at(1)->loc)); // Add internal definitions to environment frame size_t e = 2; @@ -85,7 +90,8 @@ AFn::constrain(TEnv& tenv, Constraints& c) const const ADef* def = exp->to(); if (def) { const ASymbol* sym = def->sym(); - THROW_IF(defs.count(sym) != 0, def->loc, (format("`%1%' defined twice") % sym->str()).str()); + THROW_IF(defs.count(sym) != 0, def->loc, + (format("`%1%' defined twice") % sym->str()).str()); defs.insert(def->sym()); frame.push_back(make_pair(def->sym(), make_pair(const_cast(def->at(2)), (AType*)NULL))); @@ -97,17 +103,6 @@ AFn::constrain(TEnv& tenv, Constraints& c) const Constraints cp; cp.push_back(Constraint(tenv.var(this), tenv.var(), loc)); - AType* protT = tup(loc, NULL); - size_t s = 0; - for (ATuple::const_iterator i = prot()->begin(); i != prot()->end(); ++i, ++s) { - AType* tvar = tenv.fresh((*i)->to()); - protT->push_back(tvar); - assert(frame[s].first == (*i)); - frame[s].second.first = (*i); - frame[s].second.second = tvar; - } - c.push_back(Constraint(tenv.var(at(1)), protT, at(1)->loc)); - for (size_t i = 2; i < size(); ++i) at(i)->constrain(tenv, cp); -- cgit v1.2.1