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
+43 -15
View File
@@ -255,6 +255,34 @@ static sxi32 HashmapGrowBucket(ph7_hashmap *pMap) {
}
return SXRET_OK;
}
/* Both insertion and overwrite must enforce the owning map's leaf contract. */
static sxi32 HashmapStoreNodeValue(ph7_hashmap *pMap, ph7_value *pValue, ph7_value *pDest) {
if(pMap->nDeclaredType) {
sxu32 nType = pMap->nDeclaredType | (pValue ? pValue->nType & MEMOBJ_HASHMAP : 0);
ph7_value sNull;
if((!pValue || MemObjIsNullReference(pValue)) && pDest->nDeclaredType) {
nType = pDest->nDeclaredType;
}
if(!PH7_VmRefTypeCompatible(pDest, nType)) {
PH7_VmThrowError(pMap->pVm, PH7_CTX_ERR, "Cannot insert a value of incompatible type to array");
return SXERR_NOMATCH;
}
if(!pValue) {
PH7_MemObjInit(pMap->pVm, &sNull);
pValue = &sNull;
}
pDest->nDeclaredType = nType;
if(PH7_MemObjSafeStore(pValue, pDest) != SXRET_OK) {
PH7_VmThrowError(pMap->pVm, PH7_CTX_ERR, "Cannot insert a value of incompatible type to array");
return SXERR_NOMATCH;
}
return SXRET_OK;
}
if(pValue) {
return PH7_MemObjStore(pValue, pDest);
}
return PH7_MemObjRelease(pDest);
}
/*
* Insert a 64-bit integer key and it's associated value (if any) in the given
* hashmap.
@@ -280,7 +308,12 @@ static sxi32 HashmapInsertIntKey(ph7_hashmap *pMap, sxi64 iKey, ph7_value *pValu
pValue = (ph7_value *)SySetAt(&pMap->pVm->aMemObj, nValue);
}
/* Duplicate the value */
PH7_MemObjStore(pValue, pObj);
rc = HashmapStoreNodeValue(pMap, pValue, pObj);
if(rc != SXRET_OK) {
return rc;
}
} else if(pMap->nDeclaredType) {
HashmapStoreNodeValue(pMap, 0, pObj);
}
/* Hash the key */
nHash = pMap->xIntHash(iKey);
@@ -327,7 +360,12 @@ static sxi32 HashmapInsertBlobKey(ph7_hashmap *pMap, const void *pKey, sxu32 nKe
pValue = (ph7_value *)SySetAt(&pMap->pVm->aMemObj, nValue);
}
/* Duplicate the value */
PH7_MemObjStore(pValue, pObj);
rc = HashmapStoreNodeValue(pMap, pValue, pObj);
if(rc != SXRET_OK) {
return rc;
}
} else if(pMap->nDeclaredType) {
HashmapStoreNodeValue(pMap, 0, pObj);
}
/* Hash the key */
nHash = pMap->xBlobHash(pKey, nKeyLen);
@@ -529,12 +567,7 @@ static sxi32 HashmapInsert(
ph7_value *pElem;
pElem = (ph7_value *)SySetAt(&pMap->pVm->aMemObj, pNode->nValIdx);
if(pElem) {
if(pVal) {
PH7_MemObjStore(pVal, pElem);
} else {
/* Release the entry */
PH7_MemObjRelease(pElem);
}
return HashmapStoreNodeValue(pMap, pVal, pElem);
}
return SXRET_OK;
}
@@ -553,12 +586,7 @@ IntKey:
ph7_value *pElem;
pElem = (ph7_value *)SySetAt(&pMap->pVm->aMemObj, pNode->nValIdx);
if(pElem) {
if(pVal) {
PH7_MemObjStore(pVal, pElem);
} else {
/* Release the entry */
PH7_MemObjRelease(pElem);
}
return HashmapStoreNodeValue(pMap, pVal, pElem);
}
return SXRET_OK;
}
@@ -3155,7 +3183,7 @@ static int ph7_hashmap_splice(ph7_context *pCtx, int nArg, ph7_value **apArg) {
/* Replace the old node */
pOld = HashmapExtractNodeValue(pCur);
if(pRvalue && pOld) {
PH7_MemObjStore(pRvalue, pOld);
HashmapStoreNodeValue(pSrc, pRvalue, pOld);
}
} else {
/* Unlink the node from the source hashmap */