From a65763c62f650471d906e1b5973564c26b17019b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 30 Dec 2020 13:44:05 +0100 Subject: [PATCH] :art: Cleaning --- src/emit/emit.c | 6 +++--- src/vm/vm.c | 7 +++---- src/vm/vm_code.c | 7 ++----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index d4d1a2c6..ec0d441c 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -131,7 +131,7 @@ ANN static void emit_struct_ctor(const Emitter emit, const Type type, const m_ui 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; @@ -328,7 +328,7 @@ ANN void emit_ext_ctor(const Emitter emit, const Type t) { 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; @@ -1154,7 +1154,7 @@ ANN static m_bool me_arg(MemoizeEmitter *me) { 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); diff --git a/src/vm/vm.c b/src/vm/vm.c index e12d49f8..c84c024f 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -616,10 +616,9 @@ timeadv: 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; @@ -627,7 +626,7 @@ PRAGMA_PUSH() *(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() diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index c5180e4f..21b3acc3 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -100,14 +100,12 @@ ANN static m_bit* tobytecode(MemPool p, const VM_Code code) { 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; } @@ -133,4 +131,3 @@ VM_Code new_vmcode(MemPool p, const Vector instr, const m_uint stack_depth, code->ref = 1; return code; } - -- 2.43.0