From: Jérémie Astor Date: Sun, 13 Jun 2021 11:14:52 +0000 (+0200) Subject: :art: Improve func calls X-Git-Tag: nightly~597 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=7e6007528f390cad60de5aaf72675fcb5f8ef1a6;p=gwion.git :art: Improve func calls --- diff --git a/src/emit/emit.c b/src/emit/emit.c index 1338094d..d33a0cab 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -138,6 +138,10 @@ ANN static inline m_bool ensure_emit(const Emitter emit, const Type t) { return envset_run(&es, t); } +ANN static inline m_uint emit_code_size(const Emitter emit) { + return vector_size(&emit->code->instr); +} + ANN static void emit_struct_ctor(const Emitter emit, const Type type, const m_uint offset) { emit->code->frame->curr_offset += SZ_INT; const Instr instr = emit_add_instr(emit, RegPushMem4); @@ -158,7 +162,6 @@ ANN static void emit_struct_ctor(const Emitter emit, const Type type, const m_ui const Instr prelude = emit_add_instr(emit, SetCode); prelude->m_val = -SZ_INT*4; prelude->udata.one = 2; -// prelude->udata.two = emit_code_offset(emit) + SZ_INT + sizeof(frame_t); const Instr next = emit_add_instr(emit, Overflow); next->m_val2 = code_offset; emit->code->frame->curr_offset -= SZ_INT; @@ -273,10 +276,6 @@ ANN static inline void emit_push_scope(const Emitter emit) { emit_add_instr(emit, DebugPush); } -ANN static inline m_uint emit_code_size(const Emitter emit) { - return vector_size(&emit->code->instr); -} - ANN m_uint emit_code_offset(const Emitter emit) { return emit->code->frame->curr_offset; } @@ -392,7 +391,6 @@ ANN void emit_ext_ctor(const Emitter emit, const Type t) { const Instr prelude = emit_add_instr(emit, SetCode); prelude->m_val = -SZ_INT * 2; prelude->udata.one = 2; -// prelude->udata.two = emit_code_offset(emit) + SZ_INT + sizeof(frame_t); emit_add_instr(emit, Reg2Mem); const Instr next = emit_add_instr(emit, Overflow); next->m_val2 = offset; @@ -1263,6 +1261,7 @@ ANN static Instr get_prelude(const Emitter emit, const Func f, const bool is_sta const Instr instr = emit_add_instr(emit, Recurs); instr->m_val = SZ_INT; instr->udata.one = 1; + instr->udata.two = emit_code_offset(emit) + sizeof(frame_t); return instr; } @@ -1320,7 +1319,6 @@ ANN static m_bool me_arg(MemoizeEmitter *me) { ANN static Instr emit_call(const Emitter emit, const Func f, const bool is_static) { const Instr prelude = get_prelude(emit, f, is_static); prelude->m_val += -f->def->stack_depth - SZ_INT; - prelude->udata.two = emit_code_offset(emit) + f->def->stack_depth + sizeof(frame_t); 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/lib/array.c b/src/lib/array.c index d9852bb4..9da86cf5 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -711,9 +711,7 @@ ANN static void prepare_run(m_bit *const byte, const f_instr ini, const f_instr *(unsigned*)byte = eOP_MAX; *(f_instr*)(byte + SZ_INT*2) = ini; *(unsigned*)(byte+ BYTECODE_SZ) = eSetCode; -// *(m_uint*)(byte + BYTECODE_SZ + SZ_INT*2) = 3; *(uint16_t*)(byte + BYTECODE_SZ + SZ_INT*2) = 3; -// *(uint16_t*)(byte + BYTECODE_SZ + SZ_INT*2 + sizeof(uint16_t)) = sizeof(frame_t); *(unsigned*)(byte+ BYTECODE_SZ*2) = eOverflow; *(unsigned*)(byte+ BYTECODE_SZ*3) = eOP_MAX; *(f_instr*)(byte + BYTECODE_SZ*3 + SZ_INT*2) = end; diff --git a/src/vm/vm.c b/src/vm/vm.c index ae27350b..26009df8 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -724,12 +724,12 @@ setcode: PRAGMA_PUSH() a.code = *(VM_Code*)(reg - SZ_INT); if(!a.code->builtin) { - register const uint push = *(m_uint*)reg + code->stack_depth + sizeof(frame_t); + register const uint push = *(m_uint*)reg /*+ code->stack_depth*/ + sizeof(frame_t); mem += push; *(frame_t*)(mem - sizeof(frame_t)) = (frame_t){ .code=code, .pc=PC+UVAL, .push=push }; next = eFuncUsrEnd; } else { - mem += *(m_uint*)reg /*- (code->stack_depth + */ /*- sizeof(frame_t)*/; + mem += *(m_uint*)reg; next = eFuncMemberEnd; } PRAGMA_POP() diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index 14b267e3..0438c52a 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -143,7 +143,7 @@ ANN static m_bit* tobytecode(MemPool p, const VM_Code code) { *(m_uint*)(data + SZ_INT) = new_pc; } else if(opcode == eRecurs /*|| opcode == eSetCode*/) { *(uint16_t*)(final + j * BYTECODE_SZ + SZ_INT*2) = - instr->m_val2 += j+1; + instr->udata.one += j + 1; } setpc(data, j); ++j;