Browse Source

Create a variable only on OP_LOAD.

pull/50/head
Rafal Kupiec 3 years ago
parent
commit
ae0fde152c
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
1 changed files with 20 additions and 17 deletions
  1. +20
    -17
      engine/vm.c

+ 20
- 17
engine/vm.c View File

@ -2355,7 +2355,7 @@ static sxi32 VmByteCodeExec(
break;
}
/*
* LOAD: P1 * P3
* LOAD: * P2 P3
*
* Load a variable where it's name is taken from the top of the stack or
* from the P3 operand.
@ -2383,21 +2383,24 @@ static sxi32 VmByteCodeExec(
pTos++;
}
/* Extract the requested memory object */
pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE, pInstr->iP1 != 1);
if(pObj == 0) {
if(pInstr->iP1) {
/* Variable not found,load NULL */
if(!pInstr->p3) {
PH7_MemObjRelease(pTos);
} else {
MemObjSetType(pTos, MEMOBJ_NULL);
}
pTos->nIdx = SXU32_HIGH; /* Mark as constant */
break;
pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE, FALSE);
if(pInstr->iP2) {
if(pObj) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Redeclaration of ‘$%z’ variable", &sName);
}
if(!pInstr->p3) {
PH7_MemObjRelease(pTos);
} else {
pObj = VmExtractMemObj(&(*pVm), &sName, FALSE, TRUE);
MemObjSetType(pObj, pInstr->iP2);
}
pTos->nIdx = SXU32_HIGH; /* Mark as constant */
break;
} else {
if(pObj == 0) {
/* Fatal error */
PH7_VmMemoryError(&(*pVm));
goto Abort;
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &sName);
}
}
/* Load variable contents */
@ -2719,10 +2722,10 @@ static sxi32 VmByteCodeExec(
SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3));
}
/* Extract the desired variable and if not available dynamically create it */
pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE, TRUE);
pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE, FALSE);
if(pObj == 0) {
PH7_VmMemoryError(&(*pVm));
goto Abort;
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Variable '$%z' undeclared (first use in this method/closure)", &sName);
}
if(!pInstr->p3) {
PH7_MemObjRelease(&pTos[1]);


Loading…
Cancel
Save