aboutsummaryrefslogtreecommitdiffstats
path: root/src/constrain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/constrain.cpp')
-rw-r--r--src/constrain.cpp46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp
index fd4e9f4..410df87 100644
--- a/src/constrain.cpp
+++ b/src/constrain.cpp
@@ -41,7 +41,7 @@ constrain_fn(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
// Add parameters to environment frame
TList protT;
for (ATuple::const_iterator i = prot->begin(); i != prot->end(); ++i) {
- const ASymbol* sym = (*i)->to<const ASymbol*>();
+ 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());
@@ -58,9 +58,9 @@ constrain_fn(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
// Add internal definitions to environment frame
for (++i; i != call->end(); ++i) {
const AST* exp = *i;
- const ATuple* call = exp->to<const ATuple*>();
+ const ATuple* call = exp->to_tuple();
if (call && is_form(call, "def")) {
- const ASymbol* sym = call->list_ref(1)->as<const ASymbol*>();
+ const ASymbol* sym = call->list_ref(1)->as_symbol();
THROW_IF(defs.count(sym) != 0, call->loc,
(format("`%1%' defined twice") % sym->str()).str());
defs.insert(sym);
@@ -89,7 +89,7 @@ static void
constrain_def(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
{
THROW_IF(call->list_len() != 3, call->loc, "`def' requires exactly 2 arguments");
- const ASymbol* const sym = call->list_ref(1)->as<const ASymbol*>();
+ const ASymbol* const sym = call->list_ref(1)->as_symbol();
THROW_IF(!sym, call->loc, "`def' has no symbol")
const AST* const body = call->list_ref(2);
@@ -105,19 +105,19 @@ constrain_def_type(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
{
THROW_IF(call->list_len() < 3, call->loc, "`def-type' requires at least 2 arguments");
ATuple::const_iterator i = call->iter_at(1);
- const ATuple* prot = (*i)->to<const ATuple*>();
+ const ATuple* prot = (*i)->to_tuple();
THROW_IF(!prot, (*i)->loc, "first argument of `def-type' is not a tuple");
- const ASymbol* sym = (*prot->begin())->as<const ASymbol*>();
+ 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));
for (ATuple::const_iterator i = call->iter_at(2); i != call->end(); ++i) {
- const ATuple* exp = (*i)->as<const ATuple*>();
- const ASymbol* tag = (*exp->begin())->as<const ASymbol*>();
+ const ATuple* exp = (*i)->as_tuple();
+ const ASymbol* tag = (*exp->begin())->as_symbol();
TList consT;
consT.push_back(new AType(const_cast<ASymbol*>(sym), AType::NAME));
for (ATuple::const_iterator i = exp->begin(); i != exp->end(); ++i) {
- const ASymbol* sym = (*i)->to<const ASymbol*>();
+ const ASymbol* sym = (*i)->to_symbol();
THROW_IF(!sym, (*i)->loc, "type expression element is not a symbol");
consT.push_back(new AType(const_cast<ASymbol*>(sym), AType::NAME));
}
@@ -138,15 +138,15 @@ constrain_match(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
resp_constrain(tenv, c, matchee);
for (ATuple::const_iterator i = call->iter_at(2); i != call->end();) {
const AST* exp = *i++;
- const ATuple* pattern = exp->to<const ATuple*>();
+ const ATuple* pattern = exp->to_tuple();
THROW_IF(!pattern, exp->loc, "pattern expression expected");
- const ASymbol* name = (*pattern->begin())->to<const ASymbol*>();
+ 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);
if (!matcheeT) {
- const AType* headT = consT->head()->as<const AType*>();
+ const AType* headT = consT->head()->as_type();
matcheeT = tup<AType>(call->loc, const_cast<AType*>(headT), 0);
}
@@ -184,7 +184,7 @@ constrain_if(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
static void
constrain_cons(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
{
- const ASymbol* sym = (*call->begin())->as<const ASymbol*>();
+ const ASymbol* sym = (*call->begin())->as_symbol();
const AType* type = NULL;
for (ATuple::const_iterator i = call->iter_at(1); i != call->end(); ++i)
@@ -201,7 +201,7 @@ constrain_cons(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
THROW_IF(!consTRef, call->loc,
(format("call to undefined constructor `%1%'") % sym->cppstr).str());
const AType* consT = *consTRef;
- type = tup<AType>(call->loc, const_cast<AType*>(consT->head()->as<const AType*>()), 0);
+ type = tup<AType>(call->loc, const_cast<AType*>(consT->head()->as_type()), 0);
}
c.constrain(tenv, call, type);
}
@@ -210,10 +210,12 @@ 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 ALiteral<int32_t>* idx = (*++i)->to<const ALiteral<int32_t>*>();
- THROW_IF(!idx, call->loc, "the 2nd argument to `.' must be a literal integer");
+ 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;
+
resp_constrain(tenv, c, obj);
const AType* retT = tenv.var(call);
@@ -266,7 +268,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<const ASymbol*>()->str();
+ const string n = call->head()->to_symbol()->str();
enum { ARITHMETIC, BINARY, LOGICAL, COMPARISON } type;
if (n == "+" || n == "-" || n == "*" || n == "/")
type = ARITHMETIC;
@@ -322,7 +324,7 @@ constrain_primitive(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error)
static void
constrain_tuple(TEnv& tenv, Constraints& c, const ATuple* tup) throw(Error)
{
- const ASymbol* const sym = tup->head()->to<const ASymbol*>();
+ const ASymbol* const sym = tup->head()->to_symbol();
if (!sym) {
constrain_call(tenv, c, tup);
return;
@@ -374,10 +376,10 @@ resp_constrain(TEnv& tenv, Constraints& c, const AST* ast) throw(Error)
c.constrain(tenv, ast, tenv.named("String"));
break;
case T_SYMBOL:
- constrain_symbol(tenv, c, ast->as<const ASymbol*>());
+ constrain_symbol(tenv, c, ast->as_symbol());
break;
case T_TUPLE:
- constrain_tuple(tenv, c, ast->as<const ATuple*>());
+ constrain_tuple(tenv, c, ast->as_tuple());
break;
}
}