regpush(emit, SZ_INT *2);
const Instr prelude = emit_add_instr(emit, SetCode);
prelude->m_val2 = 2;
- prelude->m_val = -SZ_INT*3;
+ prelude->m_val = -SZ_INT*4;
const Instr next = emit_add_instr(emit, Overflow);
next->m_val2 = code_offset;
emit->code->frame->curr_offset -= SZ_INT;
regpush(emit, SZ_INT*2);
const Instr prelude = emit_add_instr(emit, SetCode);
prelude->m_val2 = 2;
- prelude->m_val = -SZ_INT;
+ prelude->m_val = -SZ_INT * 2;
emit_add_instr(emit, Reg2Mem);
const Instr next = emit_add_instr(emit, Overflow);
next->m_val2 = offset;
ANN static Instr emit_call(const Emitter emit, const Func f) {
const Instr prelude = get_prelude(emit, f);
- prelude->m_val = -f->def->stack_depth;
+ prelude->m_val = -f->def->stack_depth - SZ_INT;
const m_uint member = vflag(f->value_ref, vflag_member) ? SZ_INT : 0;
if(member) {
const Instr instr = emit_add_instr(emit, Reg2Mem);
break;
setcode:
PRAGMA_PUSH()
- reg -= SZ_INT;
- a.code = *(VM_Code*)reg;
+ a.code = *(VM_Code*)(reg - SZ_INT);
if(!a.code->builtin) {
- register const m_uint push = *(m_uint*)(reg + SZ_INT) + *(m_uint*)(mem-SZ_INT);
+ register const m_uint push = *(m_uint*)reg + *(m_uint*)(mem-SZ_INT);
mem += push;
*(m_uint*) mem = push; mem += SZ_INT;
*(VM_Code*) mem = code; mem += SZ_INT;
*(m_uint*) mem = a.code->stack_depth; mem += SZ_INT;
next = eFuncUsrEnd;
} else {
- mem += *(m_uint*)(reg + SZ_INT);
+ mem += *(m_uint*)reg;
next = eFuncMemberEnd;
}
PRAGMA_POP()
if(opcode != eNoOp) {
m_bit *const base = ptr + i*BYTECODE_SZ,
*const data = final + j*BYTECODE_SZ;
-// if(!isgoto(opcode))
memcpy(data, base, BYTECODE_SZ);
if(isgoto(opcode)) {
m_bit pc = 0;
- for(m_uint k = 0; k < vector_size(&nop); ++k) {
- if(instr->m_val <= vector_at(&nop, k))
+ for(pc = 0; pc < vector_size(&nop); ++pc) {
+ if(instr->m_val <= vector_at(&nop, pc))
break;
- ++pc;
}
*(m_uint*)(data + SZ_INT) = instr->m_val > pc ? instr->m_val - pc : 0;
}
code->ref = 1;
return code;
}
-