Browse Source

Attempt to fix '$this' and '$parent' constructs.

release/v0.1
Rafal Kupiec 1 year ago
parent
commit
5256dda922
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
2 changed files with 19 additions and 5 deletions
  1. +3
    -5
      engine/oop.c
  2. +16
    -0
      engine/vm.c

+ 3
- 5
engine/oop.c View File

@ -260,11 +260,9 @@ PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_vm *pVm, ph7_class *pSub, ph7_class *pBas
continue;
}
/* Install the attribute */
if(pAttr->iProtection != PH7_CLASS_PROT_PRIVATE) {
rc = SyHashInsert(&pSub->hAttr, (const void *)pName->zString, pName->nByte, pAttr);
if(rc != SXRET_OK) {
return rc;
}
rc = SyHashInsert(&pSub->hAttr, (const void *)pName->zString, pName->nByte, pAttr);
if(rc != SXRET_OK) {
return rc;
}
}
SyHashResetLoopCursor(&pBase->hMethod);


+ 16
- 0
engine/vm.c View File

@ -4548,6 +4548,7 @@ static sxi32 VmByteCodeExec(
if(pEntry) {
ph7_vm_func_arg *aFormalArg;
ph7_class_instance *pThis;
ph7_class *pClass;
ph7_value *pFrameStack;
ph7_vm_func *pVmFunc;
ph7_class *pSelf;
@ -4559,6 +4560,7 @@ static sxi32 VmByteCodeExec(
pVmFunc = (ph7_vm_func *)pEntry->pUserData;
pThis = 0;
pSelf = 0;
pClass = 0;
if(pVmFunc->iFlags & VM_FUNC_CLASS_METHOD) {
ph7_class_method *pMeth;
/* Class method call */
@ -4569,6 +4571,16 @@ static sxi32 VmByteCodeExec(
/* Instance already loaded */
pThis = (ph7_class_instance *)pTarget->x.pOther;
pThis->iRef += 2;
pClass = pThis->pClass;
if(pTarget->iFlags & MEMOBJ_PARENTOBJ) {
/* Parent called */
if(pThis->pClass->pBase == 0) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Attempt to call parent class from non-inheritance instance of class '%z'", &pClass->sName);
}
/* Swap to parent class */
pThis->pClass = pThis->pClass->pBase;
}
pSelf = pThis->pClass;
}
if(pSelf == 0) {
@ -4925,6 +4937,10 @@ static sxi32 VmByteCodeExec(
SyMemBackendFree(&pVm->sAllocator, pFrameStack);
/* Leave the frame */
VmLeaveFrame(&(*pVm));
if(pClass != 0) {
/* Restore original class */
pThis->pClass = pClass;
}
if(rc == PH7_ABORT) {
/* Abort processing immediately */
goto Abort;


Loading…
Cancel
Save