diff options
author | David Robillard <d@drobilla.net> | 2010-12-27 17:51:29 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-27 17:51:29 +0000 |
commit | 0b014dee824646461b7d402bf9bbcf954ff0eba3 (patch) | |
tree | 6e9da06aad29bc641bbc04e181a32e272cc66af8 /src/constrain.cpp | |
parent | 28e3727290335ee85793795f7ec6d48e050db922 (diff) | |
download | resp-0b014dee824646461b7d402bf9bbcf954ff0eba3.tar.gz resp-0b014dee824646461b7d402bf9bbcf954ff0eba3.tar.bz2 resp-0b014dee824646461b7d402bf9bbcf954ff0eba3.zip |
Kill AType.
git-svn-id: http://svn.drobilla.net/resp/resp@359 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/constrain.cpp')
-rw-r--r-- | src/constrain.cpp | 83 |
1 files changed, 40 insertions, 43 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp index 45fead8..39a0287 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -27,7 +27,7 @@ static void constrain_symbol(TEnv& tenv, Constraints& c, const ASymbol* sym) throw(Error) { - const AType** ref = tenv.ref(sym); + const AST** ref = tenv.ref(sym); THROW_IF(!ref, sym->loc, (format("undefined symbol `%1%'") % sym->sym()).str()); c.constrain(tenv, sym, *ref); } @@ -36,23 +36,23 @@ static void constrain_cons(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { const ASymbol* sym = (*call->begin())->as_symbol(); - const AType* type = NULL; + const AST* type = NULL; for (ATuple::const_iterator i = call->iter_at(1); i != call->end(); ++i) resp_constrain(tenv, c, *i); if (!strcmp(sym->sym(), "Tup")) { - TList tupT(new AType(tenv.Tup, NULL, call->loc)); + List tupT(new ATuple(tenv.Tup, NULL, call->loc)); for (ATuple::const_iterator i = call->iter_at(1); i != call->end(); ++i) { tupT.push_back(tenv.var(*i)); } type = tupT; } else { - const AType** consTRef = tenv.ref(sym); + const AST** consTRef = tenv.ref(sym); THROW_IF(!consTRef, call->loc, (format("call to undefined constructor `%1%'") % sym->sym()).str()); - const AType* consT = *consTRef; - type = new AType(consT->head()->as_type(), 0, call->loc); + const AST* consT = *consTRef; + type = new ATuple(consT->as_tuple()->head(), 0, call->loc); } c.constrain(tenv, call, type); } @@ -61,19 +61,18 @@ static void constrain_dot(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { THROW_IF(call->list_len() != 3, call->loc, "`.' requires exactly 2 arguments"); - ATuple::const_iterator i = call->begin(); - const AST* obj = *++i; - const AST* idx_ast = *++i; - THROW_IF(idx_ast->tag() != T_INT32, call->loc, "the 2nd argument to `.' must be a literal integer"); - const ALiteral<int32_t>* idx = (ALiteral<int32_t>*)idx_ast; + ATuple::const_iterator i = call->begin(); + const AST* obj = *++i; + const AST* idx = *++i; + THROW_IF(idx->tag() != T_INT32, call->loc, "the 2nd argument to `.' must be a literal integer"); resp_constrain(tenv, c, obj); - const AType* retT = tenv.var(call); + const AST* retT = tenv.var(call); c.constrain(tenv, call, retT); - TList objT(new AType(tenv.Tup, NULL, call->loc)); - for (int i = 0; i < idx->val; ++i) + List objT(new ATuple(tenv.Tup, NULL, call->loc)); + for (int i = 0; i < ((ALiteral<int32_t>*)idx)->val; ++i) objT.push_back(tenv.var()); objT.push_back(retT); objT.push_back(tenv.Dots); @@ -88,7 +87,7 @@ constrain_def(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) THROW_IF(!sym, call->loc, "`def' has no symbol") const AST* const body = call->list_ref(2); - const AType* tvar = tenv.var(body); + const AST* tvar = tenv.var(body); tenv.def(sym, tvar); resp_constrain(tenv, c, body); c.constrain(tenv, sym, tvar); @@ -105,16 +104,16 @@ constrain_def_type(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) const ASymbol* sym = (*prot->begin())->as_symbol(); THROW_IF(!sym, (*prot->begin())->loc, "type name is not a symbol"); THROW_IF(tenv.ref(sym), call->loc, "type redefinition"); - TList type(new AType(tenv.U, NULL, call->loc)); + List type(new ATuple(tenv.U, NULL, call->loc)); for (ATuple::const_iterator i = call->iter_at(2); i != call->end(); ++i) { const ATuple* exp = (*i)->as_tuple(); const ASymbol* tag = (*exp->begin())->as_symbol(); - TList consT; - consT.push_back(new AType(sym, AType::NAME)); + List consT; + consT.push_back(sym); for (ATuple::const_iterator i = exp->begin(); i != exp->end(); ++i) { const ASymbol* sym = (*i)->to_symbol(); THROW_IF(!sym, (*i)->loc, "type expression element is not a symbol"); - consT.push_back(new AType(sym, AType::NAME)); + consT.push_back(sym); } consT.head->loc = exp->loc; type.push_back(consT); @@ -129,17 +128,15 @@ constrain_fn(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) set<const ASymbol*> defs; TEnv::Frame frame; - const ATuple* const prot = call->prot(); - // Add parameters to environment frame - TList protT; - for (ATuple::const_iterator i = prot->begin(); i != prot->end(); ++i) { + List protT; + FOREACHP(ATuple::const_iterator, i, call->prot()) { const ASymbol* sym = (*i)->to_symbol(); 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); - const AType* tvar = tenv.fresh(sym); + const AST* tvar = tenv.fresh(sym); frame.push_back(make_pair(sym->sym(), tvar)); protT.push_back(tvar); } @@ -157,7 +154,7 @@ constrain_fn(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) THROW_IF(defs.count(sym) != 0, call->loc, (format("`%1%' defined twice") % sym->str()).str()); defs.insert(sym); - frame.push_back(make_pair(sym->sym(), (AType*)NULL)); + frame.push_back(make_pair(sym->sym(), (AST*)NULL)); } } @@ -169,8 +166,8 @@ constrain_fn(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) resp_constrain(tenv, c, exp); } - const AType* bodyT = tenv.var(exp); - const AType* fnT = tup<const AType>(call->loc, tenv.Fn, protT.head, bodyT, 0); + const AST* bodyT = tenv.var(exp); + const ATuple* fnT = tup(call->loc, tenv.Fn, protT.head, bodyT, 0); Object::pool.addRoot(fnT); tenv.pop(); @@ -185,7 +182,7 @@ constrain_if(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) THROW_IF(call->list_len() % 2 != 0, call->loc, "`if' missing final else clause"); for (ATuple::const_iterator i = call->iter_at(1); i != call->end(); ++i) resp_constrain(tenv, c, *i); - const AType* retT = tenv.var(call); + const AST* retT = tenv.var(call); for (ATuple::const_iterator i = call->iter_at(1); true; ++i) { ATuple::const_iterator next = i; ++next; @@ -215,7 +212,7 @@ constrain_let(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) THROW_IF(val == vars->end(), sym->loc, "`let' variable missing value"); resp_constrain(tenv, c, *val); - const AType* tvar = tenv.var(*val); + const AST* tvar = tenv.var(*val); frame.push_back(make_pair(sym->sym(), tvar)); c.constrain(tenv, sym, tvar); //c.constrain(tenv, *val, tvar); @@ -235,9 +232,9 @@ static void constrain_match(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { THROW_IF(call->list_len() < 5, call->loc, "`match' requires at least 4 arguments"); - const AST* matchee = call->list_ref(1); - const AType* retT = tenv.var(); - const AType* matcheeT = NULL;// = tup<AType>(loc, tenv.U, 0); + const AST* matchee = call->list_ref(1); + const AST* retT = tenv.var(); + const AST* matcheeT = NULL; resp_constrain(tenv, c, matchee); for (ATuple::const_iterator i = call->iter_at(2); i != call->end();) { const AST* exp = *i++; @@ -246,11 +243,11 @@ constrain_match(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) const ASymbol* name = (*pattern->begin())->to_symbol(); THROW_IF(!name, (*pattern->begin())->loc, "pattern does not start with a symbol"); - const AType* consT = *tenv.ref(name); + const AST* consT = *tenv.ref(name); if (!matcheeT) { - const AType* headT = consT->head()->as_type(); - matcheeT = new AType(headT, 0, call->loc); + const AST* headT = consT->as_tuple()->head(); + matcheeT = new ATuple(headT, 0, call->loc); } THROW_IF(i == call->end(), pattern->loc, "missing pattern body"); @@ -270,22 +267,22 @@ constrain_call(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) for (ATuple::const_iterator i = call->begin(); i != call->end(); ++i) resp_constrain(tenv, c, *i); - const AType* fnType = tenv.var(head); - if (fnType->kind != AType::VAR) { + const AST* fnType = tenv.var(head); + if (!AType::is_var(fnType)) { if (!is_form(fnType, "Fn")) throw Error(call->loc, (format("call to non-function `%1%'") % head->str()).str()); - size_t numArgs = fnType->prot()->list_len(); + size_t numArgs = fnType->as_tuple()->prot()->list_len(); THROW_IF(numArgs != call->list_len() - 1, call->loc, (format("expected %1% arguments, got %2%") % numArgs % (call->list_len() - 1)).str()); } - const AType* retT = tenv.var(call); - TList argsT; + const AST* retT = tenv.var(call); + List argsT; for (ATuple::const_iterator i = call->iter_at(1); i != call->end(); ++i) argsT.push_back(tenv.var(*i)); argsT.head->loc = call->loc; - c.constrain(tenv, head, tup<AType>(head->loc, tenv.Fn, argsT.head, retT, 0)); + c.constrain(tenv, head, tup(head->loc, tenv.Fn, argsT.head, retT, 0)); c.constrain(tenv, call, retT); } @@ -312,7 +309,7 @@ constrain_primitive(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) i = call->begin(); - const AType* var = NULL; + const AST* var = NULL; switch (type) { case ARITHMETIC: if (call->list_len() < 3) @@ -382,7 +379,7 @@ resp_constrain(TEnv& tenv, Constraints& c, const AST* ast) throw(Error) { switch (ast->tag()) { case T_UNKNOWN: - case T_TYPE: + case T_TVAR: break; case T_BOOL: c.constrain(tenv, ast, tenv.named("Bool")); |