From 89f19133d50f83ee216c49991d044e24de510afa Mon Sep 17 00:00:00 2001 From: belliash Date: Tue, 16 Apr 2019 08:14:16 +0200 Subject: [PATCH] Rename VM's jump instructions for better readability. --- engine/compiler.c | 24 ++++++++++++------------ engine/vm.c | 16 ++++++++-------- include/ph7int.h | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/engine/compiler.c b/engine/compiler.c index c079d45..0ea76c8 100644 --- a/engine/compiler.c +++ b/engine/compiler.c @@ -1688,9 +1688,9 @@ static sxi32 PH7_CompileWhile(ph7_gen_state *pGen) { pGen->pIn = &pEnd[1]; pGen->pEnd = pTmp; /* Emit the false jump */ - PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JZ, 0, 0, 0, &nFalseJump); + PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMPZ, 0, 0, 0, &nFalseJump); /* Save the instruction index so we can fix it later when the jump destination is resolved */ - PH7_GenStateNewJumpFixup(pWhileBlock, PH7_OP_JZ, nFalseJump); + PH7_GenStateNewJumpFixup(pWhileBlock, PH7_OP_JMPZ, nFalseJump); /* Compile the loop body */ rc = PH7_CompileBlock(&(*pGen)); if(rc == SXERR_ABORT) { @@ -1820,7 +1820,7 @@ static sxi32 PH7_CompileDoWhile(ph7_gen_state *pGen) { pGen->pIn = &pEnd[1]; pGen->pEnd = pTmp; /* Emit the true jump to the beginning of the loop */ - PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JNZ, 0, pDoBlock->nFirstInstr, 0, 0); + PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMPNZ, 0, pDoBlock->nFirstInstr, 0, 0); /* Fix all jumps now the destination is resolved */ PH7_GenStateFixJumps(pDoBlock, -1, PH7_VmInstrLength(pGen->pVm)); /* Release the loop block */ @@ -1933,9 +1933,9 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen) { return SXERR_ABORT; } else if(rc != SXERR_EMPTY) { /* Emit the false jump */ - PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JZ, 0, 0, 0, &nFalseJump); + PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMPZ, 0, 0, 0, &nFalseJump); /* Save the instruction index so we can fix it later when the jump destination is resolved */ - PH7_GenStateNewJumpFixup(pForBlock, PH7_OP_JZ, nFalseJump); + PH7_GenStateNewJumpFixup(pForBlock, PH7_OP_JMPZ, nFalseJump); } if((pGen->pIn->nType & PH7_TK_SEMI) == 0) { /* Syntax error */ @@ -2327,9 +2327,9 @@ static sxi32 PH7_CompileIf(ph7_gen_state *pGen) { return SXERR_ABORT; } /* Emit the false jump */ - PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JZ, 0, 0, 0, &nJumpIdx); + PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMPZ, 0, 0, 0, &nJumpIdx); /* Save the instruction index so we can fix it later when the jump destination is resolved */ - PH7_GenStateNewJumpFixup(pCondBlock, PH7_OP_JZ, nJumpIdx); + PH7_GenStateNewJumpFixup(pCondBlock, PH7_OP_JMPZ, nJumpIdx); /* Compile the body */ rc = PH7_CompileBlock(&(*pGen)); if(rc == SXERR_ABORT) { @@ -2359,10 +2359,10 @@ static sxi32 PH7_CompileIf(ph7_gen_state *pGen) { /* Synchronize cursors */ pToken = pGen->pIn; /* Fix the false jump */ - PH7_GenStateFixJumps(pCondBlock, PH7_OP_JZ, PH7_VmInstrLength(pGen->pVm)); + PH7_GenStateFixJumps(pCondBlock, PH7_OP_JMPZ, PH7_VmInstrLength(pGen->pVm)); } /* For(;;) */ /* Fix the false jump */ - PH7_GenStateFixJumps(pCondBlock, PH7_OP_JZ, PH7_VmInstrLength(pGen->pVm)); + PH7_GenStateFixJumps(pCondBlock, PH7_OP_JMPZ, PH7_VmInstrLength(pGen->pVm)); if(pGen->pIn < pGen->pEnd && (pGen->pIn->nType & PH7_TK_KEYWORD) && (SX_PTR_TO_INT(pGen->pIn->pUserData) & PH7_KEYWORD_ELSE)) { /* Compile the else block */ @@ -4922,7 +4922,7 @@ static sxi32 PH7_GenStateEmitExprCode( } nJz = nJmp = 0; /* cc -O6 warning */ /* Phase#2: Emit the false jump */ - PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JZ, 0, 0, 0, &nJz); + PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMPZ, 0, 0, 0, &nJz); if(pNode->pLeft) { /* Phase#3: Compile the 'then' expression */ rc = PH7_GenStateEmitExprCode(&(*pGen), pNode->pLeft, iFlags); @@ -5018,10 +5018,10 @@ static sxi32 PH7_GenStateEmitExprCode( if(pNode->pRight) { if(iVmOp == PH7_OP_LAND) { /* Emit the false jump so we can short-circuit the logical and */ - PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JZ, 1/* Keep the value on the stack */, 0, 0, &nJmpIdx); + PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMPZ, 1/* Keep the value on the stack */, 0, 0, &nJmpIdx); } else if(iVmOp == PH7_OP_LOR) { /* Emit the true jump so we can short-circuit the logical or*/ - PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JNZ, 1/* Keep the value on the stack */, 0, 0, &nJmpIdx); + PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMPNZ, 1/* Keep the value on the stack */, 0, 0, &nJmpIdx); } else if(pNode->pOp->iPrec == 18 /* Combined binary operators [i.e: =,'.=','+=',*=' ...] precedence */) { iFlags |= EXPR_FLAG_LOAD_IDX_STORE; } diff --git a/engine/vm.c b/engine/vm.c index 9b26064..978ac30 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -2135,12 +2135,12 @@ static sxi32 VmByteCodeExec( pc = pInstr->iP2 - 1; break; /* - * JZ: P1 P2 * + * JMPZ: P1 P2 * * * Take the jump if the top value is zero (FALSE jump).Pop the top most * entry in the stack if P1 is zero. */ - case PH7_OP_JZ: + case PH7_OP_JMPZ: #ifdef UNTRUST if(pTos < pStack) { goto Abort; @@ -2159,12 +2159,12 @@ static sxi32 VmByteCodeExec( } break; /* - * JNZ: P1 P2 * + * JMPNZ: P1 P2 * * * Take the jump if the top value is not zero (TRUE jump).Pop the top most * entry in the stack if P1 is zero. */ - case PH7_OP_JNZ: + case PH7_OP_JMPNZ: #ifdef UNTRUST if(pTos < pStack) { goto Abort; @@ -5399,11 +5399,11 @@ static const char *VmInstrToString(sxi32 nOp) { case PH7_OP_JMP: zOp = "JMP"; break; - case PH7_OP_JZ: - zOp = "JZ"; + case PH7_OP_JMPZ: + zOp = "JMPZ"; break; - case PH7_OP_JNZ: - zOp = "JNZ"; + case PH7_OP_JMPNZ: + zOp = "JMPNZ"; break; case PH7_OP_POP: zOp = "POP"; diff --git a/include/ph7int.h b/include/ph7int.h index 82272a6..59e8772 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -1397,8 +1397,8 @@ enum ph7_vm_op { PH7_OP_LOAD_CLOSURE, /* Load closure */ PH7_OP_NOOP, /* NOOP */ PH7_OP_JMP, /* Unconditional jump */ - PH7_OP_JZ, /* Jump on zero (FALSE jump) */ - PH7_OP_JNZ, /* Jump on non-zero (TRUE jump) */ + PH7_OP_JMPZ, /* Jump on zero (FALSE jump) */ + PH7_OP_JMPNZ, /* Jump on non-zero (TRUE jump) */ PH7_OP_POP, /* Stack POP */ PH7_OP_CVT_INT, /* Integer cast */ PH7_OP_CVT_STR, /* String cast */