Extend native class API to support full AerScript declarations
Build / AerScript (push) Successful in 18s
Build / AerScript (push) Successful in 18s
This commit is contained in:
+58
-12
@@ -101,6 +101,10 @@ static sxi32 MemObjCallClassCastMethod(
|
||||
ph7_value *pResult /* OUT: Store the return value of the magic method here */
|
||||
) {
|
||||
ph7_class_method *pMethod = 0;
|
||||
sxi32 rc;
|
||||
if(pVm->iPendingTransfer) {
|
||||
return pVm->iPendingTransfer;
|
||||
}
|
||||
/* Check if the method is available */
|
||||
if(pThis) {
|
||||
pMethod = PH7_ClassExtractMethod(pThis->pClass, zMethod, nLen);
|
||||
@@ -110,9 +114,11 @@ static sxi32 MemObjCallClassCastMethod(
|
||||
return SXERR_NOTFOUND;
|
||||
}
|
||||
/* Invoke the desired method */
|
||||
PH7_VmCallClassMethod(&(*pVm), &(*pThis), pMethod, &(*pResult), 0, 0);
|
||||
/* Method successfully called,pResult should hold the return value */
|
||||
return SXRET_OK;
|
||||
rc = PH7_VmCallClassMethod(&(*pVm), &(*pThis), pMethod, &(*pResult), 0, 0);
|
||||
/* Scalar conversion APIs cannot carry an exception object. Preserve the
|
||||
* completion for the enclosing evaluator instead of reporting success. */
|
||||
PH7_VmDeferTransfer(pVm, rc, pResult);
|
||||
return rc;
|
||||
}
|
||||
/*
|
||||
* Return some kind of integer value which is the best we can
|
||||
@@ -444,24 +450,33 @@ PH7_PRIVATE void PH7_MemObjSetDeclaredType(ph7_value *pValue, sxu32 nType) {
|
||||
* destination are of the compatible data types.
|
||||
*/
|
||||
PH7_PRIVATE sxi32 PH7_MemObjSafeStore(ph7_value *pSrc, ph7_value *pDest) {
|
||||
/* Scalar destinations need not have initialized arena metadata. */
|
||||
ph7_vm *pVm = (pSrc->nType & MEMOBJ_HASHMAP) ? pDest->pVm : 0;
|
||||
/* Both recursive array copies and object finalizers can relocate storage. */
|
||||
ph7_vm *pVm = pDest->pVm;
|
||||
sxu32 nDest = pVm ? pDest->nIdx : SXU32_HIGH;
|
||||
sxi32 bArena = pVm && SySetAt(&pVm->aMemObj, nDest) == pDest;
|
||||
if(pVm && pVm->iPendingTransfer) {
|
||||
return pVm->iPendingTransfer;
|
||||
}
|
||||
if(pDest->nDeclaredType & MEMOBJ_NAMED) {
|
||||
sxu32 nDeclared = pDest->nDeclaredType;
|
||||
sxi32 iFlags = pDest->iFlags;
|
||||
ph7_value sValue, sPrevious;
|
||||
sxi32 rc;
|
||||
if(PH7_VmTypeCheck(pSrc, nDeclared) != SXRET_OK) {
|
||||
return SXERR_NOMATCH;
|
||||
}
|
||||
/* Retain both payloads until storage has its contract again. Releasing
|
||||
* the old object/map may invoke a destructor which writes through an
|
||||
* alias of this binding. The source can also be the destination itself. */
|
||||
PH7_MemObjInit(pDest->pVm, &sValue);
|
||||
PH7_MemObjInit(pDest->pVm, &sPrevious);
|
||||
PH7_MemObjInit(pVm, &sValue);
|
||||
PH7_MemObjInit(pVm, &sPrevious);
|
||||
PH7_MemObjLoad(pSrc, &sValue);
|
||||
/* Nominal resolution may autoload and reenter the VM. Keep no arena
|
||||
* address or borrowed source payload across that resolution. */
|
||||
if(PH7_VmTypeCheck(&sValue, nDeclared) != SXRET_OK) {
|
||||
PH7_MemObjRelease(&sValue);
|
||||
return SXERR_NOMATCH;
|
||||
}
|
||||
if(bArena) {
|
||||
pDest = (ph7_value *)SySetAt(&pVm->aMemObj, nDest);
|
||||
}
|
||||
PH7_MemObjLoad(pDest, &sPrevious);
|
||||
PH7_MemObjRelease(pDest);
|
||||
pDest->x.pOther = 0;
|
||||
@@ -538,6 +553,12 @@ PH7_PRIVATE sxi32 PH7_MemObjSafeStore(ph7_value *pSrc, ph7_value *pDest) {
|
||||
} else if(PH7_CheckVarCompat(pSrc, pDest->nType) == SXRET_OK) {
|
||||
ProcMemObjCast xCast = PH7_MemObjCastMethod(pDest->nType);
|
||||
xCast(pSrc);
|
||||
if(pVm && pVm->iPendingTransfer) {
|
||||
return pVm->iPendingTransfer;
|
||||
}
|
||||
if(bArena) {
|
||||
pDest = (ph7_value *)SySetAt(&pVm->aMemObj, nDest);
|
||||
}
|
||||
PH7_MemObjStore(pSrc, pDest);
|
||||
} else {
|
||||
return SXERR_NOMATCH;
|
||||
@@ -1019,6 +1040,31 @@ PH7_PRIVATE sxi32 PH7_MemObjStringFormat(ph7_value *pObj, const char *zFormat, v
|
||||
rc = SyBlobFormatAp(&pObj->sBlob, zFormat, ap);
|
||||
return rc;
|
||||
}
|
||||
/* Owned context output values may be reused. Copy before releasing the old
|
||||
* payload, then transfer ownership, so reentrant finalizers and aliases are safe. */
|
||||
PH7_PRIVATE sxi32 PH7_MemObjCopy(ph7_value *pSrc, ph7_value *pDest) {
|
||||
ph7_vm *pVm = pDest->pVm;
|
||||
sxu32 nDest = pDest->nIdx;
|
||||
sxi32 bArena = SySetAt(&pVm->aMemObj, nDest) == pDest;
|
||||
ph7_value sCopy;
|
||||
sxi32 rc;
|
||||
if(pSrc == pDest) {
|
||||
return SXRET_OK;
|
||||
}
|
||||
PH7_MemObjInit(pVm, &sCopy);
|
||||
rc = PH7_MemObjStore(pSrc, &sCopy);
|
||||
if(rc != SXRET_OK) {
|
||||
PH7_MemObjRelease(&sCopy);
|
||||
return rc;
|
||||
}
|
||||
PH7_MemObjRelease(pDest);
|
||||
if(bArena) {
|
||||
pDest = (ph7_value *)SySetAt(&pVm->aMemObj, nDest);
|
||||
}
|
||||
*pDest = sCopy;
|
||||
pDest->nIdx = bArena ? nDest : SXU32_HIGH;
|
||||
return SXRET_OK;
|
||||
}
|
||||
/*
|
||||
* Duplicate the contents of a ph7_value.
|
||||
*/
|
||||
@@ -1039,7 +1085,7 @@ PH7_PRIVATE sxi32 PH7_MemObjStore(ph7_value *pSrc, ph7_value *pDest) {
|
||||
pObj = (ph7_class_instance *)pDest->x.pOther;
|
||||
}
|
||||
pDest->x = pSrc->x;
|
||||
pDest->iFlags = pSrc->iFlags;
|
||||
pDest->iFlags = pSrc->iFlags & ~MEMOBJ_INDEX_HANDLE;
|
||||
pDest->nType = pSrc->nType;
|
||||
pDest->nDeclaredType = pSrc->nDeclaredType;
|
||||
rc = SXRET_OK;
|
||||
@@ -1077,7 +1123,7 @@ PH7_PRIVATE sxi32 PH7_MemObjStore(ph7_value *pSrc, ph7_value *pDest) {
|
||||
*/
|
||||
PH7_PRIVATE sxi32 PH7_MemObjLoad(ph7_value *pSrc, ph7_value *pDest) {
|
||||
pDest->x = pSrc->x;
|
||||
pDest->iFlags = pSrc->iFlags;
|
||||
pDest->iFlags = pSrc->iFlags & ~MEMOBJ_INDEX_HANDLE;
|
||||
pDest->nType = pSrc->nType;
|
||||
pDest->nDeclaredType = pSrc->nDeclaredType;
|
||||
if(pSrc->x.pOther) {
|
||||
|
||||
Reference in New Issue
Block a user