From d4b19e00b62bf9dc232af8231c0b24dae2634329 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 1 Mar 2020 19:04:45 +0100 Subject: [PATCH] :art: VM clean --- include/opcode.h | 8 -------- opcode.txt | 4 ---- src/vm/vm.c | 35 ++++++++++++++--------------------- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/include/opcode.h b/include/opcode.h index 7d0df98b..e85a433d 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -118,15 +118,11 @@ enum { eCastF2I, eTime_Advance, eSetCode, - eFuncPtr, - eFuncMember, - eFuncUsr, eRegPop, eRegPush, eReg2Mem, eReg2Mem4, eOverflow, - eNext, eFuncUsrEnd, eFuncMemberEnd, eSporkIni, @@ -295,15 +291,11 @@ enum { #define CastF2I (f_instr)eCastF2I #define Time_Advance (f_instr)eTime_Advance #define SetCode (f_instr)eSetCode -#define FuncPtr (f_instr)eFuncPtr -#define FuncMember (f_instr)eFuncMember -#define FuncUsr (f_instr)eFuncUsr #define RegPop (f_instr)eRegPop #define RegPush (f_instr)eRegPush #define Reg2Mem (f_instr)eReg2Mem #define Reg2Mem4 (f_instr)eReg2Mem4 #define Overflow (f_instr)eOverflow -#define Next (f_instr)eNext #define FuncUsrEnd (f_instr)eFuncUsrEnd #define FuncMemberEnd (f_instr)eFuncMemberEnd #define SporkIni (f_instr)eSporkIni diff --git a/opcode.txt b/opcode.txt index db75fbd5..2c401589 100644 --- a/opcode.txt +++ b/opcode.txt @@ -115,15 +115,11 @@ CastI2F CastF2I Time_Advance SetCode -FuncPtr -FuncMember -FuncUsr RegPop RegPush Reg2Mem Reg2Mem4 Overflow -Next FuncUsrEnd FuncMemberEnd SporkIni diff --git a/src/vm/vm.c b/src/vm/vm.c index b6be206b..fdc31543 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -330,8 +330,8 @@ ANN void vm_run(const VM* vm) { // lgtm [cpp/use-of-goto] &&firassign, &&firadd, &&firsub, &&firmul, &&firdiv, &&itof, &&ftoi, &&timeadv, - &&setcode, &&funcptr, &&funcmember, - &&funcusr, &®pop, &®push, &®tomem, &®tomemother, &&overflow, &&next, &&funcusrend, &&funcmemberend, + &&setcode, + &®pop, &®push, &®tomem, &®tomemother, &&overflow, &&funcusrend, &&funcmemberend, &&sporkini, &&sporkfunc, &&sporkmemberfptr, &&sporkexp, &&forkend, &&sporkend, &&brancheqint, &&branchneint, &&brancheqfloat, &&branchnefloat, &&arrayappend, &&autoloop, &&autoloopptr, &&autoloopcount, &&arraytop, &&arrayaccess, &&arrayget, &&arrayaddr, &&arrayvalid, @@ -603,28 +603,22 @@ timeadv: VM_OUT break; setcode: - a.code = *(VM_Code*)(reg-SZ_INT); -funcptr: PRAGMA_PUSH() reg -= SZ_INT; a.code = *(VM_Code*)reg; - if(!GET_FLAG((VM_Code)a.code, builtin)) - goto funcusr; + if(!GET_FLAG((VM_Code)a.code, builtin)) { + register const m_uint push = *(m_uint*)(reg + SZ_INT) + *(m_uint*)(mem-SZ_INT); + mem += push; + *(m_uint*) mem = push;mem += SZ_INT; + *(VM_Code*) mem = code; mem += SZ_INT; + *(m_uint*) mem = PC + VAL2; mem += SZ_INT; + *(m_uint*) mem = a.code->stack_depth; mem += SZ_INT; + next = eFuncUsrEnd; + } else { + mem += *(m_uint*)(reg + SZ_INT); + next = eFuncMemberEnd; + } PRAGMA_POP() -funcmember: - mem += *(m_uint*)(reg + SZ_INT); - next = eFuncMemberEnd; - goto regpop; -funcusr: -{ - register const m_uint push = *(m_uint*)(reg + SZ_INT) + *(m_uint*)(mem-SZ_INT); - mem += push; - *(m_uint*) mem = push;mem += SZ_INT; - *(VM_Code*) mem = code; mem += SZ_INT; - *(m_uint*) mem = PC + VAL2; mem += SZ_INT; - *(m_uint*) mem = a.code->stack_depth; mem += SZ_INT; - next = eFuncUsrEnd; -} regpop: reg -= VAL; DISPATCH(); @@ -643,7 +637,6 @@ overflow: exception(shred, "StackOverflow"); continue; } -next: PRAGMA_PUSH() goto *dispatch[next]; PRAGMA_POP() -- 2.43.0