ANN static m_bool emit_case_head(const Emitter emit, const Exp base,
const Exp e, const Symbol op, const Vector v) {
CHECK_BB(emit_exp1(emit, base));
-// emit_exp_addref1(emit, base, -exp_size(base));
CHECK_BB(emit_exp1(emit, e));
-// emit_exp_addref1(emit, e, -exp_size(e));
const Exp_Binary bin = {.lhs = base, .rhs = e, .op = op};
- struct Exp_ ebin = {
- .d = {.exp_binary = bin},
- };
+ struct Exp_ ebin = { .d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .pos = e->pos };
struct Op_Import opi = {.op = op,
.lhs = base->type,
.rhs = e->type,
if (!nspc_lookup_value1(emit->env->curr, e->d.prim.d.var)) {
if (!n) {
CHECK_BO(emit_exp(emit, base));
-// emit_exp_addref(emit, base, -exp_totalsize(base));
regpop(emit, base->type->size);
}
CHECK_BO(case_value(emit, base, e));
regpush(emit, SZ_INT);
CHECK_BO(emit_exp(emit, e));
const Exp_Binary bin = {.lhs = base, .rhs = e, .op = insert_symbol("?=")};
- struct Exp_ ebin = {
- .d = {.exp_binary = bin},
- };
+ struct Exp_ ebin = {.d = {.exp_binary = bin}, .pos = e->pos };
struct Op_Import opi = {.op = insert_symbol("?="),
.lhs = base->type,
.rhs = e->type,
}; \
return op_##_name(_data, &opi); \
}
+
static OP_CHECK(opck_deep_eq_any) {
Exp_Binary *bin = data;
bin->op = insert_symbol(env->gwion->st, "==");
- exp_self(bin)->exp_type = ae_exp_binary;
DECL_ON(const Type, t, = check_exp(env, exp_self(bin)));
return t;
}
static OP_CHECK(opck_deep_ne_any) {
Exp_Binary *bin = data;
bin->op = insert_symbol(env->gwion->st, "!=");
- exp_self(bin)->exp_type = ae_exp_binary;
DECL_ON(const Type, t, = check_exp(env, exp_self(bin)));
return t;
}
const m_uint lsz = vector_size(l),
rsz = vector_size(r);
if(lsz && rsz >= lsz) {
+// if(rsz >= lsz) {
for(m_uint i = 0; i < lsz; i++) {
const Value lval = (Value)vector_at(l, i),
rval = (Value)vector_at(r, i);
const Instr instr = emit_add_instr(emit, Reg2Mem);
instr->m_val2 = offset;
d->val->from->offset = instr->m_val = emit_localn(emit, d->val->type);
- d->val->from->loc = d->exp->pos;
}
ANN static void deep_emit_release(const Emitter emit, struct DeepEmit *d) {
ANN static m_bool match_case_exp(const Env env, Exp e) {
Exp last = e;
- for (m_uint i = 0; i < vector_size(&env->scope->match->cond);
- 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)vector_at(&env->scope->match->cond, i);
const Type t = check_exp(env, e);
e->next = next;
CHECK_OB(t);
- Exp_Binary bin = {.lhs = base, .rhs = e, .op = op};
- struct Exp_ ebin = {.d = {.exp_binary = bin}, .exp_type = ae_exp_binary};
+ Exp_Binary bin = {.lhs = cpy_exp(env->gwion->mp, base), .rhs = cpy_exp(env->gwion->mp, e), .op = op};
+ struct Exp_ ebin = {.d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .pos = e->pos };
struct Op_Import opi = {.op = op,
.lhs = base->type,
.rhs = e->type,
.data = (uintptr_t)&ebin.d.exp_binary,
.pos = e->pos};
- CHECK_OB(op_check(env, &opi));
+ traverse_exp(env, &ebin);
+ const Type ret = op_check(env, &opi);
+ if(ebin.exp_type == ae_exp_binary) {
+ free_exp(env->gwion->mp, bin.lhs);
+ free_exp(env->gwion->mp, bin.rhs);
+ }
+ CHECK_OB(ret);
}
}
if (e) ERR_B(e->pos, _("too many expression to match"))