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

@@ -1393,7 +1393,7 @@ static ph7_value *VmExtractMemObj(
}
break;
}
if(pFrame->pParent && pFrame->iFlags & (VM_FRAME_LOOP | VM_FRAME_EXCEPTION | VM_FRAME_CATCH | VM_FRAME_FINALLY)) {
if(pFrame->pParent && pFrame->iFlags & (VM_FRAME_CONTEXT | VM_FRAME_LOOP | VM_FRAME_EXCEPTION | VM_FRAME_CATCH | VM_FRAME_FINALLY)) {
pFrame = pFrame->pParent;
} else {
break;
@@ -1888,7 +1888,7 @@ static sxi32 VmByteCodeExec(
*/
switch(pInstr->iOp) {
/*
* DONE: P1 P2 *
* DONE: P1 P2 P3
*
* Program execution completed: Clean up the mess left behind
* and return immediately.
@@ -1901,16 +1901,20 @@ static sxi32 VmByteCodeExec(
if(pLastRef) {
*pLastRef = pTos->nIdx;
}
/* Ensure we are in active loop. Force abort all loops */
if(pVm->pFrame->iFlags & VM_FRAME_LOOP) {
while((pVm->pFrame->iFlags & VM_FRAME_ACTIVE) == 0) {
/* Ensure we are in active or context frame. Force abort all loops */
if(pInstr->p3) { /* Called from a return statement */
while(pVm->pFrame->pParent && (pVm->pFrame->iFlags & VM_FRAME_ACTIVE) == 0) {
VmLeaveFrame(&(*pVm));
}
} else if(pVm->pFrame->iFlags & VM_FRAME_LOOP) {
while(pVm->pFrame->pParent && (pVm->pFrame->iFlags & (VM_FRAME_ACTIVE | VM_FRAME_CONTEXT)) == 0) {
VmLeaveFrame(&(*pVm));
}
}
if(pResult) {
/* Execution result */
PH7_MemObjStore(pTos, pResult);
if(!pInstr->iP2 && pVm->pFrame->iFlags & VM_FRAME_ACTIVE) {
if(!pInstr->iP2 && pVm->pFrame->iFlags & (VM_FRAME_ACTIVE | VM_FRAME_CONTEXT)) {
ph7_vm_func *pFunc = (ph7_vm_func *)pVm->pFrame->pUserData;
if(pFunc->nType) {
if((pFunc->nType & MEMOBJ_MIXED) == 0) {
@@ -2022,6 +2026,33 @@ static sxi32 VmByteCodeExec(
VmPopOperand(&pTos, 1);
}
break;
/*
* CF_START: * * *
*
* Creates and enters the active context frame.
*/
case PH7_OP_CF_START: {
VmFrame *pFrame = 0;
/* Enter the context frame */
rc = VmEnterFrame(&(*pVm), pVm->pFrame->pUserData, pVm->pFrame->pThis, &pFrame);
if(rc != SXRET_OK) {
PH7_VmMemoryError(&(*pVm));
}
pFrame->iFlags = VM_FRAME_CONTEXT;
break;
}
/*
* CF_STOP: * * *
*
* Leaves and destroys the active context frame.
*/
case PH7_OP_CF_STOP: {
/* Leave the context frame */
if(pVm->pFrame->iFlags & VM_FRAME_CONTEXT) {
VmLeaveFrame(&(*pVm));
}
break;
}
/*
* LF_START: * * *
*
@@ -2292,28 +2323,6 @@ static sxi32 VmByteCodeExec(
}
break;
}
/*
* UNSET: * * P3
*
* Unset a variable. It takes the variable name indexed at P3 operand.
*/
case PH7_OP_UNSET: {
SyString sName;
VmFrame *pFrame = pVm->pFrame;
SyHashEntry *pEntry;
sxu32 nIdx;
SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3));
/* Find variable in local frame */
pEntry = SyHashGet(&pFrame->hVar, (const void *)sName.zString, sName.nByte);
if(pEntry) {
nIdx = (sxu32)SX_PTR_TO_INT(pEntry->pUserData);
/* Delete variable from local frame */
SyHashDeleteEntry(&pFrame->hVar, (const void *)sName.zString, sName.nByte, 0);
/* Call PH7_VmUnsetMemObj to release the variable */
PH7_VmUnsetMemObj(&(*pVm), nIdx, FALSE);
}
break;
}
/*
* LOADC P1 P2 *
*
@@ -2336,8 +2345,8 @@ static sxi32 VmByteCodeExec(
SyHashEntry *pEntry;
/* Candidate for expansion via user defined callbacks */
for(;;) {
pEntry = SyHashGet(&pVm->pFrame->hConst, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
if(pEntry == 0 && pFrame->iFlags & VM_FRAME_LOOP && pFrame->pParent) {
pEntry = SyHashGet(&pFrame->hConst, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
if(pEntry == 0 && pFrame->iFlags & (VM_FRAME_CONTEXT | VM_FRAME_LOOP) && pFrame->pParent) {
pFrame = pFrame->pParent;
} else {
break;