From 0078f9d2438a194f7e7bc14b09c2fffffb69ba9b Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 15 Feb 2019 00:32:14 +0100 Subject: [PATCH] :Fix: Operator emit func->code, add instr --- include/instr.h | 3 --- include/opcode.h | 6 ++++-- opcode.txt | 3 ++- src/emit/emit.c | 7 +------ src/lib/instr.c | 10 ---------- src/parse/operator.c | 2 +- src/vm/vm.c | 16 ++++++++++------ 7 files changed, 18 insertions(+), 29 deletions(-) diff --git a/include/instr.h b/include/instr.h index 8b1677be..3b57e578 100644 --- a/include/instr.h +++ b/include/instr.h @@ -34,9 +34,6 @@ INSTR(EOC); INSTR(DTOR_EOC); INSTR(DtorReturn); -INSTR(RegPushMe); -INSTR(RegPushMaybe); - /* branching */ INSTR(BranchSwitch); INSTR(SwitchIni); diff --git a/include/opcode.h b/include/opcode.h index 6af942c7..d7b01b37 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -15,10 +15,11 @@ enum { RegPushBase3, RegPushBase4, RegDup, - MemPushImm, MemSetImm, RegPop, RegPushPtr, + RegPushMe, + RegPushMaybe, FuncReturn, Goto, AllocWord, @@ -169,10 +170,11 @@ enum { #define RegPushBase3 (f_instr)RegPushBase3 #define RegPushBase4 (f_instr)RegPushBase4 #define RegDup (f_instr)RegDup -#define MemPushImm (f_instr)MemPushImm #define MemSetImm (f_instr)MemSetImm #define RegPop (f_instr)RegPop #define RegPushPtr (f_instr)RegPushPtr +#define RegPushMe (f_instr)RegPushMe +#define RegPushMaybe (f_instr)RegPushMaybe #define FuncReturn (f_instr)FuncReturn #define Goto (f_instr)Goto #define AllocWord (f_instr)AllocWord diff --git a/opcode.txt b/opcode.txt index 35ddfcc8..ef5908a0 100644 --- a/opcode.txt +++ b/opcode.txt @@ -12,10 +12,11 @@ RegPushBase2 RegPushBase3 RegPushBase4 RegDup -MemPushImm MemSetImm RegPop RegPushPtr +RegPushMe +RegPushMaybe FuncReturn Goto AllocWord diff --git a/src/emit/emit.c b/src/emit/emit.c index 3546e55a..53093395 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -814,13 +814,8 @@ ANN static m_bool spork_func(const Emitter emit, const Exp_Call* exp) { GWDEBUG_ push_spork_code(emit, SPORK_FUNC_PREFIX, exp->self->pos); if(GET_FLAG(exp->m_func, member)) SET_FLAG(emit->code, member); - const Instr op = emit_add_instr(emit, MemPushImm); - op->m_val = emit->code->stack_depth; -const Instr p = - - emit_add_instr(emit, RegPushImm); + const Instr p = emit_add_instr(emit, RegPushImm); p->m_val = (m_uint)exp->m_func->code; - CHECK_BB(emit_exp_call1(emit, exp->m_func)) const VM_Code code = finalyze(emit); const m_uint size = exp->m_func->def->stack_depth - (GET_FLAG(exp->m_func, diff --git a/src/lib/instr.c b/src/lib/instr.c index 6065c331..8c928f86 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -31,16 +31,6 @@ INSTR(EOC2) { GWDEBUG_EXE shreduler_remove(shred->vm->shreduler, shred, 0); } -INSTR(RegPushMe) { GWDEBUG_EXE - *(M_Object*)REG(0) = shred->me; - PUSH_REG(shred, SZ_INT); -} - -INSTR(RegPushMaybe) { GWDEBUG_EXE - *(m_uint*)REG(0) = gw_rand(shred->vm->rand) > (UINT32_MAX / 2); - PUSH_REG(shred, SZ_INT); -} - /* branching */ INSTR(SwitchIni) { const Vector v = (Vector)instr->m_val; diff --git a/src/parse/operator.c b/src/parse/operator.c index 2c2b7df3..fb59741d 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -173,7 +173,7 @@ ANN m_bool operator_set_func(const struct Op_Import* opi) { ANN static m_bool handle_instr(const Emitter emit, const M_Operator* mo) { if(mo->func) { const Instr instr = emit_add_instr(emit, RegPushImm); - instr->m_val = (m_uint)mo->func; + instr->m_val = (m_uint)mo->func->code; return emit_exp_call1(emit, mo->func); } emit_add_instr(emit, mo->instr); diff --git a/src/vm/vm.c b/src/vm/vm.c index 60a7f7be..a9959861 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -224,8 +224,8 @@ ANN void vm_run(const VM* vm) { &&pushnow, &&baseint, &&basefloat, &&baseother, &&baseaddr, &®dup, - &&mempushimm, &&memsetimm, - &®pop, &®pushptr, + &&memsetimm, + &®pop, &®pushptr, &®pushme, &®pushmaybe, &&funcreturn, &&_goto, &&allocint, &&allocfloat, &&allocother, &&allocaddr, @@ -358,10 +358,6 @@ regdup: *(m_uint*)reg = *(m_uint*)(reg-SZ_INT); reg += SZ_INT; DISPATCH() -mempushimm: - *(m_uint*)mem = instr->m_val; - mem += SZ_INT; - DISPATCH(); memsetimm: *(m_uint*)(mem+instr->m_val) = instr->m_val2; DISPATCH(); @@ -371,6 +367,14 @@ regpop: regpushptr: *(m_uint*)(reg-SZ_INT) = instr->m_val; DISPATCH() +regpushme: + *(M_Object*)reg = shred->me; + reg += SZ_INT; + DISPATCH() +regpushmaybe: + *(m_uint*)reg = gw_rand((uint32_t*)vm->rand) > (UINT32_MAX / 2); + reg += SZ_INT; + DISPATCH(); funcreturn: pc = *(m_uint*)(mem-SZ_INT); code = *(VM_Code*)(mem-SZ_INT*2); -- 2.43.0