diff --git a/engine/compiler.c b/engine/compiler.c index 5026716..ff6ddf3 100644 --- a/engine/compiler.c +++ b/engine/compiler.c @@ -3359,7 +3359,7 @@ loop: } pGen->pIn++; /* Jump the equal sign */ /* Allocate a new class attribute */ - pCons = PH7_NewClassAttr(pGen->pVm, pName, nLine, iProtection, iFlags); + pCons = PH7_NewClassAttr(pGen->pVm, pName, nLine, iProtection, iFlags, 0); if(pCons == 0) { PH7_GenCompileError(pGen, E_ERROR, nLine, "Fatal, PH7 is running out of memory"); return SXERR_ABORT; @@ -3438,7 +3438,7 @@ Synchronize: * Refer to the official documentation for more information on the powerful extension * introduced by the PH7 engine to the OO subsystem. */ -static sxi32 PH7_GenStateCompileClassAttr(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, ph7_class *pClass) { +static sxi32 PH7_GenStateCompileClassAttr(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, sxu32 nType, ph7_class *pClass) { sxu32 nLine = pGen->pIn->nLine; ph7_class_attr *pAttr; SyString *pName; @@ -3470,7 +3470,7 @@ loop: goto Synchronize; } /* Allocate a new class attribute */ - pAttr = PH7_NewClassAttr(pGen->pVm, pName, nLine, iProtection, iFlags); + pAttr = PH7_NewClassAttr(pGen->pVm, pName, nLine, iProtection, iFlags, nType); if(pAttr == 0) { PH7_GenCompileError(pGen, E_ERROR, nLine, "Fatal, PH7 engine is running out of memory"); return SXERR_ABORT; @@ -4286,7 +4286,7 @@ static sxi32 PH7_GenStateCompileClass(ph7_gen_state *pGen, sxi32 iFlags) { } if(pGen->pIn->nType & PH7_TK_DOLLAR/*'$'*/) { /* Attribute declaration */ - rc = PH7_GenStateCompileClassAttr(&(*pGen), iProtection, iAttrflags, pClass); + rc = PH7_GenStateCompileClassAttr(&(*pGen), iProtection, iAttrflags, nType, pClass); } else { /* Process method declaration */ rc = PH7_GenStateCompileClassMethod(&(*pGen), nType, iProtection, iAttrflags, TRUE, pClass); diff --git a/engine/oop.c b/engine/oop.c index bcc7c7c..25693f1 100644 --- a/engine/oop.c +++ b/engine/oop.c @@ -75,7 +75,7 @@ PH7_PRIVATE ph7_class *PH7_NewRawClass(ph7_vm *pVm, const SyString *pName) { * Allocate and initialize a new class attribute. * Return a pointer to the class attribute on success. NULL otherwise. */ -PH7_PRIVATE ph7_class_attr *PH7_NewClassAttr(ph7_vm *pVm, const SyString *pName, sxu32 nLine, sxi32 iProtection, sxi32 iFlags) { +PH7_PRIVATE ph7_class_attr *PH7_NewClassAttr(ph7_vm *pVm, const SyString *pName, sxu32 nLine, sxi32 iProtection, sxi32 iFlags, sxu32 nType) { ph7_class_attr *pAttr; char *zName; pAttr = (ph7_class_attr *)SyMemBackendPoolAlloc(&pVm->sAllocator, sizeof(ph7_class_attr)); @@ -96,6 +96,7 @@ PH7_PRIVATE ph7_class_attr *PH7_NewClassAttr(ph7_vm *pVm, const SyString *pName, pAttr->iProtection = iProtection; pAttr->nIdx = SXU32_HIGH; pAttr->iFlags = iFlags; + pAttr->nType = nType; pAttr->nLine = nLine; return pAttr; } diff --git a/engine/vm.c b/engine/vm.c index 27fc93d..e375f83 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -695,6 +695,7 @@ PH7_PRIVATE sxi32 PH7_VmCreateClassInstanceFrame( SyMemBackendPoolFree(&pVm->sAllocator, pVmAttr); return SXERR_MEM; } + MemObjSetType(pMemObj, pAttr->nType); pVmAttr->nIdx = pMemObj->nIdx; if(SySetUsed(&pAttr->aByteCode) > 0) { /* Initialize attribute default value (any complex expression) */ diff --git a/include/compiler.h b/include/compiler.h index a545ebc..099d227 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -128,7 +128,7 @@ static sxi32 PH7_GenStateCompileFunc(ph7_gen_state *pGen, SyString *pName, sxi32 static sxi32 PH7_CompileFunction(ph7_gen_state *pGen); static sxi32 PH7_GetProtectionLevel(sxi32 nKeyword); static sxi32 PH7_GenStateCompileClassConstant(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, ph7_class *pClass); -static sxi32 PH7_GenStateCompileClassAttr(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, ph7_class *pClass); +static sxi32 PH7_GenStateCompileClassAttr(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, sxu32 nType, ph7_class *pClass); static sxi32 PH7_GenStateCompileClassMethod(ph7_gen_state *pGen, sxu32 nType, sxi32 iProtection, sxi32 iFlags, int doBody, ph7_class *pClass); static sxi32 PH7_CompileClassInterface(ph7_gen_state *pGen); static sxi32 PH7_GenStateCompileClass(ph7_gen_state *pGen, sxi32 iFlags); diff --git a/include/ph7int.h b/include/ph7int.h index 808a986..8baa177 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -1075,6 +1075,7 @@ struct ph7_class_attr { sxi32 iFlags; /* Attribute configuration [i.e: static, variable, constant, etc.] */ sxi32 iProtection; /* Protection level [i.e: public, private, protected] */ SySet aByteCode; /* Compiled attribute body */ + sxu32 nType; /* Class attribute data type */ sxu32 nIdx; /* Attribute index */ sxu32 nLine; /* Line number on which this attribute was defined */ }; @@ -1763,7 +1764,7 @@ PH7_PRIVATE sxi32 PH7_ParseIniString(ph7_context *pCtx, const char *zIn, sxu32 n /* oo.c function prototypes */ PH7_PRIVATE ph7_class_info *PH7_NewClassInfo(ph7_vm *pVm, const SyString *pName); PH7_PRIVATE ph7_class *PH7_NewRawClass(ph7_vm *pVm, const SyString *pName); -PH7_PRIVATE ph7_class_attr *PH7_NewClassAttr(ph7_vm *pVm, const SyString *pName, sxu32 nLine, sxi32 iProtection, sxi32 iFlags); +PH7_PRIVATE ph7_class_attr *PH7_NewClassAttr(ph7_vm *pVm, const SyString *pName, sxu32 nLine, sxi32 iProtection, sxi32 iFlags, sxu32 nType); PH7_PRIVATE ph7_class_method *PH7_NewClassMethod(ph7_vm *pVm, ph7_class *pClass, const SyString *pName, sxu32 nLine, sxi32 iProtection, sxi32 iFlags, sxi32 iFuncFlags); PH7_PRIVATE ph7_class_method *PH7_ClassExtractMethod(ph7_class *pClass, const char *zName, sxu32 nByte);