Unset local for variable, fixes #62
Some checks failed
Build / AerScript (push) Failing after 26s
Some checks failed
Build / AerScript (push) Failing after 26s
This commit is contained in:
@@ -1860,6 +1860,9 @@ 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++;
|
||||
if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & PH7_TK_LPAREN) == 0) {
|
||||
@@ -1879,6 +1882,13 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen) {
|
||||
pGen->pEnd = pEnd;
|
||||
sxu32 nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData));
|
||||
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));
|
||||
}
|
||||
/* Compile initialization expressions if available */
|
||||
@@ -1976,6 +1986,11 @@ 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);
|
||||
/* Statement successfully compiled */
|
||||
|
Reference in New Issue
Block a user