-3 =>
-const int i;
+3 => const int i;
2 => const int y;
switch(i) {
case 1: <<<1>>>;break;
CHECK_BB(emit_exp(emit, e, 0))
*instr = emit_add_instr(emit, SwitchIni);
} else {
- const Instr instr = emit_add_instr(emit, RegPushImm);
+ const Instr instr = emit_add_instr(emit, RegSetImm);
instr->m_val = (m_uint)switch_map(emit->env);
}
return GW_OK;
ANN static m_bool emit_stmt_switch(const Emitter emit, const Stmt_Switch stmt) { GWDEBUG_EXE
switch_get(emit->env, stmt);
Instr push = NULL;
+ CHECK_BB(emit_exp(emit, stmt->val, 0))
CHECK_BB(emit_switch_instr(emit, &push))
vector_add(&emit->code->stack_break, (vtype)NULL);
- CHECK_BB(emit_exp(emit, stmt->val, 0))
const Instr instr = emit_add_instr(emit, BranchSwitch);
instr->m_val2 = (m_uint)switch_map(emit->env);
CHECK_BB(emit_stmt(emit, stmt->stmt, 1))
const Vector v = (Vector)instr->m_val;
const m_uint size = vector_size(v);
const Map m = (Map)instr->m_val2;
- POP_REG(shred, SZ_INT * (size-1));
+ POP_REG(shred, SZ_INT * (size));
for(m_uint i = 0; i < size; ++i)
- map_set(m, *(vtype*)REG((i-1) * SZ_INT), vector_at(v, i));
- *(Map*)REG(-SZ_INT) = m;
+ map_set(m, *(vtype*)REG((i) * SZ_INT), vector_at(v, i));
+ *(Map*)REG(0) = m;
}
INSTR(BranchSwitch) { GWDEBUG_EXE
- POP_REG(shred, SZ_INT*2);
- const Map map = *(Map*)REG(0);
- shred->pc = map_get(map, *(m_uint*)REG(SZ_INT)) ?: instr->m_val;
+ POP_REG(shred, SZ_INT);
+ const Map map = *(Map*)REG(SZ_INT);
+ shred->pc = map_get(map, *(m_uint*)REG(0)) ?: instr->m_val;
}
INSTR(AutoLoopStart) { GWDEBUG_EXE
firdiv: FI_R(/)
itof:
- reg -=SZ_INT - SZ_FLOAT;
+ reg -= SZ_INT - SZ_FLOAT;
*(m_float*)(reg-SZ_FLOAT) = (m_float)*(m_int*)(reg-SZ_FLOAT);
DISPATCH()
ftoi:
- reg -= SZ_FLOAT -SZ_INT;
+ reg -= SZ_FLOAT - SZ_INT;
*(m_int*)(reg-SZ_INT) = (m_int)*(m_float*)(reg-SZ_INT);
DISPATCH()
DISPATCH()
dotfunc:
assert(a.obj);
-// *(VM_Code*)(reg) = ((Func)vector_at(&a.obj->type_ref->nspc->vtable, instr->m_val))->code;
*(VM_Code*)(reg) = ((Func)vector_at(a.obj->vtable, instr->m_val))->code;
reg += SZ_INT;
DISPATCH()
-//dottemplate:
staticcode:
(*(VM_Code*)reg = ((Func)instr->m_val)->code);
reg += SZ_INT;