aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-10-14 01:40:27 +0000
committerDavid Robillard <d@drobilla.net>2009-10-14 01:40:27 +0000
commite59f6b218ffd75cf7970ea16ad8c66c4235d4b32 (patch)
tree32b36399db6492c839fcc6b766b839c7b452fba9
parent06682a84535d061fcc2eb50ab81b61ae204ae375 (diff)
downloadresp-e59f6b218ffd75cf7970ea16ad8c66c4235d4b32.tar.gz
resp-e59f6b218ffd75cf7970ea16ad8c66c4235d4b32.tar.bz2
resp-e59f6b218ffd75cf7970ea16ad8c66c4235d4b32.zip
Merge two loops to build parameter types.
git-svn-id: http://svn.drobilla.net/resp/tuplr@218 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r--src/constrain.cpp29
1 files 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<const ASymbol*>();
- 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<AType>(loc, NULL);
+ for (ATuple::const_iterator i = prot()->begin(); i != prot()->end(); ++i) {
+ const ASymbol* sym = (*i)->to<const ASymbol*>();
+ 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<const ADef*>();
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<AST*>(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<AType>(loc, NULL);
- size_t s = 0;
- for (ATuple::const_iterator i = prot()->begin(); i != prot()->end(); ++i, ++s) {
- AType* tvar = tenv.fresh((*i)->to<ASymbol*>());
- 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);