From e4ab5974fa36ea2d32d3713b07aea1620549c8db Mon Sep 17 00:00:00 2001 From: belliash Date: Tue, 7 Aug 2018 07:47:25 +0200 Subject: [PATCH] Let the compiler use OP_ADD instead of OP_CAT --- engine/compiler.c | 2 +- engine/vm.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/engine/compiler.c b/engine/compiler.c index da88418..cf63200 100644 --- a/engine/compiler.c +++ b/engine/compiler.c @@ -778,7 +778,7 @@ static sxi32 GenStateCompileString(ph7_gen_state *pGen) { }/*for(;;)*/ if(iCons > 1) { /* Concatenate all compiled constants */ - PH7_VmEmitInstr(pGen->pVm, PH7_OP_CAT, iCons, 0, 0, 0); + PH7_VmEmitInstr(pGen->pVm, PH7_OP_ADD, iCons, 1, 0, 0); } /* Node successfully compiled */ return SXRET_OK; diff --git a/engine/vm.c b/engine/vm.c index aec76c4..1b48aa5 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -3394,19 +3394,24 @@ static sxi32 VmByteCodeExec( VmPopOperand(&pTos, 1); break; } - /* OP_ADD * * * + /* OP_ADD P1 P2 * * * Pop the top two elements from the stack, add them together, * and push the result back onto the stack. */ case PH7_OP_ADD: { - ph7_value *pNos = &pTos[-1]; + ph7_value *pNos; + if(pInstr->iP1 < 1) { + pNos = &pTos[-1]; + } else { + pNos = &pTos[-pInstr->iP1 + 1]; + } #ifdef UNTRUST if(pNos < pStack) { goto Abort; } #endif - if(pNos->iFlags & MEMOBJ_STRING || pTos->iFlags & MEMOBJ_STRING) { + if(pInstr->iP2 || pNos->iFlags & MEMOBJ_STRING || pTos->iFlags & MEMOBJ_STRING) { /* Perform the string addition */ ph7_value *pCur; if((pNos->iFlags & MEMOBJ_STRING) == 0) {