diff --git a/engine/memobj.c b/engine/memobj.c index a09407a..18138cd 100644 --- a/engine/memobj.c +++ b/engine/memobj.c @@ -401,7 +401,7 @@ PH7_PRIVATE sxi32 PH7_CheckVarCompat(ph7_value *pObj, int nType) { * destination are of the compatible data types. */ PH7_PRIVATE sxi32 PH7_MemObjSafeStore(ph7_value *pSrc, ph7_value *pDest) { - if(pDest->nType == 0 || ((pDest->nType | MEMOBJ_FIXEDVAL | MEMOBJ_PARENTOBJ) == (pSrc->nType | MEMOBJ_FIXEDVAL | MEMOBJ_PARENTOBJ))) { + if(pDest->nType == 0 || pDest->nType == pSrc->nType) { PH7_MemObjStore(pSrc, pDest); } else if(pDest->nType & MEMOBJ_MIXED) { if(pDest->nType & MEMOBJ_HASHMAP) { diff --git a/engine/vm.c b/engine/vm.c index ad225ed..5819f5d 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -2765,7 +2765,7 @@ static sxi32 VmByteCodeExec( if(pObj == 0) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &sName); - } else if(pObj->iFlags & MEMOBJ_FIXEDVAL) { + } else if(pObj->iFlags != MEMOBJ_VARIABLE) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot re-assign a value of '$%z' statement", &sName); } if(!pInstr->p3) { @@ -4154,7 +4154,7 @@ static sxi32 VmByteCodeExec( pThis = (ph7_class_instance *)pNos->x.pOther; /* Point to the instantiated class */ pClass = pThis->pClass; - if(pNos->iFlags & MEMOBJ_PARENTOBJ) { + if(pNos->iFlags == MEMOBJ_PARENTOBJ) { if(pClass->pBase == 0) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Attempt to call parent class from non-inheritance instance of class '%z'", &pClass->sName); @@ -4175,7 +4175,7 @@ static sxi32 VmByteCodeExec( &pClass->sName, &sName ); } else { - if(pNos->iFlags & MEMOBJ_PARENTOBJ && pMeth->iProtection == PH7_CLASS_PROT_PRIVATE) { + if(pNos->iFlags == MEMOBJ_PARENTOBJ && pMeth->iProtection == PH7_CLASS_PROT_PRIVATE) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Access to the class method '%z->%z()' is forbidden", &pClass->sName, &sName); } @@ -4572,7 +4572,7 @@ static sxi32 VmByteCodeExec( pThis = (ph7_class_instance *)pTarget->x.pOther; pThis->iRef += 2; pClass = pThis->pClass; - if(pTarget->iFlags & MEMOBJ_PARENTOBJ) { + if(pTarget->iFlags == MEMOBJ_PARENTOBJ) { /* Parent called */ if(pThis->pClass->pBase == 0) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, @@ -4648,18 +4648,18 @@ static sxi32 VmByteCodeExec( pObj = VmCreateMemObj(&(*pVm), &sParent, TRUE); if(pObj) { /* Reflect the change */ + pObj->iFlags = MEMOBJ_PARENTOBJ; pObj->x.pOther = pThis; MemObjSetType(pObj, MEMOBJ_OBJ); - pObj->iFlags |= MEMOBJ_FIXEDVAL | MEMOBJ_PARENTOBJ; } /* Install the '$this' variable */ static const SyString sThis = { "this", sizeof("this") - 1 }; pObj = VmCreateMemObj(&(*pVm), &sThis, TRUE); if(pObj) { /* Reflect the change */ + pObj->iFlags = MEMOBJ_THISOBJ; pObj->x.pOther = pThis; MemObjSetType(pObj, MEMOBJ_OBJ); - pObj->iFlags |= MEMOBJ_FIXEDVAL; } } if(SySetUsed(&pVmFunc->aStatic) > 0) { diff --git a/include/ph7int.h b/include/ph7int.h index 7d2cc45..2c3b6cc 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -631,8 +631,10 @@ struct ph7_value { sxu32 nIdx; /* Index number of this entry in the global object allocator */ }; /* Variable control flags */ -#define MEMOBJ_FIXEDVAL 0x1000 /* Memory value is fixed and cannot be modified */ -#define MEMOBJ_PARENTOBJ 0x2000 /* Memory value is a parent object */ +#define MEMOBJ_VARIABLE 0 /* Memory value is variable */ +#define MEMOBJ_BASEOBJ 1 /* Memory value is 'base' object */ +#define MEMOBJ_PARENTOBJ 2 /* Memory value is 'parent' object */ +#define MEMOBJ_THISOBJ 3 /* Memory value is 'this' object */ /* Allowed variable data types. */ #define MEMOBJ_BOOL 0x0001 /* Memory value is a boolean */