#ifndef __MATCH
#define __MATCH
struct Match_ {
- struct Map_ map;
+ struct Vector_ cond;
struct Vector_ vec;
};
ANN static inline void match_map(struct Match_ * const match, Exp e) {
- const Map map = &match->map;
- map_init(map);
+ const Vector cond = &match->cond;
+ vector_init(cond);
Exp next;
do {
next = e->next;
e->next = NULL;
- map_set(map, (vtype)e, 0);
+ vector_add(cond, (vtype)e);
} while((e = next));
}
ANN static inline void match_unmap(struct Match_ * const match) {
- const Map map = &match->map;
- const vtype sz = map_size(map);
- for(m_uint i = 0; i < sz; ++i) {
- const Exp e = (Exp)VKEY(map, i),
- next = (i < (sz-2)) ? (Exp)VKEY(map, i + 1) : NULL;
+ const Vector cond = &match->cond;
+ const vtype sz = vector_size(cond);
+ for(m_uint i = 0; i < sz -1; ++i) {
+ const Exp e = (Exp)vector_at(cond, i),
+ next = (Exp)vector_at(cond, i + 1);
e->next = next;
}
- map_release(map);
+ vector_release(cond);
}
#define MATCH_INI(scope) \
ANN static m_bool _emit_stmt_match_case(const Emitter emit, const struct Stmt_Match_* stmt,
const Vector v) {
Exp e = stmt->cond;
- const Map map = &emit->env->scope->match->map;
- for(m_uint i = 0; i < map_size(map) && e; e = e->next, ++i) {
- const Exp base = (Exp)VKEY(map, i);
+ const Vector cond = &emit->env->scope->match->cond;
+ for(m_uint i = 0; i < vector_size(cond) && e; e = e->next, ++i) {
+ const Exp base = (Exp)vector_at(cond, i);
const Symbol op = case_op(emit, base, e, v, 0);
if(op != CASE_PASS)
CHECK_BB(emit_case_head(emit, base, e, op, v))
return stmt->val ? check_exp(env, stmt->val) ? 1 : -1 : 1;
}
-ANN static Value match_value(const Env env, const Type base, const Exp_Primary* prim, const m_uint i) {
+ANN static Value match_value(const Env env, const Type base, const Exp_Primary* prim) {
const Symbol sym = prim->d.var;
const Value v = new_value(env->gwion->mp, base, s_name(sym));
set_vflag(v, vflag_valid);
nspc_add_value(env->curr, sym, v);
- VVAL(&env->scope->match->map, i) = (vtype)v;
return v;
}
-ANN static Symbol case_op(const Env env, const Type base, const Exp e, const m_uint i) {
+ANN static Symbol case_op(const Env env, const Type base, const Exp e) {
if(e->exp_type == ae_exp_primary) {
if(e->d.prim.prim_type == ae_prim_id) {
if(e->d.prim.d.var == insert_symbol("_"))
return NULL;
if(!nspc_lookup_value1(env->curr, e->d.prim.d.var)) {
- e->d.prim.value = match_value(env, base, &e->d.prim, i);
+ e->d.prim.value = match_value(env, base, &e->d.prim);
return NULL;
}
}
if(func->d.prim.prim_type == ae_prim_id) {
const Value v= find_value(actual_type(env->gwion, base), func->d.prim.d.var);
if(v) {
- if(!i)
- e->type = v->type;
- case_op(env, v->type, e->d.exp_call.args, i);
+ e->type = v->type;
+ case_op(env, v->type, e->d.exp_call.args);
e->d.exp_call.args->type = v->type;
return NULL;
}
ANN static m_bool match_case_exp(const Env env, Exp e) {
Exp last = e;
- for(m_uint i = 0; i < map_size(&env->scope->match->map); e = e->next, ++i) {
+ for(m_uint i = 0; i < vector_size(&env->scope->match->cond); e = e->next, ++i) {
if(!e)
ERR_B(last->pos, _("no enough to match"))
last = e;
- const Exp base = (Exp)VKEY(&env->scope->match->map, i);
- const Symbol op = case_op(env, base->type, e, i);
+ const Exp base = (Exp)vector_at(&env->scope->match->cond, i);
+ const Symbol op = case_op(env, base->type, e);
if(op) {
const Exp next = e->next;
e->next = NULL;