diff options
Diffstat (limited to 'src/constrain.cpp')
-rw-r--r-- | src/constrain.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp index 7530f01..a4a1ad3 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -83,6 +83,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"); + THROW_IF(!call->frst()->to_symbol(), call->frst()->loc, "`def' name is not a symbol"); 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); @@ -111,9 +112,7 @@ constrain_def_type(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) 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(sym); + consT.push_back(*i); // FIXME: ensure symbol, or list of symbol } consT.head->loc = exp->loc; type.push_back(consT); @@ -260,14 +259,28 @@ constrain_match(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) } static void +resp_constrain_quoted(TEnv& tenv, Constraints& c, const AST* ast) throw(Error) +{ + switch (ast->tag()) { + case T_SYMBOL: + c.constrain(tenv, ast, tenv.named("Symbol")); + return; + case T_TUPLE: + c.constrain(tenv, ast, tenv.named("List")); + FOREACHP(ATuple::const_iterator, i, ast->as_tuple()) + resp_constrain_quoted(tenv, c, *i); + return; + default: + resp_constrain(tenv, c, ast); + } +} + +static void constrain_quote(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) { THROW_IF(call->list_len() != 2, call->loc, "`quote' requires exactly 1 argument"); - switch (call->list_ref(1)->tag()) { - case T_TUPLE: c.constrain(tenv, call, tenv.named("List")); return; - case T_SYMBOL: c.constrain(tenv, call, tenv.named("Symbol")); return; - default: return; - } + resp_constrain_quoted(tenv, c, call->frst()); + c.constrain(tenv, call, tenv.var(call->frst())); } static void |