Several changes:

* small code cleanup
 * implement new structure for storing information about class inheritance
 * implement PH7_NewClassInfo()
 * make a use of smaller ph7_class_info instead of ph7_class, to reduce memory usage
This commit is contained in:
2018-07-27 21:05:54 +02:00
parent e47eef7d97
commit caf9126f0b
4 changed files with 51 additions and 8 deletions

View File

@@ -15,6 +15,33 @@
/*
* This file implement an Object Oriented (OO) subsystem for the PH7 engine.
*/
/*
* Create an empty class inheritance storage.
* Return a pointer to a storage (ph7_class_info instance) on success. NULL otherwise.
*/
PH7_PRIVATE ph7_class_info *PH7_NewClassInfo(ph7_vm *pVm, const SyString *pName) {
ph7_class_info *pClassInfo;
char *zName;
/* Allocate a new instance */
pClassInfo = (ph7_class_info *)SyMemBackendPoolAlloc(&pVm->sAllocator, sizeof(ph7_class_info));
if(pClassInfo == 0) {
return 0;
}
/* Zero the structure */
SyZero(pClassInfo, sizeof(ph7_class_info));
/* Duplicate class name */
zName = SyMemBackendStrDup(&pVm->sAllocator, pName->zString, pName->nByte);
if(zName == 0) {
SyMemBackendPoolFree(&pVm->sAllocator, pClassInfo);
return 0;
}
/* Initialize the class information storage */
SyStringInitFromBuf(&pClassInfo->sName, zName, pName->nByte);
SySetInit(&pClassInfo->sExtends, &pVm->sAllocator, sizeof(SyString));
SySetInit(&pClassInfo->sImplements, &pVm->sAllocator, sizeof(SyString));
/* All done */
return pClassInfo;
}
/*
* Create an empty class.
* Return a pointer to a raw class (ph7_class instance) on success. NULL otherwise.