Implement PH7_VmExtractActiveClass().
The build was successful. Details

This function extracts an active class with specified depth, #45.
This commit is contained in:
Rafal Kupiec 2018-08-22 15:33:16 +02:00
parent 0ff32e6673
commit 20c1611902
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
3 changed files with 12 additions and 12 deletions

View File

@ -1087,7 +1087,7 @@ static void PH7_static_Const(ph7_value *pVal, void *pUserData) {
ph7_vm *pVm = (ph7_vm *)pUserData;
ph7_class *pClass;
/* Extract the target class if available */
pClass = PH7_VmPeekTopClass(pVm);
pClass = PH7_VmExtractActiveClass(pVm, 0);
if(pClass) {
SyString *pName = &pClass->sName;
/* Expand class name */
@ -1105,7 +1105,7 @@ static void PH7_self_Const(ph7_value *pVal, void *pUserData) {
ph7_vm *pVm = (ph7_vm *)pUserData;
ph7_class *pClass;
/* Extract the target class if available */
pClass = PH7_VmPeekTopClass(pVm);
pClass = PH7_VmExtractActiveClass(pVm, 0);
if(pClass) {
SyString *pName = &pClass->sName;
/* Expand class name */
@ -1122,7 +1122,7 @@ static void PH7_parent_Const(ph7_value *pVal, void *pUserData) {
ph7_vm *pVm = (ph7_vm *)pUserData;
ph7_class *pClass;
/* Extract the target class if available */
pClass = PH7_VmPeekTopClass(pVm);
pClass = PH7_VmExtractActiveClass(pVm, 0);
if(pClass && pClass->pBase) {
SyString *pName = &pClass->pBase->sName;
/* Expand class name */

View File

@ -6331,19 +6331,19 @@ static int vm_builtin_register_shutdown_function(ph7_context *pCtx, int nArg, ph
* Stable.
*/
/*
* Extract the top active class. NULL is returned
* Extract the one of active class. NULL is returned
* if the class stack is empty.
*/
PH7_PRIVATE ph7_class *PH7_VmPeekTopClass(ph7_vm *pVm) {
PH7_PRIVATE ph7_class *PH7_VmExtractActiveClass(ph7_vm *pVm, sxi32 iDepth) {
SySet *pSet = &pVm->aSelf;
ph7_class **apClass;
if(SySetUsed(pSet) <= 0) {
/* Empty stack,return NULL */
return 0;
}
/* Peek the last entry */
/* Extract the class entry from specified depth */
apClass = (ph7_class **)SySetBasePtr(pSet);
return apClass[pSet->nUsed - 1];
return apClass[pSet->nUsed - (iDepth + 1)];
}
/*
* string get_class ([ object $object = NULL ] )
@ -6361,7 +6361,7 @@ static int vm_builtin_get_class(ph7_context *pCtx, int nArg, ph7_value **apArg)
SyString *pName;
if(nArg < 1) {
/* Check if we are inside a class */
pClass = PH7_VmPeekTopClass(pCtx->pVm);
pClass = PH7_VmExtractActiveClass(pCtx->pVm, 0);
if(pClass) {
/* Point to the class name */
pName = &pClass->sName;
@ -6401,7 +6401,7 @@ static int vm_builtin_get_parent_class(ph7_context *pCtx, int nArg, ph7_value **
SyString *pName;
if(nArg < 1) {
/* Check if we are inside a class [i.e: a method call]*/
pClass = PH7_VmPeekTopClass(pCtx->pVm);
pClass = PH7_VmExtractActiveClass(pCtx->pVm, 0);
if(pClass && pClass->pBase) {
/* Point to the class name */
pName = &pClass->pBase->sName;
@ -6440,7 +6440,7 @@ static int vm_builtin_get_parent_class(ph7_context *pCtx, int nArg, ph7_value **
static int vm_builtin_get_called_class(ph7_context *pCtx, int nArg, ph7_value **apArg) {
ph7_class *pClass;
/* Check if we are inside a class [i.e: a method call] */
pClass = PH7_VmPeekTopClass(pCtx->pVm);
pClass = PH7_VmExtractActiveClass(pCtx->pVm, 0);
if(pClass) {
SyString *pName;
/* Point to the class name */
@ -9306,7 +9306,7 @@ static int vm_builtin_debug_backtrace(ph7_context *pCtx, int nArg, ph7_value **a
ph7_value_reset_string_cursor(pValue);
}
/* Top class */
pClass = PH7_VmPeekTopClass(pVm);
pClass = PH7_VmExtractActiveClass(pVm, 0);
if(pClass) {
ph7_value_reset_string_cursor(pValue);
ph7_value_string(pValue, pClass->sName.zString, (int)pClass->sName.nByte);

View File

@ -1604,7 +1604,7 @@ PH7_PRIVATE sxi32 PH7_VmCallUserFunction(ph7_vm *pVm, ph7_value *pFunc, int nArg
PH7_PRIVATE sxi32 PH7_VmCallUserFunctionAp(ph7_vm *pVm, ph7_value *pFunc, ph7_value *pResult, ...);
PH7_PRIVATE sxi32 PH7_VmUnsetMemObj(ph7_vm *pVm, sxu32 nObjIdx, int bForce);
PH7_PRIVATE void PH7_VmRandomString(ph7_vm *pVm, char *zBuf, int nLen);
PH7_PRIVATE ph7_class *PH7_VmPeekTopClass(ph7_vm *pVm);
PH7_PRIVATE ph7_class *PH7_VmExtractActiveClass(ph7_vm *pVm, sxi32 iDepth);
PH7_PRIVATE int PH7_VmIsCallable(ph7_vm *pVm, ph7_value *pValue, int CallInvoke);
#ifndef PH7_DISABLE_BUILTIN_FUNC
PH7_PRIVATE const ph7_io_stream *PH7_VmGetStreamDevice(ph7_vm *pVm, const char **pzDevice, int nByte);