Implement nominal class and interface types across declarations and calls
Build / AerScript (push) Successful in 37s

This commit is contained in:
2026-10-29 15:48:44 +01:00
parent 5f75319be9
commit 4f6dd45058
6 changed files with 534 additions and 193 deletions
+12
View File
@@ -618,6 +618,7 @@ struct ph7_value {
} x;
sxi32 iFlags; /* Control flags (see below) */
sxu32 nType; /* Variable data type */
sxu32 nDeclaredType; /* Immutable nominal storage contract, independent of value */
ph7_vm *pVm; /* Virtual machine that own this instance */
SyBlob sBlob; /* String values */
sxu32 nIdx; /* Index number of this entry in the global object allocator */
@@ -640,6 +641,11 @@ struct ph7_value {
#define MEMOBJ_MIXED 0x0200 /* Memory value is mixed */
#define MEMOBJ_HASHMAP 0x0400 /* Memory value is a hashmap aka 'array' in the PHP jargon */
#define MEMOBJ_NULL 0x0800 /* Memory value is NULL */
/* VM-local interned nominal names occupy bits above the value type flags. */
#define MEMOBJ_NAMED 0x7ffff000
#define MEMOBJ_TYPEMASK 0x00000fff
/* NULL and an empty object reference carry no dynamic nominal identity. */
#define MemObjIsNullReference(OBJ) (((OBJ)->nType & MEMOBJ_HASHMAP) == 0 && (((OBJ)->nType & MEMOBJ_NULL) || (((OBJ)->nType & MEMOBJ_OBJ) && (OBJ)->x.pOther == 0)))
/* Mask of all known types */
#define MEMOBJ_ALL (MEMOBJ_STRING|MEMOBJ_INT|MEMOBJ_REAL|MEMOBJ_BOOL|MEMOBJ_NULL|MEMOBJ_HASHMAP|MEMOBJ_OBJ|MEMOBJ_RES|MEMOBJ_CALL|MEMOBJ_CHAR|MEMOBJ_VOID)
/* Scalar variables
@@ -773,6 +779,7 @@ struct ph7_hashmap_node {
* by an instance of the following structure.
*/
struct ph7_hashmap {
sxu32 nDeclaredType; /* Nominal leaf contract, or zero */
ph7_vm *pVm; /* VM that own this instance */
ph7_hashmap_node **apBucket; /* Hash bucket */
ph7_hashmap_node *pFirst; /* First inserted entry */
@@ -1213,6 +1220,7 @@ struct ph7_vm {
ph7_value *aOps; /* Operand stack */
SySet aFreeObj; /* Stack of free memory objects */
SyHash hClass; /* Compiled classes container */
SySet aTypeNames; /* VM-owned interned nominal annotation names */
SyHash hConstant; /* Host-application and user defined constants container */
SyHash hHostFunction; /* Host-application installable functions */
SyHash hFunction; /* Compiled functions */
@@ -1798,6 +1806,10 @@ PH7_PRIVATE void PH7_RegisterHashmapFunctions(ph7_vm *pVm);
PH7_PRIVATE sxi32 PH7_HashmapDump(SyBlob *pOut, ph7_hashmap *pMap, int ShowType, int nTab, int nDepth);
PH7_PRIVATE sxi32 PH7_HashmapWalk(ph7_hashmap *pMap, int (*xWalk)(ph7_value *, ph7_value *, void *), void *pUserData);
PH7_PRIVATE sxi32 PH7_HashmapCast(ph7_value *pObj, sxu32 nType);
PH7_PRIVATE ph7_class *PH7_VmTypeClass(ph7_vm *pVm, sxu32 nType, sxi32 bResolve);
PH7_PRIVATE sxi32 PH7_VmTypeCheck(ph7_value *pValue, sxu32 nType);
PH7_PRIVATE sxi32 PH7_VmRefTypeCompatible(ph7_value *pStorage, sxu32 nType);
PH7_PRIVATE void PH7_MemObjSetDeclaredType(ph7_value *pValue, sxu32 nType);
PH7_PRIVATE int PH7_HashmapValuesToSet(ph7_hashmap *pMap, SySet *pOut);
/* builtin.c function prototypes */
PH7_PRIVATE sxi32 PH7_InputFormat(int (*xConsumer)(ph7_context *, const char *, int, void *),