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 */
|
||||
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 */
|
||||
if(pNode->pLeft) {
|
||||
if(iVmOp == PH7_OP_CALL) {
|
||||
|
||||
Reference in New Issue
Block a user