ANN m_bool ensure_emit(const Emitter, const Type);
ANN m_bool emit_ensure_func(const Emitter emit, const Func f);
ANN m_bool get_emit_var(const Emitter emit, const Type t, bool is_var);
+
+ANN static inline void emit_regmove(const Emitter emit, const m_uint i) {
+ const Instr instr = emit_add_instr(emit, RegMove);
+ instr->m_val = i;
+}
+
#endif
if (!tflag(type, tflag_struct))
emit_add_instr(emit, ArrayBottom);
else
- regpop(emit, SZ_INT);
- regpop(emit, SZ_INT);
+ emit_regmove(emit, -SZ_INT);
+ emit_regmove(emit, -SZ_INT);
const Instr pc = emit_add_instr(emit, Goto);
pc->m_val = start_index;
top->m_val = emit_code_size(emit);
- regpop(emit, SZ_INT * 3);
+ emit_regmove(emit, -SZ_INT*3);
emit_add_instr(emit, ArrayPost);
return GW_OK;
}
ANN static m_bool emit_prim_array_exp(const Emitter emit, const Type t, Exp e) {
do {
CHECK_BB(emit_exp1(emit, e));
- regpop(emit, t->size - t->actual_size);
+ emit_regmove(emit, - t->size + t->actual_size);
} while((e = e->next));
return GW_OK;
}
init->m_val = int2pow2(count);
init->m_val2 = (m_uint)t;
const m_uint sz = (key->size + val->size + SZ_INT) * count;
- regpop(emit, sz);
+ emit_regmove(emit, -sz);
const Instr ctor = emit_add_instr(emit, dict_lit_ctor);
ctor->m_val = sz;
ctor->m_val2 = count;
regpushi(emit, (m_uint)string);
regpushi(emit, (m_uint)emit->locale->code);
emit_exp_call1(emit, emit->locale, true);
- regpop(emit, emit->locale->def->base->ret_type->size);
+ emit_regmove(emit, -emit->locale->def->base->ret_type->size);
const VM_Code code = finalyze(emit, EOC);
const VM_Shred shred = new_vm_shred(emit->gwion->mp, code);
vm_add_shred(emit->gwion->vm, shred);
emit_add_instr(emit, Assign);
// if(get_depth(var_decl->value->type) && !is_ref)
// (void)emit_object_addref(emit, -SZ_INT, 0);
- regpop(emit, SZ_INT);
+ emit_regmove(emit, -SZ_INT);
return GW_OK;
}
if (!emit_var)
emit_add_instr(emit, Assign);
else {
- regpop(emit, SZ_INT);
+ emit_regmove(emit, -SZ_INT);
const Instr instr = emit_add_instr(emit, Reg2Reg);
instr->m_val = -SZ_INT;
}
value->from->offset = emit_local(emit, value->type);
nspc_add_value(emit->env->curr, arg->var_decl.xid, value);
}
- regpop(emit, f->code->stack_depth);
+ emit_regmove(emit, -f->code->stack_depth);
const Instr cpy = emit_add_instr(emit, Reg2Mem4);
cpy->m_val2 = f->code->stack_depth;
cpy->m_val = start_offset;
CHECK_BB(_emit_exp_call(emit, exp_call));
const Type t = exp_self(exp_call)->type;
if (exp_getvar(e)) {
- regpop(emit, exp_self(exp_call)->type->size);
+ emit_regmove(emit, -exp_self(exp_call)->type->size);
if(isa(t, emit->gwion->type[et_object]) > 0)
emit_local_exp(emit, e);
const Instr instr = emit_add_instr(emit, Reg2RegAddr);
} else {
if (!is_func(emit->gwion, exp_call->func->type) && // is_callable
tflag(e->type, tflag_struct))
- regpop(emit, SZ_INT);
+ emit_regmove(emit, -SZ_INT);
}
// if(isa(e->type, emit->gwion->type[et_object]) > 0)
// emit_local_exp(emit, e);
ANN static inline void pop_exp(const Emitter emit, Exp e) {
const m_uint size = pop_exp_size(e);
- if (size) regpop(emit, size);
+ if (size) emit_regmove(emit, -size);
}
ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp e) {
}
ANN static void emit_exp_spork_finish(const Emitter emit, const m_uint depth) {
- regpop(emit, depth);
+ emit_regmove(emit, -depth);
const Instr spork = emit_add_instr(emit, SporkFunc);
spork->m_val = depth + SZ_INT;
spork->m_val2 = -SZ_INT;
}
}
if(offset) {
- regpop(emit, offset);
+ regpop(emit, offset);// emit_regmove(emit, offset);
const Instr args = emit_add_instr(emit, SporkCode);
args->m_val = offset;
}
if (e->args) {
emit_func_args(emit, e);
const Func f = e->func->type->info->func;
- regpop(emit, f->def->stack_depth);
+ emit_regmove(emit, -f->def->stack_depth);
emit_args(emit, f);
}
emit_add_instr(emit, Goto);
nspc_push_value(emit->gwion->mp, emit->env->curr);
CHECK_BB(emit_exp(emit, stmt->exp)); // add ref?
- regpop(emit, SZ_INT);
+ emit_regmove(emit, -SZ_INT);
if (n) {
unroll_init(emit, n);
idx->m_val2 = -1;
}
CHECK_BB(emit_exp_pop_next(emit, stmt->cond));
- regpop(emit, SZ_INT);
+ emit_regmove(emit, -SZ_INT);
const Instr tomem = emit_add_instr(emit, Reg2Mem);
tomem->m_val = offset + (!stmt->idx ? 0 : SZ_INT);
*index = emit_code_size(emit);
if (!nspc_lookup_value1(emit->env->curr, e->d.prim.d.var)) {
if (!n) {
CHECK_BO(emit_exp(emit, base));
- regpop(emit, base->type->size);
+ emit_regmove(emit, -base->type->size);
}
CHECK_BO(case_value(emit, base, e));
return CASE_PASS;
const Instr instr =
emit_unionmember(emit, v->type->size, false /*emit_addr*/);
instr->m_val = i;
- regpop(emit, v->type->size);
+ emit_regmove(emit, -v->type->size);
case_op(emit, e->d.exp_call.args, e->d.exp_call.args, vec, i + 1);
return CASE_PASS;
}
vmcode_addref(f->code);
return f->code;
} else if (f->def->base->xid == insert_symbol("@gack")) {
- regpop(emit, SZ_INT + f->value_ref->from->owner_class->size);
+ emit_regmove(emit, -SZ_INT - f->value_ref->from->owner_class->size);
const Instr instr = emit_add_instr(emit, RegPushMem);
instr->m_val = SZ_INT;
f->code = finalyze(emit, FuncReturn);
const Instr idx = emit_add_instr(me->emit, RegPushMem4);
idx->m_val = me->offset;
emit_add_instr(me->emit, int_pre_inc);
- regpop(me->emit, SZ_INT);
+ emit_regmove(me->emit, -SZ_INT);
const Instr loop = emit_add_instr(me->emit, Goto);
loop->m_val = pc;
}
ANN static inline m_bool emit_array_shift(const Emitter emit,
const f_instr exec) {
- const Instr pop = emit_add_instr(emit, RegMove);
- pop->m_val = -SZ_INT;
+ emit_regmove(emit, -SZ_INT);
(void)emit_add_instr(emit, exec);
return GW_OK;
}
const Exp_Binary *bin = (Exp_Binary *)data;
if (shift_match(bin->lhs->type, bin->rhs->type))
return emit_array_shift(emit, ArrayConcatRight);
- const Instr pop = emit_add_instr(emit, RegMove);
- pop->m_val = -SZ_INT;
+ emit_regmove(emit, -SZ_INT);
if (isa(bin->lhs->type, emit->gwion->type[et_compound]) > 0)
emit_compound_addref(emit, bin->lhs->type, -SZ_INT*2, false);
(void)emit_add_instr(emit, ArrayAppendFront);
return emit_array_shift(emit, ArrayConcatLeft);
if (isa(bin->rhs->type, emit->gwion->type[et_compound]) > 0)
emit_compound_addref(emit, bin->rhs->type, -SZ_INT, false);
- const Instr pop = emit_add_instr(emit, RegMove);
- pop->m_val = -bin->rhs->type->size;
+ emit_regmove(emit, -bin->rhs->type->size);
emit_add_instr(emit, ArrayAppend);
return GW_OK;
}
}
ANN static void array_loop(const Emitter emit, const m_uint depth) {
- const Instr pre_pop = emit_add_instr(emit, RegMove);
- pre_pop->m_val = -depth * SZ_INT;
+ emit_regmove(emit, -depth * SZ_INT);
for (m_uint i = 0; i < depth - 1; ++i) {
const Instr access = emit_add_instr(emit, ArrayAccess);
access->m_val = i * SZ_INT;
const Instr ex = emit_add_instr(emit, GWOP_EXCEPT);
ex->m_val = -SZ_INT;
}
- const Instr post_pop = emit_add_instr(emit, RegMove);
- post_pop->m_val = -SZ_INT;
+ emit_regmove(emit, -SZ_INT);
const Instr access = emit_add_instr(emit, ArrayAccess);
access->m_val = depth * SZ_INT;
}
emit_add_instr(emit, GWOP_EXCEPT);
}
get->m_val = array->depth * SZ_INT;
- const Instr push = emit_add_instr(emit, RegMove);
- push->m_val = is_var ? SZ_INT : t->size;
+ emit_regmove(emit, is_var ? SZ_INT : t->size);
}
ANN static inline m_bool array_do(const Emitter emit, const Array_Sub array,
};
static void deep_emits_init(const Emitter emit, struct DeepEmits *ds) {
- emit_add_instr(emit, RegMove)->m_val = -SZ_INT;
+ emit_regmove(emit, -SZ_INT);
deep_emit_init(emit, ds->lhs, -SZ_INT);
deep_emit_init(emit, ds->rhs, 0);
vector_init(&ds->acc);
const Instr top = emit_add_instr(emit, Goto);
top->m_val = pc;
ok->m_val = emit_code_size(emit);
- const Instr _pop = emit_add_instr(emit, RegMove);
- _pop->m_val = -SZ_INT;// - key->size;
+ emit_regmove(emit, -SZ_INT);
return GW_OK;
}
if(t == imp->t) {
const Instr cpy = emit_add_instr(emit, Reg2RegOther2); // kind
cpy->m_val2 = SZ_INT;
- const Instr instr = emit_add_instr(emit, RegMove);
- instr->m_val = imp->t->size - SZ_INT;
+ emit_regmove(emit, imp->t->size - SZ_INT);
} else {
- const Instr push = emit_add_instr(emit, RegMove);
- push->m_val = SZ_INT;
+ emit_regmove(emit, SZ_INT);
struct Op_Import opi = {.lhs = t,
.op = insert_symbol(emit->gwion->st, "@implicit"),
.rhs = imp->t};
CHECK_BB(op_emit(emit, &opi));
- const Instr pop = emit_add_instr(emit, RegMove);
- pop->m_val = -SZ_INT;
+ emit_regmove(emit, -SZ_INT);
const Instr cpy = emit_add_instr(emit, Reg2RegOther2); // kind
cpy->m_val = cpy->m_val2 = imp->t->size;
}
if (f->def->base->tmpl) {
if(member->is_call) emit_dottmpl(emit, f);
else {
- if(vflag(f->value_ref, vflag_member)) {
- const Instr instr = emit_add_instr(emit, RegMove);
- instr->m_val = -SZ_INT;
- }
+ if(vflag(f->value_ref, vflag_member))
+ emit_regmove(emit, -SZ_INT);
const Instr instr = emit_add_instr(emit, RegPushImm);
instr->m_val = (m_uint)f;
return;
if (!vflag(f->value_ref, vflag_member))
instr->m_val2 = -SZ_INT;
else {
- if(member->is_call){
- const Instr instr = emit_add_instr(emit, RegMove);
- instr->m_val = SZ_INT;
- } else instr->m_val2 = -SZ_INT;
+ if(member->is_call) emit_regmove(emit, SZ_INT);
+ else instr->m_val2 = -SZ_INT;
}
}
return;
const bool emit_addr) {
const Instr instr = emit_structmember(emit, v->type->size, emit_addr);
instr->m_val = v->from->offset;
- if (!emit_addr) {
- const Instr instr = emit_add_instr(emit, RegMove);
- instr->m_val = v->type->size - SZ_INT;
- }
+ if (!emit_addr) emit_regmove(emit, v->type->size - SZ_INT);
}
ANN m_bool not_from_owner_class(const Env env, const Type t, const Value v,
.rhs = imp->t,
.data = (m_uint)imp};
CHECK_BB(op_emit(emit, &opi));
- const Instr instr = emit_add_instr(emit, RegMove);
- instr->m_val = -imp->e->type->size;
+ emit_regmove(emit, -imp->e->type->size);
exp_setvar(imp->e, true);
imp->e->cast_to = NULL;
return emit_exp(emit, imp->e);
.rhs = base,
.data = (m_uint)&cast};
CHECK_BB(op_emit(emit, &opi));
- const Instr instr = emit_add_instr(emit, RegMove);
- instr->m_val = -imp->e->type->size;
+ emit_regmove(emit, -imp->e->type->size);
exp_setvar(imp->e, true);
imp->e->cast_to = NULL;
emit_exp(emit, imp->e);
}
static OP_EMIT(opem_none) {
- const Instr instr = emit_add_instr(emit, RegMove);
- instr->m_val = -SZ_INT;
+ emit_regmove(emit, -SZ_INT);
return GW_OK;
}
const Instr instr = emit_add_instr(emit, Reg2RegOther);
instr->m_val = -(t->size + SZ_INT);
instr->m_val2 = t->size;
- const Instr pop = emit_add_instr(emit, RegMove);
- pop->m_val = -SZ_INT;
+ emit_regmove(emit, -SZ_INT);
}
emit_struct_addref(emit, t, 0, false);
return GW_OK;