Implement short-circuit evaluation for the null coalescing operator
Build / AerScript (push) Successful in 40s
Build / AerScript (push) Successful in 40s
This commit is contained in:
@@ -4648,6 +4648,25 @@ static sxi32 PH7_GenStateEmitExprCode(
|
|||||||
/* All done */
|
/* All done */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
if(iVmOp == PH7_OP_NULLC) {
|
||||||
|
/* The parser stores the source LHS in pRight for this right-associative operator. */
|
||||||
|
rc = PH7_GenStateEmitExprCode(&(*pGen), pNode->pRight, iFlags);
|
||||||
|
if(rc != SXRET_OK) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
/* Preserve a non-empty LHS without converting it to boolean. */
|
||||||
|
PH7_VmEmitInstr(pGen->pVm, pGen->pIn->nLine, PH7_OP_JMPNZ, 2, 0, 0, &nJmpIdx);
|
||||||
|
PH7_VmEmitInstr(pGen->pVm, pGen->pIn->nLine, PH7_OP_POP, 1, 0, 0, 0);
|
||||||
|
rc = PH7_GenStateEmitExprCode(&(*pGen), pNode->pLeft, iFlags);
|
||||||
|
if(rc != SXRET_OK) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
pInstr = PH7_VmGetInstr(pGen->pVm, nJmpIdx);
|
||||||
|
if(pInstr) {
|
||||||
|
pInstr->iP2 = PH7_VmInstrLength(pGen->pVm);
|
||||||
|
}
|
||||||
|
return SXRET_OK;
|
||||||
|
}
|
||||||
/* Generate code for the left tree */
|
/* Generate code for the left tree */
|
||||||
if(pNode->pLeft) {
|
if(pNode->pLeft) {
|
||||||
if(iVmOp == PH7_OP_CALL) {
|
if(iVmOp == PH7_OP_CALL) {
|
||||||
|
|||||||
@@ -2344,11 +2344,18 @@ static sxi32 VmByteCodeExec(
|
|||||||
*
|
*
|
||||||
* Take the jump if the top value is not zero (TRUE jump).Pop the top most
|
* Take the jump if the top value is not zero (TRUE jump).Pop the top most
|
||||||
* entry in the stack if P1 is zero.
|
* entry in the stack if P1 is zero.
|
||||||
|
* If P1 is 2, test for a non-empty value without converting or popping it.
|
||||||
*/
|
*/
|
||||||
case PH7_OP_JMPNZ:
|
case PH7_OP_JMPNZ:
|
||||||
if(pTos < pStack) {
|
if(pTos < pStack) {
|
||||||
goto Abort;
|
goto Abort;
|
||||||
}
|
}
|
||||||
|
if(pInstr->iP1 == 2) {
|
||||||
|
if(!PH7_MemObjIsNull(pTos)) {
|
||||||
|
pc = pInstr->iP2 - 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
/* Get a boolean value */
|
/* Get a boolean value */
|
||||||
if((pTos->nType & MEMOBJ_BOOL) == 0) {
|
if((pTos->nType & MEMOBJ_BOOL) == 0) {
|
||||||
PH7_MemObjToBool(pTos);
|
PH7_MemObjToBool(pTos);
|
||||||
|
|||||||
Reference in New Issue
Block a user