From 5fb05d4ef700b31f5d7de9e9c287391883d809c1 Mon Sep 17 00:00:00 2001 From: yvan-burrie Date: Thu, 2 Aug 2018 07:41:37 +0200 Subject: [PATCH] Enable classes to inherit or implement built-in classes --- engine/oop.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/engine/oop.c b/engine/oop.c index 4ef6686..18e5f9b 100644 --- a/engine/oop.c +++ b/engine/oop.c @@ -336,6 +336,22 @@ PH7_PRIVATE sxi32 PH7_ClassInterfaceInherit(ph7_class *pSub, ph7_class *pBase) { SyHashEntry *pEntry; SyString *pName; sxi32 rc; + /* Copy flags */ + if( pBase->iFlags & PH7_CLASS_THROWABLE ){ + pSub->iFlags |= PH7_CLASS_THROWABLE; + } + if( pBase->iFlags & PH7_CLASS_ARRAYACCESS ){ + pSub->iFlags |= PH7_CLASS_ARRAYACCESS; + } + if( pBase->iFlags & PH7_CLASS_COUNTABLE ){ + pSub->iFlags |= PH7_CLASS_COUNTABLE; + } + if( pBase->iFlags & PH7_CLASS_TRAVERSE ){ + pSub->iFlags |= PH7_CLASS_TRAVERSE; + } + if( pBase->iFlags & PH7_CLASS_CALLABLE ){ + pSub->iFlags |= PH7_CLASS_CALLABLE; + } /* Install in the derived hashtable */ SyHashInsert(&pBase->hDerived, (const void *)SyStringData(&pSub->sName), SyStringLength(&pSub->sName), pSub); SyHashResetLoopCursor(&pBase->hAttr); @@ -389,6 +405,19 @@ PH7_PRIVATE sxi32 PH7_ClassImplement(ph7_class *pMain, ph7_class *pInterface) { SyHashEntry *pEntry; SyString *pName; sxi32 rc; + /* Copy flags */ + if( pInterface->iFlags & PH7_CLASS_THROWABLE ){ + pMain->iFlags |= PH7_CLASS_THROWABLE; + } + if( pInterface->iFlags & PH7_CLASS_ARRAYACCESS ){ + pMain->iFlags |= PH7_CLASS_ARRAYACCESS; + } + if( pInterface->iFlags & PH7_CLASS_COUNTABLE ){ + pMain->iFlags |= PH7_CLASS_COUNTABLE; + } + if( pInterface->iFlags & PH7_CLASS_TRAVERSE ){ + pMain->iFlags |= PH7_CLASS_TRAVERSE; + } /* First off,copy all constants declared inside the interface */ SyHashResetLoopCursor(&pInterface->hAttr); while((pEntry = SyHashGetNextEntry(&pInterface->hAttr)) != 0) { @@ -821,7 +850,7 @@ PH7_PRIVATE sxi32 PH7_ClassInstanceCmp(ph7_class_instance *pLeft, ph7_class_inst * are identical if and only if they refer to the same instance * of the same class. */ - return !(pLeft == pRight); + return pLeft != pRight; } /* * Attribute comparison.