Get rid of OP_UNUSED and implement additional context frame to resolve scope issue
Some checks failed
Build / AerScript (push) Failing after 28s

This commit is contained in:
2025-08-29 14:32:01 +02:00
parent a167e4bc87
commit 5ff7d03ed1
4 changed files with 63 additions and 55 deletions

View File

@@ -1860,8 +1860,6 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen) {
sxu32 nLine;
sxi32 rc;
nLine = pGen->pIn->nLine;
SyString *pName = NULL;
char *zName = NULL;
/* Jump the 'for' keyword */
pGen->pIn++;
@@ -1881,13 +1879,9 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen) {
pTmp = pGen->pEnd;
pGen->pEnd = pEnd;
sxu32 nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData));
/* Emit the OP_CF_START instruction to enter a context frame */
PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_CF_START, 0, 0, 0, 0);
if(nKey & (PH7_KEYWORD_AUTO | PH7_KEYWORD_TYPEDEF)) {
/* Local for variable, store its name */
pName = &pGen->pIn[2].sData;
zName = SyMemBackendStrDup(&pGen->pVm->sAllocator, pName->zString, pName->nByte);
if(zName == 0) {
PH7_GenCompileError(pGen, E_ERROR, nLine, "PH7 engine is running out-of-memory");
}
/* Compile variable */
PH7_CompileVar(&(*pGen));
}
@@ -1943,6 +1937,10 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen) {
if(rc == SXERR_ABORT) {
return SXERR_ABORT;
}
/* compile the post-expressions if available */
while(pPostStart < pEnd && (pPostStart->nType & PH7_TK_SEMI)) {
pPostStart++;
}
/* Fix post-continue jumps */
if(SySetUsed(&pForBlock->aPostContFix) > 0) {
JumpFixup *aPost;
@@ -1959,10 +1957,6 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen) {
}
}
}
/* compile the post-expressions if available */
while(pPostStart < pEnd && (pPostStart->nType & PH7_TK_SEMI)) {
pPostStart++;
}
if(pPostStart < pEnd) {
SyToken *pTmpIn, *pTmpEnd;
SWAP_DELIMITER(pGen, pPostStart, pEnd);
@@ -1986,13 +1980,10 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen) {
PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_JMP, 0, pForBlock->nFirstInstr, 0, 0);
/* Fix all jumps now the destination is resolved */
PH7_GenStateFixJumps(pForBlock, -1, PH7_VmInstrLength(pGen->pVm));
/* If local for loop variable, unset it */
if(zName != NULL) {
/* Emit instruction to unset the variable after its initialization */
PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_UNSET, 0, 0, (void*)zName, 0);
}
/* Release the loop block */
PH7_GenStateLeaveBlock(pGen, 0);
/* Emit the OP_CF_STOP instruction to leave the context frame */
PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_CF_STOP, 0, 0, 0, 0);
/* Statement successfully compiled */
return SXRET_OK;
}
@@ -2352,7 +2343,7 @@ static sxi32 PH7_CompileReturn(ph7_gen_state *pGen) {
}
}
/* Emit the done instruction */
PH7_VmEmitInstr(pGen->pVm, pGen->pIn->nLine, PH7_OP_DONE, nRet, 0, 0, 0);
PH7_VmEmitInstr(pGen->pVm, pGen->pIn->nLine, PH7_OP_DONE, nRet, 0, (void *)1, 0);
return SXRET_OK;
}
/*