Store variable type in dedicated field.
The build was successful.
Details
The build was successful.
Details
This commit is contained in:
parent
0f4a666b89
commit
3cca5faa76
48
engine/api.c
48
engine/api.c
|
@ -1236,7 +1236,7 @@ const char *ph7_value_to_string(ph7_value *pValue, int *pLen) {
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
void *ph7_value_to_resource(ph7_value *pValue) {
|
void *ph7_value_to_resource(ph7_value *pValue) {
|
||||||
if((pValue->iFlags & MEMOBJ_RES) == 0) {
|
if((pValue->nType & MEMOBJ_RES) == 0) {
|
||||||
/* Not a resource,return NULL */
|
/* Not a resource,return NULL */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1310,7 +1310,7 @@ int ph7_result_string_format(ph7_context *pCtx, const char *zFormat, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int rc;
|
int rc;
|
||||||
p = pCtx->pRet;
|
p = pCtx->pRet;
|
||||||
if((p->iFlags & MEMOBJ_STRING) == 0) {
|
if((p->nType & MEMOBJ_STRING) == 0) {
|
||||||
/* Invalidate any prior representation */
|
/* Invalidate any prior representation */
|
||||||
PH7_MemObjRelease(p);
|
PH7_MemObjRelease(p);
|
||||||
MemObjSetType(p, MEMOBJ_STRING);
|
MemObjSetType(p, MEMOBJ_STRING);
|
||||||
|
@ -1469,7 +1469,7 @@ ph7_value *ph7_array_fetch(ph7_value *pArray, const char *zKey, int nByte) {
|
||||||
ph7_value skey;
|
ph7_value skey;
|
||||||
int rc;
|
int rc;
|
||||||
/* Make sure we are dealing with a valid hashmap */
|
/* Make sure we are dealing with a valid hashmap */
|
||||||
if((pArray->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if((pArray->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(nByte < 0) {
|
if(nByte < 0) {
|
||||||
|
@ -1499,7 +1499,7 @@ int ph7_array_walk(ph7_value *pArray, int (*xWalk)(ph7_value *pValue, ph7_value
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
/* Make sure we are dealing with a valid hashmap */
|
/* Make sure we are dealing with a valid hashmap */
|
||||||
if((pArray->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if((pArray->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
/* Start the walk process */
|
/* Start the walk process */
|
||||||
|
@ -1513,7 +1513,7 @@ int ph7_array_walk(ph7_value *pArray, int (*xWalk)(ph7_value *pValue, ph7_value
|
||||||
int ph7_array_add_elem(ph7_value *pArray, ph7_value *pKey, ph7_value *pValue) {
|
int ph7_array_add_elem(ph7_value *pArray, ph7_value *pKey, ph7_value *pValue) {
|
||||||
int rc;
|
int rc;
|
||||||
/* Make sure we are dealing with a valid hashmap */
|
/* Make sure we are dealing with a valid hashmap */
|
||||||
if((pArray->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if((pArray->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
/* Perform the insertion */
|
/* Perform the insertion */
|
||||||
|
@ -1527,7 +1527,7 @@ int ph7_array_add_elem(ph7_value *pArray, ph7_value *pKey, ph7_value *pValue) {
|
||||||
int ph7_array_add_strkey_elem(ph7_value *pArray, const char *zKey, ph7_value *pValue) {
|
int ph7_array_add_strkey_elem(ph7_value *pArray, const char *zKey, ph7_value *pValue) {
|
||||||
int rc;
|
int rc;
|
||||||
/* Make sure we are dealing with a valid hashmap */
|
/* Make sure we are dealing with a valid hashmap */
|
||||||
if((pArray->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if((pArray->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
/* Perform the insertion */
|
/* Perform the insertion */
|
||||||
|
@ -1551,7 +1551,7 @@ int ph7_array_add_intkey_elem(ph7_value *pArray, int iKey, ph7_value *pValue) {
|
||||||
ph7_value sKey;
|
ph7_value sKey;
|
||||||
int rc;
|
int rc;
|
||||||
/* Make sure we are dealing with a valid hashmap */
|
/* Make sure we are dealing with a valid hashmap */
|
||||||
if((pArray->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if((pArray->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
PH7_MemObjInitFromInt(pArray->pVm, &sKey, iKey);
|
PH7_MemObjInitFromInt(pArray->pVm, &sKey, iKey);
|
||||||
|
@ -1567,7 +1567,7 @@ int ph7_array_add_intkey_elem(ph7_value *pArray, int iKey, ph7_value *pValue) {
|
||||||
unsigned int ph7_array_count(ph7_value *pArray) {
|
unsigned int ph7_array_count(ph7_value *pArray) {
|
||||||
ph7_hashmap *pMap;
|
ph7_hashmap *pMap;
|
||||||
/* Make sure we are dealing with a valid hashmap */
|
/* Make sure we are dealing with a valid hashmap */
|
||||||
if((pArray->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if((pArray->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Point to the internal representation of the hashmap */
|
/* Point to the internal representation of the hashmap */
|
||||||
|
@ -1584,7 +1584,7 @@ int ph7_object_walk(ph7_value *pObject, int (*xWalk)(const char *, ph7_value *,
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
/* Make sure we are dealing with a valid class instance */
|
/* Make sure we are dealing with a valid class instance */
|
||||||
if((pObject->iFlags & MEMOBJ_OBJ) == 0) {
|
if((pObject->nType & MEMOBJ_OBJ) == 0) {
|
||||||
return PH7_CORRUPT;
|
return PH7_CORRUPT;
|
||||||
}
|
}
|
||||||
/* Start the walk process */
|
/* Start the walk process */
|
||||||
|
@ -1599,7 +1599,7 @@ ph7_value *ph7_object_fetch_attr(ph7_value *pObject, const char *zAttr) {
|
||||||
ph7_value *pValue;
|
ph7_value *pValue;
|
||||||
SyString sAttr;
|
SyString sAttr;
|
||||||
/* Make sure we are dealing with a valid class instance */
|
/* Make sure we are dealing with a valid class instance */
|
||||||
if((pObject->iFlags & MEMOBJ_OBJ) == 0 || zAttr == 0) {
|
if((pObject->nType & MEMOBJ_OBJ) == 0 || zAttr == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SyStringInitFromBuf(&sAttr, zAttr, SyStrlen(zAttr));
|
SyStringInitFromBuf(&sAttr, zAttr, SyStrlen(zAttr));
|
||||||
|
@ -1618,7 +1618,7 @@ const char *ph7_object_get_class_name(ph7_value *pObject, int *pLength) {
|
||||||
*pLength = 0;
|
*pLength = 0;
|
||||||
}
|
}
|
||||||
/* Make sure we are dealing with a valid class instance */
|
/* Make sure we are dealing with a valid class instance */
|
||||||
if((pObject->iFlags & MEMOBJ_OBJ) == 0) {
|
if((pObject->nType & MEMOBJ_OBJ) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Point to the class */
|
/* Point to the class */
|
||||||
|
@ -1809,7 +1809,7 @@ int ph7_value_void(ph7_value *pVal) {
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_string(ph7_value *pVal, const char *zString, int nLen) {
|
int ph7_value_string(ph7_value *pVal, const char *zString, int nLen) {
|
||||||
if((pVal->iFlags & MEMOBJ_STRING) == 0) {
|
if((pVal->nType & MEMOBJ_STRING) == 0) {
|
||||||
/* Invalidate any prior representation */
|
/* Invalidate any prior representation */
|
||||||
PH7_MemObjRelease(pVal);
|
PH7_MemObjRelease(pVal);
|
||||||
MemObjSetType(pVal, MEMOBJ_STRING);
|
MemObjSetType(pVal, MEMOBJ_STRING);
|
||||||
|
@ -1830,7 +1830,7 @@ int ph7_value_string(ph7_value *pVal, const char *zString, int nLen) {
|
||||||
int ph7_value_string_format(ph7_value *pVal, const char *zFormat, ...) {
|
int ph7_value_string_format(ph7_value *pVal, const char *zFormat, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int rc;
|
int rc;
|
||||||
if((pVal->iFlags & MEMOBJ_STRING) == 0) {
|
if((pVal->nType & MEMOBJ_STRING) == 0) {
|
||||||
/* Invalidate any prior representation */
|
/* Invalidate any prior representation */
|
||||||
PH7_MemObjRelease(pVal);
|
PH7_MemObjRelease(pVal);
|
||||||
MemObjSetType(pVal, MEMOBJ_STRING);
|
MemObjSetType(pVal, MEMOBJ_STRING);
|
||||||
|
@ -1874,42 +1874,42 @@ int ph7_value_release(ph7_value *pVal) {
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_int(ph7_value *pVal) {
|
int ph7_value_is_int(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_INT) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_INT) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_value_is_float()]
|
* [CAPIREF: ph7_value_is_float()]
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_float(ph7_value *pVal) {
|
int ph7_value_is_float(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_REAL) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_REAL) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_value_is_bool()]
|
* [CAPIREF: ph7_value_is_bool()]
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_bool(ph7_value *pVal) {
|
int ph7_value_is_bool(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_BOOL) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_BOOL) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_value_is_char()]
|
* [CAPIREF: ph7_value_is_char()]
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_char(ph7_value *pVal) {
|
int ph7_value_is_char(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_CHAR) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_CHAR) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_value_is_void()]
|
* [CAPIREF: ph7_value_is_void()]
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_void(ph7_value *pVal) {
|
int ph7_value_is_void(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_VOID) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_VOID) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_value_is_string()]
|
* [CAPIREF: ph7_value_is_string()]
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_string(ph7_value *pVal) {
|
int ph7_value_is_string(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_STRING) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_STRING) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_value_is_numeric()]
|
* [CAPIREF: ph7_value_is_numeric()]
|
||||||
|
@ -1934,33 +1934,33 @@ int ph7_value_is_callable(ph7_value *pVal) {
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_callback(ph7_value *pVal) {
|
int ph7_value_is_callback(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_CALL) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_CALL) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_value_is_scalar()]
|
* [CAPIREF: ph7_value_is_scalar()]
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_scalar(ph7_value *pVal) {
|
int ph7_value_is_scalar(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_SCALAR) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_SCALAR) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_value_is_array()]
|
* [CAPIREF: ph7_value_is_array()]
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_array(ph7_value *pVal) {
|
int ph7_value_is_array(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_HASHMAP) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_HASHMAP) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_value_is_object()]
|
* [CAPIREF: ph7_value_is_object()]
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_object(ph7_value *pVal) {
|
int ph7_value_is_object(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_OBJ) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_OBJ) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* [CAPIREF: ph7_value_is_resource()]
|
* [CAPIREF: ph7_value_is_resource()]
|
||||||
* Please refer to the official documentation for function purpose and expected parameters.
|
* Please refer to the official documentation for function purpose and expected parameters.
|
||||||
*/
|
*/
|
||||||
int ph7_value_is_resource(ph7_value *pVal) {
|
int ph7_value_is_resource(ph7_value *pVal) {
|
||||||
return (pVal->iFlags & MEMOBJ_RES) ? TRUE : FALSE;
|
return (pVal->nType & MEMOBJ_RES) ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -947,7 +947,7 @@ PH7_PRIVATE sxi32 PH7_CompileClosure(ph7_gen_state *pGen, sxi32 iCompileFlag) {
|
||||||
}
|
}
|
||||||
SyStringInitFromBuf(&sName, zName, nLen);
|
SyStringInitFromBuf(&sName, zName, nLen);
|
||||||
PH7_MemObjInitFromString(pGen->pVm, pObj, &sName);
|
PH7_MemObjInitFromString(pGen->pVm, pObj, &sName);
|
||||||
pObj->iFlags = MEMOBJ_CALL;
|
pObj->nType = MEMOBJ_CALL;
|
||||||
/* Compile the closure body */
|
/* Compile the closure body */
|
||||||
rc = PH7_GenStateCompileFunc(&(*pGen), &sName, 0, TRUE, &pAnonFunc);
|
rc = PH7_GenStateCompileFunc(&(*pGen), &sName, 0, TRUE, &pAnonFunc);
|
||||||
if(rc == SXERR_ABORT) {
|
if(rc == SXERR_ABORT) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ static sxi64 HashmapCount(ph7_hashmap *pMap, int bRecursive, int iRecCount) {
|
||||||
/* Point to the element value */
|
/* Point to the element value */
|
||||||
pElem = (ph7_value *)SySetAt(&pMap->pVm->aMemObj, pEntry->nValIdx);
|
pElem = (ph7_value *)SySetAt(&pMap->pVm->aMemObj, pEntry->nValIdx);
|
||||||
if(pElem) {
|
if(pElem) {
|
||||||
if(pElem->iFlags & MEMOBJ_HASHMAP) {
|
if(pElem->nType & MEMOBJ_HASHMAP) {
|
||||||
if(iRecCount > 31) {
|
if(iRecCount > 31) {
|
||||||
/* Nesting limit reached */
|
/* Nesting limit reached */
|
||||||
return iCount;
|
return iCount;
|
||||||
|
@ -455,8 +455,8 @@ static sxi32 HashmapLookup(
|
||||||
) {
|
) {
|
||||||
ph7_hashmap_node *pNode = 0; /* cc -O6 warning */
|
ph7_hashmap_node *pNode = 0; /* cc -O6 warning */
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
if(pKey->iFlags & (MEMOBJ_STRING | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) {
|
if(pKey->nType & (MEMOBJ_STRING | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) {
|
||||||
if((pKey->iFlags & MEMOBJ_STRING) == 0) {
|
if((pKey->nType & MEMOBJ_STRING) == 0) {
|
||||||
/* Force a string cast */
|
/* Force a string cast */
|
||||||
PH7_MemObjToString(&(*pKey));
|
PH7_MemObjToString(&(*pKey));
|
||||||
}
|
}
|
||||||
|
@ -467,7 +467,7 @@ static sxi32 HashmapLookup(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Perform an int lookup */
|
/* Perform an int lookup */
|
||||||
if((pKey->iFlags & MEMOBJ_INT) == 0) {
|
if((pKey->nType & MEMOBJ_INT) == 0) {
|
||||||
/* Force an integer cast */
|
/* Force an integer cast */
|
||||||
PH7_MemObjToInteger(pKey);
|
PH7_MemObjToInteger(pKey);
|
||||||
}
|
}
|
||||||
|
@ -497,8 +497,8 @@ static sxi32 HashmapInsert(
|
||||||
) {
|
) {
|
||||||
ph7_hashmap_node *pNode = 0;
|
ph7_hashmap_node *pNode = 0;
|
||||||
sxi32 rc = SXRET_OK;
|
sxi32 rc = SXRET_OK;
|
||||||
if(pKey && pKey->iFlags & (MEMOBJ_STRING | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) {
|
if(pKey && pKey->nType & (MEMOBJ_STRING | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) {
|
||||||
if((pKey->iFlags & MEMOBJ_STRING) == 0) {
|
if((pKey->nType & MEMOBJ_STRING) == 0) {
|
||||||
/* Force a string cast */
|
/* Force a string cast */
|
||||||
PH7_MemObjToString(&(*pKey));
|
PH7_MemObjToString(&(*pKey));
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ static sxi32 HashmapInsert(
|
||||||
}
|
}
|
||||||
IntKey:
|
IntKey:
|
||||||
if(pKey) {
|
if(pKey) {
|
||||||
if((pKey->iFlags & MEMOBJ_INT) == 0) {
|
if((pKey->nType & MEMOBJ_INT) == 0) {
|
||||||
/* Force an integer cast */
|
/* Force an integer cast */
|
||||||
PH7_MemObjToInteger(pKey);
|
PH7_MemObjToInteger(pKey);
|
||||||
}
|
}
|
||||||
|
@ -698,9 +698,9 @@ static int HashmapFindValue(
|
||||||
/* Extract node value */
|
/* Extract node value */
|
||||||
pVal = HashmapExtractNodeValue(pEntry);
|
pVal = HashmapExtractNodeValue(pEntry);
|
||||||
if(pVal) {
|
if(pVal) {
|
||||||
if((pVal->iFlags | pNeedle->iFlags) & MEMOBJ_NULL) {
|
if((pVal->nType | pNeedle->nType) & MEMOBJ_NULL) {
|
||||||
sxi32 iF1 = pVal->iFlags;
|
sxi32 iF1 = pVal->nType;
|
||||||
sxi32 iF2 = pNeedle->iFlags;
|
sxi32 iF2 = pNeedle->nType;
|
||||||
if(iF1 == iF2) {
|
if(iF1 == iF2) {
|
||||||
/* NULL values are equals */
|
/* NULL values are equals */
|
||||||
if(ppNode) {
|
if(ppNode) {
|
||||||
|
@ -769,7 +769,7 @@ static int HashmapFindValueByCallback(
|
||||||
rc = PH7_VmCallUserFunction(pMap->pVm, pCallback, 2, apArg, &sResult);
|
rc = PH7_VmCallUserFunction(pMap->pVm, pCallback, 2, apArg, &sResult);
|
||||||
if(rc == SXRET_OK) {
|
if(rc == SXRET_OK) {
|
||||||
/* Extract callback result */
|
/* Extract callback result */
|
||||||
if((sResult.iFlags & MEMOBJ_INT) == 0) {
|
if((sResult.nType & MEMOBJ_INT) == 0) {
|
||||||
/* Perform an int cast */
|
/* Perform an int cast */
|
||||||
PH7_MemObjToInteger(&sResult);
|
PH7_MemObjToInteger(&sResult);
|
||||||
}
|
}
|
||||||
|
@ -1490,10 +1490,10 @@ static sxi32 HashmapCmpCallback1(ph7_hashmap_node *pA, ph7_hashmap_node *pB, voi
|
||||||
PH7_HashmapExtractNodeValue(pB, &sB, FALSE);
|
PH7_HashmapExtractNodeValue(pB, &sB, FALSE);
|
||||||
if(iFlags == 5) {
|
if(iFlags == 5) {
|
||||||
/* String cast */
|
/* String cast */
|
||||||
if((sA.iFlags & MEMOBJ_STRING) == 0) {
|
if((sA.nType & MEMOBJ_STRING) == 0) {
|
||||||
PH7_MemObjToString(&sA);
|
PH7_MemObjToString(&sA);
|
||||||
}
|
}
|
||||||
if((sB.iFlags & MEMOBJ_STRING) == 0) {
|
if((sB.nType & MEMOBJ_STRING) == 0) {
|
||||||
PH7_MemObjToString(&sB);
|
PH7_MemObjToString(&sB);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1569,10 +1569,10 @@ static sxi32 HashmapCmpCallback3(ph7_hashmap_node *pA, ph7_hashmap_node *pB, voi
|
||||||
PH7_HashmapExtractNodeValue(pB, &sB, FALSE);
|
PH7_HashmapExtractNodeValue(pB, &sB, FALSE);
|
||||||
if(iFlags == 5) {
|
if(iFlags == 5) {
|
||||||
/* String cast */
|
/* String cast */
|
||||||
if((sA.iFlags & MEMOBJ_STRING) == 0) {
|
if((sA.nType & MEMOBJ_STRING) == 0) {
|
||||||
PH7_MemObjToString(&sA);
|
PH7_MemObjToString(&sA);
|
||||||
}
|
}
|
||||||
if((sB.iFlags & MEMOBJ_STRING) == 0) {
|
if((sB.nType & MEMOBJ_STRING) == 0) {
|
||||||
PH7_MemObjToString(&sB);
|
PH7_MemObjToString(&sB);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1611,7 +1611,7 @@ static sxi32 HashmapCmpCallback4(ph7_hashmap_node *pA, ph7_hashmap_node *pB, voi
|
||||||
rc = -1; /* Set a dummy result */
|
rc = -1; /* Set a dummy result */
|
||||||
} else {
|
} else {
|
||||||
/* Extract callback result */
|
/* Extract callback result */
|
||||||
if((sResult.iFlags & MEMOBJ_INT) == 0) {
|
if((sResult.nType & MEMOBJ_INT) == 0) {
|
||||||
/* Perform an int cast */
|
/* Perform an int cast */
|
||||||
PH7_MemObjToInteger(&sResult);
|
PH7_MemObjToInteger(&sResult);
|
||||||
}
|
}
|
||||||
|
@ -1691,7 +1691,7 @@ static sxi32 HashmapCmpCallback6(ph7_hashmap_node *pA, ph7_hashmap_node *pB, voi
|
||||||
rc = -1; /* Set a dummy result */
|
rc = -1; /* Set a dummy result */
|
||||||
} else {
|
} else {
|
||||||
/* Extract callback result */
|
/* Extract callback result */
|
||||||
if((sResult.iFlags & MEMOBJ_INT) == 0) {
|
if((sResult.nType & MEMOBJ_INT) == 0) {
|
||||||
/* Perform an int cast */
|
/* Perform an int cast */
|
||||||
PH7_MemObjToInteger(&sResult);
|
PH7_MemObjToInteger(&sResult);
|
||||||
}
|
}
|
||||||
|
@ -4333,7 +4333,7 @@ static int ph7_hashmap_flip(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||||
for(n = 0 ; n < pSrc->nEntry ; n++) {
|
for(n = 0 ; n < pSrc->nEntry ; n++) {
|
||||||
/* Extract the node value */
|
/* Extract the node value */
|
||||||
pKey = HashmapExtractNodeValue(pEntry);
|
pKey = HashmapExtractNodeValue(pEntry);
|
||||||
if(pKey && (pKey->iFlags & MEMOBJ_NULL) == 0) {
|
if(pKey && (pKey->nType & MEMOBJ_NULL) == 0) {
|
||||||
/* Prepare the value for insertion */
|
/* Prepare the value for insertion */
|
||||||
if(pEntry->iType == HASHMAP_INT_NODE) {
|
if(pEntry->iType == HASHMAP_INT_NODE) {
|
||||||
PH7_MemObjInitFromInt(pSrc->pVm, &sVal, pEntry->xKey.iKey);
|
PH7_MemObjInitFromInt(pSrc->pVm, &sVal, pEntry->xKey.iKey);
|
||||||
|
@ -4372,12 +4372,12 @@ static void DoubleSum(ph7_context *pCtx, ph7_hashmap *pMap) {
|
||||||
pEntry = pMap->pFirst;
|
pEntry = pMap->pFirst;
|
||||||
for(n = 0 ; n < pMap->nEntry ; n++) {
|
for(n = 0 ; n < pMap->nEntry ; n++) {
|
||||||
pObj = HashmapExtractNodeValue(pEntry);
|
pObj = HashmapExtractNodeValue(pEntry);
|
||||||
if(pObj && (pObj->iFlags & (MEMOBJ_NULL | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) == 0) {
|
if(pObj && (pObj->nType & (MEMOBJ_NULL | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) == 0) {
|
||||||
if(pObj->iFlags & MEMOBJ_REAL) {
|
if(pObj->nType & MEMOBJ_REAL) {
|
||||||
dSum += pObj->x.rVal;
|
dSum += pObj->x.rVal;
|
||||||
} else if(pObj->iFlags & (MEMOBJ_INT | MEMOBJ_BOOL)) {
|
} else if(pObj->nType & (MEMOBJ_INT | MEMOBJ_BOOL)) {
|
||||||
dSum += (double)pObj->x.iVal;
|
dSum += (double)pObj->x.iVal;
|
||||||
} else if(pObj->iFlags & MEMOBJ_STRING) {
|
} else if(pObj->nType & MEMOBJ_STRING) {
|
||||||
if(SyBlobLength(&pObj->sBlob) > 0) {
|
if(SyBlobLength(&pObj->sBlob) > 0) {
|
||||||
double dv = 0;
|
double dv = 0;
|
||||||
SyStrToReal((const char *)SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob), (void *)&dv, 0);
|
SyStrToReal((const char *)SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob), (void *)&dv, 0);
|
||||||
|
@ -4399,12 +4399,12 @@ static void Int64Sum(ph7_context *pCtx, ph7_hashmap *pMap) {
|
||||||
pEntry = pMap->pFirst;
|
pEntry = pMap->pFirst;
|
||||||
for(n = 0 ; n < pMap->nEntry ; n++) {
|
for(n = 0 ; n < pMap->nEntry ; n++) {
|
||||||
pObj = HashmapExtractNodeValue(pEntry);
|
pObj = HashmapExtractNodeValue(pEntry);
|
||||||
if(pObj && (pObj->iFlags & (MEMOBJ_NULL | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) == 0) {
|
if(pObj && (pObj->nType & (MEMOBJ_NULL | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) == 0) {
|
||||||
if(pObj->iFlags & MEMOBJ_REAL) {
|
if(pObj->nType & MEMOBJ_REAL) {
|
||||||
nSum += (sxi64)pObj->x.rVal;
|
nSum += (sxi64)pObj->x.rVal;
|
||||||
} else if(pObj->iFlags & (MEMOBJ_INT | MEMOBJ_BOOL)) {
|
} else if(pObj->nType & (MEMOBJ_INT | MEMOBJ_BOOL)) {
|
||||||
nSum += pObj->x.iVal;
|
nSum += pObj->x.iVal;
|
||||||
} else if(pObj->iFlags & MEMOBJ_STRING) {
|
} else if(pObj->nType & MEMOBJ_STRING) {
|
||||||
if(SyBlobLength(&pObj->sBlob) > 0) {
|
if(SyBlobLength(&pObj->sBlob) > 0) {
|
||||||
sxi64 nv = 0;
|
sxi64 nv = 0;
|
||||||
SyStrToInt64((const char *)SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob), (void *)&nv, 0);
|
SyStrToInt64((const char *)SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob), (void *)&nv, 0);
|
||||||
|
@ -4449,7 +4449,7 @@ static int ph7_hashmap_sum(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||||
ph7_result_int(pCtx, 0);
|
ph7_result_int(pCtx, 0);
|
||||||
return PH7_OK;
|
return PH7_OK;
|
||||||
}
|
}
|
||||||
if(pObj->iFlags & MEMOBJ_REAL) {
|
if(pObj->nType & MEMOBJ_REAL) {
|
||||||
DoubleSum(pCtx, pMap);
|
DoubleSum(pCtx, pMap);
|
||||||
} else {
|
} else {
|
||||||
Int64Sum(pCtx, pMap);
|
Int64Sum(pCtx, pMap);
|
||||||
|
@ -4473,12 +4473,12 @@ static void DoubleProd(ph7_context *pCtx, ph7_hashmap *pMap) {
|
||||||
dProd = 1;
|
dProd = 1;
|
||||||
for(n = 0 ; n < pMap->nEntry ; n++) {
|
for(n = 0 ; n < pMap->nEntry ; n++) {
|
||||||
pObj = HashmapExtractNodeValue(pEntry);
|
pObj = HashmapExtractNodeValue(pEntry);
|
||||||
if(pObj && (pObj->iFlags & (MEMOBJ_NULL | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) == 0) {
|
if(pObj && (pObj->nType & (MEMOBJ_NULL | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) == 0) {
|
||||||
if(pObj->iFlags & MEMOBJ_REAL) {
|
if(pObj->nType & MEMOBJ_REAL) {
|
||||||
dProd *= pObj->x.rVal;
|
dProd *= pObj->x.rVal;
|
||||||
} else if(pObj->iFlags & (MEMOBJ_INT | MEMOBJ_BOOL)) {
|
} else if(pObj->nType & (MEMOBJ_INT | MEMOBJ_BOOL)) {
|
||||||
dProd *= (double)pObj->x.iVal;
|
dProd *= (double)pObj->x.iVal;
|
||||||
} else if(pObj->iFlags & MEMOBJ_STRING) {
|
} else if(pObj->nType & MEMOBJ_STRING) {
|
||||||
if(SyBlobLength(&pObj->sBlob) > 0) {
|
if(SyBlobLength(&pObj->sBlob) > 0) {
|
||||||
double dv = 0;
|
double dv = 0;
|
||||||
SyStrToReal((const char *)SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob), (void *)&dv, 0);
|
SyStrToReal((const char *)SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob), (void *)&dv, 0);
|
||||||
|
@ -4501,12 +4501,12 @@ static void Int64Prod(ph7_context *pCtx, ph7_hashmap *pMap) {
|
||||||
nProd = 1;
|
nProd = 1;
|
||||||
for(n = 0 ; n < pMap->nEntry ; n++) {
|
for(n = 0 ; n < pMap->nEntry ; n++) {
|
||||||
pObj = HashmapExtractNodeValue(pEntry);
|
pObj = HashmapExtractNodeValue(pEntry);
|
||||||
if(pObj && (pObj->iFlags & (MEMOBJ_NULL | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) == 0) {
|
if(pObj && (pObj->nType & (MEMOBJ_NULL | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) == 0) {
|
||||||
if(pObj->iFlags & MEMOBJ_REAL) {
|
if(pObj->nType & MEMOBJ_REAL) {
|
||||||
nProd *= (sxi64)pObj->x.rVal;
|
nProd *= (sxi64)pObj->x.rVal;
|
||||||
} else if(pObj->iFlags & (MEMOBJ_INT | MEMOBJ_BOOL)) {
|
} else if(pObj->nType & (MEMOBJ_INT | MEMOBJ_BOOL)) {
|
||||||
nProd *= pObj->x.iVal;
|
nProd *= pObj->x.iVal;
|
||||||
} else if(pObj->iFlags & MEMOBJ_STRING) {
|
} else if(pObj->nType & MEMOBJ_STRING) {
|
||||||
if(SyBlobLength(&pObj->sBlob) > 0) {
|
if(SyBlobLength(&pObj->sBlob) > 0) {
|
||||||
sxi64 nv = 0;
|
sxi64 nv = 0;
|
||||||
SyStrToInt64((const char *)SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob), (void *)&nv, 0);
|
SyStrToInt64((const char *)SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob), (void *)&nv, 0);
|
||||||
|
@ -4551,7 +4551,7 @@ static int ph7_hashmap_product(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||||
ph7_result_int(pCtx, 0);
|
ph7_result_int(pCtx, 0);
|
||||||
return PH7_OK;
|
return PH7_OK;
|
||||||
}
|
}
|
||||||
if(pObj->iFlags & MEMOBJ_REAL) {
|
if(pObj->nType & MEMOBJ_REAL) {
|
||||||
DoubleProd(pCtx, pMap);
|
DoubleProd(pCtx, pMap);
|
||||||
} else {
|
} else {
|
||||||
Int64Prod(pCtx, pMap);
|
Int64Prod(pCtx, pMap);
|
||||||
|
@ -5124,7 +5124,7 @@ static int HashmapWalkRecursive(
|
||||||
/* Extract the node value */
|
/* Extract the node value */
|
||||||
pValue = HashmapExtractNodeValue(pEntry);
|
pValue = HashmapExtractNodeValue(pEntry);
|
||||||
if(pValue) {
|
if(pValue) {
|
||||||
if(pValue->iFlags & MEMOBJ_HASHMAP) {
|
if(pValue->nType & MEMOBJ_HASHMAP) {
|
||||||
if(iNest < 32) {
|
if(iNest < 32) {
|
||||||
/* Recurse */
|
/* Recurse */
|
||||||
iNest++;
|
iNest++;
|
||||||
|
@ -5392,8 +5392,8 @@ PH7_PRIVATE sxi32 PH7_HashmapWalk(
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_HashmapCast(ph7_value *pObj, sxi32 nType) {
|
PH7_PRIVATE sxi32 PH7_HashmapCast(ph7_value *pObj, sxi32 nType) {
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
if((pObj->iFlags & MEMOBJ_HASHMAP)) {
|
if((pObj->nType & MEMOBJ_HASHMAP)) {
|
||||||
if((pObj->iFlags & nType) == 0) {
|
if((pObj->nType & nType) == 0) {
|
||||||
ph7_hashmap *pMap;
|
ph7_hashmap *pMap;
|
||||||
ph7_hashmap_node *pNode;
|
ph7_hashmap_node *pNode;
|
||||||
ph7_value pValue, pKey;
|
ph7_value pValue, pKey;
|
||||||
|
@ -5413,10 +5413,10 @@ PH7_PRIVATE sxi32 PH7_HashmapCast(ph7_value *pObj, sxi32 nType) {
|
||||||
}
|
}
|
||||||
PH7_HashmapInsert(pMap, &pKey, &pValue);
|
PH7_HashmapInsert(pMap, &pKey, &pValue);
|
||||||
}
|
}
|
||||||
pObj->iFlags = MEMOBJ_HASHMAP | nType;
|
pObj->nType = MEMOBJ_HASHMAP | nType;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(pObj->iFlags != nType && PH7_CheckVarCompat(pObj, nType) != SXRET_OK) {
|
if(pObj->nType != nType && PH7_CheckVarCompat(pObj, nType) != SXRET_OK) {
|
||||||
return SXERR_NOMATCH;
|
return SXERR_NOMATCH;
|
||||||
}
|
}
|
||||||
ProcMemObjCast xCast = PH7_MemObjCastMethod(nType);
|
ProcMemObjCast xCast = PH7_MemObjCastMethod(nType);
|
||||||
|
|
344
engine/memobj.c
344
engine/memobj.c
|
@ -124,23 +124,23 @@ static sxi32 MemObjCallClassCastMethod(
|
||||||
* If pObj represents a NULL value, return 0.
|
* If pObj represents a NULL value, return 0.
|
||||||
*/
|
*/
|
||||||
static sxi64 MemObjIntValue(ph7_value *pObj) {
|
static sxi64 MemObjIntValue(ph7_value *pObj) {
|
||||||
sxi32 iFlags;
|
sxi32 nType;
|
||||||
iFlags = pObj->iFlags;
|
nType = pObj->nType;
|
||||||
if(iFlags & MEMOBJ_REAL) {
|
if(nType & MEMOBJ_REAL) {
|
||||||
return MemObjRealToInt(&(*pObj));
|
return MemObjRealToInt(&(*pObj));
|
||||||
} else if(iFlags & (MEMOBJ_INT | MEMOBJ_BOOL | MEMOBJ_CHAR)) {
|
} else if(nType & (MEMOBJ_INT | MEMOBJ_BOOL | MEMOBJ_CHAR)) {
|
||||||
return pObj->x.iVal;
|
return pObj->x.iVal;
|
||||||
} else if(iFlags & MEMOBJ_STRING) {
|
} else if(nType & MEMOBJ_STRING) {
|
||||||
return MemObjStringToInt(&(*pObj));
|
return MemObjStringToInt(&(*pObj));
|
||||||
} else if(iFlags & (MEMOBJ_CALL | MEMOBJ_NULL | MEMOBJ_VOID)) {
|
} else if(nType & (MEMOBJ_CALL | MEMOBJ_NULL | MEMOBJ_VOID)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if(iFlags & MEMOBJ_HASHMAP) {
|
} else if(nType & MEMOBJ_HASHMAP) {
|
||||||
ph7_hashmap *pMap = (ph7_hashmap *)pObj->x.pOther;
|
ph7_hashmap *pMap = (ph7_hashmap *)pObj->x.pOther;
|
||||||
sxu32 n = pMap->nEntry;
|
sxu32 n = pMap->nEntry;
|
||||||
PH7_HashmapUnref(pMap);
|
PH7_HashmapUnref(pMap);
|
||||||
/* Return total number of entries in the hashmap */
|
/* Return total number of entries in the hashmap */
|
||||||
return n;
|
return n;
|
||||||
} else if(iFlags & MEMOBJ_OBJ) {
|
} else if(nType & MEMOBJ_OBJ) {
|
||||||
ph7_value sResult;
|
ph7_value sResult;
|
||||||
sxi64 iVal = 1;
|
sxi64 iVal = 1;
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
|
@ -148,14 +148,14 @@ static sxi64 MemObjIntValue(ph7_value *pObj) {
|
||||||
PH7_MemObjInit(pObj->pVm, &sResult);
|
PH7_MemObjInit(pObj->pVm, &sResult);
|
||||||
rc = MemObjCallClassCastMethod(pObj->pVm, (ph7_class_instance *)pObj->x.pOther,
|
rc = MemObjCallClassCastMethod(pObj->pVm, (ph7_class_instance *)pObj->x.pOther,
|
||||||
"__toInt", sizeof("__toInt") - 1, &sResult);
|
"__toInt", sizeof("__toInt") - 1, &sResult);
|
||||||
if(rc == SXRET_OK && (sResult.iFlags & MEMOBJ_INT)) {
|
if(rc == SXRET_OK && (sResult.nType & MEMOBJ_INT)) {
|
||||||
/* Extract method return value */
|
/* Extract method return value */
|
||||||
iVal = sResult.x.iVal;
|
iVal = sResult.x.iVal;
|
||||||
}
|
}
|
||||||
PH7_ClassInstanceUnref((ph7_class_instance *)pObj->x.pOther);
|
PH7_ClassInstanceUnref((ph7_class_instance *)pObj->x.pOther);
|
||||||
PH7_MemObjRelease(&sResult);
|
PH7_MemObjRelease(&sResult);
|
||||||
return iVal;
|
return iVal;
|
||||||
} else if(iFlags & MEMOBJ_RES) {
|
} else if(nType & MEMOBJ_RES) {
|
||||||
return pObj->x.pOther != 0;
|
return pObj->x.pOther != 0;
|
||||||
}
|
}
|
||||||
/* CANT HAPPEN */
|
/* CANT HAPPEN */
|
||||||
|
@ -172,13 +172,13 @@ static sxi64 MemObjIntValue(ph7_value *pObj) {
|
||||||
* If pObj represents a NULL value, return 0.0
|
* If pObj represents a NULL value, return 0.0
|
||||||
*/
|
*/
|
||||||
static ph7_real MemObjRealValue(ph7_value *pObj) {
|
static ph7_real MemObjRealValue(ph7_value *pObj) {
|
||||||
sxi32 iFlags;
|
sxi32 nType;
|
||||||
iFlags = pObj->iFlags;
|
nType = pObj->nType;
|
||||||
if(iFlags & MEMOBJ_REAL) {
|
if(nType & MEMOBJ_REAL) {
|
||||||
return pObj->x.rVal;
|
return pObj->x.rVal;
|
||||||
} else if(iFlags & (MEMOBJ_INT | MEMOBJ_BOOL | MEMOBJ_CHAR)) {
|
} else if(nType & (MEMOBJ_INT | MEMOBJ_BOOL | MEMOBJ_CHAR)) {
|
||||||
return (ph7_real)pObj->x.iVal;
|
return (ph7_real)pObj->x.iVal;
|
||||||
} else if(iFlags & MEMOBJ_STRING) {
|
} else if(nType & MEMOBJ_STRING) {
|
||||||
SyString sString;
|
SyString sString;
|
||||||
ph7_real rVal = 0.0;
|
ph7_real rVal = 0.0;
|
||||||
SyStringInitFromBuf(&sString, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
|
SyStringInitFromBuf(&sString, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
|
||||||
|
@ -187,15 +187,15 @@ static ph7_real MemObjRealValue(ph7_value *pObj) {
|
||||||
SyStrToReal(sString.zString, sString.nByte, (void *)&rVal, 0);
|
SyStrToReal(sString.zString, sString.nByte, (void *)&rVal, 0);
|
||||||
}
|
}
|
||||||
return rVal;
|
return rVal;
|
||||||
} else if(iFlags & (MEMOBJ_CALL | MEMOBJ_NULL | MEMOBJ_VOID)) {
|
} else if(nType & (MEMOBJ_CALL | MEMOBJ_NULL | MEMOBJ_VOID)) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
} else if(iFlags & MEMOBJ_HASHMAP) {
|
} else if(nType & MEMOBJ_HASHMAP) {
|
||||||
/* Return the total number of entries in the hashmap */
|
/* Return the total number of entries in the hashmap */
|
||||||
ph7_hashmap *pMap = (ph7_hashmap *)pObj->x.pOther;
|
ph7_hashmap *pMap = (ph7_hashmap *)pObj->x.pOther;
|
||||||
ph7_real n = (ph7_real)pMap->nEntry;
|
ph7_real n = (ph7_real)pMap->nEntry;
|
||||||
PH7_HashmapUnref(pMap);
|
PH7_HashmapUnref(pMap);
|
||||||
return n;
|
return n;
|
||||||
} else if(iFlags & MEMOBJ_OBJ) {
|
} else if(nType & MEMOBJ_OBJ) {
|
||||||
ph7_value sResult;
|
ph7_value sResult;
|
||||||
ph7_real rVal = 1;
|
ph7_real rVal = 1;
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
|
@ -203,14 +203,14 @@ static ph7_real MemObjRealValue(ph7_value *pObj) {
|
||||||
PH7_MemObjInit(pObj->pVm, &sResult);
|
PH7_MemObjInit(pObj->pVm, &sResult);
|
||||||
rc = MemObjCallClassCastMethod(pObj->pVm, (ph7_class_instance *)pObj->x.pOther,
|
rc = MemObjCallClassCastMethod(pObj->pVm, (ph7_class_instance *)pObj->x.pOther,
|
||||||
"__toFloat", sizeof("__toFloat") - 1, &sResult);
|
"__toFloat", sizeof("__toFloat") - 1, &sResult);
|
||||||
if(rc == SXRET_OK && (sResult.iFlags & MEMOBJ_REAL)) {
|
if(rc == SXRET_OK && (sResult.nType & MEMOBJ_REAL)) {
|
||||||
/* Extract method return value */
|
/* Extract method return value */
|
||||||
rVal = sResult.x.rVal;
|
rVal = sResult.x.rVal;
|
||||||
}
|
}
|
||||||
PH7_ClassInstanceUnref((ph7_class_instance *)pObj->x.pOther);
|
PH7_ClassInstanceUnref((ph7_class_instance *)pObj->x.pOther);
|
||||||
PH7_MemObjRelease(&sResult);
|
PH7_MemObjRelease(&sResult);
|
||||||
return rVal;
|
return rVal;
|
||||||
} else if(iFlags & MEMOBJ_RES) {
|
} else if(nType & MEMOBJ_RES) {
|
||||||
return (ph7_real)(pObj->x.pOther != 0);
|
return (ph7_real)(pObj->x.pOther != 0);
|
||||||
}
|
}
|
||||||
/* NOT REACHED */
|
/* NOT REACHED */
|
||||||
|
@ -221,12 +221,12 @@ static ph7_real MemObjRealValue(ph7_value *pObj) {
|
||||||
* This function never fail and always return SXRET_OK.
|
* This function never fail and always return SXRET_OK.
|
||||||
*/
|
*/
|
||||||
static sxi32 MemObjStringValue(SyBlob *pOut, ph7_value *pObj, sxu8 bStrictBool) {
|
static sxi32 MemObjStringValue(SyBlob *pOut, ph7_value *pObj, sxu8 bStrictBool) {
|
||||||
if(pObj->iFlags & MEMOBJ_REAL) {
|
if(pObj->nType & MEMOBJ_REAL) {
|
||||||
SyBlobFormat(&(*pOut), "%.15g", pObj->x.rVal);
|
SyBlobFormat(&(*pOut), "%.15g", pObj->x.rVal);
|
||||||
} else if(pObj->iFlags & MEMOBJ_INT) {
|
} else if(pObj->nType & MEMOBJ_INT) {
|
||||||
SyBlobFormat(&(*pOut), "%qd", pObj->x.iVal);
|
SyBlobFormat(&(*pOut), "%qd", pObj->x.iVal);
|
||||||
/* %qd (BSD quad) is equivalent to %lld in the libc printf */
|
/* %qd (BSD quad) is equivalent to %lld in the libc printf */
|
||||||
} else if(pObj->iFlags & MEMOBJ_BOOL) {
|
} else if(pObj->nType & MEMOBJ_BOOL) {
|
||||||
if(pObj->x.iVal) {
|
if(pObj->x.iVal) {
|
||||||
SyBlobAppend(&(*pOut), "TRUE", sizeof("TRUE") - 1);
|
SyBlobAppend(&(*pOut), "TRUE", sizeof("TRUE") - 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -234,21 +234,21 @@ static sxi32 MemObjStringValue(SyBlob *pOut, ph7_value *pObj, sxu8 bStrictBool)
|
||||||
SyBlobAppend(&(*pOut), "FALSE", sizeof("FALSE") - 1);
|
SyBlobAppend(&(*pOut), "FALSE", sizeof("FALSE") - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(pObj->iFlags & MEMOBJ_CHAR) {
|
} else if(pObj->nType & MEMOBJ_CHAR) {
|
||||||
if(pObj->x.iVal > 0) {
|
if(pObj->x.iVal > 0) {
|
||||||
SyBlobFormat(&(*pOut), "%c", pObj->x.iVal);
|
SyBlobFormat(&(*pOut), "%c", pObj->x.iVal);
|
||||||
}
|
}
|
||||||
} else if(pObj->iFlags & MEMOBJ_HASHMAP) {
|
} else if(pObj->nType & MEMOBJ_HASHMAP) {
|
||||||
SyBlobAppend(&(*pOut), "Array", sizeof("Array") - 1);
|
SyBlobAppend(&(*pOut), "Array", sizeof("Array") - 1);
|
||||||
PH7_HashmapUnref((ph7_hashmap *)pObj->x.pOther);
|
PH7_HashmapUnref((ph7_hashmap *)pObj->x.pOther);
|
||||||
} else if(pObj->iFlags & MEMOBJ_OBJ) {
|
} else if(pObj->nType & MEMOBJ_OBJ) {
|
||||||
ph7_value sResult;
|
ph7_value sResult;
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
/* Invoke the __toString() method if available */
|
/* Invoke the __toString() method if available */
|
||||||
PH7_MemObjInit(pObj->pVm, &sResult);
|
PH7_MemObjInit(pObj->pVm, &sResult);
|
||||||
rc = MemObjCallClassCastMethod(pObj->pVm, (ph7_class_instance *)pObj->x.pOther,
|
rc = MemObjCallClassCastMethod(pObj->pVm, (ph7_class_instance *)pObj->x.pOther,
|
||||||
"__toString", sizeof("__toString") - 1, &sResult);
|
"__toString", sizeof("__toString") - 1, &sResult);
|
||||||
if(rc == SXRET_OK && (sResult.iFlags & MEMOBJ_STRING) && SyBlobLength(&sResult.sBlob) > 0) {
|
if(rc == SXRET_OK && (sResult.nType & MEMOBJ_STRING) && SyBlobLength(&sResult.sBlob) > 0) {
|
||||||
/* Expand method return value */
|
/* Expand method return value */
|
||||||
SyBlobDup(&sResult.sBlob, pOut);
|
SyBlobDup(&sResult.sBlob, pOut);
|
||||||
} else {
|
} else {
|
||||||
|
@ -257,7 +257,7 @@ static sxi32 MemObjStringValue(SyBlob *pOut, ph7_value *pObj, sxu8 bStrictBool)
|
||||||
}
|
}
|
||||||
PH7_ClassInstanceUnref((ph7_class_instance *)pObj->x.pOther);
|
PH7_ClassInstanceUnref((ph7_class_instance *)pObj->x.pOther);
|
||||||
PH7_MemObjRelease(&sResult);
|
PH7_MemObjRelease(&sResult);
|
||||||
} else if(pObj->iFlags & MEMOBJ_RES) {
|
} else if(pObj->nType & MEMOBJ_RES) {
|
||||||
SyBlobFormat(&(*pOut), "ResourceID_%#x", pObj->x.pOther);
|
SyBlobFormat(&(*pOut), "ResourceID_%#x", pObj->x.pOther);
|
||||||
}
|
}
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
|
@ -275,13 +275,13 @@ static sxi32 MemObjStringValue(SyBlob *pOut, ph7_value *pObj, sxu8 bStrictBool)
|
||||||
* an array with zero elements.
|
* an array with zero elements.
|
||||||
*/
|
*/
|
||||||
static sxi32 MemObjBooleanValue(ph7_value *pObj) {
|
static sxi32 MemObjBooleanValue(ph7_value *pObj) {
|
||||||
sxi32 iFlags;
|
sxi32 nType;
|
||||||
iFlags = pObj->iFlags;
|
nType = pObj->nType;
|
||||||
if(iFlags & MEMOBJ_REAL) {
|
if(nType & MEMOBJ_REAL) {
|
||||||
return pObj->x.rVal != 0.0 ? 1 : 0;
|
return pObj->x.rVal != 0.0 ? 1 : 0;
|
||||||
} else if(iFlags & (MEMOBJ_INT | MEMOBJ_CHAR)) {
|
} else if(nType & (MEMOBJ_INT | MEMOBJ_CHAR)) {
|
||||||
return pObj->x.iVal ? 1 : 0;
|
return pObj->x.iVal ? 1 : 0;
|
||||||
} else if(iFlags & MEMOBJ_STRING) {
|
} else if(nType & MEMOBJ_STRING) {
|
||||||
SyString sString;
|
SyString sString;
|
||||||
SyStringInitFromBuf(&sString, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
|
SyStringInitFromBuf(&sString, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
|
||||||
if(sString.nByte == 0) {
|
if(sString.nByte == 0) {
|
||||||
|
@ -302,7 +302,7 @@ static sxi32 MemObjBooleanValue(ph7_value *pObj) {
|
||||||
}
|
}
|
||||||
return zIn >= zEnd ? 0 : 1;
|
return zIn >= zEnd ? 0 : 1;
|
||||||
}
|
}
|
||||||
} else if(iFlags & MEMOBJ_CALL) {
|
} else if(nType & MEMOBJ_CALL) {
|
||||||
SyString sString;
|
SyString sString;
|
||||||
SyStringInitFromBuf(&sString, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
|
SyStringInitFromBuf(&sString, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
|
||||||
if(sString.nByte == 0) {
|
if(sString.nByte == 0) {
|
||||||
|
@ -312,14 +312,14 @@ static sxi32 MemObjBooleanValue(ph7_value *pObj) {
|
||||||
/* Something set, return true */
|
/* Something set, return true */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if(iFlags & (MEMOBJ_NULL | MEMOBJ_VOID)) {
|
} else if(nType & (MEMOBJ_NULL | MEMOBJ_VOID)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if(iFlags & MEMOBJ_HASHMAP) {
|
} else if(nType & MEMOBJ_HASHMAP) {
|
||||||
ph7_hashmap *pMap = (ph7_hashmap *)pObj->x.pOther;
|
ph7_hashmap *pMap = (ph7_hashmap *)pObj->x.pOther;
|
||||||
sxu32 n = pMap->nEntry;
|
sxu32 n = pMap->nEntry;
|
||||||
PH7_HashmapUnref(pMap);
|
PH7_HashmapUnref(pMap);
|
||||||
return n > 0 ? TRUE : FALSE;
|
return n > 0 ? TRUE : FALSE;
|
||||||
} else if(iFlags & MEMOBJ_OBJ) {
|
} else if(nType & MEMOBJ_OBJ) {
|
||||||
ph7_value sResult;
|
ph7_value sResult;
|
||||||
sxi32 iVal = 1;
|
sxi32 iVal = 1;
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
|
@ -330,14 +330,14 @@ static sxi32 MemObjBooleanValue(ph7_value *pObj) {
|
||||||
PH7_MemObjInit(pObj->pVm, &sResult);
|
PH7_MemObjInit(pObj->pVm, &sResult);
|
||||||
rc = MemObjCallClassCastMethod(pObj->pVm, (ph7_class_instance *)pObj->x.pOther,
|
rc = MemObjCallClassCastMethod(pObj->pVm, (ph7_class_instance *)pObj->x.pOther,
|
||||||
"__toBool", sizeof("__toBool") - 1, &sResult);
|
"__toBool", sizeof("__toBool") - 1, &sResult);
|
||||||
if(rc == SXRET_OK && (sResult.iFlags & (MEMOBJ_INT | MEMOBJ_BOOL))) {
|
if(rc == SXRET_OK && (sResult.nType & (MEMOBJ_INT | MEMOBJ_BOOL))) {
|
||||||
/* Extract method return value */
|
/* Extract method return value */
|
||||||
iVal = (sxi32)(sResult.x.iVal != 0); /* Stupid cc warning -W -Wall -O6 */
|
iVal = (sxi32)(sResult.x.iVal != 0); /* Stupid cc warning -W -Wall -O6 */
|
||||||
}
|
}
|
||||||
PH7_ClassInstanceUnref((ph7_class_instance *)pObj->x.pOther);
|
PH7_ClassInstanceUnref((ph7_class_instance *)pObj->x.pOther);
|
||||||
PH7_MemObjRelease(&sResult);
|
PH7_MemObjRelease(&sResult);
|
||||||
return iVal;
|
return iVal;
|
||||||
} else if(iFlags & MEMOBJ_RES) {
|
} else if(nType & MEMOBJ_RES) {
|
||||||
return pObj->x.pOther != 0;
|
return pObj->x.pOther != 0;
|
||||||
}
|
}
|
||||||
/* NOT REACHED */
|
/* NOT REACHED */
|
||||||
|
@ -348,13 +348,13 @@ static sxi32 MemObjBooleanValue(ph7_value *pObj) {
|
||||||
* This function never fail and always return SXRET_OK.
|
* This function never fail and always return SXRET_OK.
|
||||||
*/
|
*/
|
||||||
static ph7_real MemObjCharValue(ph7_value *pObj) {
|
static ph7_real MemObjCharValue(ph7_value *pObj) {
|
||||||
sxi32 iFlags;
|
sxi32 nType;
|
||||||
iFlags = pObj->iFlags;
|
nType = pObj->nType;
|
||||||
if(iFlags & (MEMOBJ_CALL | MEMOBJ_REAL | MEMOBJ_HASHMAP | MEMOBJ_RES | MEMOBJ_NULL | MEMOBJ_VOID)) {
|
if(nType & (MEMOBJ_CALL | MEMOBJ_REAL | MEMOBJ_HASHMAP | MEMOBJ_RES | MEMOBJ_NULL | MEMOBJ_VOID)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if(iFlags & MEMOBJ_INT) {
|
} else if(nType & MEMOBJ_INT) {
|
||||||
return pObj->x.iVal;
|
return pObj->x.iVal;
|
||||||
} else if(iFlags & MEMOBJ_STRING) {
|
} else if(nType & MEMOBJ_STRING) {
|
||||||
SyString sString;
|
SyString sString;
|
||||||
SyStringInitFromBuf(&sString, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
|
SyStringInitFromBuf(&sString, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
|
||||||
if(sString.nByte == 0) {
|
if(sString.nByte == 0) {
|
||||||
|
@ -370,26 +370,26 @@ static ph7_real MemObjCharValue(ph7_value *pObj) {
|
||||||
* Checks a ph7_value variable compatibility with nType data type.
|
* Checks a ph7_value variable compatibility with nType data type.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_CheckVarCompat(ph7_value *pObj, int nType) {
|
PH7_PRIVATE sxi32 PH7_CheckVarCompat(ph7_value *pObj, int nType) {
|
||||||
if(((nType & MEMOBJ_HASHMAP) == 0) && ((pObj->iFlags & MEMOBJ_HASHMAP) == 0)) {
|
if(((nType & MEMOBJ_HASHMAP) == 0) && ((pObj->nType & MEMOBJ_HASHMAP) == 0)) {
|
||||||
if(pObj->iFlags & MEMOBJ_NULL) {
|
if(pObj->nType & MEMOBJ_NULL) {
|
||||||
/* Always allow to store a NULL */
|
/* Always allow to store a NULL */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
} else if((nType & MEMOBJ_REAL) && (pObj->iFlags & MEMOBJ_INT)) {
|
} else if((nType & MEMOBJ_REAL) && (pObj->nType & MEMOBJ_INT)) {
|
||||||
/* Allow to store INT to FLOAT variable */
|
/* Allow to store INT to FLOAT variable */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
} else if((nType & MEMOBJ_CHAR) && (pObj->iFlags & MEMOBJ_INT)) {
|
} else if((nType & MEMOBJ_CHAR) && (pObj->nType & MEMOBJ_INT)) {
|
||||||
/* Allow to store INT to CHAR variable */
|
/* Allow to store INT to CHAR variable */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
} else if((nType & MEMOBJ_STRING) && (pObj->iFlags & MEMOBJ_CHAR)) {
|
} else if((nType & MEMOBJ_STRING) && (pObj->nType & MEMOBJ_CHAR)) {
|
||||||
/* Allow to store CHAR to STRING variable */
|
/* Allow to store CHAR to STRING variable */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
} else if((nType & MEMOBJ_CHAR) && (pObj->iFlags & MEMOBJ_STRING)) {
|
} else if((nType & MEMOBJ_CHAR) && (pObj->nType & MEMOBJ_STRING)) {
|
||||||
/* Allow to store STRING to CHAR variable (if not too long) */
|
/* Allow to store STRING to CHAR variable (if not too long) */
|
||||||
int len = SyBlobLength(&pObj->sBlob);
|
int len = SyBlobLength(&pObj->sBlob);
|
||||||
if(len == 0 || len == 1) {
|
if(len == 0 || len == 1) {
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
} else if((nType & MEMOBJ_CALL) && (pObj->iFlags & MEMOBJ_STRING)) {
|
} else if((nType & MEMOBJ_CALL) && (pObj->nType & MEMOBJ_STRING)) {
|
||||||
/* Allow to store STRING to CALLBACK variable */
|
/* Allow to store STRING to CALLBACK variable */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
@ -401,48 +401,48 @@ PH7_PRIVATE sxi32 PH7_CheckVarCompat(ph7_value *pObj, int nType) {
|
||||||
* destination are of the compatible data types.
|
* destination are of the compatible data types.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjSafeStore(ph7_value *pSrc, ph7_value *pDest) {
|
PH7_PRIVATE sxi32 PH7_MemObjSafeStore(ph7_value *pSrc, ph7_value *pDest) {
|
||||||
if(pDest->iFlags == 0 || ((pDest->iFlags | MEMOBJ_FIXEDVAL | MEMOBJ_PARENTOBJ) == (pSrc->iFlags | MEMOBJ_FIXEDVAL | MEMOBJ_PARENTOBJ))) {
|
if(pDest->nType == 0 || ((pDest->nType | MEMOBJ_FIXEDVAL | MEMOBJ_PARENTOBJ) == (pSrc->nType | MEMOBJ_FIXEDVAL | MEMOBJ_PARENTOBJ))) {
|
||||||
PH7_MemObjStore(pSrc, pDest);
|
PH7_MemObjStore(pSrc, pDest);
|
||||||
} else if(pDest->iFlags & MEMOBJ_MIXED) {
|
} else if(pDest->nType & MEMOBJ_MIXED) {
|
||||||
if(pDest->iFlags & MEMOBJ_HASHMAP) {
|
if(pDest->nType & MEMOBJ_HASHMAP) {
|
||||||
/* mixed[] */
|
/* mixed[] */
|
||||||
if(pSrc->iFlags & MEMOBJ_HASHMAP) {
|
if(pSrc->nType & MEMOBJ_HASHMAP) {
|
||||||
PH7_MemObjStore(pSrc, pDest);
|
PH7_MemObjStore(pSrc, pDest);
|
||||||
pDest->iFlags |= MEMOBJ_MIXED;
|
pDest->nType |= MEMOBJ_MIXED;
|
||||||
} else if(pSrc->iFlags & MEMOBJ_NULL) {
|
} else if(pSrc->nType & MEMOBJ_NULL) {
|
||||||
PH7_MemObjToHashmap(pSrc);
|
PH7_MemObjToHashmap(pSrc);
|
||||||
MemObjSetType(pSrc, pDest->iFlags);
|
MemObjSetType(pSrc, pDest->nType);
|
||||||
PH7_MemObjStore(pSrc, pDest);
|
PH7_MemObjStore(pSrc, pDest);
|
||||||
} else {
|
} else {
|
||||||
return SXERR_NOMATCH;
|
return SXERR_NOMATCH;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* mixed */
|
/* mixed */
|
||||||
if(pSrc->iFlags == MEMOBJ_NULL) {
|
if(pSrc->nType == MEMOBJ_NULL) {
|
||||||
MemObjSetType(pDest, MEMOBJ_MIXED | MEMOBJ_VOID);
|
MemObjSetType(pDest, MEMOBJ_MIXED | MEMOBJ_VOID);
|
||||||
} else if((pSrc->iFlags & MEMOBJ_HASHMAP) == 0) {
|
} else if((pSrc->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
PH7_MemObjStore(pSrc, pDest);
|
PH7_MemObjStore(pSrc, pDest);
|
||||||
pDest->iFlags |= MEMOBJ_MIXED;
|
pDest->nType |= MEMOBJ_MIXED;
|
||||||
} else {
|
} else {
|
||||||
return SXERR_NOMATCH;
|
return SXERR_NOMATCH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if((pDest->iFlags & MEMOBJ_HASHMAP)) {
|
} else if((pDest->nType & MEMOBJ_HASHMAP)) {
|
||||||
/* [] */
|
/* [] */
|
||||||
if(pSrc->iFlags & MEMOBJ_NULL) {
|
if(pSrc->nType & MEMOBJ_NULL) {
|
||||||
PH7_MemObjToHashmap(pSrc);
|
PH7_MemObjToHashmap(pSrc);
|
||||||
MemObjSetType(pSrc, pDest->iFlags);
|
MemObjSetType(pSrc, pDest->nType);
|
||||||
PH7_MemObjStore(pSrc, pDest);
|
PH7_MemObjStore(pSrc, pDest);
|
||||||
} else if(pSrc->iFlags & MEMOBJ_HASHMAP) {
|
} else if(pSrc->nType & MEMOBJ_HASHMAP) {
|
||||||
if(PH7_HashmapCast(pSrc, pDest->iFlags ^ MEMOBJ_HASHMAP) != SXRET_OK) {
|
if(PH7_HashmapCast(pSrc, pDest->nType ^ MEMOBJ_HASHMAP) != SXRET_OK) {
|
||||||
return SXERR_NOMATCH;
|
return SXERR_NOMATCH;
|
||||||
}
|
}
|
||||||
PH7_MemObjStore(pSrc, pDest);
|
PH7_MemObjStore(pSrc, pDest);
|
||||||
} else {
|
} else {
|
||||||
return SXERR_NOMATCH;
|
return SXERR_NOMATCH;
|
||||||
}
|
}
|
||||||
} else if(PH7_CheckVarCompat(pSrc, pDest->iFlags) == SXRET_OK) {
|
} else if(PH7_CheckVarCompat(pSrc, pDest->nType) == SXRET_OK) {
|
||||||
ProcMemObjCast xCast = PH7_MemObjCastMethod(pDest->iFlags);
|
ProcMemObjCast xCast = PH7_MemObjCastMethod(pDest->nType);
|
||||||
xCast(pSrc);
|
xCast(pSrc);
|
||||||
PH7_MemObjStore(pSrc, pDest);
|
PH7_MemObjStore(pSrc, pDest);
|
||||||
} else {
|
} else {
|
||||||
|
@ -454,7 +454,7 @@ PH7_PRIVATE sxi32 PH7_MemObjSafeStore(ph7_value *pSrc, ph7_value *pDest) {
|
||||||
* Convert a ph7_value to type integer.Invalidate any prior representations.
|
* Convert a ph7_value to type integer.Invalidate any prior representations.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToInteger(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToInteger(ph7_value *pObj) {
|
||||||
if((pObj->iFlags & MEMOBJ_INT) == 0) {
|
if((pObj->nType & MEMOBJ_INT) == 0) {
|
||||||
/* Preform the conversion */
|
/* Preform the conversion */
|
||||||
pObj->x.iVal = MemObjIntValue(&(*pObj));
|
pObj->x.iVal = MemObjIntValue(&(*pObj));
|
||||||
/* Invalidate any prior representations */
|
/* Invalidate any prior representations */
|
||||||
|
@ -468,7 +468,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToInteger(ph7_value *pObj) {
|
||||||
* Invalidate any prior representations
|
* Invalidate any prior representations
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToReal(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToReal(ph7_value *pObj) {
|
||||||
if((pObj->iFlags & MEMOBJ_REAL) == 0) {
|
if((pObj->nType & MEMOBJ_REAL) == 0) {
|
||||||
/* Preform the conversion */
|
/* Preform the conversion */
|
||||||
pObj->x.rVal = MemObjRealValue(&(*pObj));
|
pObj->x.rVal = MemObjRealValue(&(*pObj));
|
||||||
/* Invalidate any prior representations */
|
/* Invalidate any prior representations */
|
||||||
|
@ -481,7 +481,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToReal(ph7_value *pObj) {
|
||||||
* Convert a ph7_value to type boolean.Invalidate any prior representations.
|
* Convert a ph7_value to type boolean.Invalidate any prior representations.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToBool(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToBool(ph7_value *pObj) {
|
||||||
if((pObj->iFlags & MEMOBJ_BOOL) == 0) {
|
if((pObj->nType & MEMOBJ_BOOL) == 0) {
|
||||||
/* Preform the conversion */
|
/* Preform the conversion */
|
||||||
pObj->x.iVal = MemObjBooleanValue(&(*pObj));
|
pObj->x.iVal = MemObjBooleanValue(&(*pObj));
|
||||||
/* Invalidate any prior representations */
|
/* Invalidate any prior representations */
|
||||||
|
@ -491,7 +491,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToBool(ph7_value *pObj) {
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToChar(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToChar(ph7_value *pObj) {
|
||||||
if((pObj->iFlags & MEMOBJ_CHAR) == 0) {
|
if((pObj->nType & MEMOBJ_CHAR) == 0) {
|
||||||
/* Preform the conversion */
|
/* Preform the conversion */
|
||||||
pObj->x.iVal = MemObjCharValue(&(*pObj));
|
pObj->x.iVal = MemObjCharValue(&(*pObj));
|
||||||
/* Invalidate any prior representations */
|
/* Invalidate any prior representations */
|
||||||
|
@ -504,7 +504,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToChar(ph7_value *pObj) {
|
||||||
* Convert a ph7_value to type void.Invalidate any prior representations.
|
* Convert a ph7_value to type void.Invalidate any prior representations.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToVoid(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToVoid(ph7_value *pObj) {
|
||||||
if((pObj->iFlags & MEMOBJ_VOID) == 0) {
|
if((pObj->nType & MEMOBJ_VOID) == 0) {
|
||||||
PH7_MemObjRelease(pObj);
|
PH7_MemObjRelease(pObj);
|
||||||
MemObjSetType(pObj, MEMOBJ_VOID);
|
MemObjSetType(pObj, MEMOBJ_VOID);
|
||||||
}
|
}
|
||||||
|
@ -512,7 +512,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToVoid(ph7_value *pObj) {
|
||||||
}
|
}
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToCallback(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToCallback(ph7_value *pObj) {
|
||||||
sxi32 rc = SXRET_OK;
|
sxi32 rc = SXRET_OK;
|
||||||
if((pObj->iFlags & (MEMOBJ_CALL | MEMOBJ_STRING)) == 0) {
|
if((pObj->nType & (MEMOBJ_CALL | MEMOBJ_STRING)) == 0) {
|
||||||
SyBlobReset(&pObj->sBlob); /* Reset the internal buffer */
|
SyBlobReset(&pObj->sBlob); /* Reset the internal buffer */
|
||||||
rc = MemObjStringValue(&pObj->sBlob, &(*pObj), TRUE);
|
rc = MemObjStringValue(&pObj->sBlob, &(*pObj), TRUE);
|
||||||
}
|
}
|
||||||
|
@ -521,10 +521,10 @@ PH7_PRIVATE sxi32 PH7_MemObjToCallback(ph7_value *pObj) {
|
||||||
}
|
}
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToResource(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToResource(ph7_value *pObj) {
|
||||||
sxi32 rc = SXRET_OK;
|
sxi32 rc = SXRET_OK;
|
||||||
if((pObj->iFlags & MEMOBJ_NULL) == 0) {
|
if((pObj->nType & MEMOBJ_NULL) == 0) {
|
||||||
PH7_VmThrowError(&(*pObj->pVm), PH7_CTX_WARNING, "Unsafe type casting condition, assuming default value");
|
PH7_VmThrowError(&(*pObj->pVm), PH7_CTX_WARNING, "Unsafe type casting condition, assuming default value");
|
||||||
}
|
}
|
||||||
if((pObj->iFlags & MEMOBJ_RES) == 0) {
|
if((pObj->nType & MEMOBJ_RES) == 0) {
|
||||||
pObj->x.iVal = 0;
|
pObj->x.iVal = 0;
|
||||||
}
|
}
|
||||||
MemObjSetType(pObj, MEMOBJ_RES);
|
MemObjSetType(pObj, MEMOBJ_RES);
|
||||||
|
@ -535,8 +535,8 @@ PH7_PRIVATE sxi32 PH7_MemObjToResource(ph7_value *pObj) {
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToString(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToString(ph7_value *pObj) {
|
||||||
sxi32 rc = SXRET_OK;
|
sxi32 rc = SXRET_OK;
|
||||||
if((pObj->iFlags & MEMOBJ_STRING) == 0) {
|
if((pObj->nType & MEMOBJ_STRING) == 0) {
|
||||||
if((pObj->iFlags & MEMOBJ_CALL) == 0) {
|
if((pObj->nType & MEMOBJ_CALL) == 0) {
|
||||||
/* Perform the conversion */
|
/* Perform the conversion */
|
||||||
SyBlobReset(&pObj->sBlob); /* Reset the internal buffer */
|
SyBlobReset(&pObj->sBlob); /* Reset the internal buffer */
|
||||||
rc = MemObjStringValue(&pObj->sBlob, &(*pObj), TRUE);
|
rc = MemObjStringValue(&pObj->sBlob, &(*pObj), TRUE);
|
||||||
|
@ -553,21 +553,21 @@ PH7_PRIVATE sxi32 PH7_MemObjToString(ph7_value *pObj) {
|
||||||
* and the value of the scalar which was converted.
|
* and the value of the scalar which was converted.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToHashmap(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToHashmap(ph7_value *pObj) {
|
||||||
if((pObj->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if((pObj->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
ph7_hashmap *pMap;
|
ph7_hashmap *pMap;
|
||||||
/* Allocate a new hashmap instance */
|
/* Allocate a new hashmap instance */
|
||||||
pMap = PH7_NewHashmap(pObj->pVm, 0, 0);
|
pMap = PH7_NewHashmap(pObj->pVm, 0, 0);
|
||||||
if(pMap == 0) {
|
if(pMap == 0) {
|
||||||
return SXERR_MEM;
|
return SXERR_MEM;
|
||||||
}
|
}
|
||||||
if((pObj->iFlags & (MEMOBJ_NULL | MEMOBJ_RES)) == 0) {
|
if((pObj->nType & (MEMOBJ_NULL | MEMOBJ_RES)) == 0) {
|
||||||
/*
|
/*
|
||||||
* According to the PHP language reference manual.
|
* According to the PHP language reference manual.
|
||||||
* For any of the types: integer, float, string, boolean converting a value
|
* For any of the types: integer, float, string, boolean converting a value
|
||||||
* to an array results in an array with a single element with index zero
|
* to an array results in an array with a single element with index zero
|
||||||
* and the value of the scalar which was converted.
|
* and the value of the scalar which was converted.
|
||||||
*/
|
*/
|
||||||
if(pObj->iFlags & MEMOBJ_OBJ) {
|
if(pObj->nType & MEMOBJ_OBJ) {
|
||||||
/* Object cast */
|
/* Object cast */
|
||||||
PH7_ClassInstanceToHashmap((ph7_class_instance *)pObj->x.pOther, pMap);
|
PH7_ClassInstanceToHashmap((ph7_class_instance *)pObj->x.pOther, pMap);
|
||||||
} else {
|
} else {
|
||||||
|
@ -599,12 +599,12 @@ PH7_PRIVATE sxi32 PH7_MemObjToHashmap(ph7_value *pObj) {
|
||||||
* Refer to the official documentation for more information.
|
* Refer to the official documentation for more information.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToObject(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToObject(ph7_value *pObj) {
|
||||||
if(pObj->iFlags & MEMOBJ_NULL) {
|
if(pObj->nType & MEMOBJ_NULL) {
|
||||||
/* Invalidate any prior representation */
|
/* Invalidate any prior representation */
|
||||||
PH7_MemObjRelease(pObj);
|
PH7_MemObjRelease(pObj);
|
||||||
/* Typecast the value */
|
/* Typecast the value */
|
||||||
MemObjSetType(pObj, MEMOBJ_OBJ);
|
MemObjSetType(pObj, MEMOBJ_OBJ);
|
||||||
} else if((pObj->iFlags & MEMOBJ_OBJ) == 0) {
|
} else if((pObj->nType & MEMOBJ_OBJ) == 0) {
|
||||||
ph7_class_instance *pStd;
|
ph7_class_instance *pStd;
|
||||||
ph7_class_method *pCons;
|
ph7_class_method *pCons;
|
||||||
ph7_class *pClass;
|
ph7_class *pClass;
|
||||||
|
@ -655,24 +655,24 @@ PH7_PRIVATE sxi32 PH7_MemObjToObject(ph7_value *pObj) {
|
||||||
* to variable $var, $var becomes a string. If an integer value is then
|
* to variable $var, $var becomes a string. If an integer value is then
|
||||||
* assigned to $var, it becomes an integer.
|
* assigned to $var, it becomes an integer.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE ProcMemObjCast PH7_MemObjCastMethod(sxi32 iFlags) {
|
PH7_PRIVATE ProcMemObjCast PH7_MemObjCastMethod(sxi32 nType) {
|
||||||
if(iFlags & MEMOBJ_STRING) {
|
if(nType & MEMOBJ_STRING) {
|
||||||
return PH7_MemObjToString;
|
return PH7_MemObjToString;
|
||||||
} else if(iFlags & MEMOBJ_INT) {
|
} else if(nType & MEMOBJ_INT) {
|
||||||
return PH7_MemObjToInteger;
|
return PH7_MemObjToInteger;
|
||||||
} else if(iFlags & MEMOBJ_REAL) {
|
} else if(nType & MEMOBJ_REAL) {
|
||||||
return PH7_MemObjToReal;
|
return PH7_MemObjToReal;
|
||||||
} else if(iFlags & MEMOBJ_BOOL) {
|
} else if(nType & MEMOBJ_BOOL) {
|
||||||
return PH7_MemObjToBool;
|
return PH7_MemObjToBool;
|
||||||
} else if(iFlags & MEMOBJ_CHAR) {
|
} else if(nType & MEMOBJ_CHAR) {
|
||||||
return PH7_MemObjToChar;
|
return PH7_MemObjToChar;
|
||||||
} else if(iFlags & MEMOBJ_OBJ) {
|
} else if(nType & MEMOBJ_OBJ) {
|
||||||
return PH7_MemObjToObject;
|
return PH7_MemObjToObject;
|
||||||
} else if(iFlags & MEMOBJ_CALL) {
|
} else if(nType & MEMOBJ_CALL) {
|
||||||
return PH7_MemObjToCallback;
|
return PH7_MemObjToCallback;
|
||||||
} else if(iFlags & MEMOBJ_RES) {
|
} else if(nType & MEMOBJ_RES) {
|
||||||
return PH7_MemObjToResource;
|
return PH7_MemObjToResource;
|
||||||
} else if(iFlags & MEMOBJ_VOID) {
|
} else if(nType & MEMOBJ_VOID) {
|
||||||
return PH7_MemObjToVoid;
|
return PH7_MemObjToVoid;
|
||||||
}
|
}
|
||||||
/* Release the variable */
|
/* Release the variable */
|
||||||
|
@ -684,7 +684,7 @@ PH7_PRIVATE ProcMemObjCast PH7_MemObjCastMethod(sxi32 iFlags) {
|
||||||
* Return TRUE if numeric.FALSE otherwise.
|
* Return TRUE if numeric.FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjIsNumeric(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjIsNumeric(ph7_value *pObj) {
|
||||||
if(pObj->iFlags & (MEMOBJ_INT | MEMOBJ_REAL)) {
|
if(pObj->nType & (MEMOBJ_INT | MEMOBJ_REAL)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -698,9 +698,9 @@ PH7_PRIVATE sxi32 PH7_MemObjIsNumeric(ph7_value *pObj) {
|
||||||
* and ignore the rest.
|
* and ignore the rest.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjToNumeric(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjToNumeric(ph7_value *pObj) {
|
||||||
if(pObj->iFlags & (MEMOBJ_INT | MEMOBJ_REAL | MEMOBJ_BOOL | MEMOBJ_NULL)) {
|
if(pObj->nType & (MEMOBJ_INT | MEMOBJ_REAL | MEMOBJ_BOOL | MEMOBJ_NULL)) {
|
||||||
if(pObj->iFlags & (MEMOBJ_BOOL | MEMOBJ_NULL | MEMOBJ_VOID)) {
|
if(pObj->nType & (MEMOBJ_BOOL | MEMOBJ_NULL | MEMOBJ_VOID)) {
|
||||||
if(pObj->iFlags & (MEMOBJ_CALL | MEMOBJ_NULL | MEMOBJ_VOID)) {
|
if(pObj->nType & (MEMOBJ_CALL | MEMOBJ_NULL | MEMOBJ_VOID)) {
|
||||||
pObj->x.iVal = 0;
|
pObj->x.iVal = 0;
|
||||||
}
|
}
|
||||||
MemObjSetType(pObj, MEMOBJ_INT);
|
MemObjSetType(pObj, MEMOBJ_INT);
|
||||||
|
@ -708,7 +708,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToNumeric(ph7_value *pObj) {
|
||||||
/* Already numeric */
|
/* Already numeric */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
if(pObj->iFlags & MEMOBJ_STRING) {
|
if(pObj->nType & MEMOBJ_STRING) {
|
||||||
sxi32 rc = SXERR_INVALID;
|
sxi32 rc = SXERR_INVALID;
|
||||||
sxu8 bReal = FALSE;
|
sxu8 bReal = FALSE;
|
||||||
SyString sString;
|
SyString sString;
|
||||||
|
@ -730,7 +730,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToNumeric(ph7_value *pObj) {
|
||||||
MemObjSetType(pObj, MEMOBJ_INT);
|
MemObjSetType(pObj, MEMOBJ_INT);
|
||||||
SyBlobRelease(&pObj->sBlob);
|
SyBlobRelease(&pObj->sBlob);
|
||||||
}
|
}
|
||||||
} else if(pObj->iFlags & (MEMOBJ_OBJ | MEMOBJ_HASHMAP | MEMOBJ_RES)) {
|
} else if(pObj->nType & (MEMOBJ_OBJ | MEMOBJ_HASHMAP | MEMOBJ_RES)) {
|
||||||
PH7_MemObjToInteger(pObj);
|
PH7_MemObjToInteger(pObj);
|
||||||
} else {
|
} else {
|
||||||
/* Perform a blind cast */
|
/* Perform a blind cast */
|
||||||
|
@ -748,7 +748,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInit(ph7_vm *pVm, ph7_value *pObj) {
|
||||||
pObj->pVm = pVm;
|
pObj->pVm = pVm;
|
||||||
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
||||||
/* Set the NULL type */
|
/* Set the NULL type */
|
||||||
pObj->iFlags = MEMOBJ_NULL;
|
pObj->nType = MEMOBJ_NULL;
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -762,7 +762,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromInt(ph7_vm *pVm, ph7_value *pObj, sxi64 iVal
|
||||||
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
||||||
/* Set the desired type */
|
/* Set the desired type */
|
||||||
pObj->x.iVal = iVal;
|
pObj->x.iVal = iVal;
|
||||||
pObj->iFlags = MEMOBJ_INT;
|
pObj->nType = MEMOBJ_INT;
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -776,7 +776,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromBool(ph7_vm *pVm, ph7_value *pObj, sxi32 iVa
|
||||||
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
||||||
/* Set the desired type */
|
/* Set the desired type */
|
||||||
pObj->x.iVal = iVal ? 1 : 0;
|
pObj->x.iVal = iVal ? 1 : 0;
|
||||||
pObj->iFlags = MEMOBJ_BOOL;
|
pObj->nType = MEMOBJ_BOOL;
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -790,7 +790,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromReal(ph7_vm *pVm, ph7_value *pObj, ph7_real
|
||||||
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
||||||
/* Set the desired type */
|
/* Set the desired type */
|
||||||
pObj->x.rVal = rVal;
|
pObj->x.rVal = rVal;
|
||||||
pObj->iFlags = MEMOBJ_REAL;
|
pObj->nType = MEMOBJ_REAL;
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -803,7 +803,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromVoid(ph7_vm *pVm, ph7_value *pObj, ph7_real
|
||||||
pObj->pVm = pVm;
|
pObj->pVm = pVm;
|
||||||
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
||||||
/* Set the desired type */
|
/* Set the desired type */
|
||||||
pObj->iFlags = MEMOBJ_VOID;
|
pObj->nType = MEMOBJ_VOID;
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}/*
|
}/*
|
||||||
* Initialize a ph7_value to the array type.
|
* Initialize a ph7_value to the array type.
|
||||||
|
@ -815,7 +815,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromArray(ph7_vm *pVm, ph7_value *pObj, ph7_hash
|
||||||
pObj->pVm = pVm;
|
pObj->pVm = pVm;
|
||||||
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
SyBlobInit(&pObj->sBlob, &pVm->sAllocator);
|
||||||
/* Set the desired type */
|
/* Set the desired type */
|
||||||
pObj->iFlags = MEMOBJ_HASHMAP;
|
pObj->nType = MEMOBJ_HASHMAP;
|
||||||
pObj->x.pOther = pArray;
|
pObj->x.pOther = pArray;
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
@ -833,7 +833,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromString(ph7_vm *pVm, ph7_value *pObj, const S
|
||||||
SyBlobAppend(&pObj->sBlob, (const void *)pVal->zString, pVal->nByte);
|
SyBlobAppend(&pObj->sBlob, (const void *)pVal->zString, pVal->nByte);
|
||||||
}
|
}
|
||||||
/* Set the desired type */
|
/* Set the desired type */
|
||||||
pObj->iFlags = MEMOBJ_STRING;
|
pObj->nType = MEMOBJ_STRING;
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -844,7 +844,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromString(ph7_vm *pVm, ph7_value *pObj, const S
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjStringAppend(ph7_value *pObj, const char *zData, sxu32 nLen) {
|
PH7_PRIVATE sxi32 PH7_MemObjStringAppend(ph7_value *pObj, const char *zData, sxu32 nLen) {
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
if((pObj->iFlags & MEMOBJ_STRING) == 0) {
|
if((pObj->nType & MEMOBJ_STRING) == 0) {
|
||||||
/* Invalidate any prior representation */
|
/* Invalidate any prior representation */
|
||||||
PH7_MemObjRelease(pObj);
|
PH7_MemObjRelease(pObj);
|
||||||
MemObjSetType(pObj, MEMOBJ_STRING);
|
MemObjSetType(pObj, MEMOBJ_STRING);
|
||||||
|
@ -861,7 +861,7 @@ PH7_PRIVATE sxi32 PH7_MemObjStringAppend(ph7_value *pObj, const char *zData, sxu
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjStringFormat(ph7_value *pObj, const char *zFormat, va_list ap) {
|
PH7_PRIVATE sxi32 PH7_MemObjStringFormat(ph7_value *pObj, const char *zFormat, va_list ap) {
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
if((pObj->iFlags & MEMOBJ_STRING) == 0) {
|
if((pObj->nType & MEMOBJ_STRING) == 0) {
|
||||||
/* Invalidate any prior representation */
|
/* Invalidate any prior representation */
|
||||||
PH7_MemObjRelease(pObj);
|
PH7_MemObjRelease(pObj);
|
||||||
MemObjSetType(pObj, MEMOBJ_STRING);
|
MemObjSetType(pObj, MEMOBJ_STRING);
|
||||||
|
@ -878,15 +878,15 @@ PH7_PRIVATE sxi32 PH7_MemObjStore(ph7_value *pSrc, ph7_value *pDest) {
|
||||||
ph7_hashmap *pSrcMap = 0;
|
ph7_hashmap *pSrcMap = 0;
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
if(pSrc->x.pOther) {
|
if(pSrc->x.pOther) {
|
||||||
if(pSrc->iFlags & MEMOBJ_HASHMAP) {
|
if(pSrc->nType & MEMOBJ_HASHMAP) {
|
||||||
/* Dump source hashmap */
|
/* Dump source hashmap */
|
||||||
pSrcMap = (ph7_hashmap *)pSrc->x.pOther;
|
pSrcMap = (ph7_hashmap *)pSrc->x.pOther;
|
||||||
} else if(pSrc->iFlags & MEMOBJ_OBJ) {
|
} else if(pSrc->nType & MEMOBJ_OBJ) {
|
||||||
/* Increment reference count */
|
/* Increment reference count */
|
||||||
((ph7_class_instance *)pSrc->x.pOther)->iRef++;
|
((ph7_class_instance *)pSrc->x.pOther)->iRef++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(pDest->iFlags & MEMOBJ_OBJ) {
|
if(pDest->nType & MEMOBJ_OBJ) {
|
||||||
pObj = (ph7_class_instance *)pDest->x.pOther;
|
pObj = (ph7_class_instance *)pDest->x.pOther;
|
||||||
}
|
}
|
||||||
SyMemcpy((const void *) & (*pSrc), &(*pDest), sizeof(ph7_value) - (sizeof(ph7_vm *) + sizeof(SyBlob) + sizeof(sxu32)));
|
SyMemcpy((const void *) & (*pSrc), &(*pDest), sizeof(ph7_value) - (sizeof(ph7_vm *) + sizeof(SyBlob) + sizeof(sxu32)));
|
||||||
|
@ -918,10 +918,10 @@ PH7_PRIVATE sxi32 PH7_MemObjLoad(ph7_value *pSrc, ph7_value *pDest) {
|
||||||
SyMemcpy((const void *) & (*pSrc), &(*pDest),
|
SyMemcpy((const void *) & (*pSrc), &(*pDest),
|
||||||
sizeof(ph7_value) - (sizeof(ph7_vm *) + sizeof(SyBlob) + sizeof(sxu32)));
|
sizeof(ph7_value) - (sizeof(ph7_vm *) + sizeof(SyBlob) + sizeof(sxu32)));
|
||||||
if(pSrc->x.pOther) {
|
if(pSrc->x.pOther) {
|
||||||
if(pSrc->iFlags & MEMOBJ_HASHMAP) {
|
if(pSrc->nType & MEMOBJ_HASHMAP) {
|
||||||
/* Increment reference count */
|
/* Increment reference count */
|
||||||
((ph7_hashmap *)pSrc->x.pOther)->iRef++;
|
((ph7_hashmap *)pSrc->x.pOther)->iRef++;
|
||||||
} else if(pSrc->iFlags & MEMOBJ_OBJ) {
|
} else if(pSrc->nType & MEMOBJ_OBJ) {
|
||||||
/* Increment reference count */
|
/* Increment reference count */
|
||||||
((ph7_class_instance *)pSrc->x.pOther)->iRef++;
|
((ph7_class_instance *)pSrc->x.pOther)->iRef++;
|
||||||
}
|
}
|
||||||
|
@ -938,18 +938,18 @@ PH7_PRIVATE sxi32 PH7_MemObjLoad(ph7_value *pSrc, ph7_value *pDest) {
|
||||||
* Invalidate any prior representation of a given ph7_value.
|
* Invalidate any prior representation of a given ph7_value.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjRelease(ph7_value *pObj) {
|
PH7_PRIVATE sxi32 PH7_MemObjRelease(ph7_value *pObj) {
|
||||||
if((pObj->iFlags & MEMOBJ_NULL) == 0) {
|
if((pObj->nType & MEMOBJ_NULL) == 0) {
|
||||||
if(pObj->x.pOther) {
|
if(pObj->x.pOther) {
|
||||||
if(pObj->iFlags & MEMOBJ_HASHMAP) {
|
if(pObj->nType & MEMOBJ_HASHMAP) {
|
||||||
PH7_HashmapUnref((ph7_hashmap *)pObj->x.pOther);
|
PH7_HashmapUnref((ph7_hashmap *)pObj->x.pOther);
|
||||||
} else if(pObj->iFlags & MEMOBJ_OBJ) {
|
} else if(pObj->nType & MEMOBJ_OBJ) {
|
||||||
PH7_ClassInstanceUnref((ph7_class_instance *)pObj->x.pOther);
|
PH7_ClassInstanceUnref((ph7_class_instance *)pObj->x.pOther);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Release the internal buffer */
|
/* Release the internal buffer */
|
||||||
SyBlobRelease(&pObj->sBlob);
|
SyBlobRelease(&pObj->sBlob);
|
||||||
/* Invalidate any prior representation */
|
/* Invalidate any prior representation */
|
||||||
pObj->iFlags = MEMOBJ_NULL;
|
pObj->nType = MEMOBJ_NULL;
|
||||||
}
|
}
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
@ -1012,31 +1012,31 @@ PH7_PRIVATE sxi32 PH7_MemObjCmp(ph7_value *pObj1, ph7_value *pObj2, int bStrict,
|
||||||
if(bStrict) {
|
if(bStrict) {
|
||||||
sxi32 iF1, iF2;
|
sxi32 iF1, iF2;
|
||||||
/* Strict comparisons with === */
|
/* Strict comparisons with === */
|
||||||
iF1 = pObj1->iFlags;
|
iF1 = pObj1->nType;
|
||||||
iF2 = pObj2->iFlags;
|
iF2 = pObj2->nType;
|
||||||
if(iF1 != iF2) {
|
if(iF1 != iF2) {
|
||||||
/* Not of the same type */
|
/* Not of the same type */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Combine flag together */
|
/* Combine flag together */
|
||||||
iComb = pObj1->iFlags | pObj2->iFlags;
|
iComb = pObj1->nType | pObj2->nType;
|
||||||
if(iComb & (MEMOBJ_NULL | MEMOBJ_RES | MEMOBJ_BOOL)) {
|
if(iComb & (MEMOBJ_NULL | MEMOBJ_RES | MEMOBJ_BOOL)) {
|
||||||
/* Convert to boolean: Keep in mind FALSE < TRUE */
|
/* Convert to boolean: Keep in mind FALSE < TRUE */
|
||||||
if((pObj1->iFlags & MEMOBJ_BOOL) == 0) {
|
if((pObj1->nType & MEMOBJ_BOOL) == 0) {
|
||||||
PH7_MemObjToBool(pObj1);
|
PH7_MemObjToBool(pObj1);
|
||||||
}
|
}
|
||||||
if((pObj2->iFlags & MEMOBJ_BOOL) == 0) {
|
if((pObj2->nType & MEMOBJ_BOOL) == 0) {
|
||||||
PH7_MemObjToBool(pObj2);
|
PH7_MemObjToBool(pObj2);
|
||||||
}
|
}
|
||||||
return (sxi32)((pObj1->x.iVal != 0) - (pObj2->x.iVal != 0));
|
return (sxi32)((pObj1->x.iVal != 0) - (pObj2->x.iVal != 0));
|
||||||
} else if(iComb & MEMOBJ_HASHMAP) {
|
} else if(iComb & MEMOBJ_HASHMAP) {
|
||||||
/* Hashmap aka 'array' comparison */
|
/* Hashmap aka 'array' comparison */
|
||||||
if((pObj1->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if((pObj1->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
/* Array is always greater */
|
/* Array is always greater */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if((pObj2->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if((pObj2->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
/* Array is always greater */
|
/* Array is always greater */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1045,11 +1045,11 @@ PH7_PRIVATE sxi32 PH7_MemObjCmp(ph7_value *pObj1, ph7_value *pObj2, int bStrict,
|
||||||
return rc;
|
return rc;
|
||||||
} else if(iComb & MEMOBJ_OBJ) {
|
} else if(iComb & MEMOBJ_OBJ) {
|
||||||
/* Object comparison */
|
/* Object comparison */
|
||||||
if((pObj1->iFlags & MEMOBJ_OBJ) == 0) {
|
if((pObj1->nType & MEMOBJ_OBJ) == 0) {
|
||||||
/* Object is always greater */
|
/* Object is always greater */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if((pObj2->iFlags & MEMOBJ_OBJ) == 0) {
|
if((pObj2->nType & MEMOBJ_OBJ) == 0) {
|
||||||
/* Object is always greater */
|
/* Object is always greater */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1076,10 +1076,10 @@ PH7_PRIVATE sxi32 PH7_MemObjCmp(ph7_value *pObj1, ph7_value *pObj2, int bStrict,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Perform a strict string comparison.*/
|
/* Perform a strict string comparison.*/
|
||||||
if((pObj1->iFlags & MEMOBJ_STRING) == 0) {
|
if((pObj1->nType & MEMOBJ_STRING) == 0) {
|
||||||
PH7_MemObjToString(pObj1);
|
PH7_MemObjToString(pObj1);
|
||||||
}
|
}
|
||||||
if((pObj2->iFlags & MEMOBJ_STRING) == 0) {
|
if((pObj2->nType & MEMOBJ_STRING) == 0) {
|
||||||
PH7_MemObjToString(pObj2);
|
PH7_MemObjToString(pObj2);
|
||||||
}
|
}
|
||||||
SyStringInitFromBuf(&s1, SyBlobData(&pObj1->sBlob), SyBlobLength(&pObj1->sBlob));
|
SyStringInitFromBuf(&s1, SyBlobData(&pObj1->sBlob), SyBlobLength(&pObj1->sBlob));
|
||||||
|
@ -1098,20 +1098,20 @@ PH7_PRIVATE sxi32 PH7_MemObjCmp(ph7_value *pObj1, ph7_value *pObj2, int bStrict,
|
||||||
} else if(iComb & (MEMOBJ_INT | MEMOBJ_REAL)) {
|
} else if(iComb & (MEMOBJ_INT | MEMOBJ_REAL)) {
|
||||||
Numeric:
|
Numeric:
|
||||||
/* Perform a numeric comparison if one of the operand is numeric(integer or real) */
|
/* Perform a numeric comparison if one of the operand is numeric(integer or real) */
|
||||||
if((pObj1->iFlags & (MEMOBJ_INT | MEMOBJ_REAL)) == 0) {
|
if((pObj1->nType & (MEMOBJ_INT | MEMOBJ_REAL)) == 0) {
|
||||||
PH7_MemObjToNumeric(pObj1);
|
PH7_MemObjToNumeric(pObj1);
|
||||||
}
|
}
|
||||||
if((pObj2->iFlags & (MEMOBJ_INT | MEMOBJ_REAL)) == 0) {
|
if((pObj2->nType & (MEMOBJ_INT | MEMOBJ_REAL)) == 0) {
|
||||||
PH7_MemObjToNumeric(pObj2);
|
PH7_MemObjToNumeric(pObj2);
|
||||||
}
|
}
|
||||||
if((pObj1->iFlags & pObj2->iFlags & MEMOBJ_INT) == 0) {
|
if((pObj1->nType & pObj2->nType & MEMOBJ_INT) == 0) {
|
||||||
ph7_real r1, r2;
|
ph7_real r1, r2;
|
||||||
/* Compare as reals */
|
/* Compare as reals */
|
||||||
if((pObj1->iFlags & MEMOBJ_REAL) == 0) {
|
if((pObj1->nType & MEMOBJ_REAL) == 0) {
|
||||||
PH7_MemObjToReal(pObj1);
|
PH7_MemObjToReal(pObj1);
|
||||||
}
|
}
|
||||||
r1 = pObj1->x.rVal;
|
r1 = pObj1->x.rVal;
|
||||||
if((pObj2->iFlags & MEMOBJ_REAL) == 0) {
|
if((pObj2->nType & MEMOBJ_REAL) == 0) {
|
||||||
PH7_MemObjToReal(pObj2);
|
PH7_MemObjToReal(pObj2);
|
||||||
}
|
}
|
||||||
r2 = pObj2->x.rVal;
|
r2 = pObj2->x.rVal;
|
||||||
|
@ -1147,17 +1147,17 @@ Numeric:
|
||||||
* This function take care of handling all the scenarios.
|
* This function take care of handling all the scenarios.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_MemObjAdd(ph7_value *pObj1, ph7_value *pObj2, int bAddStore) {
|
PH7_PRIVATE sxi32 PH7_MemObjAdd(ph7_value *pObj1, ph7_value *pObj2, int bAddStore) {
|
||||||
if(((pObj1->iFlags | pObj2->iFlags) & MEMOBJ_HASHMAP) == 0) {
|
if(((pObj1->nType | pObj2->nType) & MEMOBJ_HASHMAP) == 0) {
|
||||||
/* Arithemtic operation */
|
/* Arithemtic operation */
|
||||||
PH7_MemObjToNumeric(pObj1);
|
PH7_MemObjToNumeric(pObj1);
|
||||||
PH7_MemObjToNumeric(pObj2);
|
PH7_MemObjToNumeric(pObj2);
|
||||||
if((pObj1->iFlags | pObj2->iFlags) & MEMOBJ_REAL) {
|
if((pObj1->nType | pObj2->nType) & MEMOBJ_REAL) {
|
||||||
/* Floating point arithmetic */
|
/* Floating point arithmetic */
|
||||||
ph7_real a, b;
|
ph7_real a, b;
|
||||||
if((pObj1->iFlags & MEMOBJ_REAL) == 0) {
|
if((pObj1->nType & MEMOBJ_REAL) == 0) {
|
||||||
PH7_MemObjToReal(pObj1);
|
PH7_MemObjToReal(pObj1);
|
||||||
}
|
}
|
||||||
if((pObj2->iFlags & MEMOBJ_REAL) == 0) {
|
if((pObj2->nType & MEMOBJ_REAL) == 0) {
|
||||||
PH7_MemObjToReal(pObj2);
|
PH7_MemObjToReal(pObj2);
|
||||||
}
|
}
|
||||||
a = pObj1->x.rVal;
|
a = pObj1->x.rVal;
|
||||||
|
@ -1173,13 +1173,13 @@ PH7_PRIVATE sxi32 PH7_MemObjAdd(ph7_value *pObj1, ph7_value *pObj2, int bAddStor
|
||||||
MemObjSetType(pObj1, MEMOBJ_INT);
|
MemObjSetType(pObj1, MEMOBJ_INT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if((pObj1->iFlags | pObj2->iFlags) & MEMOBJ_HASHMAP) {
|
if((pObj1->nType | pObj2->nType) & MEMOBJ_HASHMAP) {
|
||||||
ph7_hashmap *pMap;
|
ph7_hashmap *pMap;
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
if(bAddStore) {
|
if(bAddStore) {
|
||||||
/* Do not duplicate the hashmap,use the left one since its an add&store operation.
|
/* Do not duplicate the hashmap,use the left one since its an add&store operation.
|
||||||
*/
|
*/
|
||||||
if((pObj1->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if((pObj1->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
/* Force a hashmap cast */
|
/* Force a hashmap cast */
|
||||||
rc = PH7_MemObjToHashmap(pObj1);
|
rc = PH7_MemObjToHashmap(pObj1);
|
||||||
if(rc != SXRET_OK) {
|
if(rc != SXRET_OK) {
|
||||||
|
@ -1196,27 +1196,27 @@ PH7_PRIVATE sxi32 PH7_MemObjAdd(ph7_value *pObj1, ph7_value *pObj2, int bAddStor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!bAddStore) {
|
if(!bAddStore) {
|
||||||
if(pObj1->iFlags & MEMOBJ_HASHMAP) {
|
if(pObj1->nType & MEMOBJ_HASHMAP) {
|
||||||
/* Perform a hashmap duplication */
|
/* Perform a hashmap duplication */
|
||||||
PH7_HashmapDup((ph7_hashmap *)pObj1->x.pOther, pMap);
|
PH7_HashmapDup((ph7_hashmap *)pObj1->x.pOther, pMap);
|
||||||
} else {
|
} else {
|
||||||
if((pObj1->iFlags & MEMOBJ_NULL) == 0) {
|
if((pObj1->nType & MEMOBJ_NULL) == 0) {
|
||||||
/* Simple insertion */
|
/* Simple insertion */
|
||||||
PH7_HashmapInsert(pMap, 0, pObj1);
|
PH7_HashmapInsert(pMap, 0, pObj1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Perform the union */
|
/* Perform the union */
|
||||||
if(pObj2->iFlags & MEMOBJ_HASHMAP) {
|
if(pObj2->nType & MEMOBJ_HASHMAP) {
|
||||||
PH7_HashmapUnion(pMap, (ph7_hashmap *)pObj2->x.pOther);
|
PH7_HashmapUnion(pMap, (ph7_hashmap *)pObj2->x.pOther);
|
||||||
} else {
|
} else {
|
||||||
if((pObj2->iFlags & MEMOBJ_NULL) == 0) {
|
if((pObj2->nType & MEMOBJ_NULL) == 0) {
|
||||||
/* Simple insertion */
|
/* Simple insertion */
|
||||||
PH7_HashmapInsert(pMap, 0, pObj2);
|
PH7_HashmapInsert(pMap, 0, pObj2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Reflect the change */
|
/* Reflect the change */
|
||||||
if(pObj1->iFlags & MEMOBJ_STRING) {
|
if(pObj1->nType & MEMOBJ_STRING) {
|
||||||
SyBlobRelease(&pObj1->sBlob);
|
SyBlobRelease(&pObj1->sBlob);
|
||||||
}
|
}
|
||||||
pObj1->x.pOther = pMap;
|
pObj1->x.pOther = pMap;
|
||||||
|
@ -1231,48 +1231,48 @@ PH7_PRIVATE sxi32 PH7_MemObjAdd(ph7_value *pObj1, ph7_value *pObj2, int bAddStor
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE const char *PH7_MemObjTypeDump(ph7_value *pVal) {
|
PH7_PRIVATE const char *PH7_MemObjTypeDump(ph7_value *pVal) {
|
||||||
const char *zType = "";
|
const char *zType = "";
|
||||||
if(pVal->iFlags & MEMOBJ_NULL) {
|
if(pVal->nType & MEMOBJ_NULL) {
|
||||||
zType = "NULL";
|
zType = "NULL";
|
||||||
} else {
|
} else {
|
||||||
if(pVal->iFlags & MEMOBJ_HASHMAP) {
|
if(pVal->nType & MEMOBJ_HASHMAP) {
|
||||||
if(pVal->iFlags & MEMOBJ_MIXED) {
|
if(pVal->nType & MEMOBJ_MIXED) {
|
||||||
zType = "array(mixed, ";
|
zType = "array(mixed, ";
|
||||||
} else if(pVal->iFlags & MEMOBJ_OBJ) {
|
} else if(pVal->nType & MEMOBJ_OBJ) {
|
||||||
zType = "array(object, ";
|
zType = "array(object, ";
|
||||||
} else if(pVal->iFlags & MEMOBJ_INT) {
|
} else if(pVal->nType & MEMOBJ_INT) {
|
||||||
zType = "array(int, ";
|
zType = "array(int, ";
|
||||||
} else if(pVal->iFlags & MEMOBJ_REAL) {
|
} else if(pVal->nType & MEMOBJ_REAL) {
|
||||||
zType = "array(float, ";
|
zType = "array(float, ";
|
||||||
} else if(pVal->iFlags & MEMOBJ_STRING) {
|
} else if(pVal->nType & MEMOBJ_STRING) {
|
||||||
zType = "array(string, ";
|
zType = "array(string, ";
|
||||||
} else if(pVal->iFlags & MEMOBJ_BOOL) {
|
} else if(pVal->nType & MEMOBJ_BOOL) {
|
||||||
zType = "array(bool, ";
|
zType = "array(bool, ";
|
||||||
} else if(pVal->iFlags & MEMOBJ_CHAR) {
|
} else if(pVal->nType & MEMOBJ_CHAR) {
|
||||||
zType = "array(char, ";
|
zType = "array(char, ";
|
||||||
} else if(pVal->iFlags & MEMOBJ_RES) {
|
} else if(pVal->nType & MEMOBJ_RES) {
|
||||||
zType = "array(resource, ";
|
zType = "array(resource, ";
|
||||||
} else if(pVal->iFlags & MEMOBJ_CALL) {
|
} else if(pVal->nType & MEMOBJ_CALL) {
|
||||||
zType = "array(callback, ";
|
zType = "array(callback, ";
|
||||||
} else if(pVal->iFlags & MEMOBJ_VOID) {
|
} else if(pVal->nType & MEMOBJ_VOID) {
|
||||||
zType = "array(void, ";
|
zType = "array(void, ";
|
||||||
}
|
}
|
||||||
} else if(pVal->iFlags & MEMOBJ_OBJ) {
|
} else if(pVal->nType & MEMOBJ_OBJ) {
|
||||||
zType = "object";
|
zType = "object";
|
||||||
} else if(pVal->iFlags & MEMOBJ_INT) {
|
} else if(pVal->nType & MEMOBJ_INT) {
|
||||||
zType = "int";
|
zType = "int";
|
||||||
} else if(pVal->iFlags & MEMOBJ_REAL) {
|
} else if(pVal->nType & MEMOBJ_REAL) {
|
||||||
zType = "float";
|
zType = "float";
|
||||||
} else if(pVal->iFlags & MEMOBJ_STRING) {
|
} else if(pVal->nType & MEMOBJ_STRING) {
|
||||||
zType = "string";
|
zType = "string";
|
||||||
} else if(pVal->iFlags & MEMOBJ_BOOL) {
|
} else if(pVal->nType & MEMOBJ_BOOL) {
|
||||||
zType = "bool";
|
zType = "bool";
|
||||||
} else if(pVal->iFlags & MEMOBJ_CHAR) {
|
} else if(pVal->nType & MEMOBJ_CHAR) {
|
||||||
zType = "char";
|
zType = "char";
|
||||||
} else if(pVal->iFlags & MEMOBJ_RES) {
|
} else if(pVal->nType & MEMOBJ_RES) {
|
||||||
zType = "resource";
|
zType = "resource";
|
||||||
} else if(pVal->iFlags & MEMOBJ_CALL) {
|
} else if(pVal->nType & MEMOBJ_CALL) {
|
||||||
zType = "callback";
|
zType = "callback";
|
||||||
} else if(pVal->iFlags & MEMOBJ_VOID) {
|
} else if(pVal->nType & MEMOBJ_VOID) {
|
||||||
zType = "void";
|
zType = "void";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1300,22 +1300,22 @@ PH7_PRIVATE sxi32 PH7_MemObjDump(
|
||||||
zType = PH7_MemObjTypeDump(pObj);
|
zType = PH7_MemObjTypeDump(pObj);
|
||||||
SyBlobAppend(&(*pOut), zType, SyStrlen(zType));
|
SyBlobAppend(&(*pOut), zType, SyStrlen(zType));
|
||||||
}
|
}
|
||||||
if((pObj->iFlags & MEMOBJ_NULL) == 0) {
|
if((pObj->nType & MEMOBJ_NULL) == 0) {
|
||||||
if(ShowType && (pObj->iFlags & MEMOBJ_HASHMAP) == 0) {
|
if(ShowType && (pObj->nType & MEMOBJ_HASHMAP) == 0) {
|
||||||
SyBlobAppend(&(*pOut), "(", sizeof(char));
|
SyBlobAppend(&(*pOut), "(", sizeof(char));
|
||||||
}
|
}
|
||||||
if(pObj->iFlags & MEMOBJ_HASHMAP) {
|
if(pObj->nType & MEMOBJ_HASHMAP) {
|
||||||
/* Dump hashmap entries */
|
/* Dump hashmap entries */
|
||||||
rc = PH7_HashmapDump(&(*pOut), (ph7_hashmap *)pObj->x.pOther, ShowType, nTab + 1, nDepth + 1);
|
rc = PH7_HashmapDump(&(*pOut), (ph7_hashmap *)pObj->x.pOther, ShowType, nTab + 1, nDepth + 1);
|
||||||
} else if(pObj->iFlags & MEMOBJ_OBJ) {
|
} else if(pObj->nType & MEMOBJ_OBJ) {
|
||||||
/* Dump class instance attributes */
|
/* Dump class instance attributes */
|
||||||
rc = PH7_ClassInstanceDump(&(*pOut), (ph7_class_instance *)pObj->x.pOther, ShowType, nTab + 1, nDepth + 1);
|
rc = PH7_ClassInstanceDump(&(*pOut), (ph7_class_instance *)pObj->x.pOther, ShowType, nTab + 1, nDepth + 1);
|
||||||
} else if(pObj->iFlags & MEMOBJ_VOID) {
|
} else if(pObj->nType & MEMOBJ_VOID) {
|
||||||
SyBlobAppend(&(*pOut), "NULL", sizeof("NULL") - 1);
|
SyBlobAppend(&(*pOut), "NULL", sizeof("NULL") - 1);
|
||||||
} else {
|
} else {
|
||||||
SyBlob *pContents = &pObj->sBlob;
|
SyBlob *pContents = &pObj->sBlob;
|
||||||
/* Get a printable representation of the contents */
|
/* Get a printable representation of the contents */
|
||||||
if((pObj->iFlags & (MEMOBJ_STRING | MEMOBJ_CALL)) == 0) {
|
if((pObj->nType & (MEMOBJ_STRING | MEMOBJ_CALL)) == 0) {
|
||||||
MemObjStringValue(&(*pOut), &(*pObj), FALSE);
|
MemObjStringValue(&(*pOut), &(*pObj), FALSE);
|
||||||
} else {
|
} else {
|
||||||
/* Append length first */
|
/* Append length first */
|
||||||
|
@ -1331,7 +1331,7 @@ PH7_PRIVATE sxi32 PH7_MemObjDump(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(ShowType) {
|
if(ShowType) {
|
||||||
if((pObj->iFlags & (MEMOBJ_HASHMAP | MEMOBJ_OBJ)) == 0) {
|
if((pObj->nType & (MEMOBJ_HASHMAP | MEMOBJ_OBJ)) == 0) {
|
||||||
SyBlobAppend(&(*pOut), ")", sizeof(char));
|
SyBlobAppend(&(*pOut), ")", sizeof(char));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
306
engine/vm.c
306
engine/vm.c
File diff suppressed because it is too large
Load Diff
|
@ -625,7 +625,7 @@ struct ph7_value {
|
||||||
void *pOther; /* Other values (Object, Array, Resource, Namespace, etc.) */
|
void *pOther; /* Other values (Object, Array, Resource, Namespace, etc.) */
|
||||||
} x;
|
} x;
|
||||||
sxi32 iFlags; /* Control flags (see below) */
|
sxi32 iFlags; /* Control flags (see below) */
|
||||||
sxi32 iType; /* Variable data type */
|
sxi32 nType; /* Variable data type */
|
||||||
ph7_vm *pVm; /* Virtual machine that own this instance */
|
ph7_vm *pVm; /* Virtual machine that own this instance */
|
||||||
SyBlob sBlob; /* String values */
|
SyBlob sBlob; /* String values */
|
||||||
sxu32 nIdx; /* Index number of this entry in the global object allocator */
|
sxu32 nIdx; /* Index number of this entry in the global object allocator */
|
||||||
|
@ -659,7 +659,7 @@ struct ph7_value {
|
||||||
* The following macro clear the current ph7_value type and replace
|
* The following macro clear the current ph7_value type and replace
|
||||||
* it with the given one.
|
* it with the given one.
|
||||||
*/
|
*/
|
||||||
#define MemObjSetType(OBJ,TYPE) ((OBJ)->iFlags = ((OBJ)->iFlags&~MEMOBJ_ALL)|TYPE)
|
#define MemObjSetType(OBJ,TYPE) ((OBJ)->nType = ((OBJ)->nType&~MEMOBJ_ALL)|TYPE)
|
||||||
/* ph7_value cast method signature */
|
/* ph7_value cast method signature */
|
||||||
typedef sxi32(*ProcMemObjCast)(ph7_value *);
|
typedef sxi32(*ProcMemObjCast)(ph7_value *);
|
||||||
/* Forward reference */
|
/* Forward reference */
|
||||||
|
|
Loading…
Reference in New Issue