From 58022c8885bc5737402e40e9813372e45169ac66 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 10 Oct 2019 15:12:33 +0200 Subject: [PATCH] :art: Improve VM --- src/emit/emit.c | 3 +-- src/vm/vm.c | 4 ++-- src/vm/vm_code.c | 15 +++------------ tests/sh/import.sh | 2 +- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 5274fbad..ad16f13f 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1688,8 +1688,7 @@ ANN static m_bool emit_member_func(const Emitter emit, const Exp_Dot* member) { const Func f = exp_self(member)->type->e->d.func; if(is_class(emit->gwion, member->t_base) || GET_FLAG(member->base->type, force)) { const Instr func_i = emit_add_instr(emit, f->code ? RegPushImm : PushStaticCode); - if(f->code) - func_i->m_val = (m_uint)(f->code ?: (VM_Code)f); + func_i->m_val = (m_uint)f->code; return GW_OK; } if(f->def->base->tmpl) diff --git a/src/vm/vm.c b/src/vm/vm.c index 55e9c921..b41fbc93 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -54,9 +54,9 @@ uint32_t gw_rand(uint32_t s[2]) { void vm_remove(const VM* vm, const m_uint index) { const Vector v = (Vector)&vm->shreduler->shreds; LOOP_OPTIM - for(m_uint i = vector_size(v) + 1; i--;) { + for(m_uint i = vector_size(v) + 1; --i;) { const VM_Shred sh = (VM_Shred)vector_at(v, i - 1); - if(sh->tick->xid == index) + if(sh && sh->tick->xid == index) Except(sh, "MsgRemove"); } } diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index 597007f5..c9c008e6 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -49,18 +49,9 @@ ANN static m_bit* tobytecode(MemPool p, const VM_Code code) { m_bit *ptr = _mp_malloc(p, sz * BYTECODE_SZ); for(m_uint i= 0; i < sz; ++i) { const Instr instr = (Instr)vector_at(v, i); - if(instr->opcode == ePushStaticCode) { - if(!instr->m_val) { - instr->opcode = eRegPushImm; - instr->m_val = (m_uint)code; - } else { - const Func f = (Func)instr->m_val; - if(f->code) { - instr->opcode = eRegSetImm; - instr->m_val = (m_uint)((Func)instr->m_val)->code; - instr->m_val2 = -SZ_INT; - } - } + if(instr->opcode == ePushStaticCode && !instr->m_val) { + instr->opcode = eRegPushImm; + instr->m_val = (m_uint)code; } if(instr->opcode < eGack) memcpy(ptr + i*BYTECODE_SZ, instr, BYTECODE_SZ); diff --git a/tests/sh/import.sh b/tests/sh/import.sh index bf9653c5..00441d4c 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #37 +# [test] #38 n=0 [ "$1" ] && n="$1" -- 2.43.0