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:
+108
@@ -463,6 +463,9 @@ static sxi32 ProcessSourceFile(
|
||||
int iFileDir, rc;
|
||||
char *pFileDir, fFilePath[PATH_MAX + 1];
|
||||
char pFilePath[PATH_MAX + 1];
|
||||
if(pVm->bNativeRegister) {
|
||||
return SXERR_LOCKED;
|
||||
}
|
||||
/* Track the initialized VM before compilation can trigger library shutdown. */
|
||||
MACRO_LD_PUSH(pEngine->pVms, pVm);
|
||||
pEngine->iVm++;
|
||||
@@ -611,6 +614,9 @@ int ph7_vm_exec(ph7_vm *pVm, int *pExitStatus) {
|
||||
if(PH7_VM_MISUSE(pVm)) {
|
||||
return PH7_CORRUPT;
|
||||
}
|
||||
if(pVm->bNativeRegister) {
|
||||
return SXERR_LOCKED;
|
||||
}
|
||||
/* Execute PH7 byte-code */
|
||||
rc = PH7_VmByteCodeExec(&(*pVm));
|
||||
if(pExitStatus) {
|
||||
@@ -630,6 +636,9 @@ int ph7_vm_reset(ph7_vm *pVm) {
|
||||
if(PH7_VM_MISUSE(pVm)) {
|
||||
return PH7_CORRUPT;
|
||||
}
|
||||
if(pVm->bNativeRegister) {
|
||||
return SXERR_LOCKED;
|
||||
}
|
||||
rc = PH7_VmReset(&(*pVm));
|
||||
return rc;
|
||||
}
|
||||
@@ -644,6 +653,9 @@ int ph7_vm_release(ph7_vm *pVm) {
|
||||
if(PH7_VM_MISUSE(pVm)) {
|
||||
return PH7_CORRUPT;
|
||||
}
|
||||
if(pVm->bNativeRegister) {
|
||||
return SXERR_LOCKED;
|
||||
}
|
||||
pEngine = pVm->pEngine;
|
||||
rc = PH7_VmRelease(&(*pVm));
|
||||
if(rc == PH7_OK) {
|
||||
@@ -686,6 +698,102 @@ int ph7_create_class(ph7_vm *pVm, const ph7_class_def *pDef) {
|
||||
}
|
||||
return PH7_VmCreateNativeClass(pVm, pDef);
|
||||
}
|
||||
int ph7_context_arg_value(ph7_context *pCtx, unsigned int nArg, ph7_value *pOut) {
|
||||
VmFrame *pFrame = pCtx ? (VmFrame *)pCtx->pNativeFrame : 0;
|
||||
VmSlot *pSlot;
|
||||
if(pFrame == 0 || pOut == 0 || pOut->pVm != pCtx->pVm ||
|
||||
nArg >= SySetUsed(&pFrame->sArg)) {
|
||||
return PH7_CORRUPT;
|
||||
}
|
||||
pSlot = (VmSlot *)SySetAt(&pFrame->sArg, nArg);
|
||||
return PH7_MemObjCopy((ph7_value *)SySetAt(&pCtx->pVm->aMemObj, pSlot->nIdx), pOut);
|
||||
}
|
||||
int ph7_context_arg_store(ph7_context *pCtx, unsigned int nArg, ph7_value *pValue) {
|
||||
VmFrame *pFrame = pCtx ? (VmFrame *)pCtx->pNativeFrame : 0;
|
||||
VmSlot *pSlot;
|
||||
ph7_vm_func *pFunc;
|
||||
ph7_value sChecked;
|
||||
sxi32 rc;
|
||||
if(pFrame == 0 || pValue == 0 || pValue->pVm != pCtx->pVm ||
|
||||
nArg >= SySetUsed(&pFrame->sArg)) {
|
||||
return PH7_CORRUPT;
|
||||
}
|
||||
pFunc = (ph7_vm_func *)pFrame->pUserData;
|
||||
PH7_MemObjInit(pCtx->pVm, &sChecked);
|
||||
if(pFunc && nArg < SySetUsed(&pFunc->aArgs)) {
|
||||
ph7_vm_func_arg *pFormal = (ph7_vm_func_arg *)SySetAt(&pFunc->aArgs, nArg);
|
||||
MemObjSetType(&sChecked, pFormal->nType & MEMOBJ_TYPEMASK);
|
||||
PH7_MemObjSetDeclaredType(&sChecked, pFormal->nType);
|
||||
}
|
||||
rc = PH7_MemObjSafeStore(pValue, &sChecked);
|
||||
if(rc == PH7_OK && pCtx->pVm->iPendingTransfer == 0) {
|
||||
pSlot = (VmSlot *)SySetAt(&pFrame->sArg, nArg);
|
||||
rc = PH7_MemObjSafeStore(&sChecked,
|
||||
(ph7_value *)SySetAt(&pCtx->pVm->aMemObj, pSlot->nIdx));
|
||||
}
|
||||
PH7_MemObjRelease(&sChecked);
|
||||
return pCtx->pVm->iPendingTransfer ? pCtx->pVm->iPendingTransfer : rc;
|
||||
}
|
||||
int ph7_context_arg_bind(ph7_context *pCtx, unsigned int nArg, ph7_value *pOut) {
|
||||
int rc = ph7_context_arg_value(pCtx, nArg, pOut);
|
||||
if(rc == PH7_OK) {
|
||||
VmFrame *pFrame = (VmFrame *)pCtx->pNativeFrame;
|
||||
VmSlot *pSlot = (VmSlot *)SySetAt(&pFrame->sArg, nArg);
|
||||
pOut->nIdx = pSlot->nIdx;
|
||||
pOut->iFlags |= MEMOBJ_INDEX_HANDLE;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
int ph7_context_attr_value(ph7_context *pCtx, ph7_value *pObject,
|
||||
const char *zClass, const char *zName, ph7_value *pOut) {
|
||||
return PH7_VmContextAttr(pCtx, pObject, zClass, zName, pOut, FALSE);
|
||||
}
|
||||
int ph7_context_attr_store(ph7_context *pCtx, ph7_value *pObject,
|
||||
const char *zClass, const char *zName, ph7_value *pValue) {
|
||||
return PH7_VmContextAttr(pCtx, pObject, zClass, zName, pValue, TRUE);
|
||||
}
|
||||
int ph7_context_call(ph7_context *pCtx, ph7_value *pCallable,
|
||||
int nArg, ph7_value **apArg, ph7_value *pResult) {
|
||||
ph7_value sResult;
|
||||
int rc;
|
||||
if(pCtx == 0 || pCallable == 0 || pCallable->pVm != pCtx->pVm ||
|
||||
pResult == 0 || pResult->pVm != pCtx->pVm || nArg < 0 || (nArg && apArg == 0)) {
|
||||
return PH7_CORRUPT;
|
||||
}
|
||||
PH7_MemObjInit(pCtx->pVm, &sResult);
|
||||
rc = PH7_VmCallUserFunction(pCtx->pVm, pCallable, nArg, apArg, &sResult);
|
||||
if(rc == PH7_OK || rc == PH7_EXCEPTION) {
|
||||
int copy_rc = PH7_MemObjCopy(&sResult, pResult);
|
||||
if(copy_rc != PH7_OK) rc = copy_rc;
|
||||
}
|
||||
PH7_MemObjRelease(&sResult);
|
||||
return rc;
|
||||
}
|
||||
int ph7_context_parent(ph7_context *pCtx, const char *zMethod,
|
||||
int nArg, ph7_value **apArg, ph7_value *pResult) {
|
||||
ph7_value sResult;
|
||||
int rc;
|
||||
if(pCtx == 0 || pResult == 0 || pResult->pVm != pCtx->pVm) {
|
||||
return PH7_CORRUPT;
|
||||
}
|
||||
PH7_MemObjInit(pCtx->pVm, &sResult);
|
||||
rc = PH7_VmContextParent(pCtx, zMethod, nArg, apArg, &sResult);
|
||||
if(rc == PH7_OK || rc == PH7_EXCEPTION) {
|
||||
int copy_rc = PH7_MemObjCopy(&sResult, pResult);
|
||||
if(copy_rc != PH7_OK) rc = copy_rc;
|
||||
}
|
||||
PH7_MemObjRelease(&sResult);
|
||||
return rc;
|
||||
}
|
||||
int ph7_context_var_value(ph7_context *pCtx, const char *zName, ph7_value *pOut) {
|
||||
return PH7_VmContextVar(pCtx, zName, pOut, FALSE);
|
||||
}
|
||||
int ph7_context_var_store(ph7_context *pCtx, const char *zName, ph7_value *pValue) {
|
||||
return PH7_VmContextVar(pCtx, zName, pValue, TRUE);
|
||||
}
|
||||
int ph7_context_status(ph7_context *pCtx) {
|
||||
return pCtx ? (pCtx->pVm->iPendingTransfer ? pCtx->pVm->iPendingTransfer : PH7_OK) : PH7_CORRUPT;
|
||||
}
|
||||
/*
|
||||
* [CAPIREF: ph7_delete_function()]
|
||||
* Please refer to the official documentation for function purpose and expected parameters.
|
||||
|
||||
Reference in New Issue
Block a user