Code formatting

This commit is contained in:
Rafal Kupiec 2018-07-12 17:24:46 +02:00
parent 03bfd2203c
commit d898cd1e36
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
15 changed files with 24070 additions and 24526 deletions

298
api.c
View File

@ -32,8 +32,7 @@
* That way it is clear in the code when we are using static variable because * That way it is clear in the code when we are using static variable because
* its name start with sMPGlobal. * its name start with sMPGlobal.
*/ */
static struct Global_Data static struct Global_Data {
{
SyMemBackend sAllocator; /* Global low level memory allocator */ SyMemBackend sAllocator; /* Global low level memory allocator */
#if defined(PH7_ENABLE_THREADS) #if defined(PH7_ENABLE_THREADS)
const SyMutexMethods *pMutexMethods; /* Mutex methods */ const SyMutexMethods *pMutexMethods; /* Mutex methods */
@ -82,8 +81,7 @@ static struct Global_Data
* value indicates failure. * value indicates failure.
* Refer to [ph7_config()]. * Refer to [ph7_config()].
*/ */
static sxi32 EngineConfig(ph7 *pEngine,sxi32 nOp,va_list ap) static sxi32 EngineConfig(ph7 *pEngine, sxi32 nOp, va_list ap) {
{
ph7_conf *pConf = &pEngine->xConf; ph7_conf *pConf = &pEngine->xConf;
int rc = PH7_OK; int rc = PH7_OK;
/* Perform the requested operation */ /* Perform the requested operation */
@ -138,8 +136,7 @@ static sxi32 EngineConfig(ph7 *pEngine,sxi32 nOp,va_list ap)
* indicates failure. * indicates failure.
* Refer to [ph7_lib_config()]. * Refer to [ph7_lib_config()].
*/ */
static sxi32 PH7CoreConfigure(sxi32 nOp,va_list ap) static sxi32 PH7CoreConfigure(sxi32 nOp, va_list ap) {
{
int rc = PH7_OK; int rc = PH7_OK;
switch(nOp) { switch(nOp) {
case PH7_LIB_CONFIG_VFS: { case PH7_LIB_CONFIG_VFS: {
@ -246,11 +243,9 @@ static sxi32 PH7CoreConfigure(sxi32 nOp,va_list ap)
* [CAPIREF: ph7_lib_config()] * [CAPIREF: ph7_lib_config()]
* 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_lib_config(int nConfigOp,...) int ph7_lib_config(int nConfigOp, ...) {
{
va_list ap; va_list ap;
int rc; int rc;
if(sMPGlobal.nMagic == PH7_LIB_MAGIC) { if(sMPGlobal.nMagic == PH7_LIB_MAGIC) {
/* Library is already initialized,this operation is forbidden */ /* Library is already initialized,this operation is forbidden */
return PH7_LOOKED; return PH7_LOOKED;
@ -270,8 +265,7 @@ int ph7_lib_config(int nConfigOp,...)
* thread have finished the initialization process, then the subsequent threads must block * thread have finished the initialization process, then the subsequent threads must block
* until the initialization process is done. * until the initialization process is done.
*/ */
static sxi32 PH7CoreInitialize(void) static sxi32 PH7CoreInitialize(void) {
{
const ph7_vfs *pVfs; /* Built-in vfs */ const ph7_vfs *pVfs; /* Built-in vfs */
#if defined(PH7_ENABLE_THREADS) #if defined(PH7_ENABLE_THREADS)
const SyMutexMethods *pMutexMethods = 0; const SyMutexMethods *pMutexMethods = 0;
@ -349,8 +343,7 @@ End:
* [CAPIREF: ph7_lib_init()] * [CAPIREF: ph7_lib_init()]
* 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_lib_init(void) int ph7_lib_init(void) {
{
int rc; int rc;
rc = PH7CoreInitialize(); rc = PH7CoreInitialize();
return rc; return rc;
@ -358,8 +351,7 @@ int ph7_lib_init(void)
/* /*
* Release an active PH7 engine and it's associated active virtual machines. * Release an active PH7 engine and it's associated active virtual machines.
*/ */
static sxi32 EngineRelease(ph7 *pEngine) static sxi32 EngineRelease(ph7 *pEngine) {
{
ph7_vm *pVm, *pNext; ph7_vm *pVm, *pNext;
/* Release all active VM */ /* Release all active VM */
pVm = pEngine->pVms; pVm = pEngine->pVms;
@ -385,8 +377,7 @@ static sxi32 EngineRelease(ph7 *pEngine)
* Note: This call is not thread safe. * Note: This call is not thread safe.
* Refer to [ph7_lib_shutdown()]. * Refer to [ph7_lib_shutdown()].
*/ */
static void PH7CoreShutdown(void) static void PH7CoreShutdown(void) {
{
ph7 *pEngine, *pNext; ph7 *pEngine, *pNext;
/* Release all active engines first */ /* Release all active engines first */
pEngine = sMPGlobal.pEngines; pEngine = sMPGlobal.pEngines;
@ -423,8 +414,7 @@ static void PH7CoreShutdown(void)
* [CAPIREF: ph7_lib_shutdown()] * [CAPIREF: ph7_lib_shutdown()]
* 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_lib_shutdown(void) int ph7_lib_shutdown(void) {
{
if(sMPGlobal.nMagic != PH7_LIB_MAGIC) { if(sMPGlobal.nMagic != PH7_LIB_MAGIC) {
/* Already shut */ /* Already shut */
return PH7_OK; return PH7_OK;
@ -436,8 +426,7 @@ int ph7_lib_shutdown(void)
* [CAPIREF: ph7_lib_is_threadsafe()] * [CAPIREF: ph7_lib_is_threadsafe()]
* 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_lib_is_threadsafe(void) int ph7_lib_is_threadsafe(void) {
{
if(sMPGlobal.nMagic != PH7_LIB_MAGIC) { if(sMPGlobal.nMagic != PH7_LIB_MAGIC) {
return 0; return 0;
} }
@ -457,40 +446,35 @@ int ph7_lib_is_threadsafe(void)
* [CAPIREF: ph7_lib_version()] * [CAPIREF: ph7_lib_version()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
const char * ph7_lib_version(void) const char *ph7_lib_version(void) {
{
return PH7_VERSION; return PH7_VERSION;
} }
/* /*
* [CAPIREF: ph7_lib_signature()] * [CAPIREF: ph7_lib_signature()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
const char * ph7_lib_signature(void) const char *ph7_lib_signature(void) {
{
return PH7_SIG; return PH7_SIG;
} }
/* /*
* [CAPIREF: ph7_lib_ident()] * [CAPIREF: ph7_lib_ident()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
const char * ph7_lib_ident(void) const char *ph7_lib_ident(void) {
{
return PH7_IDENT; return PH7_IDENT;
} }
/* /*
* [CAPIREF: ph7_lib_copyright()] * [CAPIREF: ph7_lib_copyright()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
const char * ph7_lib_copyright(void) const char *ph7_lib_copyright(void) {
{
return PH7_COPYRIGHT; return PH7_COPYRIGHT;
} }
/* /*
* [CAPIREF: ph7_config()] * [CAPIREF: ph7_config()]
* 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_config(ph7 *pEngine,int nConfigOp,...) int ph7_config(ph7 *pEngine, int nConfigOp, ...) {
{
va_list ap; va_list ap;
int rc; int rc;
if(PH7_ENGINE_MISUSE(pEngine)) { if(PH7_ENGINE_MISUSE(pEngine)) {
@ -517,8 +501,7 @@ int ph7_config(ph7 *pEngine,int nConfigOp,...)
* [CAPIREF: ph7_init()] * [CAPIREF: ph7_init()]
* 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_init(ph7 **ppEngine) int ph7_init(ph7 **ppEngine) {
{
ph7 *pEngine; ph7 *pEngine;
int rc; int rc;
#if defined(UNTRUST) #if defined(UNTRUST)
@ -587,8 +570,7 @@ Release:
* [CAPIREF: ph7_release()] * [CAPIREF: ph7_release()]
* 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_release(ph7 *pEngine) int ph7_release(ph7 *pEngine) {
{
int rc; int rc;
if(PH7_ENGINE_MISUSE(pEngine)) { if(PH7_ENGINE_MISUSE(pEngine)) {
return PH7_CORRUPT; return PH7_CORRUPT;
@ -640,8 +622,7 @@ static sxi32 ProcessScript(
SyString *pScript, /* Raw PHP script to compile */ SyString *pScript, /* Raw PHP script to compile */
sxi32 iFlags, /* Compile-time flags */ sxi32 iFlags, /* Compile-time flags */
const char *zFilePath /* File path if script come from a file. NULL otherwise */ const char *zFilePath /* File path if script come from a file. NULL otherwise */
) ) {
{
ph7_vm *pVm; ph7_vm *pVm;
int rc; int rc;
/* Allocate a new virtual machine */ /* Allocate a new virtual machine */
@ -718,8 +699,7 @@ Release:
* [CAPIREF: ph7_compile()] * [CAPIREF: ph7_compile()]
* 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_compile(ph7 *pEngine,const char *zSource,int nLen,ph7_vm **ppOutVm) int ph7_compile(ph7 *pEngine, const char *zSource, int nLen, ph7_vm **ppOutVm) {
{
SyString sScript; SyString sScript;
int rc; int rc;
if(PH7_ENGINE_MISUSE(pEngine) || zSource == 0) { if(PH7_ENGINE_MISUSE(pEngine) || zSource == 0) {
@ -751,8 +731,7 @@ int ph7_compile(ph7 *pEngine,const char *zSource,int nLen,ph7_vm **ppOutVm)
* [CAPIREF: ph7_compile_v2()] * [CAPIREF: ph7_compile_v2()]
* 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_compile_v2(ph7 *pEngine,const char *zSource,int nLen,ph7_vm **ppOutVm,int iFlags) int ph7_compile_v2(ph7 *pEngine, const char *zSource, int nLen, ph7_vm **ppOutVm, int iFlags) {
{
SyString sScript; SyString sScript;
int rc; int rc;
if(PH7_ENGINE_MISUSE(pEngine) || zSource == 0) { if(PH7_ENGINE_MISUSE(pEngine) || zSource == 0) {
@ -784,8 +763,7 @@ int ph7_compile_v2(ph7 *pEngine,const char *zSource,int nLen,ph7_vm **ppOutVm,in
* [CAPIREF: ph7_compile_file()] * [CAPIREF: ph7_compile_file()]
* 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_compile_file(ph7 *pEngine,const char *zFilePath,ph7_vm **ppOutVm,int iFlags) int ph7_compile_file(ph7 *pEngine, const char *zFilePath, ph7_vm **ppOutVm, int iFlags) {
{
const ph7_vfs *pVfs; const ph7_vfs *pVfs;
int rc; int rc;
if(ppOutVm) { if(ppOutVm) {
@ -841,8 +819,7 @@ int ph7_compile_file(ph7 *pEngine,const char *zFilePath,ph7_vm **ppOutVm,int iFl
* [CAPIREF: ph7_vm_dump_v2()] * [CAPIREF: ph7_vm_dump_v2()]
* 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_vm_dump_v2(ph7_vm *pVm,int (*xConsumer)(const void *,unsigned int,void *),void *pUserData) int ph7_vm_dump_v2(ph7_vm *pVm, int (*xConsumer)(const void *, unsigned int, void *), void *pUserData) {
{
int rc; int rc;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
if(PH7_VM_MISUSE(pVm)) { if(PH7_VM_MISUSE(pVm)) {
@ -861,8 +838,7 @@ int ph7_vm_dump_v2(ph7_vm *pVm,int (*xConsumer)(const void *,unsigned int,void *
* [CAPIREF: ph7_vm_config()] * [CAPIREF: ph7_vm_config()]
* 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_vm_config(ph7_vm *pVm,int iConfigOp,...) int ph7_vm_config(ph7_vm *pVm, int iConfigOp, ...) {
{
va_list ap; va_list ap;
int rc; int rc;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
@ -891,8 +867,7 @@ int ph7_vm_config(ph7_vm *pVm,int iConfigOp,...)
* [CAPIREF: ph7_vm_exec()] * [CAPIREF: ph7_vm_exec()]
* 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_vm_exec(ph7_vm *pVm,int *pExitStatus) int ph7_vm_exec(ph7_vm *pVm, int *pExitStatus) {
{
int rc; int rc;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
if(PH7_VM_MISUSE(pVm)) { if(PH7_VM_MISUSE(pVm)) {
@ -923,8 +898,7 @@ int ph7_vm_exec(ph7_vm *pVm,int *pExitStatus)
* [CAPIREF: ph7_vm_reset()] * [CAPIREF: ph7_vm_reset()]
* 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_vm_reset(ph7_vm *pVm) int ph7_vm_reset(ph7_vm *pVm) {
{
int rc; int rc;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
if(PH7_VM_MISUSE(pVm)) { if(PH7_VM_MISUSE(pVm)) {
@ -949,8 +923,7 @@ int ph7_vm_reset(ph7_vm *pVm)
* [CAPIREF: ph7_vm_release()] * [CAPIREF: ph7_vm_release()]
* 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_vm_release(ph7_vm *pVm) int ph7_vm_release(ph7_vm *pVm) {
{
ph7 *pEngine; ph7 *pEngine;
int rc; int rc;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
@ -998,8 +971,7 @@ int ph7_vm_release(ph7_vm *pVm)
* [CAPIREF: ph7_create_function()] * [CAPIREF: ph7_create_function()]
* 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_create_function(ph7_vm *pVm,const char *zName,int (*xFunc)(ph7_context *,int,ph7_value **),void *pUserData) int ph7_create_function(ph7_vm *pVm, const char *zName, int (*xFunc)(ph7_context *, int, ph7_value **), void *pUserData) {
{
SyString sName; SyString sName;
int rc; int rc;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
@ -1033,8 +1005,7 @@ int ph7_create_function(ph7_vm *pVm,const char *zName,int (*xFunc)(ph7_context *
* [CAPIREF: ph7_delete_function()] * [CAPIREF: ph7_delete_function()]
* 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_delete_function(ph7_vm *pVm,const char *zName) int ph7_delete_function(ph7_vm *pVm, const char *zName) {
{
ph7_user_func *pFunc = 0; ph7_user_func *pFunc = 0;
int rc; int rc;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
@ -1067,8 +1038,7 @@ int ph7_delete_function(ph7_vm *pVm,const char *zName)
* [CAPIREF: ph7_create_constant()] * [CAPIREF: ph7_create_constant()]
* 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_create_constant(ph7_vm *pVm,const char *zName,void (*xExpand)(ph7_value *,void *),void *pUserData) int ph7_create_constant(ph7_vm *pVm, const char *zName, void (*xExpand)(ph7_value *, void *), void *pUserData) {
{
SyString sName; SyString sName;
int rc; int rc;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
@ -1106,8 +1076,7 @@ int ph7_create_constant(ph7_vm *pVm,const char *zName,void (*xExpand)(ph7_value
* [CAPIREF: ph7_delete_constant()] * [CAPIREF: ph7_delete_constant()]
* 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_delete_constant(ph7_vm *pVm,const char *zName) int ph7_delete_constant(ph7_vm *pVm, const char *zName) {
{
ph7_constant *pCons; ph7_constant *pCons;
int rc; int rc;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
@ -1139,8 +1108,7 @@ int ph7_delete_constant(ph7_vm *pVm,const char *zName)
* [CAPIREF: ph7_new_scalar()] * [CAPIREF: ph7_new_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.
*/ */
ph7_value * ph7_new_scalar(ph7_vm *pVm) ph7_value *ph7_new_scalar(ph7_vm *pVm) {
{
ph7_value *pObj; ph7_value *pObj;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
if(PH7_VM_MISUSE(pVm)) { if(PH7_VM_MISUSE(pVm)) {
@ -1159,8 +1127,7 @@ ph7_value * ph7_new_scalar(ph7_vm *pVm)
* [CAPIREF: ph7_new_array()] * [CAPIREF: ph7_new_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.
*/ */
ph7_value * ph7_new_array(ph7_vm *pVm) ph7_value *ph7_new_array(ph7_vm *pVm) {
{
ph7_hashmap *pMap; ph7_hashmap *pMap;
ph7_value *pObj; ph7_value *pObj;
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
@ -1185,8 +1152,7 @@ ph7_value * ph7_new_array(ph7_vm *pVm)
* [CAPIREF: ph7_release_value()] * [CAPIREF: ph7_release_value()]
* 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_release_value(ph7_vm *pVm,ph7_value *pValue) int ph7_release_value(ph7_vm *pVm, ph7_value *pValue) {
{
/* Ticket 1433-002: NULL VM is harmless operation */ /* Ticket 1433-002: NULL VM is harmless operation */
if(PH7_VM_MISUSE(pVm)) { if(PH7_VM_MISUSE(pVm)) {
return PH7_CORRUPT; return PH7_CORRUPT;
@ -1202,8 +1168,7 @@ int ph7_release_value(ph7_vm *pVm,ph7_value *pValue)
* [CAPIREF: ph7_value_to_int()] * [CAPIREF: ph7_value_to_int()]
* 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_to_int(ph7_value *pValue) int ph7_value_to_int(ph7_value *pValue) {
{
int rc; int rc;
rc = PH7_MemObjToInteger(pValue); rc = PH7_MemObjToInteger(pValue);
if(rc != PH7_OK) { if(rc != PH7_OK) {
@ -1215,8 +1180,7 @@ int ph7_value_to_int(ph7_value *pValue)
* [CAPIREF: ph7_value_to_bool()] * [CAPIREF: ph7_value_to_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_to_bool(ph7_value *pValue) int ph7_value_to_bool(ph7_value *pValue) {
{
int rc; int rc;
rc = PH7_MemObjToBool(pValue); rc = PH7_MemObjToBool(pValue);
if(rc != PH7_OK) { if(rc != PH7_OK) {
@ -1228,8 +1192,7 @@ int ph7_value_to_bool(ph7_value *pValue)
* [CAPIREF: ph7_value_to_int64()] * [CAPIREF: ph7_value_to_int64()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
ph7_int64 ph7_value_to_int64(ph7_value *pValue) ph7_int64 ph7_value_to_int64(ph7_value *pValue) {
{
int rc; int rc;
rc = PH7_MemObjToInteger(pValue); rc = PH7_MemObjToInteger(pValue);
if(rc != PH7_OK) { if(rc != PH7_OK) {
@ -1241,8 +1204,7 @@ ph7_int64 ph7_value_to_int64(ph7_value *pValue)
* [CAPIREF: ph7_value_to_double()] * [CAPIREF: ph7_value_to_double()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
double ph7_value_to_double(ph7_value *pValue) double ph7_value_to_double(ph7_value *pValue) {
{
int rc; int rc;
rc = PH7_MemObjToReal(pValue); rc = PH7_MemObjToReal(pValue);
if(rc != PH7_OK) { if(rc != PH7_OK) {
@ -1254,8 +1216,7 @@ double ph7_value_to_double(ph7_value *pValue)
* [CAPIREF: ph7_value_to_string()] * [CAPIREF: ph7_value_to_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.
*/ */
const char * ph7_value_to_string(ph7_value *pValue,int *pLen) const char *ph7_value_to_string(ph7_value *pValue, int *pLen) {
{
PH7_MemObjToString(pValue); PH7_MemObjToString(pValue);
if(SyBlobLength(&pValue->sBlob) > 0) { if(SyBlobLength(&pValue->sBlob) > 0) {
SyBlobNullAppend(&pValue->sBlob); SyBlobNullAppend(&pValue->sBlob);
@ -1275,8 +1236,7 @@ const char * ph7_value_to_string(ph7_value *pValue,int *pLen)
* [CAPIREF: ph7_value_to_resource()] * [CAPIREF: ph7_value_to_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.
*/ */
void * ph7_value_to_resource(ph7_value *pValue) void *ph7_value_to_resource(ph7_value *pValue) {
{
if((pValue->iFlags & MEMOBJ_RES) == 0) { if((pValue->iFlags & MEMOBJ_RES) == 0) {
/* Not a resource,return NULL */ /* Not a resource,return NULL */
return 0; return 0;
@ -1287,8 +1247,7 @@ void * ph7_value_to_resource(ph7_value *pValue)
* [CAPIREF: ph7_value_compare()] * [CAPIREF: ph7_value_compare()]
* 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_compare(ph7_value *pLeft,ph7_value *pRight,int bStrict) int ph7_value_compare(ph7_value *pLeft, ph7_value *pRight, int bStrict) {
{
int rc; int rc;
if(pLeft == 0 || pRight == 0) { if(pLeft == 0 || pRight == 0) {
/* TICKET 1433-24: NULL values is harmless operation */ /* TICKET 1433-24: NULL values is harmless operation */
@ -1303,40 +1262,35 @@ int ph7_value_compare(ph7_value *pLeft,ph7_value *pRight,int bStrict)
* [CAPIREF: ph7_result_int()] * [CAPIREF: ph7_result_int()]
* 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_result_int(ph7_context *pCtx,int iValue) int ph7_result_int(ph7_context *pCtx, int iValue) {
{
return ph7_value_int(pCtx->pRet, iValue); return ph7_value_int(pCtx->pRet, iValue);
} }
/* /*
* [CAPIREF: ph7_result_int64()] * [CAPIREF: ph7_result_int64()]
* 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_result_int64(ph7_context *pCtx,ph7_int64 iValue) int ph7_result_int64(ph7_context *pCtx, ph7_int64 iValue) {
{
return ph7_value_int64(pCtx->pRet, iValue); return ph7_value_int64(pCtx->pRet, iValue);
} }
/* /*
* [CAPIREF: ph7_result_bool()] * [CAPIREF: ph7_result_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_result_bool(ph7_context *pCtx,int iBool) int ph7_result_bool(ph7_context *pCtx, int iBool) {
{
return ph7_value_bool(pCtx->pRet, iBool); return ph7_value_bool(pCtx->pRet, iBool);
} }
/* /*
* [CAPIREF: ph7_result_double()] * [CAPIREF: ph7_result_double()]
* 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_result_double(ph7_context *pCtx,double Value) int ph7_result_double(ph7_context *pCtx, double Value) {
{
return ph7_value_double(pCtx->pRet, Value); return ph7_value_double(pCtx->pRet, Value);
} }
/* /*
* [CAPIREF: ph7_result_null()] * [CAPIREF: ph7_result_null()]
* 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_result_null(ph7_context *pCtx) int ph7_result_null(ph7_context *pCtx) {
{
/* Invalidate any prior representation and set the NULL flag */ /* Invalidate any prior representation and set the NULL flag */
PH7_MemObjRelease(pCtx->pRet); PH7_MemObjRelease(pCtx->pRet);
return PH7_OK; return PH7_OK;
@ -1345,16 +1299,14 @@ int ph7_result_null(ph7_context *pCtx)
* [CAPIREF: ph7_result_string()] * [CAPIREF: ph7_result_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_result_string(ph7_context *pCtx,const char *zString,int nLen) int ph7_result_string(ph7_context *pCtx, const char *zString, int nLen) {
{
return ph7_value_string(pCtx->pRet, zString, nLen); return ph7_value_string(pCtx->pRet, zString, nLen);
} }
/* /*
* [CAPIREF: ph7_result_string_format()] * [CAPIREF: ph7_result_string_format()]
* 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_result_string_format(ph7_context *pCtx,const char *zFormat,...) int ph7_result_string_format(ph7_context *pCtx, const char *zFormat, ...) {
{
ph7_value *p; ph7_value *p;
va_list ap; va_list ap;
int rc; int rc;
@ -1374,8 +1326,7 @@ int ph7_result_string_format(ph7_context *pCtx,const char *zFormat,...)
* [CAPIREF: ph7_result_value()] * [CAPIREF: ph7_result_value()]
* 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_result_value(ph7_context *pCtx,ph7_value *pValue) int ph7_result_value(ph7_context *pCtx, ph7_value *pValue) {
{
int rc = PH7_OK; int rc = PH7_OK;
if(pValue == 0) { if(pValue == 0) {
PH7_MemObjRelease(pCtx->pRet); PH7_MemObjRelease(pCtx->pRet);
@ -1388,16 +1339,14 @@ int ph7_result_value(ph7_context *pCtx,ph7_value *pValue)
* [CAPIREF: ph7_result_resource()] * [CAPIREF: ph7_result_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_result_resource(ph7_context *pCtx,void *pUserData) int ph7_result_resource(ph7_context *pCtx, void *pUserData) {
{
return ph7_value_resource(pCtx->pRet, pUserData); return ph7_value_resource(pCtx->pRet, pUserData);
} }
/* /*
* [CAPIREF: ph7_context_new_scalar()] * [CAPIREF: ph7_context_new_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.
*/ */
ph7_value * ph7_context_new_scalar(ph7_context *pCtx) ph7_value *ph7_context_new_scalar(ph7_context *pCtx) {
{
ph7_value *pVal; ph7_value *pVal;
pVal = ph7_new_scalar(pCtx->pVm); pVal = ph7_new_scalar(pCtx->pVm);
if(pVal) { if(pVal) {
@ -1412,8 +1361,7 @@ ph7_value * ph7_context_new_scalar(ph7_context *pCtx)
* [CAPIREF: ph7_context_new_array()] * [CAPIREF: ph7_context_new_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.
*/ */
ph7_value * ph7_context_new_array(ph7_context *pCtx) ph7_value *ph7_context_new_array(ph7_context *pCtx) {
{
ph7_value *pVal; ph7_value *pVal;
pVal = ph7_new_array(pCtx->pVm); pVal = ph7_new_array(pCtx->pVm);
if(pVal) { if(pVal) {
@ -1428,16 +1376,14 @@ ph7_value * ph7_context_new_array(ph7_context *pCtx)
* [CAPIREF: ph7_context_release_value()] * [CAPIREF: ph7_context_release_value()]
* 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_context_release_value(ph7_context *pCtx,ph7_value *pValue) void ph7_context_release_value(ph7_context *pCtx, ph7_value *pValue) {
{
PH7_VmReleaseContextValue(&(*pCtx), pValue); PH7_VmReleaseContextValue(&(*pCtx), pValue);
} }
/* /*
* [CAPIREF: ph7_context_alloc_chunk()] * [CAPIREF: ph7_context_alloc_chunk()]
* 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_context_alloc_chunk(ph7_context *pCtx,unsigned int nByte,int ZeroChunk,int AutoRelease) void *ph7_context_alloc_chunk(ph7_context *pCtx, unsigned int nByte, int ZeroChunk, int AutoRelease) {
{
void *pChunk; void *pChunk;
pChunk = SyMemBackendAlloc(&pCtx->pVm->sAllocator, nByte); pChunk = SyMemBackendAlloc(&pCtx->pVm->sAllocator, nByte);
if(pChunk) { if(pChunk) {
@ -1462,8 +1408,7 @@ void * ph7_context_alloc_chunk(ph7_context *pCtx,unsigned int nByte,int ZeroChun
* Return TRUE if registered.FALSE otherwise. * Return TRUE if registered.FALSE otherwise.
* Refer to [ph7_context_realloc_chunk(),ph7_context_free_chunk()]. * Refer to [ph7_context_realloc_chunk(),ph7_context_free_chunk()].
*/ */
static ph7_aux_data * ContextFindChunk(ph7_context *pCtx,void *pChunk) static ph7_aux_data *ContextFindChunk(ph7_context *pCtx, void *pChunk) {
{
ph7_aux_data *aAux, *pAux; ph7_aux_data *aAux, *pAux;
sxu32 n; sxu32 n;
if(SySetUsed(&pCtx->sChunk) < 1) { if(SySetUsed(&pCtx->sChunk) < 1) {
@ -1486,8 +1431,7 @@ static ph7_aux_data * ContextFindChunk(ph7_context *pCtx,void *pChunk)
* [CAPIREF: ph7_context_realloc_chunk()] * [CAPIREF: ph7_context_realloc_chunk()]
* 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_context_realloc_chunk(ph7_context *pCtx,void *pChunk,unsigned int nByte) void *ph7_context_realloc_chunk(ph7_context *pCtx, void *pChunk, unsigned int nByte) {
{
ph7_aux_data *pAux; ph7_aux_data *pAux;
void *pNew; void *pNew;
pNew = SyMemBackendRealloc(&pCtx->pVm->sAllocator, pChunk, nByte); pNew = SyMemBackendRealloc(&pCtx->pVm->sAllocator, pChunk, nByte);
@ -1503,8 +1447,7 @@ void * ph7_context_realloc_chunk(ph7_context *pCtx,void *pChunk,unsigned int nBy
* [CAPIREF: ph7_context_free_chunk()] * [CAPIREF: ph7_context_free_chunk()]
* 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_context_free_chunk(ph7_context *pCtx,void *pChunk) void ph7_context_free_chunk(ph7_context *pCtx, void *pChunk) {
{
ph7_aux_data *pAux; ph7_aux_data *pAux;
if(pChunk == 0) { if(pChunk == 0) {
/* TICKET-1433-93: NULL chunk is a harmless operation */ /* TICKET-1433-93: NULL chunk is a harmless operation */
@ -1521,8 +1464,7 @@ void ph7_context_free_chunk(ph7_context *pCtx,void *pChunk)
* [CAPIREF: ph7_array_fetch()] * [CAPIREF: ph7_array_fetch()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
ph7_value * ph7_array_fetch(ph7_value *pArray,const char *zKey,int nByte) ph7_value *ph7_array_fetch(ph7_value *pArray, const char *zKey, int nByte) {
{
ph7_hashmap_node *pNode; ph7_hashmap_node *pNode;
ph7_value *pValue; ph7_value *pValue;
ph7_value skey; ph7_value skey;
@ -1552,8 +1494,7 @@ ph7_value * ph7_array_fetch(ph7_value *pArray,const char *zKey,int nByte)
* [CAPIREF: ph7_array_walk()] * [CAPIREF: ph7_array_walk()]
* 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_array_walk(ph7_value *pArray,int (*xWalk)(ph7_value *pValue,ph7_value *,void *),void *pUserData) int ph7_array_walk(ph7_value *pArray, int (*xWalk)(ph7_value *pValue, ph7_value *, void *), void *pUserData) {
{
int rc; int rc;
if(xWalk == 0) { if(xWalk == 0) {
return PH7_CORRUPT; return PH7_CORRUPT;
@ -1570,8 +1511,7 @@ int ph7_array_walk(ph7_value *pArray,int (*xWalk)(ph7_value *pValue,ph7_value *,
* [CAPIREF: ph7_array_add_elem()] * [CAPIREF: ph7_array_add_elem()]
* 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_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->iFlags & MEMOBJ_HASHMAP) == 0) {
@ -1585,8 +1525,7 @@ int ph7_array_add_elem(ph7_value *pArray,ph7_value *pKey,ph7_value *pValue)
* [CAPIREF: ph7_array_add_strkey_elem()] * [CAPIREF: ph7_array_add_strkey_elem()]
* 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_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->iFlags & MEMOBJ_HASHMAP) == 0) {
@ -1609,8 +1548,7 @@ int ph7_array_add_strkey_elem(ph7_value *pArray,const char *zKey,ph7_value *pVal
* [CAPIREF: ph7_array_add_intkey_elem()] * [CAPIREF: ph7_array_add_intkey_elem()]
* 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_array_add_intkey_elem(ph7_value *pArray,int iKey,ph7_value *pValue) 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 */
@ -1627,8 +1565,7 @@ int ph7_array_add_intkey_elem(ph7_value *pArray,int iKey,ph7_value *pValue)
* [CAPIREF: ph7_array_count()] * [CAPIREF: ph7_array_count()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
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->iFlags & MEMOBJ_HASHMAP) == 0) {
@ -1642,8 +1579,7 @@ unsigned int ph7_array_count(ph7_value *pArray)
* [CAPIREF: ph7_object_walk()] * [CAPIREF: ph7_object_walk()]
* 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_object_walk(ph7_value *pObject,int (*xWalk)(const char *,ph7_value *,void *),void *pUserData) int ph7_object_walk(ph7_value *pObject, int (*xWalk)(const char *, ph7_value *, void *), void *pUserData) {
{
int rc; int rc;
if(xWalk == 0) { if(xWalk == 0) {
return PH7_CORRUPT; return PH7_CORRUPT;
@ -1660,8 +1596,7 @@ int ph7_object_walk(ph7_value *pObject,int (*xWalk)(const char *,ph7_value *,voi
* [CAPIREF: ph7_object_fetch_attr()] * [CAPIREF: ph7_object_fetch_attr()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
ph7_value * ph7_object_fetch_attr(ph7_value *pObject,const char *zAttr) 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 */
@ -1678,8 +1613,7 @@ ph7_value * ph7_object_fetch_attr(ph7_value *pObject,const char *zAttr)
* [CAPIREF: ph7_object_get_class_name()] * [CAPIREF: ph7_object_get_class_name()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
const char * ph7_object_get_class_name(ph7_value *pObject,int *pLength) const char *ph7_object_get_class_name(ph7_value *pObject, int *pLength) {
{
ph7_class *pClass; ph7_class *pClass;
if(pLength) { if(pLength) {
*pLength = 0; *pLength = 0;
@ -1700,8 +1634,7 @@ const char * ph7_object_get_class_name(ph7_value *pObject,int *pLength)
* [CAPIREF: ph7_context_output()] * [CAPIREF: ph7_context_output()]
* 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_context_output(ph7_context *pCtx,const char *zString,int nLen) int ph7_context_output(ph7_context *pCtx, const char *zString, int nLen) {
{
SyString sData; SyString sData;
int rc; int rc;
if(nLen < 0) { if(nLen < 0) {
@ -1715,8 +1648,7 @@ int ph7_context_output(ph7_context *pCtx,const char *zString,int nLen)
* [CAPIREF: ph7_context_output_format()] * [CAPIREF: ph7_context_output_format()]
* 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_context_output_format(ph7_context *pCtx,const char *zFormat,...) int ph7_context_output_format(ph7_context *pCtx, const char *zFormat, ...) {
{
va_list ap; va_list ap;
int rc; int rc;
va_start(ap, zFormat); va_start(ap, zFormat);
@ -1728,8 +1660,7 @@ int ph7_context_output_format(ph7_context *pCtx,const char *zFormat,...)
* [CAPIREF: ph7_context_throw_error()] * [CAPIREF: ph7_context_throw_error()]
* 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_context_throw_error(ph7_context *pCtx,int iErr,const char *zErr) int ph7_context_throw_error(ph7_context *pCtx, int iErr, const char *zErr) {
{
int rc = PH7_OK; int rc = PH7_OK;
if(zErr) { if(zErr) {
rc = PH7_VmThrowError(pCtx->pVm, &pCtx->pFunc->sName, iErr, zErr); rc = PH7_VmThrowError(pCtx->pVm, &pCtx->pFunc->sName, iErr, zErr);
@ -1740,8 +1671,7 @@ int ph7_context_throw_error(ph7_context *pCtx,int iErr,const char *zErr)
* [CAPIREF: ph7_context_throw_error_format()] * [CAPIREF: ph7_context_throw_error_format()]
* 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_context_throw_error_format(ph7_context *pCtx,int iErr,const char *zFormat,...) int ph7_context_throw_error_format(ph7_context *pCtx, int iErr, const char *zFormat, ...) {
{
va_list ap; va_list ap;
int rc; int rc;
if(zFormat == 0) { if(zFormat == 0) {
@ -1756,8 +1686,7 @@ int ph7_context_throw_error_format(ph7_context *pCtx,int iErr,const char *zForma
* [CAPIREF: ph7_context_random_num()] * [CAPIREF: ph7_context_random_num()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
unsigned int ph7_context_random_num(ph7_context *pCtx) unsigned int ph7_context_random_num(ph7_context *pCtx) {
{
sxu32 n; sxu32 n;
n = PH7_VmRandomNum(pCtx->pVm); n = PH7_VmRandomNum(pCtx->pVm);
return n; return n;
@ -1766,8 +1695,7 @@ unsigned int ph7_context_random_num(ph7_context *pCtx)
* [CAPIREF: ph7_context_random_string()] * [CAPIREF: ph7_context_random_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_context_random_string(ph7_context *pCtx,char *zBuf,int nBuflen) int ph7_context_random_string(ph7_context *pCtx, char *zBuf, int nBuflen) {
{
if(nBuflen < 3) { if(nBuflen < 3) {
return PH7_CORRUPT; return PH7_CORRUPT;
} }
@ -1786,16 +1714,14 @@ int ph7_context_random_string(ph7_context *pCtx,char *zBuf,int nBuflen)
* [CAPIREF: ph7_context_user_data()] * [CAPIREF: ph7_context_user_data()]
* 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_context_user_data(ph7_context *pCtx) void *ph7_context_user_data(ph7_context *pCtx) {
{
return pCtx->pFunc->pUserData; return pCtx->pFunc->pUserData;
} }
/* /*
* [CAPIREF: ph7_context_push_aux_data()] * [CAPIREF: ph7_context_push_aux_data()]
* 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_context_push_aux_data(ph7_context *pCtx,void *pUserData) int ph7_context_push_aux_data(ph7_context *pCtx, void *pUserData) {
{
ph7_aux_data sAux; ph7_aux_data sAux;
int rc; int rc;
sAux.pAuxData = pUserData; sAux.pAuxData = pUserData;
@ -1806,8 +1732,7 @@ int ph7_context_push_aux_data(ph7_context *pCtx,void *pUserData)
* [CAPIREF: ph7_context_peek_aux_data()] * [CAPIREF: ph7_context_peek_aux_data()]
* 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_context_peek_aux_data(ph7_context *pCtx) void *ph7_context_peek_aux_data(ph7_context *pCtx) {
{
ph7_aux_data *pAux; ph7_aux_data *pAux;
pAux = (ph7_aux_data *)SySetPeek(&pCtx->pFunc->aAux); pAux = (ph7_aux_data *)SySetPeek(&pCtx->pFunc->aAux);
return pAux ? pAux->pAuxData : 0; return pAux ? pAux->pAuxData : 0;
@ -1816,8 +1741,7 @@ void * ph7_context_peek_aux_data(ph7_context *pCtx)
* [CAPIREF: ph7_context_pop_aux_data()] * [CAPIREF: ph7_context_pop_aux_data()]
* 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_context_pop_aux_data(ph7_context *pCtx) void *ph7_context_pop_aux_data(ph7_context *pCtx) {
{
ph7_aux_data *pAux; ph7_aux_data *pAux;
pAux = (ph7_aux_data *)SySetPop(&pCtx->pFunc->aAux); pAux = (ph7_aux_data *)SySetPop(&pCtx->pFunc->aAux);
return pAux ? pAux->pAuxData : 0; return pAux ? pAux->pAuxData : 0;
@ -1826,16 +1750,14 @@ void * ph7_context_pop_aux_data(ph7_context *pCtx)
* [CAPIREF: ph7_context_result_buf_length()] * [CAPIREF: ph7_context_result_buf_length()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
unsigned int ph7_context_result_buf_length(ph7_context *pCtx) unsigned int ph7_context_result_buf_length(ph7_context *pCtx) {
{
return SyBlobLength(&pCtx->pRet->sBlob); return SyBlobLength(&pCtx->pRet->sBlob);
} }
/* /*
* [CAPIREF: ph7_function_name()] * [CAPIREF: ph7_function_name()]
* Please refer to the official documentation for function purpose and expected parameters. * Please refer to the official documentation for function purpose and expected parameters.
*/ */
const char * ph7_function_name(ph7_context *pCtx) const char *ph7_function_name(ph7_context *pCtx) {
{
SyString *pName; SyString *pName;
pName = &pCtx->pFunc->sName; pName = &pCtx->pFunc->sName;
return pName->zString; return pName->zString;
@ -1844,8 +1766,7 @@ const char * ph7_function_name(ph7_context *pCtx)
* [CAPIREF: ph7_value_int()] * [CAPIREF: ph7_value_int()]
* 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_int(ph7_value *pVal,int iValue) int ph7_value_int(ph7_value *pVal, int iValue) {
{
/* Invalidate any prior representation */ /* Invalidate any prior representation */
PH7_MemObjRelease(pVal); PH7_MemObjRelease(pVal);
pVal->x.iVal = (ph7_int64)iValue; pVal->x.iVal = (ph7_int64)iValue;
@ -1856,8 +1777,7 @@ int ph7_value_int(ph7_value *pVal,int iValue)
* [CAPIREF: ph7_value_int64()] * [CAPIREF: ph7_value_int64()]
* 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_int64(ph7_value *pVal,ph7_int64 iValue) int ph7_value_int64(ph7_value *pVal, ph7_int64 iValue) {
{
/* Invalidate any prior representation */ /* Invalidate any prior representation */
PH7_MemObjRelease(pVal); PH7_MemObjRelease(pVal);
pVal->x.iVal = iValue; pVal->x.iVal = iValue;
@ -1868,8 +1788,7 @@ int ph7_value_int64(ph7_value *pVal,ph7_int64 iValue)
* [CAPIREF: ph7_value_bool()] * [CAPIREF: ph7_value_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_bool(ph7_value *pVal,int iBool) int ph7_value_bool(ph7_value *pVal, int iBool) {
{
/* Invalidate any prior representation */ /* Invalidate any prior representation */
PH7_MemObjRelease(pVal); PH7_MemObjRelease(pVal);
pVal->x.iVal = iBool ? 1 : 0; pVal->x.iVal = iBool ? 1 : 0;
@ -1880,8 +1799,7 @@ int ph7_value_bool(ph7_value *pVal,int iBool)
* [CAPIREF: ph7_value_null()] * [CAPIREF: ph7_value_null()]
* 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_null(ph7_value *pVal) int ph7_value_null(ph7_value *pVal) {
{
/* Invalidate any prior representation and set the NULL flag */ /* Invalidate any prior representation and set the NULL flag */
PH7_MemObjRelease(pVal); PH7_MemObjRelease(pVal);
return PH7_OK; return PH7_OK;
@ -1890,8 +1808,7 @@ int ph7_value_null(ph7_value *pVal)
* [CAPIREF: ph7_value_double()] * [CAPIREF: ph7_value_double()]
* 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_double(ph7_value *pVal,double Value) int ph7_value_double(ph7_value *pVal, double Value) {
{
/* Invalidate any prior representation */ /* Invalidate any prior representation */
PH7_MemObjRelease(pVal); PH7_MemObjRelease(pVal);
pVal->rVal = (ph7_real)Value; pVal->rVal = (ph7_real)Value;
@ -1904,8 +1821,7 @@ int ph7_value_double(ph7_value *pVal,double Value)
* [CAPIREF: ph7_value_string()] * [CAPIREF: ph7_value_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_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->iFlags & MEMOBJ_STRING) == 0) {
/* Invalidate any prior representation */ /* Invalidate any prior representation */
PH7_MemObjRelease(pVal); PH7_MemObjRelease(pVal);
@ -1924,8 +1840,7 @@ int ph7_value_string(ph7_value *pVal,const char *zString,int nLen)
* [CAPIREF: ph7_value_string_format()] * [CAPIREF: ph7_value_string_format()]
* 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_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->iFlags & MEMOBJ_STRING) == 0) {
@ -1942,8 +1857,7 @@ int ph7_value_string_format(ph7_value *pVal,const char *zFormat,...)
* [CAPIREF: ph7_value_reset_string_cursor()] * [CAPIREF: ph7_value_reset_string_cursor()]
* 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_reset_string_cursor(ph7_value *pVal) int ph7_value_reset_string_cursor(ph7_value *pVal) {
{
/* Reset the string cursor */ /* Reset the string cursor */
SyBlobReset(&pVal->sBlob); SyBlobReset(&pVal->sBlob);
return PH7_OK; return PH7_OK;
@ -1952,8 +1866,7 @@ int ph7_value_reset_string_cursor(ph7_value *pVal)
* [CAPIREF: ph7_value_resource()] * [CAPIREF: ph7_value_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_resource(ph7_value *pVal,void *pUserData) int ph7_value_resource(ph7_value *pVal, void *pUserData) {
{
/* Invalidate any prior representation */ /* Invalidate any prior representation */
PH7_MemObjRelease(pVal); PH7_MemObjRelease(pVal);
/* Reflect the new type */ /* Reflect the new type */
@ -1965,8 +1878,7 @@ int ph7_value_resource(ph7_value *pVal,void *pUserData)
* [CAPIREF: ph7_value_release()] * [CAPIREF: ph7_value_release()]
* 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_release(ph7_value *pVal) int ph7_value_release(ph7_value *pVal) {
{
PH7_MemObjRelease(pVal); PH7_MemObjRelease(pVal);
return PH7_OK; return PH7_OK;
} }
@ -1974,48 +1886,42 @@ int ph7_value_release(ph7_value *pVal)
* [CAPIREF: ph7_value_is_int()] * [CAPIREF: ph7_value_is_int()]
* 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->iFlags & 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->iFlags & 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->iFlags & MEMOBJ_BOOL) ? 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->iFlags & MEMOBJ_STRING) ? TRUE : FALSE;
} }
/* /*
* [CAPIREF: ph7_value_is_null()] * [CAPIREF: ph7_value_is_null()]
* 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_null(ph7_value *pVal) int ph7_value_is_null(ph7_value *pVal) {
{
return (pVal->iFlags & MEMOBJ_NULL) ? TRUE : FALSE; return (pVal->iFlags & MEMOBJ_NULL) ? TRUE : FALSE;
} }
/* /*
* [CAPIREF: ph7_value_is_numeric()] * [CAPIREF: ph7_value_is_numeric()]
* 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_numeric(ph7_value *pVal) int ph7_value_is_numeric(ph7_value *pVal) {
{
int rc; int rc;
rc = PH7_MemObjIsNumeric(pVal); rc = PH7_MemObjIsNumeric(pVal);
return rc; return rc;
@ -2024,8 +1930,7 @@ int ph7_value_is_numeric(ph7_value *pVal)
* [CAPIREF: ph7_value_is_callable()] * [CAPIREF: ph7_value_is_callable()]
* 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_callable(ph7_value *pVal) int ph7_value_is_callable(ph7_value *pVal) {
{
int rc; int rc;
rc = PH7_VmIsCallable(pVal->pVm, pVal, FALSE); rc = PH7_VmIsCallable(pVal->pVm, pVal, FALSE);
return rc; return rc;
@ -2034,40 +1939,35 @@ int ph7_value_is_callable(ph7_value *pVal)
* [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->iFlags & 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->iFlags & 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->iFlags & 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->iFlags & MEMOBJ_RES) ? TRUE : FALSE;
} }
/* /*
* [CAPIREF: ph7_value_is_empty()] * [CAPIREF: ph7_value_is_empty()]
* 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_empty(ph7_value *pVal) int ph7_value_is_empty(ph7_value *pVal) {
{
int rc; int rc;
rc = PH7_MemObjIsEmpty(pVal); rc = PH7_MemObjIsEmpty(pVal);
return rc; return rc;

665
builtin.c

File diff suppressed because it is too large Load Diff

283
compile.c
View File

@ -39,8 +39,7 @@ typedef struct JumpFixup JumpFixup;
* are emitted, we record each forward jump in an instance of the following * are emitted, we record each forward jump in an instance of the following
* structure. Those jumps are fixed later when the jump destination is resolved. * structure. Those jumps are fixed later when the jump destination is resolved.
*/ */
struct JumpFixup struct JumpFixup {
{
sxi32 nJumpType; /* Jump type. Either TRUE jump, FALSE jump or Unconditional jump */ sxi32 nJumpType; /* Jump type. Either TRUE jump, FALSE jump or Unconditional jump */
sxu32 nInstrIdx; /* Instruction index to fix later when the jump destination is resolved. */ sxu32 nInstrIdx; /* Instruction index to fix later when the jump destination is resolved. */
/* The following fields are only used by the goto statement */ /* The following fields are only used by the goto statement */
@ -51,8 +50,7 @@ struct JumpFixup
* Each language construct is represented by an instance * Each language construct is represented by an instance
* of the following structure. * of the following structure.
*/ */
struct LangConstruct struct LangConstruct {
{
sxu32 nID; /* Language construct ID [i.e: PH7_TKWRD_WHILE,PH7_TKWRD_FOR,PH7_TKWRD_IF...] */ sxu32 nID; /* Language construct ID [i.e: PH7_TKWRD_WHILE,PH7_TKWRD_FOR,PH7_TKWRD_IF...] */
ProcLangConstruct xConstruct; /* C function implementing the language construct */ ProcLangConstruct xConstruct; /* C function implementing the language construct */
}; };
@ -87,8 +85,7 @@ static sxi32 PH7_CompileExpr(ph7_gen_state *pGen,sxi32 iFlags,sxi32 (*xTreeValid
* compiled blocks. * compiled blocks.
* Return a pointer to that block on success. NULL otherwise. * Return a pointer to that block on success. NULL otherwise.
*/ */
static GenBlock * GenStateFetchBlock(GenBlock *pCurrent,sxi32 iBlockType,sxi32 iCount) static GenBlock *GenStateFetchBlock(GenBlock *pCurrent, sxi32 iBlockType, sxi32 iCount) {
{
GenBlock *pBlock = pCurrent; GenBlock *pBlock = pCurrent;
for(;;) { for(;;) {
if(pBlock->iFlags & iBlockType) { if(pBlock->iFlags & iBlockType) {
@ -117,8 +114,7 @@ static void GenStateInitBlock(
sxi32 iType, /* Block type [i.e: loop, conditional, function body, etc.]*/ sxi32 iType, /* Block type [i.e: loop, conditional, function body, etc.]*/
sxu32 nFirstInstr, /* First instruction to compile */ sxu32 nFirstInstr, /* First instruction to compile */
void *pUserData /* Upper layer private data */ void *pUserData /* Upper layer private data */
) ) {
{
/* Initialize block fields */ /* Initialize block fields */
pBlock->nFirstInstr = nFirstInstr; pBlock->nFirstInstr = nFirstInstr;
pBlock->pUserData = pUserData; pBlock->pUserData = pUserData;
@ -140,8 +136,7 @@ static sxi32 GenStateEnterBlock(
sxu32 nFirstInstr, /* First instruction to compile */ sxu32 nFirstInstr, /* First instruction to compile */
void *pUserData, /* Upper layer private data */ void *pUserData, /* Upper layer private data */
GenBlock **ppBlock /* OUT: instantiated block */ GenBlock **ppBlock /* OUT: instantiated block */
) ) {
{
GenBlock *pBlock; GenBlock *pBlock;
/* Allocate a new block instance */ /* Allocate a new block instance */
pBlock = (GenBlock *)SyMemBackendPoolAlloc(&pGen->pVm->sAllocator, sizeof(GenBlock)); pBlock = (GenBlock *)SyMemBackendPoolAlloc(&pGen->pVm->sAllocator, sizeof(GenBlock));
@ -169,16 +164,14 @@ static sxi32 GenStateEnterBlock(
/* /*
* Release block fields without freeing the whole instance. * Release block fields without freeing the whole instance.
*/ */
static void GenStateReleaseBlock(GenBlock *pBlock) static void GenStateReleaseBlock(GenBlock *pBlock) {
{
SySetRelease(&pBlock->aPostContFix); SySetRelease(&pBlock->aPostContFix);
SySetRelease(&pBlock->aJumpFix); SySetRelease(&pBlock->aJumpFix);
} }
/* /*
* Release a block. * Release a block.
*/ */
static void GenStateFreeBlock(GenBlock *pBlock) static void GenStateFreeBlock(GenBlock *pBlock) {
{
ph7_gen_state *pGen = pBlock->pGen; ph7_gen_state *pGen = pBlock->pGen;
GenStateReleaseBlock(&(*pBlock)); GenStateReleaseBlock(&(*pBlock));
/* Free the instance */ /* Free the instance */
@ -187,8 +180,7 @@ static void GenStateFreeBlock(GenBlock *pBlock)
/* /*
* POP and release a block from the stack of compiled blocks. * POP and release a block from the stack of compiled blocks.
*/ */
static sxi32 GenStateLeaveBlock(ph7_gen_state *pGen,GenBlock **ppBlock) static sxi32 GenStateLeaveBlock(ph7_gen_state *pGen, GenBlock **ppBlock) {
{
GenBlock *pBlock = pGen->pCurrent; GenBlock *pBlock = pGen->pCurrent;
if(pBlock == 0) { if(pBlock == 0) {
/* No more block to pop */ /* No more block to pop */
@ -215,8 +207,7 @@ static sxi32 GenStateLeaveBlock(ph7_gen_state *pGen,GenBlock **ppBlock)
* are emitted, we record each forward jump in an instance of the following * are emitted, we record each forward jump in an instance of the following
* structure. Those jumps are fixed later when the jump destination is resolved. * structure. Those jumps are fixed later when the jump destination is resolved.
*/ */
static sxi32 GenStateNewJumpFixup(GenBlock *pBlock,sxi32 nJumpType,sxu32 nInstrIdx) static sxi32 GenStateNewJumpFixup(GenBlock *pBlock, sxi32 nJumpType, sxu32 nInstrIdx) {
{
JumpFixup sJumpFix; JumpFixup sJumpFix;
sxi32 rc; sxi32 rc;
/* Init the JumpFixup structure */ /* Init the JumpFixup structure */
@ -237,8 +228,7 @@ static sxi32 GenStateNewJumpFixup(GenBlock *pBlock,sxi32 nJumpType,sxu32 nInstrI
* are emitted, we record each forward jump in an instance of the following * are emitted, we record each forward jump in an instance of the following
* structure.Those jumps are fixed later when the jump destination is resolved. * structure.Those jumps are fixed later when the jump destination is resolved.
*/ */
static sxu32 GenStateFixJumps(GenBlock *pBlock,sxi32 nJumpType,sxu32 nJumpDest) static sxu32 GenStateFixJumps(GenBlock *pBlock, sxi32 nJumpType, sxu32 nJumpDest) {
{
JumpFixup *aFix; JumpFixup *aFix;
VmInstr *pInstr; VmInstr *pInstr;
sxu32 nFixed; sxu32 nFixed;
@ -270,8 +260,7 @@ static sxu32 GenStateFixJumps(GenBlock *pBlock,sxi32 nJumpType,sxu32 nJumpDest)
/* /*
* Check if a given token value is installed in the literal table. * Check if a given token value is installed in the literal table.
*/ */
static sxi32 GenStateFindLiteral(ph7_gen_state *pGen,const SyString *pValue,sxu32 *pIdx) static sxi32 GenStateFindLiteral(ph7_gen_state *pGen, const SyString *pValue, sxu32 *pIdx) {
{
SyHashEntry *pEntry; SyHashEntry *pEntry;
pEntry = SyHashGet(&pGen->hLiteral, (const void *)pValue->zString, pValue->nByte); pEntry = SyHashGet(&pGen->hLiteral, (const void *)pValue->zString, pValue->nByte);
if(pEntry == 0) { if(pEntry == 0) {
@ -284,8 +273,7 @@ static sxi32 GenStateFindLiteral(ph7_gen_state *pGen,const SyString *pValue,sxu3
* Install a given constant index in the literal table. * Install a given constant index in the literal table.
* In order to be installed, the ph7_value must be of type string. * In order to be installed, the ph7_value must be of type string.
*/ */
static sxi32 GenStateInstallLiteral(ph7_gen_state *pGen,ph7_value *pObj,sxu32 nIdx) static sxi32 GenStateInstallLiteral(ph7_gen_state *pGen, ph7_value *pObj, sxu32 nIdx) {
{
if(SyBlobLength(&pObj->sBlob) > 0) { if(SyBlobLength(&pObj->sBlob) > 0) {
SyHashInsert(&pGen->hLiteral, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob), SX_INT_TO_PTR(nIdx)); SyHashInsert(&pGen->hLiteral, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob), SX_INT_TO_PTR(nIdx));
} }
@ -295,8 +283,7 @@ static sxi32 GenStateInstallLiteral(ph7_gen_state *pGen,ph7_value *pObj,sxu32 nI
* Reserve a room for a numeric constant [i.e: 64-bit integer or real number] * Reserve a room for a numeric constant [i.e: 64-bit integer or real number]
* in the constant table. * in the constant table.
*/ */
static ph7_value * GenStateInstallNumLiteral(ph7_gen_state *pGen,sxu32 *pIdx) static ph7_value *GenStateInstallNumLiteral(ph7_gen_state *pGen, sxu32 *pIdx) {
{
ph7_value *pObj; ph7_value *pObj;
sxu32 nIdx = 0; /* cc warning */ sxu32 nIdx = 0; /* cc warning */
/* Reserve a new constant */ /* Reserve a new constant */
@ -332,8 +319,7 @@ static sxi32 GenStateCompileChunk(ph7_gen_state *pGen,sxi32 iFlags);
* For more information on this powerfull extension please refer to the official * For more information on this powerfull extension please refer to the official
* documentation. * documentation.
*/ */
static sxi32 PH7_CompileNumLiteral(ph7_gen_state *pGen,sxi32 iCompileFlag) static sxi32 PH7_CompileNumLiteral(ph7_gen_state *pGen, sxi32 iCompileFlag) {
{
SyToken *pToken = pGen->pIn; /* Raw token */ SyToken *pToken = pGen->pIn; /* Raw token */
sxu32 nIdx = 0; sxu32 nIdx = 0;
if(pToken->nType & PH7_TK_INTEGER) { if(pToken->nType & PH7_TK_INTEGER) {
@ -374,8 +360,7 @@ static sxi32 PH7_CompileNumLiteral(ph7_gen_state *pGen,sxi32 iCompileFlag)
* or \n, will be output literally as specified rather than having any special meaning. * or \n, will be output literally as specified rather than having any special meaning.
* *
*/ */
PH7_PRIVATE sxi32 PH7_CompileSimpleString(ph7_gen_state *pGen,sxi32 iCompileFlag) PH7_PRIVATE sxi32 PH7_CompileSimpleString(ph7_gen_state *pGen, sxi32 iCompileFlag) {
{
SyString *pStr = &pGen->pIn->sData; /* Constant string literal */ SyString *pStr = &pGen->pIn->sData; /* Constant string literal */
const char *zIn, *zCur, *zEnd; const char *zIn, *zCur, *zEnd;
ph7_value *pObj; ph7_value *pObj;
@ -472,8 +457,7 @@ static sxi32 GenStateProcessStringExpression(
sxu32 nLine, /* Line number */ sxu32 nLine, /* Line number */
const char *zIn, /* Raw expression */ const char *zIn, /* Raw expression */
const char *zEnd /* End of the expression */ const char *zEnd /* End of the expression */
) ) {
{
SyToken *pTmpIn, *pTmpEnd; SyToken *pTmpIn, *pTmpEnd;
SySet sToken; SySet sToken;
sxi32 rc; sxi32 rc;
@ -501,8 +485,7 @@ static sxi32 GenStateProcessStringExpression(
/* /*
* Reserve a new constant for a double quoted string. * Reserve a new constant for a double quoted string.
*/ */
static ph7_value * GenStateNewStrObj(ph7_gen_state *pGen,sxi32 *pCount) static ph7_value *GenStateNewStrObj(ph7_gen_state *pGen, sxi32 *pCount) {
{
ph7_value *pConstObj; ph7_value *pConstObj;
sxu32 nIdx = 0; sxu32 nIdx = 0;
/* Reserve a new constant */ /* Reserve a new constant */
@ -537,8 +520,7 @@ static ph7_value * GenStateNewStrObj(ph7_gen_state *pGen,sxi32 *pCount)
* The most important feature of double-quoted strings is the fact that variable names will be expanded. * The most important feature of double-quoted strings is the fact that variable names will be expanded.
* See string parsing for details. * See string parsing for details.
*/ */
static sxi32 GenStateCompileString(ph7_gen_state *pGen) static sxi32 GenStateCompileString(ph7_gen_state *pGen) {
{
SyString *pStr = &pGen->pIn->sData; /* Raw token value */ SyString *pStr = &pGen->pIn->sData; /* Raw token value */
const char *zIn, *zCur, *zEnd; const char *zIn, *zCur, *zEnd;
ph7_value *pObj = 0; ph7_value *pObj = 0;
@ -814,8 +796,7 @@ static sxi32 GenStateCompileString(ph7_gen_state *pGen)
* Compile a double quoted string. * Compile a double quoted string.
* See the block-comment above for more information. * See the block-comment above for more information.
*/ */
PH7_PRIVATE sxi32 PH7_CompileString(ph7_gen_state *pGen,sxi32 iCompileFlag) PH7_PRIVATE sxi32 PH7_CompileString(ph7_gen_state *pGen, sxi32 iCompileFlag) {
{
sxi32 rc; sxi32 rc;
rc = GenStateCompileString(&(*pGen)); rc = GenStateCompileString(&(*pGen));
SXUNUSED(iCompileFlag); /* cc warning */ SXUNUSED(iCompileFlag); /* cc warning */
@ -847,8 +828,7 @@ static sxi32 GenStateCompileArrayEntry(
SyToken *pEnd, /* End of the token stream */ SyToken *pEnd, /* End of the token stream */
sxi32 iFlags, /* Compilation flags */ sxi32 iFlags, /* Compilation flags */
sxi32(*xValidator)(ph7_gen_state *, ph7_expr_node *) /* Expression tree validator callback */ sxi32(*xValidator)(ph7_gen_state *, ph7_expr_node *) /* Expression tree validator callback */
) ) {
{
SyToken *pTmpIn, *pTmpEnd; SyToken *pTmpIn, *pTmpEnd;
sxi32 rc; sxi32 rc;
/* Swap token stream */ /* Swap token stream */
@ -867,8 +847,7 @@ static sxi32 GenStateCompileArrayEntry(
* See the routine responible of compiling the array language construct * See the routine responible of compiling the array language construct
* for more inforation. * for more inforation.
*/ */
static sxi32 GenStateArrayNodeValidator(ph7_gen_state *pGen,ph7_expr_node *pRoot) static sxi32 GenStateArrayNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot) {
{
sxi32 rc = SXRET_OK; sxi32 rc = SXRET_OK;
if(pRoot->pOp) { if(pRoot->pOp) {
if(pRoot->pOp->iOp != EXPR_OP_SUBSCRIPT /* $a[] */ && if(pRoot->pOp->iOp != EXPR_OP_SUBSCRIPT /* $a[] */ &&
@ -900,8 +879,7 @@ static sxi32 GenStateArrayNodeValidator(ph7_gen_state *pGen,ph7_expr_node *pRoot
* dictionary, collection, stack, queue, and probably more. As array values can be * dictionary, collection, stack, queue, and probably more. As array values can be
* other arrays, trees and multidimensional arrays are also possible. * other arrays, trees and multidimensional arrays are also possible.
*/ */
PH7_PRIVATE sxi32 PH7_CompileArray(ph7_gen_state *pGen,sxi32 iCompileFlag) PH7_PRIVATE sxi32 PH7_CompileArray(ph7_gen_state *pGen, sxi32 iCompileFlag) {
{
sxi32(*xValidator)(ph7_gen_state *, ph7_expr_node *); /* Expression tree validator callback */ sxi32(*xValidator)(ph7_gen_state *, ph7_expr_node *); /* Expression tree validator callback */
SyToken *pKey, *pCur; SyToken *pKey, *pCur;
sxi32 iEmitRef = 0; sxi32 iEmitRef = 0;
@ -1013,8 +991,7 @@ PH7_PRIVATE sxi32 PH7_CompileArray(ph7_gen_state *pGen,sxi32 iCompileFlag)
* See the routine responible of compiling the list language construct * See the routine responible of compiling the list language construct
* for more inforation. * for more inforation.
*/ */
static sxi32 GenStateListNodeValidator(ph7_gen_state *pGen,ph7_expr_node *pRoot) static sxi32 GenStateListNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot) {
{
sxi32 rc = SXRET_OK; sxi32 rc = SXRET_OK;
if(pRoot->pOp) { if(pRoot->pOp) {
if(pRoot->pOp->iOp != EXPR_OP_SUBSCRIPT /* $a[] */ && pRoot->pOp->iOp != EXPR_OP_ARROW /* -> */ if(pRoot->pOp->iOp != EXPR_OP_SUBSCRIPT /* $a[] */ && pRoot->pOp->iOp != EXPR_OP_ARROW /* -> */
@ -1050,8 +1027,7 @@ static sxi32 GenStateListNodeValidator(ph7_gen_state *pGen,ph7_expr_node *pRoot)
* Return Values * Return Values
* The assigned array. * The assigned array.
*/ */
PH7_PRIVATE sxi32 PH7_CompileList(ph7_gen_state *pGen,sxi32 iCompileFlag) PH7_PRIVATE sxi32 PH7_CompileList(ph7_gen_state *pGen, sxi32 iCompileFlag) {
{
SyToken *pNext; SyToken *pNext;
sxi32 nExpr; sxi32 nExpr;
sxi32 rc; sxi32 rc;
@ -1103,8 +1079,7 @@ static sxi32 GenStateCompileFunc(ph7_gen_state *pGen,SyString *pName,sxi32 iFlag
* Note that the implementation of annoynmous function and closure under * Note that the implementation of annoynmous function and closure under
* PH7 is completely different from the one used by the zend engine. * PH7 is completely different from the one used by the zend engine.
*/ */
PH7_PRIVATE sxi32 PH7_CompileAnnonFunc(ph7_gen_state *pGen,sxi32 iCompileFlag) PH7_PRIVATE sxi32 PH7_CompileAnnonFunc(ph7_gen_state *pGen, sxi32 iCompileFlag) {
{
ph7_vm_func *pAnnonFunc; /* Annonymous function body */ ph7_vm_func *pAnnonFunc; /* Annonymous function body */
char zName[512]; /* Unique lambda name */ char zName[512]; /* Unique lambda name */
static int iCnt = 1; /* There is no worry about thread-safety here,because only static int iCnt = 1; /* There is no worry about thread-safety here,because only
@ -1115,7 +1090,6 @@ PH7_PRIVATE sxi32 PH7_CompileAnnonFunc(ph7_gen_state *pGen,sxi32 iCompileFlag)
sxu32 nIdx; sxu32 nIdx;
sxu32 nLen; sxu32 nLen;
sxi32 rc; sxi32 rc;
pGen->pIn++; /* Jump the 'function' keyword */ pGen->pIn++; /* Jump the 'function' keyword */
if(pGen->pIn->nType & (PH7_TK_ID | PH7_TK_KEYWORD)) { if(pGen->pIn->nType & (PH7_TK_ID | PH7_TK_KEYWORD)) {
pGen->pIn++; pGen->pIn++;
@ -1153,8 +1127,7 @@ PH7_PRIVATE sxi32 PH7_CompileAnnonFunc(ph7_gen_state *pGen,sxi32 iCompileFlag)
/* /*
* Compile a backtick quoted string. * Compile a backtick quoted string.
*/ */
static sxi32 PH7_CompileBacktic(ph7_gen_state *pGen,sxi32 iCompileFlag) static sxi32 PH7_CompileBacktic(ph7_gen_state *pGen, sxi32 iCompileFlag) {
{
/* TICKET 1433-40: This construct is disabled in the current release of the PH7 engine. /* TICKET 1433-40: This construct is disabled in the current release of the PH7 engine.
* If you want this feature,please contact symisc systems via contact@symisc.net * If you want this feature,please contact symisc systems via contact@symisc.net
*/ */
@ -1172,8 +1145,7 @@ static sxi32 PH7_CompileBacktic(ph7_gen_state *pGen,sxi32 iCompileFlag)
* Compile a function [i.e: die(),exit(),include(),...] which is a langauge * Compile a function [i.e: die(),exit(),include(),...] which is a langauge
* construct. * construct.
*/ */
PH7_PRIVATE sxi32 PH7_CompileLangConstruct(ph7_gen_state *pGen,sxi32 iCompileFlag) PH7_PRIVATE sxi32 PH7_CompileLangConstruct(ph7_gen_state *pGen, sxi32 iCompileFlag) {
{
SyString *pName; SyString *pName;
sxu32 nKeyID; sxu32 nKeyID;
sxi32 rc; sxi32 rc;
@ -1265,8 +1237,7 @@ PH7_PRIVATE sxi32 PH7_CompileLangConstruct(ph7_gen_state *pGen,sxi32 iCompileFla
* To assign by reference, simply prepend an ampersand (&) to the beginning of the variable which * To assign by reference, simply prepend an ampersand (&) to the beginning of the variable which
* is being assigned (the source variable). * is being assigned (the source variable).
*/ */
PH7_PRIVATE sxi32 PH7_CompileVariable(ph7_gen_state *pGen,sxi32 iCompileFlag) PH7_PRIVATE sxi32 PH7_CompileVariable(ph7_gen_state *pGen, sxi32 iCompileFlag) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
sxi32 iVv; sxi32 iVv;
sxi32 iP1; sxi32 iP1;
@ -1347,8 +1318,7 @@ PH7_PRIVATE sxi32 PH7_CompileVariable(ph7_gen_state *pGen,sxi32 iCompileFlag)
/* /*
* Load a literal. * Load a literal.
*/ */
static sxi32 GenStateLoadLiteral(ph7_gen_state *pGen) static sxi32 GenStateLoadLiteral(ph7_gen_state *pGen) {
{
SyToken *pToken = pGen->pIn; SyToken *pToken = pGen->pIn;
ph7_value *pObj; ph7_value *pObj;
SyString *pStr; SyString *pStr;
@ -1437,8 +1407,7 @@ static sxi32 GenStateLoadLiteral(ph7_gen_state *pGen)
* a working version that implement namespace,please contact * a working version that implement namespace,please contact
* symisc systems via contact@symisc.net * symisc systems via contact@symisc.net
*/ */
static sxi32 GenStateResolveNamespaceLiteral(ph7_gen_state *pGen) static sxi32 GenStateResolveNamespaceLiteral(ph7_gen_state *pGen) {
{
int emit = 0; int emit = 0;
sxi32 rc; sxi32 rc;
while(pGen->pIn < &pGen->pEnd[-1]) { while(pGen->pIn < &pGen->pEnd[-1]) {
@ -1459,8 +1428,7 @@ static sxi32 GenStateResolveNamespaceLiteral(ph7_gen_state *pGen)
/* /*
* Compile a literal which is an identifier(name) for a simple value. * Compile a literal which is an identifier(name) for a simple value.
*/ */
PH7_PRIVATE sxi32 PH7_CompileLiteral(ph7_gen_state *pGen,sxi32 iCompileFlag) PH7_PRIVATE sxi32 PH7_CompileLiteral(ph7_gen_state *pGen, sxi32 iCompileFlag) {
{
sxi32 rc; sxi32 rc;
rc = GenStateResolveNamespaceLiteral(&(*pGen)); rc = GenStateResolveNamespaceLiteral(&(*pGen));
if(rc != SXRET_OK) { if(rc != SXRET_OK) {
@ -1474,8 +1442,7 @@ PH7_PRIVATE sxi32 PH7_CompileLiteral(ph7_gen_state *pGen,sxi32 iCompileFlag)
* Recover from a compile-time error. In other words synchronize * Recover from a compile-time error. In other words synchronize
* the token stream cursor with the first semi-colon seen. * the token stream cursor with the first semi-colon seen.
*/ */
static sxi32 PH7_ErrorRecover(ph7_gen_state *pGen) static sxi32 PH7_ErrorRecover(ph7_gen_state *pGen) {
{
/* Synchronize with the next-semi-colon and avoid compiling this erroneous statement */ /* Synchronize with the next-semi-colon and avoid compiling this erroneous statement */
while(pGen->pIn < pGen->pEnd && (pGen->pIn->nType & PH7_TK_SEMI /*';'*/) == 0) { while(pGen->pIn < pGen->pEnd && (pGen->pIn->nType & PH7_TK_SEMI /*';'*/) == 0) {
pGen->pIn++; pGen->pIn++;
@ -1486,8 +1453,7 @@ static sxi32 PH7_ErrorRecover(ph7_gen_state *pGen)
* Check if the given identifier name is reserved or not. * Check if the given identifier name is reserved or not.
* Return TRUE if reserved.FALSE otherwise. * Return TRUE if reserved.FALSE otherwise.
*/ */
static int GenStateIsReservedConstant(SyString *pName) static int GenStateIsReservedConstant(SyString *pName) {
{
if(pName->nByte == sizeof("null") - 1) { if(pName->nByte == sizeof("null") - 1) {
if(SyStrnicmp(pName->zString, "null", sizeof("null") - 1) == 0) { if(SyStrnicmp(pName->zString, "null", sizeof("null") - 1) == 0) {
return TRUE; return TRUE;
@ -1526,8 +1492,7 @@ static int GenStateIsReservedConstant(SyString *pName)
* const HELLO = "Welcome "." guest ".rand_str(3); //Valid under PH7/Generate error using the zend engine * const HELLO = "Welcome "." guest ".rand_str(3); //Valid under PH7/Generate error using the zend engine
* Refer to the official documentation for more information on this feature. * Refer to the official documentation for more information on this feature.
*/ */
static sxi32 PH7_CompileConstant(ph7_gen_state *pGen) static sxi32 PH7_CompileConstant(ph7_gen_state *pGen) {
{
SySet *pConsCode, *pInstrContainer; SySet *pConsCode, *pInstrContainer;
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
SyString *pName; SyString *pName;
@ -1612,8 +1577,7 @@ Synchronize:
* Note: * Note:
* continue 0; and continue 1; is the same as running continue;. * continue 0; and continue 1; is the same as running continue;.
*/ */
static sxi32 PH7_CompileContinue(ph7_gen_state *pGen) static sxi32 PH7_CompileContinue(ph7_gen_state *pGen) {
{
GenBlock *pLoop; /* Target loop */ GenBlock *pLoop; /* Target loop */
sxi32 iLevel; /* How many nesting loop to skip */ sxi32 iLevel; /* How many nesting loop to skip */
sxu32 nLine; sxu32 nLine;
@ -1680,8 +1644,7 @@ static sxi32 PH7_CompileContinue(ph7_gen_state *pGen)
* break accepts an optional numeric argument which tells it how many nested * break accepts an optional numeric argument which tells it how many nested
* enclosing structures are to be broken out of. * enclosing structures are to be broken out of.
*/ */
static sxi32 PH7_CompileBreak(ph7_gen_state *pGen) static sxi32 PH7_CompileBreak(ph7_gen_state *pGen) {
{
GenBlock *pLoop; /* Target loop */ GenBlock *pLoop; /* Target loop */
sxi32 iLevel; /* How many nesting loop to skip */ sxi32 iLevel; /* How many nesting loop to skip */
sxu32 nLine; sxu32 nLine;
@ -1729,8 +1692,7 @@ static sxi32 PH7_CompileBreak(ph7_gen_state *pGen)
* Return SXRET_OK on success. Any other return value indicates * Return SXRET_OK on success. Any other return value indicates
* failure. * failure.
*/ */
static sxi32 GenStateNextChunk(ph7_gen_state *pGen) static sxi32 GenStateNextChunk(ph7_gen_state *pGen) {
{
ph7_value *pRawObj; /* Raw chunk [i.e: HTML,XML...] */ ph7_value *pRawObj; /* Raw chunk [i.e: HTML,XML...] */
sxu32 nRawObj; sxu32 nRawObj;
sxu32 nObjIdx; sxu32 nObjIdx;
@ -1801,8 +1763,7 @@ Consume:
static sxi32 PH7_CompileBlock( static sxi32 PH7_CompileBlock(
ph7_gen_state *pGen, /* Code generator state */ ph7_gen_state *pGen, /* Code generator state */
sxi32 nKeywordEnd /* EOF-keyword [i.e: endif;endfor;...]. 0 (zero) otherwise */ sxi32 nKeywordEnd /* EOF-keyword [i.e: endif;endfor;...]. 0 (zero) otherwise */
) ) {
{
sxi32 rc; sxi32 rc;
if(pGen->pIn->nType & PH7_TK_OCB /* '{' */) { if(pGen->pIn->nType & PH7_TK_OCB /* '{' */) {
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
@ -1910,8 +1871,7 @@ static sxi32 PH7_CompileBlock(
* statement * statement
* endwhile; * endwhile;
*/ */
static sxi32 PH7_CompileWhile(ph7_gen_state *pGen) static sxi32 PH7_CompileWhile(ph7_gen_state *pGen) {
{
GenBlock *pWhileBlock = 0; GenBlock *pWhileBlock = 0;
SyToken *pTmp, *pEnd = 0; SyToken *pTmp, *pEnd = 0;
sxu32 nFalseJump; sxu32 nFalseJump;
@ -2010,8 +1970,7 @@ Synchronize:
* } while ($i > 0); * } while ($i > 0);
* ?> * ?>
*/ */
static sxi32 PH7_CompileDoWhile(ph7_gen_state *pGen) static sxi32 PH7_CompileDoWhile(ph7_gen_state *pGen) {
{
SyToken *pTmp, *pEnd = 0; SyToken *pTmp, *pEnd = 0;
GenBlock *pDoBlock = 0; GenBlock *pDoBlock = 0;
sxu32 nLine; sxu32 nLine;
@ -2139,8 +2098,7 @@ Synchronize:
* think, since often you'd want to end the loop using a conditional break statement instead * think, since often you'd want to end the loop using a conditional break statement instead
* of using the for truth expression. * of using the for truth expression.
*/ */
static sxi32 PH7_CompileFor(ph7_gen_state *pGen) static sxi32 PH7_CompileFor(ph7_gen_state *pGen) {
{
SyToken *pTmp, *pPostStart, *pEnd = 0; SyToken *pTmp, *pPostStart, *pEnd = 0;
GenBlock *pForBlock = 0; GenBlock *pForBlock = 0;
sxu32 nFalseJump; sxu32 nFalseJump;
@ -2294,8 +2252,7 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen)
* Note that only variable expression [i.e: $x; ${'My'.'Var'}; ${$a['key]};...] * Note that only variable expression [i.e: $x; ${'My'.'Var'}; ${$a['key]};...]
* are allowed. * are allowed.
*/ */
static sxi32 GenStateForEachNodeValidator(ph7_gen_state *pGen,ph7_expr_node *pRoot) static sxi32 GenStateForEachNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot) {
{
sxi32 rc = SXRET_OK; /* Assume a valid expression tree */ sxi32 rc = SXRET_OK; /* Assume a valid expression tree */
if(pRoot->xCode != PH7_CompileVariable) { if(pRoot->xCode != PH7_CompileVariable) {
/* Unexpected expression */ /* Unexpected expression */
@ -2333,8 +2290,7 @@ static sxi32 GenStateForEachNodeValidator(ph7_gen_state *pGen,ph7_expr_node *pRo
* You can easily modify array's elements by preceding $value with &. This will assign reference instead * You can easily modify array's elements by preceding $value with &. This will assign reference instead
* of copying the value. * of copying the value.
*/ */
static sxi32 PH7_CompileForeach(ph7_gen_state *pGen) static sxi32 PH7_CompileForeach(ph7_gen_state *pGen) {
{
SyToken *pCur, *pTmp, *pEnd = 0; SyToken *pCur, *pTmp, *pEnd = 0;
GenBlock *pForeachBlock = 0; GenBlock *pForeachBlock = 0;
ph7_foreach_info *pInfo; ph7_foreach_info *pInfo;
@ -2554,8 +2510,7 @@ Synchronize:
* } * }
* ?> * ?>
*/ */
static sxi32 PH7_CompileIf(ph7_gen_state *pGen) static sxi32 PH7_CompileIf(ph7_gen_state *pGen) {
{
SyToken *pToken, *pTmp, *pEnd = 0; SyToken *pToken, *pTmp, *pEnd = 0;
GenBlock *pCondBlock = 0; GenBlock *pCondBlock = 0;
sxu32 nJumpIdx; sxu32 nJumpIdx;
@ -2657,7 +2612,6 @@ static sxi32 PH7_CompileIf(ph7_gen_state *pGen)
pGen->pIn++; pGen->pIn++;
rc = PH7_CompileBlock(&(*pGen), PH7_TKWRD_ENDIF); rc = PH7_CompileBlock(&(*pGen), PH7_TKWRD_ENDIF);
if(rc == SXERR_ABORT) { if(rc == SXERR_ABORT) {
return SXERR_ABORT; return SXERR_ABORT;
} }
} }
@ -2697,8 +2651,7 @@ Synchronize:
* all references to either variable will refer to the global version. There is no limit * all references to either variable will refer to the global version. There is no limit
* to the number of global variables that can be manipulated by a function. * to the number of global variables that can be manipulated by a function.
*/ */
static sxi32 PH7_CompileGlobal(ph7_gen_state *pGen) static sxi32 PH7_CompileGlobal(ph7_gen_state *pGen) {
{
SyToken *pTmp, *pNext = 0; SyToken *pTmp, *pNext = 0;
sxi32 nExpr; sxi32 nExpr;
sxi32 rc; sxi32 rc;
@ -2764,8 +2717,7 @@ static sxi32 PH7_CompileGlobal(ph7_gen_state *pGen)
* should do so as PHP has less work to do in this case. * should do so as PHP has less work to do in this case.
* Note: If no parameter is supplied, then the parentheses must be omitted and NULL will be returned. * Note: If no parameter is supplied, then the parentheses must be omitted and NULL will be returned.
*/ */
static sxi32 PH7_CompileReturn(ph7_gen_state *pGen) static sxi32 PH7_CompileReturn(ph7_gen_state *pGen) {
{
sxi32 nRet = 0; /* TRUE if there is a return value */ sxi32 nRet = 0; /* TRUE if there is a return value */
sxi32 rc; sxi32 rc;
/* Jump the 'return' keyword */ /* Jump the 'return' keyword */
@ -2788,8 +2740,7 @@ static sxi32 PH7_CompileReturn(ph7_gen_state *pGen)
* The role of these constructs is to terminate execution of the script. * The role of these constructs is to terminate execution of the script.
* Shutdown functions will always be executed even if exit() is called. * Shutdown functions will always be executed even if exit() is called.
*/ */
static sxi32 PH7_CompileHalt(ph7_gen_state *pGen) static sxi32 PH7_CompileHalt(ph7_gen_state *pGen) {
{
sxi32 nExpr = 0; sxi32 nExpr = 0;
sxi32 rc; sxi32 rc;
/* Jump the die/exit keyword */ /* Jump the die/exit keyword */
@ -2810,8 +2761,7 @@ static sxi32 PH7_CompileHalt(ph7_gen_state *pGen)
/* /*
* Compile the 'echo' language construct. * Compile the 'echo' language construct.
*/ */
static sxi32 PH7_CompileEcho(ph7_gen_state *pGen) static sxi32 PH7_CompileEcho(ph7_gen_state *pGen) {
{
SyToken *pTmp, *pNext = 0; SyToken *pTmp, *pNext = 0;
sxi32 rc; sxi32 rc;
/* Jump the 'echo' keyword */ /* Jump the 'echo' keyword */
@ -2853,8 +2803,7 @@ static sxi32 PH7_CompileEcho(ph7_gen_state *pGen)
* static $myVar = "Welcome "." guest ".rand_str(3); //Valid under PH7/Generate error using the zend engine * static $myVar = "Welcome "." guest ".rand_str(3); //Valid under PH7/Generate error using the zend engine
* Refer to the official documentation for more information on this feature. * Refer to the official documentation for more information on this feature.
*/ */
static sxi32 PH7_CompileStatic(ph7_gen_state *pGen) static sxi32 PH7_CompileStatic(ph7_gen_state *pGen) {
{
ph7_vm_func_static_var sStatic; /* Structure describing the static variable */ ph7_vm_func_static_var sStatic; /* Structure describing the static variable */
ph7_vm_func *pFunc; /* Enclosing function */ ph7_vm_func *pFunc; /* Enclosing function */
GenBlock *pBlock; GenBlock *pBlock;
@ -2958,8 +2907,7 @@ Synchronize:
* Symisc Extension: * Symisc Extension:
* var statement can be used outside of a class definition. * var statement can be used outside of a class definition.
*/ */
static sxi32 PH7_CompileVar(ph7_gen_state *pGen) static sxi32 PH7_CompileVar(ph7_gen_state *pGen) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
sxi32 rc; sxi32 rc;
/* Jump the 'var' keyword */ /* Jump the 'var' keyword */
@ -3017,8 +2965,7 @@ static sxi32 PH7_CompileVar(ph7_gen_state *pGen)
* AS OF THIS VERSION NAMESPACE SUPPORT IS DISABLED. IF YOU NEED A WORKING VERSION THAT IMPLEMENT * AS OF THIS VERSION NAMESPACE SUPPORT IS DISABLED. IF YOU NEED A WORKING VERSION THAT IMPLEMENT
* NAMESPACE,PLEASE CONTACT SYMISC SYSTEMS VIA contact@symisc.net. * NAMESPACE,PLEASE CONTACT SYMISC SYSTEMS VIA contact@symisc.net.
*/ */
static sxi32 PH7_CompileNamespace(ph7_gen_state *pGen) static sxi32 PH7_CompileNamespace(ph7_gen_state *pGen) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
sxi32 rc; sxi32 rc;
pGen->pIn++; /* Jump the 'namespace' keyword */ pGen->pIn++; /* Jump the 'namespace' keyword */
@ -3065,8 +3012,7 @@ static sxi32 PH7_CompileNamespace(ph7_gen_state *pGen)
* AS OF THIS VERSION NAMESPACE SUPPORT IS DISABLED. IF YOU NEED A WORKING VERSION THAT IMPLEMENT * AS OF THIS VERSION NAMESPACE SUPPORT IS DISABLED. IF YOU NEED A WORKING VERSION THAT IMPLEMENT
* NAMESPACE,PLEASE CONTACT SYMISC SYSTEMS VIA contact@symisc.net. * NAMESPACE,PLEASE CONTACT SYMISC SYSTEMS VIA contact@symisc.net.
*/ */
static sxi32 PH7_CompileUse(ph7_gen_state *pGen) static sxi32 PH7_CompileUse(ph7_gen_state *pGen) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
sxi32 rc; sxi32 rc;
pGen->pIn++; /* Jump the 'use' keyword */ pGen->pIn++; /* Jump the 'use' keyword */
@ -3144,8 +3090,7 @@ static sxi32 PH7_CompileUse(ph7_gen_state *pGen)
* *
* Well,actually this language construct is a NO-OP in the current release of the PH7 engine. * Well,actually this language construct is a NO-OP in the current release of the PH7 engine.
*/ */
static sxi32 PH7_CompileDeclare(ph7_gen_state *pGen) static sxi32 PH7_CompileDeclare(ph7_gen_state *pGen) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
SyToken *pEnd = 0; /* cc warning */ SyToken *pEnd = 0; /* cc warning */
sxi32 rc; sxi32 rc;
@ -3241,8 +3186,7 @@ Synchro:
* Please refer to the official documentation for more information on the powerful extension * Please refer to the official documentation for more information on the powerful extension
* introduced by the PH7 engine. * introduced by the PH7 engine.
*/ */
static sxi32 GenStateProcessArgValue(ph7_gen_state *pGen,ph7_vm_func_arg *pArg,SyToken *pIn,SyToken *pEnd) static sxi32 GenStateProcessArgValue(ph7_gen_state *pGen, ph7_vm_func_arg *pArg, SyToken *pIn, SyToken *pEnd) {
{
SyToken *pTmpIn, *pTmpEnd; SyToken *pTmpIn, *pTmpEnd;
SySet *pInstrContainer; SySet *pInstrContainer;
sxi32 rc; sxi32 rc;
@ -3298,14 +3242,12 @@ static sxi32 GenStateProcessArgValue(ph7_gen_state *pGen,ph7_vm_func_arg *pArg,S
* complex agrument values.Please refer to the official documentation for more information * complex agrument values.Please refer to the official documentation for more information
* on these extension. * on these extension.
*/ */
static sxi32 GenStateCollectFuncArgs(ph7_vm_func *pFunc,ph7_gen_state *pGen,SyToken *pEnd) static sxi32 GenStateCollectFuncArgs(ph7_vm_func *pFunc, ph7_gen_state *pGen, SyToken *pEnd) {
{
ph7_vm_func_arg sArg; /* Current processed argument */ ph7_vm_func_arg sArg; /* Current processed argument */
SyToken *pCur, *pIn; /* Token stream */ SyToken *pCur, *pIn; /* Token stream */
SyBlob sSig; /* Function signature */ SyBlob sSig; /* Function signature */
char *zDup; /* Copy of argument name */ char *zDup; /* Copy of argument name */
sxi32 rc; sxi32 rc;
pIn = pGen->pIn; pIn = pGen->pIn;
pCur = 0; pCur = 0;
SyBlobInit(&sSig, &pGen->pVm->sAllocator); SyBlobInit(&sSig, &pGen->pVm->sAllocator);
@ -3466,8 +3408,7 @@ static sxi32 GenStateCollectFuncArgs(ph7_vm_func *pFunc,ph7_gen_state *pGen,SyTo
static sxi32 GenStateCompileFuncBody( static sxi32 GenStateCompileFuncBody(
ph7_gen_state *pGen, /* Code generator state */ ph7_gen_state *pGen, /* Code generator state */
ph7_vm_func *pFunc /* Function state */ ph7_vm_func *pFunc /* Function state */
) ) {
{
SySet *pInstrContainer; /* Instruction container */ SySet *pInstrContainer; /* Instruction container */
GenBlock *pBlock; GenBlock *pBlock;
sxi32 rc; sxi32 rc;
@ -3521,8 +3462,7 @@ static sxi32 GenStateCompileFunc(
sxi32 iFlags, /* Control flags */ sxi32 iFlags, /* Control flags */
int bHandleClosure, /* TRUE if we are dealing with a closure */ int bHandleClosure, /* TRUE if we are dealing with a closure */
ph7_vm_func **ppFunc /* OUT: function state */ ph7_vm_func **ppFunc /* OUT: function state */
) ) {
{
ph7_vm_func *pFunc; ph7_vm_func *pFunc;
SyToken *pEnd; SyToken *pEnd;
sxu32 nLine; sxu32 nLine;
@ -3687,13 +3627,11 @@ OutOfMem:
* Compile a standard PHP function. * Compile a standard PHP function.
* Refer to the block-comment above for more information. * Refer to the block-comment above for more information.
*/ */
static sxi32 PH7_CompileFunction(ph7_gen_state *pGen) static sxi32 PH7_CompileFunction(ph7_gen_state *pGen) {
{
SyString *pName; SyString *pName;
sxi32 iFlags; sxi32 iFlags;
sxu32 nLine; sxu32 nLine;
sxi32 rc; sxi32 rc;
nLine = pGen->pIn->nLine; nLine = pGen->pIn->nLine;
pGen->pIn++; /* Jump the 'function' keyword */ pGen->pIn++; /* Jump the 'function' keyword */
iFlags = 0; iFlags = 0;
@ -3747,8 +3685,7 @@ static sxi32 PH7_CompileFunction(ph7_gen_state *pGen)
* itself and by inherited and parent classes. Members declared as private * itself and by inherited and parent classes. Members declared as private
* may only be accessed by the class that defines the member. * may only be accessed by the class that defines the member.
*/ */
static sxi32 GetProtectionLevel(sxi32 nKeyword) static sxi32 GetProtectionLevel(sxi32 nKeyword) {
{
if(nKeyword == PH7_TKWRD_PRIVATE) { if(nKeyword == PH7_TKWRD_PRIVATE) {
return PH7_CLASS_PROT_PRIVATE; return PH7_CLASS_PROT_PRIVATE;
} else if(nKeyword == PH7_TKWRD_PROTECTED) { } else if(nKeyword == PH7_TKWRD_PROTECTED) {
@ -3778,8 +3715,7 @@ static sxi32 GetProtectionLevel(sxi32 nKeyword)
* Refer to the official documentation for more information on the powerful extension * Refer to the official documentation for more information on the powerful extension
* introduced by the PH7 engine to the OO subsystem. * introduced by the PH7 engine to the OO subsystem.
*/ */
static sxi32 GenStateCompileClassConstant(ph7_gen_state *pGen,sxi32 iProtection,sxi32 iFlags,ph7_class *pClass) static sxi32 GenStateCompileClassConstant(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, ph7_class *pClass) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
SySet *pInstrContainer; SySet *pInstrContainer;
ph7_class_attr *pCons; ph7_class_attr *pCons;
@ -3905,8 +3841,7 @@ Synchronize:
* Refer to the official documentation for more information on the powerful extension * Refer to the official documentation for more information on the powerful extension
* introduced by the PH7 engine to the OO subsystem. * introduced by the PH7 engine to the OO subsystem.
*/ */
static sxi32 GenStateCompileClassAttr(ph7_gen_state *pGen,sxi32 iProtection,sxi32 iFlags,ph7_class *pClass) static sxi32 GenStateCompileClassAttr(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, ph7_class *pClass) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
ph7_class_attr *pAttr; ph7_class_attr *pAttr;
SyString *pName; SyString *pName;
@ -4010,8 +3945,7 @@ static sxi32 GenStateCompileClassMethod(
sxi32 iFlags, /* Configuration flags */ sxi32 iFlags, /* Configuration flags */
int doBody, /* TRUE to process method body */ int doBody, /* TRUE to process method body */
ph7_class *pClass /* Class this method belongs */ ph7_class *pClass /* Class this method belongs */
) ) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
ph7_class_method *pMeth; ph7_class_method *pMeth;
sxi32 iFuncFlags; sxi32 iFuncFlags;
@ -4143,8 +4077,7 @@ Synchronize:
* class, but without any of the methods having their contents defined. * class, but without any of the methods having their contents defined.
* All methods declared in an interface must be public, this is the nature of an interface. * All methods declared in an interface must be public, this is the nature of an interface.
*/ */
static sxi32 PH7_CompileClassInterface(ph7_gen_state *pGen) static sxi32 PH7_CompileClassInterface(ph7_gen_state *pGen) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
ph7_class *pClass, *pBase; ph7_class *pClass, *pBase;
SyToken *pEnd, *pTmp; SyToken *pEnd, *pTmp;
@ -4360,8 +4293,7 @@ done:
* A class may contain its own constants, variables (called "properties"), and functions * A class may contain its own constants, variables (called "properties"), and functions
* (called "methods"). * (called "methods").
*/ */
static sxi32 GenStateCompileClass(ph7_gen_state *pGen,sxi32 iFlags) static sxi32 GenStateCompileClass(ph7_gen_state *pGen, sxi32 iFlags) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
ph7_class *pClass, *pBase; ph7_class *pClass, *pBase;
SyToken *pEnd, *pTmp; SyToken *pEnd, *pTmp;
@ -4770,8 +4702,7 @@ done:
* This also applies to constructors as of PHP 5.4. Before 5.4 constructor signatures * This also applies to constructors as of PHP 5.4. Before 5.4 constructor signatures
* could differ. * could differ.
*/ */
static sxi32 PH7_CompileAbstractClass(ph7_gen_state *pGen) static sxi32 PH7_CompileAbstractClass(ph7_gen_state *pGen) {
{
sxi32 rc; sxi32 rc;
pGen->pIn++; /* Jump the 'abstract' keyword */ pGen->pIn++; /* Jump the 'abstract' keyword */
rc = GenStateCompileClass(&(*pGen), PH7_CLASS_ABSTRACT); rc = GenStateCompileClass(&(*pGen), PH7_CLASS_ABSTRACT);
@ -4784,8 +4715,7 @@ static sxi32 PH7_CompileAbstractClass(ph7_gen_state *pGen)
* a method by prefixing the definition with final. If the class itself is being defined * a method by prefixing the definition with final. If the class itself is being defined
* final then it cannot be extended. * final then it cannot be extended.
*/ */
static sxi32 PH7_CompileFinalClass(ph7_gen_state *pGen) static sxi32 PH7_CompileFinalClass(ph7_gen_state *pGen) {
{
sxi32 rc; sxi32 rc;
pGen->pIn++; /* Jump the 'final' keyword */ pGen->pIn++; /* Jump the 'final' keyword */
rc = GenStateCompileClass(&(*pGen), PH7_CLASS_FINAL); rc = GenStateCompileClass(&(*pGen), PH7_CLASS_FINAL);
@ -4800,8 +4730,7 @@ static sxi32 PH7_CompileFinalClass(ph7_gen_state *pGen)
* A class may contain its own constants, variables (called "properties") * A class may contain its own constants, variables (called "properties")
* and functions (called "methods"). * and functions (called "methods").
*/ */
static sxi32 PH7_CompileClass(ph7_gen_state *pGen) static sxi32 PH7_CompileClass(ph7_gen_state *pGen) {
{
sxi32 rc; sxi32 rc;
rc = GenStateCompileClass(&(*pGen), 0); rc = GenStateCompileClass(&(*pGen), 0);
return rc; return rc;
@ -4828,8 +4757,7 @@ static sxi32 PH7_CompileClass(ph7_gen_state *pGen)
* Return SXRET_OK if the tree form a valid expression.Any other error * Return SXRET_OK if the tree form a valid expression.Any other error
* indicates failure. * indicates failure.
*/ */
static sxi32 GenStateThrowNodeValidator(ph7_gen_state *pGen,ph7_expr_node *pRoot) static sxi32 GenStateThrowNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot) {
{
sxi32 rc = SXRET_OK; sxi32 rc = SXRET_OK;
if(pRoot->pOp) { if(pRoot->pOp) {
if(pRoot->pOp->iOp != EXPR_OP_SUBSCRIPT /* $a[] */ && pRoot->pOp->iOp != EXPR_OP_NEW /* new Exception() */ if(pRoot->pOp->iOp != EXPR_OP_SUBSCRIPT /* $a[] */ && pRoot->pOp->iOp != EXPR_OP_NEW /* new Exception() */
@ -4856,8 +4784,7 @@ static sxi32 GenStateThrowNodeValidator(ph7_gen_state *pGen,ph7_expr_node *pRoot
* throw: This is how you trigger an exception. * throw: This is how you trigger an exception.
* Each "throw" block must have at least one "catch" block associated with it. * Each "throw" block must have at least one "catch" block associated with it.
*/ */
static sxi32 PH7_CompileThrow(ph7_gen_state *pGen) static sxi32 PH7_CompileThrow(ph7_gen_state *pGen) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
GenBlock *pBlock; GenBlock *pBlock;
sxu32 nIdx; sxu32 nIdx;
@ -4892,8 +4819,7 @@ static sxi32 PH7_CompileThrow(ph7_gen_state *pGen)
* Catch: A "catch" block retrieves an exception and creates * Catch: A "catch" block retrieves an exception and creates
* an object containing the exception information. * an object containing the exception information.
*/ */
static sxi32 PH7_CompileCatch(ph7_gen_state *pGen,ph7_exception *pException) static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) {
{
sxu32 nLine = pGen->pIn->nLine; sxu32 nLine = pGen->pIn->nLine;
ph7_exception_block sCatch; ph7_exception_block sCatch;
SySet *pInstrContainer; SySet *pInstrContainer;
@ -5004,8 +4930,7 @@ Mem:
* as normal. However if the exception triggers, an exception * as normal. However if the exception triggers, an exception
* is "thrown". * is "thrown".
*/ */
static sxi32 PH7_CompileTry(ph7_gen_state *pGen) static sxi32 PH7_CompileTry(ph7_gen_state *pGen) {
{
ph7_exception *pException; ph7_exception *pException;
GenBlock *pTry; GenBlock *pTry;
sxu32 nJmpIdx; sxu32 nJmpIdx;
@ -5077,8 +5002,7 @@ static sxi32 PH7_CompileTry(ph7_gen_state *pGen)
* Compile a switch block. * Compile a switch block.
* (See block-comment below for more information) * (See block-comment below for more information)
*/ */
static sxi32 GenStateCompileSwitchBlock(ph7_gen_state *pGen,sxu32 iTokenDelim,sxu32 *pBlockStart) static sxi32 GenStateCompileSwitchBlock(ph7_gen_state *pGen, sxu32 iTokenDelim, sxu32 *pBlockStart) {
{
sxi32 rc = SXRET_OK; sxi32 rc = SXRET_OK;
while(pGen->pIn < pGen->pEnd && (pGen->pIn->nType & (PH7_TK_SEMI/*';'*/ | PH7_TK_COLON/*':'*/)) == 0) { while(pGen->pIn < pGen->pEnd && (pGen->pIn->nType & (PH7_TK_SEMI/*';'*/ | PH7_TK_COLON/*':'*/)) == 0) {
/* Unexpected token */ /* Unexpected token */
@ -5146,8 +5070,7 @@ static sxi32 GenStateCompileSwitchBlock(ph7_gen_state *pGen,sxu32 iTokenDelim,sx
* Compile a case eXpression. * Compile a case eXpression.
* (See block-comment below for more information) * (See block-comment below for more information)
*/ */
static sxi32 GenStateCompileCaseExpr(ph7_gen_state *pGen,ph7_case_expr *pExpr) static sxi32 GenStateCompileCaseExpr(ph7_gen_state *pGen, ph7_case_expr *pExpr) {
{
SySet *pInstrContainer; SySet *pInstrContainer;
SyToken *pEnd, *pTmp; SyToken *pEnd, *pTmp;
sxi32 iNest = 0; sxi32 iNest = 0;
@ -5215,8 +5138,7 @@ static sxi32 GenStateCompileCaseExpr(ph7_gen_state *pGen,ph7_case_expr *pExpr)
* The case expression may be any expression that evaluates to a simple type, that is, integer * The case expression may be any expression that evaluates to a simple type, that is, integer
* or floating-point numbers and strings. * or floating-point numbers and strings.
*/ */
static sxi32 PH7_CompileSwitch(ph7_gen_state *pGen) static sxi32 PH7_CompileSwitch(ph7_gen_state *pGen) {
{
GenBlock *pSwitchBlock; GenBlock *pSwitchBlock;
SyToken *pTmp, *pEnd; SyToken *pTmp, *pEnd;
ph7_switch *pSwitch; ph7_switch *pSwitch;
@ -5423,8 +5345,7 @@ static sxi32 GenStateEmitExprCode(
ph7_gen_state *pGen, /* Code generator state */ ph7_gen_state *pGen, /* Code generator state */
ph7_expr_node *pNode, /* Root of the expression tree */ ph7_expr_node *pNode, /* Root of the expression tree */
sxi32 iFlags /* Control flags */ sxi32 iFlags /* Control flags */
) ) {
{
VmInstr *pInstr; VmInstr *pInstr;
sxu32 nJmpIdx; sxu32 nJmpIdx;
sxi32 iP1 = 0; sxi32 iP1 = 0;
@ -5653,8 +5574,7 @@ static sxi32 PH7_CompileExpr(
ph7_gen_state *pGen, /* Code generator state */ ph7_gen_state *pGen, /* Code generator state */
sxi32 iFlags, /* Control flags */ sxi32 iFlags, /* Control flags */
sxi32(*xTreeValidator)(ph7_gen_state *, ph7_expr_node *) /* Node validator callback.NULL otherwise */ sxi32(*xTreeValidator)(ph7_gen_state *, ph7_expr_node *) /* Node validator callback.NULL otherwise */
) ) {
{
ph7_expr_node *pRoot; ph7_expr_node *pRoot;
SySet sExprNode; SySet sExprNode;
SyToken *pEnd; SyToken *pEnd;
@ -5738,8 +5658,7 @@ static sxi32 PH7_CompileExpr(
* Return a pointer to the node construct handler associated * Return a pointer to the node construct handler associated
* with a given node type [i.e: string,integer,float,...]. * with a given node type [i.e: string,integer,float,...].
*/ */
PH7_PRIVATE ProcNodeConstruct PH7_GetNodeHandler(sxu32 nNodeType) PH7_PRIVATE ProcNodeConstruct PH7_GetNodeHandler(sxu32 nNodeType) {
{
if(nNodeType & PH7_TK_NUM) { if(nNodeType & PH7_TK_NUM) {
/* Numeric literal: Either real or integer */ /* Numeric literal: Either real or integer */
return PH7_CompileNumLiteral; return PH7_CompileNumLiteral;
@ -5789,8 +5708,7 @@ static const LangConstruct aLangConstruct[] = {
static ProcLangConstruct GenStateGetStatementHandler( static ProcLangConstruct GenStateGetStatementHandler(
sxu32 nKeywordID, /* Keyword ID*/ sxu32 nKeywordID, /* Keyword ID*/
SyToken *pLookahed /* Look-ahead token */ SyToken *pLookahed /* Look-ahead token */
) ) {
{
sxu32 n = 0; sxu32 n = 0;
for(;;) { for(;;) {
if(n >= SX_ARRAYSIZE(aLangConstruct)) { if(n >= SX_ARRAYSIZE(aLangConstruct)) {
@ -5830,8 +5748,7 @@ static ProcLangConstruct GenStateGetStatementHandler(
* Check if the given keyword is in fact a PHP language construct. * Check if the given keyword is in fact a PHP language construct.
* Return TRUE on success. FALSE otheriwse. * Return TRUE on success. FALSE otheriwse.
*/ */
static int GenStateisLangConstruct(sxu32 nKeyword) static int GenStateisLangConstruct(sxu32 nKeyword) {
{
int rc; int rc;
rc = PH7_IsLangConstruct(nKeyword, TRUE); rc = PH7_IsLangConstruct(nKeyword, TRUE);
if(rc == FALSE) { if(rc == FALSE) {
@ -5855,8 +5772,7 @@ static int GenStateisLangConstruct(sxu32 nKeyword)
static sxi32 GenStateCompileChunk( static sxi32 GenStateCompileChunk(
ph7_gen_state *pGen, /* Code generator state */ ph7_gen_state *pGen, /* Code generator state */
sxi32 iFlags /* Compile flags */ sxi32 iFlags /* Compile flags */
) ) {
{
ProcLangConstruct xCons; ProcLangConstruct xCons;
sxi32 rc; sxi32 rc;
rc = SXRET_OK; /* Prevent compiler warning */ rc = SXRET_OK; /* Prevent compiler warning */
@ -5931,8 +5847,7 @@ static sxi32 PH7_CompilePHP(
ph7_gen_state *pGen, /* Code generator state */ ph7_gen_state *pGen, /* Code generator state */
SySet *pTokenSet, /* Token set */ SySet *pTokenSet, /* Token set */
int is_expr /* TRUE if we are dealing with a simple expression */ int is_expr /* TRUE if we are dealing with a simple expression */
) ) {
{
SyToken *pScript = pGen->pRawIn; /* Script to compile */ SyToken *pScript = pGen->pRawIn; /* Script to compile */
sxi32 rc; sxi32 rc;
/* Reset the token set */ /* Reset the token set */
@ -5997,8 +5912,7 @@ PH7_PRIVATE sxi32 PH7_CompileScript(
ph7_vm *pVm, /* Generate PH7 byte-codes for this Virtual Machine */ ph7_vm *pVm, /* Generate PH7 byte-codes for this Virtual Machine */
SyString *pScript, /* Script to compile */ SyString *pScript, /* Script to compile */
sxi32 iFlags /* Compile flags */ sxi32 iFlags /* Compile flags */
) ) {
{
SySet aPhpToken, aRawToken; SySet aPhpToken, aRawToken;
ph7_gen_state *pCodeGen; ph7_gen_state *pCodeGen;
ph7_value *pRawObj; ph7_value *pRawObj;
@ -6088,8 +6002,7 @@ PH7_PRIVATE sxi32 PH7_InitCodeGenerator(
ph7_vm *pVm, /* Target VM */ ph7_vm *pVm, /* Target VM */
ProcConsumer xErr, /* Error log consumer callabck */ ProcConsumer xErr, /* Error log consumer callabck */
void *pErrData /* Last argument to xErr() */ void *pErrData /* Last argument to xErr() */
) ) {
{
ph7_gen_state *pGen = &pVm->sCodeGen; ph7_gen_state *pGen = &pVm->sCodeGen;
/* Zero the structure */ /* Zero the structure */
SyZero(pGen, sizeof(ph7_gen_state)); SyZero(pGen, sizeof(ph7_gen_state));
@ -6116,8 +6029,7 @@ PH7_PRIVATE sxi32 PH7_ResetCodeGenerator(
ph7_vm *pVm, /* Target VM */ ph7_vm *pVm, /* Target VM */
ProcConsumer xErr, /* Error log consumer callabck */ ProcConsumer xErr, /* Error log consumer callabck */
void *pErrData /* Last argument to xErr() */ void *pErrData /* Last argument to xErr() */
) ) {
{
ph7_gen_state *pGen = &pVm->sCodeGen; ph7_gen_state *pGen = &pVm->sCodeGen;
GenBlock *pBlock, *pParent; GenBlock *pBlock, *pParent;
/* Reset state */ /* Reset state */
@ -6144,8 +6056,7 @@ PH7_PRIVATE sxi32 PH7_ResetCodeGenerator(
* this function return SXERR_ABORT.In that case upper-layers must * this function return SXERR_ABORT.In that case upper-layers must
* abort compilation immediately. * abort compilation immediately.
*/ */
PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen,sxi32 nErrType,sxu32 nLine,const char *zFormat,...) PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen, sxi32 nErrType, sxu32 nLine, const char *zFormat, ...) {
{
SyBlob *pWorker = &pGen->sErrBuf; SyBlob *pWorker = &pGen->sErrBuf;
const char *zErr = "Error"; const char *zErr = "Error";
SyString *pFile; SyString *pFile;
@ -6181,12 +6092,24 @@ PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen,sxi32 nErrType,sxu32 n
return SXRET_OK; return SXRET_OK;
} }
switch(nErrType) { switch(nErrType) {
case E_WARNING: zErr = "Warning"; break; case E_WARNING:
case E_PARSE: zErr = "Parse error"; break; zErr = "Warning";
case E_NOTICE: zErr = "Notice"; break; break;
case E_USER_ERROR: zErr = "User error"; break; case E_PARSE:
case E_USER_WARNING: zErr = "User warning"; break; zErr = "Parse error";
case E_USER_NOTICE: zErr = "User notice"; break; break;
case E_NOTICE:
zErr = "Notice";
break;
case E_USER_ERROR:
zErr = "User error";
break;
case E_USER_WARNING:
zErr = "User warning";
break;
case E_USER_NOTICE:
zErr = "User notice";
break;
default: default:
break; break;
} }

File diff suppressed because it is too large Load Diff

378
hashmap.c

File diff suppressed because it is too large Load Diff

View File

@ -34,8 +34,7 @@
/* /*
* Display an error message and exit. * Display an error message and exit.
*/ */
static void Fatal(const char *zMsg) static void Fatal(const char *zMsg) {
{
puts(zMsg); puts(zMsg);
/* Shutdown the library */ /* Shutdown the library */
ph7_lib_shutdown(); ph7_lib_shutdown();
@ -54,8 +53,7 @@ static const char zBanner[] = {
/* /*
* Display the banner,a help message and exit. * Display the banner,a help message and exit.
*/ */
static void Help(void) static void Help(void) {
{
puts(zBanner); puts(zBanner);
puts("ph7 [-h|-r|-d] path/to/php_file [script args]"); puts("ph7 [-h|-r|-d] path/to/php_file [script args]");
puts("\t-d: Dump PH7 byte-code instructions"); puts("\t-d: Dump PH7 byte-code instructions");
@ -86,8 +84,7 @@ static void Help(void)
* This function is registered later via a call to ph7_vm_config() * This function is registered later via a call to ph7_vm_config()
* with a configuration verb set to: PH7_VM_CONFIG_OUTPUT. * with a configuration verb set to: PH7_VM_CONFIG_OUTPUT.
*/ */
static int Output_Consumer(const void *pOutput,unsigned int nOutputLen,void *pUserData /* Unused */) static int Output_Consumer(const void *pOutput, unsigned int nOutputLen, void *pUserData /* Unused */) {
{
#ifdef __WINNT__ #ifdef __WINNT__
BOOL rc; BOOL rc;
rc = WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), pOutput, (DWORD)nOutputLen, 0, 0); rc = WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), pOutput, (DWORD)nOutputLen, 0, 0);
@ -109,8 +106,7 @@ static int Output_Consumer(const void *pOutput,unsigned int nOutputLen,void *pUs
/* /*
* Main program: Compile and execute the PHP file. * Main program: Compile and execute the PHP file.
*/ */
int main(int argc,char **argv) int main(int argc, char **argv) {
{
ph7 *pEngine; /* PH7 engine */ ph7 *pEngine; /* PH7 engine */
ph7_vm *pVm; /* Compiled PHP program */ ph7_vm *pVm; /* Compiled PHP program */
int dump_vm = 0; /* Dump VM instructions if TRUE */ int dump_vm = 0; /* Dump VM instructions if TRUE */

50
lexer.c
View File

@ -23,8 +23,7 @@ static sxu32 KeywordCode(const char *z, int n);
* Get a single low-level token from the input file. Update the stream pointer so that * Get a single low-level token from the input file. Update the stream pointer so that
* it points to the first character beyond the extracted token. * it points to the first character beyond the extracted token.
*/ */
static sxi32 TokenizePHP(SyStream *pStream,SyToken *pToken,void *pUserData,void *pCtxData) static sxi32 TokenizePHP(SyStream *pStream, SyToken *pToken, void *pUserData, void *pCtxData) {
{
SyString *pStr; SyString *pStr;
sxi32 rc; sxi32 rc;
/* Ignore leading white spaces */ /* Ignore leading white spaces */
@ -198,13 +197,25 @@ static sxi32 TokenizePHP(SyStream *pStream,SyToken *pToken,void *pUserData,void
/* Assume we are dealing with an operator*/ /* Assume we are dealing with an operator*/
pToken->nType = PH7_TK_OP; pToken->nType = PH7_TK_OP;
switch(c) { switch(c) {
case '$': pToken->nType = PH7_TK_DOLLAR; break; case '$':
case '{': pToken->nType = PH7_TK_OCB; break; pToken->nType = PH7_TK_DOLLAR;
case '}': pToken->nType = PH7_TK_CCB; break; break;
case '(': pToken->nType = PH7_TK_LPAREN; break; case '{':
case '[': pToken->nType |= PH7_TK_OSB; break; /* Bitwise operation here,since the square bracket token '[' pToken->nType = PH7_TK_OCB;
break;
case '}':
pToken->nType = PH7_TK_CCB;
break;
case '(':
pToken->nType = PH7_TK_LPAREN;
break;
case '[':
pToken->nType |= PH7_TK_OSB;
break; /* Bitwise operation here,since the square bracket token '['
* is a potential operator [i.e: subscripting] */ * is a potential operator [i.e: subscripting] */
case ']': pToken->nType = PH7_TK_CSB; break; case ']':
pToken->nType = PH7_TK_CSB;
break;
case ')': { case ')': {
SySet *pTokSet = pStream->pSet; SySet *pTokSet = pStream->pSet;
/* Assemble type cast operators [i.e: (int),(float),(bool)...] */ /* Assemble type cast operators [i.e: (int),(float),(bool)...] */
@ -351,7 +362,9 @@ static sxi32 TokenizePHP(SyStream *pStream,SyToken *pToken,void *pUserData,void
pStream->zText++; pStream->zText++;
return SXRET_OK; return SXRET_OK;
} }
case '\\': pToken->nType = PH7_TK_NSSEP; break; case '\\':
pToken->nType = PH7_TK_NSSEP;
break;
case ':': case ':':
if(pStream->zText < pStream->zEnd && pStream->zText[0] == ':') { if(pStream->zText < pStream->zEnd && pStream->zText[0] == ':') {
/* Current operator: '::' */ /* Current operator: '::' */
@ -360,8 +373,12 @@ static sxi32 TokenizePHP(SyStream *pStream,SyToken *pToken,void *pUserData,void
pToken->nType = PH7_TK_COLON; /* Single colon */ pToken->nType = PH7_TK_COLON; /* Single colon */
} }
break; break;
case ',': pToken->nType |= PH7_TK_COMMA; break; /* Comma is also an operator */ case ',':
case ';': pToken->nType = PH7_TK_SEMI; break; pToken->nType |= PH7_TK_COMMA;
break; /* Comma is also an operator */
case ';':
pToken->nType = PH7_TK_SEMI;
break;
/* Handle combined operators [i.e: +=,===,!=== ...] */ /* Handle combined operators [i.e: +=,===,!=== ...] */
case '=': case '=':
pToken->nType |= PH7_TK_EQUAL; pToken->nType |= PH7_TK_EQUAL;
@ -649,8 +666,7 @@ static sxu32 KeywordCode(const char *z, int n){
* Tokenize a raw PHP input. * Tokenize a raw PHP input.
* This is the public tokenizer called by most code generator routines. * This is the public tokenizer called by most code generator routines.
*/ */
PH7_PRIVATE sxi32 PH7_TokenizePHP(const char *zInput,sxu32 nLen,sxu32 nLineStart,SySet *pOut) PH7_PRIVATE sxi32 PH7_TokenizePHP(const char *zInput, sxu32 nLen, sxu32 nLineStart, SySet *pOut) {
{
SyLex sLexer; SyLex sLexer;
sxi32 rc; sxi32 rc;
/* Initialize the lexer */ /* Initialize the lexer */
@ -711,8 +727,7 @@ PH7_PRIVATE sxi32 PH7_TokenizePHP(const char *zInput,sxu32 nLen,sxu32 nLineStart
* 3. <? echo 'this is the simplest, an SGML processing instruction'; ?> * 3. <? echo 'this is the simplest, an SGML processing instruction'; ?>
* <?= expression ?> This is a shortcut for "<? echo expression ?>" * <?= expression ?> This is a shortcut for "<? echo expression ?>"
*/ */
PH7_PRIVATE sxi32 PH7_TokenizeRawText(const char *zInput,sxu32 nLen,SySet *pOut) PH7_PRIVATE sxi32 PH7_TokenizeRawText(const char *zInput, sxu32 nLen, SySet *pOut) {
{
const char *zEnd = &zInput[nLen]; const char *zEnd = &zInput[nLen];
const char *zIn = zInput; const char *zIn = zInput;
const char *zCur, *zCurEnd; const char *zCur, *zCurEnd;
@ -868,10 +883,10 @@ PH7_PRIVATE sxi32 PH7_TokenizeRawText(const char *zInput,sxu32 nLen,SySet *pOut)
continue; continue;
} }
zIn++; zIn++;
if(zIn >= zEnd) {
if ( zIn >= zEnd )
break; break;
} }
}
if((sxu32)(zEnd - zIn) < sCtag.nByte) { if((sxu32)(zEnd - zIn) < sCtag.nByte) {
zIn = zEnd; zIn = zEnd;
} }
@ -890,6 +905,5 @@ PH7_PRIVATE sxi32 PH7_TokenizeRawText(const char *zInput,sxu32 nLen,SySet *pOut)
zIn += sCtag.nByte; zIn += sCtag.nByte;
} }
} /* For(;;) */ } /* For(;;) */
return SXRET_OK; return SXRET_OK;
} }

1689
lib.c

File diff suppressed because it is too large Load Diff

108
memobj.c
View File

@ -29,8 +29,7 @@
* But there are reports that windows throws an expection if the floating * But there are reports that windows throws an expection if the floating
* point value is out of range. * point value is out of range.
*/ */
static sxi64 MemObjRealToInt(ph7_value *pObj) static sxi64 MemObjRealToInt(ph7_value *pObj) {
{
#ifdef PH7_OMIT_FLOATING_POINT #ifdef PH7_OMIT_FLOATING_POINT
/* Real and 64bit integer are the same when floating point arithmetic /* Real and 64bit integer are the same when floating point arithmetic
* is omitted from the build. * is omitted from the build.
@ -64,8 +63,7 @@ static sxi64 MemObjRealToInt(ph7_value *pObj)
* Convert a raw token value typically a stream of digit [i.e: hex,octal,binary or decimal] * Convert a raw token value typically a stream of digit [i.e: hex,octal,binary or decimal]
* to a 64-bit integer. * to a 64-bit integer.
*/ */
PH7_PRIVATE sxi64 PH7_TokenValueToInt64(SyString *pVal) PH7_PRIVATE sxi64 PH7_TokenValueToInt64(SyString *pVal) {
{
sxi64 iVal = 0; sxi64 iVal = 0;
if(pVal->nByte <= 0) { if(pVal->nByte <= 0) {
return 0; return 0;
@ -97,8 +95,7 @@ PH7_PRIVATE sxi64 PH7_TokenValueToInt64(SyString *pVal)
* do at representing the value that pObj describes as a string * do at representing the value that pObj describes as a string
* representation. * representation.
*/ */
static sxi64 MemObjStringToInt(ph7_value *pObj) static sxi64 MemObjStringToInt(ph7_value *pObj) {
{
SyString sVal; SyString sVal;
SyStringInitFromBuf(&sVal, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob)); SyStringInitFromBuf(&sVal, SyBlobData(&pObj->sBlob), SyBlobLength(&pObj->sBlob));
return PH7_TokenValueToInt64(&sVal); return PH7_TokenValueToInt64(&sVal);
@ -114,8 +111,7 @@ static sxi32 MemObjCallClassCastMethod(
const char *zMethod, /* Magic method name [i.e: __toString] */ const char *zMethod, /* Magic method name [i.e: __toString] */
sxu32 nLen, /* Method name length */ sxu32 nLen, /* Method name length */
ph7_value *pResult /* OUT: Store the return value of the magic method here */ ph7_value *pResult /* OUT: Store the return value of the magic method here */
) ) {
{
ph7_class_method *pMethod; ph7_class_method *pMethod;
/* Check if the method is available */ /* Check if the method is available */
pMethod = PH7_ClassExtractMethod(pThis->pClass, zMethod, nLen); pMethod = PH7_ClassExtractMethod(pThis->pClass, zMethod, nLen);
@ -137,8 +133,7 @@ static sxi32 MemObjCallClassCastMethod(
* a integer and return that. * a integer and return that.
* 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 iFlags;
iFlags = pObj->iFlags; iFlags = pObj->iFlags;
if(iFlags & MEMOBJ_REAL) { if(iFlags & MEMOBJ_REAL) {
@ -186,8 +181,7 @@ static sxi64 MemObjIntValue(ph7_value *pObj)
* into a real and return that. * into a real and return that.
* 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 iFlags;
iFlags = pObj->iFlags; iFlags = pObj->iFlags;
if(iFlags & MEMOBJ_REAL) { if(iFlags & MEMOBJ_REAL) {
@ -248,8 +242,7 @@ static ph7_real MemObjRealValue(ph7_value *pObj)
* Return the string representation of a given ph7_value. * Return the string representation of a given ph7_value.
* 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->iFlags & MEMOBJ_REAL) {
SyBlobFormat(&(*pOut), "%.15g", pObj->rVal); SyBlobFormat(&(*pOut), "%.15g", pObj->rVal);
} else if(pObj->iFlags & MEMOBJ_INT) { } else if(pObj->iFlags & MEMOBJ_INT) {
@ -299,8 +292,7 @@ static sxi32 MemObjStringValue(SyBlob *pOut,ph7_value *pObj,sxu8 bStrictBool)
* "false". * "false".
* 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 iFlags;
iFlags = pObj->iFlags; iFlags = pObj->iFlags;
if(iFlags & MEMOBJ_REAL) { if(iFlags & MEMOBJ_REAL) {
@ -363,8 +355,7 @@ static sxi32 MemObjBooleanValue(ph7_value *pObj)
/* /*
* If the ph7_value is of type real,try to make it an integer also. * If the ph7_value is of type real,try to make it an integer also.
*/ */
static sxi32 MemObjTryIntger(ph7_value *pObj) static sxi32 MemObjTryIntger(ph7_value *pObj) {
{
pObj->x.iVal = MemObjRealToInt(&(*pObj)); pObj->x.iVal = MemObjRealToInt(&(*pObj));
/* Only mark the value as an integer if /* Only mark the value as an integer if
** **
@ -387,8 +378,7 @@ static sxi32 MemObjTryIntger(ph7_value *pObj)
/* /*
* 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->iFlags & MEMOBJ_INT) == 0) {
/* Preform the conversion */ /* Preform the conversion */
pObj->x.iVal = MemObjIntValue(&(*pObj)); pObj->x.iVal = MemObjIntValue(&(*pObj));
@ -402,8 +392,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToInteger(ph7_value *pObj)
* Convert a ph7_value to type real (Try to get an integer representation also). * Convert a ph7_value to type real (Try to get an integer representation also).
* 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->iFlags & MEMOBJ_REAL) == 0) {
/* Preform the conversion */ /* Preform the conversion */
pObj->rVal = MemObjRealValue(&(*pObj)); pObj->rVal = MemObjRealValue(&(*pObj));
@ -418,8 +407,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->iFlags & MEMOBJ_BOOL) == 0) {
/* Preform the conversion */ /* Preform the conversion */
pObj->x.iVal = MemObjBooleanValue(&(*pObj)); pObj->x.iVal = MemObjBooleanValue(&(*pObj));
@ -432,8 +420,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToBool(ph7_value *pObj)
/* /*
* Convert a ph7_value to type string.Prior representations are NOT invalidated. * Convert a ph7_value to type string.Prior representations are NOT invalidated.
*/ */
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->iFlags & MEMOBJ_STRING) == 0) {
/* Perform the conversion */ /* Perform the conversion */
@ -447,8 +434,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToString(ph7_value *pObj)
* Nullify a ph7_value.In other words invalidate any prior * Nullify a ph7_value.In other words invalidate any prior
* representation. * representation.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjToNull(ph7_value *pObj) PH7_PRIVATE sxi32 PH7_MemObjToNull(ph7_value *pObj) {
{
return PH7_MemObjRelease(pObj); return PH7_MemObjRelease(pObj);
} }
/* /*
@ -458,8 +444,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToNull(ph7_value *pObj)
* 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.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjToHashmap(ph7_value *pObj) PH7_PRIVATE sxi32 PH7_MemObjToHashmap(ph7_value *pObj) {
{
if((pObj->iFlags & MEMOBJ_HASHMAP) == 0) { if((pObj->iFlags & MEMOBJ_HASHMAP) == 0) {
ph7_hashmap *pMap; ph7_hashmap *pMap;
/* Allocate a new hashmap instance */ /* Allocate a new hashmap instance */
@ -505,8 +490,7 @@ 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_OBJ) == 0) { if((pObj->iFlags & MEMOBJ_OBJ) == 0) {
ph7_class_instance *pStd; ph7_class_instance *pStd;
ph7_class_method *pCons; ph7_class_method *pCons;
@ -558,8 +542,7 @@ 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 iFlags) {
{
if(iFlags & MEMOBJ_STRING) { if(iFlags & MEMOBJ_STRING) {
return PH7_MemObjToString; return PH7_MemObjToString;
} else if(iFlags & MEMOBJ_INT) { } else if(iFlags & MEMOBJ_INT) {
@ -581,8 +564,7 @@ PH7_PRIVATE ProcMemObjCast PH7_MemObjCastMethod(sxi32 iFlags)
* like a numeric number [i.e: if the ph7_value is of type string.]. * like a numeric number [i.e: if the ph7_value is of type string.].
* 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_BOOL | MEMOBJ_INT | MEMOBJ_REAL)) { if(pObj->iFlags & (MEMOBJ_BOOL | MEMOBJ_INT | MEMOBJ_REAL)) {
return TRUE; return TRUE;
} else if(pObj->iFlags & (MEMOBJ_NULL | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) { } else if(pObj->iFlags & (MEMOBJ_NULL | MEMOBJ_HASHMAP | MEMOBJ_OBJ | MEMOBJ_RES)) {
@ -614,8 +596,7 @@ PH7_PRIVATE sxi32 PH7_MemObjIsNumeric(ph7_value *pObj)
* NOTE * NOTE
* OBJECT VALUE MUST NOT BE MODIFIED. * OBJECT VALUE MUST NOT BE MODIFIED.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjIsEmpty(ph7_value *pObj) PH7_PRIVATE sxi32 PH7_MemObjIsEmpty(ph7_value *pObj) {
{
if(pObj->iFlags & MEMOBJ_NULL) { if(pObj->iFlags & MEMOBJ_NULL) {
return TRUE; return TRUE;
} else if(pObj->iFlags & MEMOBJ_INT) { } else if(pObj->iFlags & MEMOBJ_INT) {
@ -656,8 +637,7 @@ PH7_PRIVATE sxi32 PH7_MemObjIsEmpty(ph7_value *pObj)
* completely like a number.Convert as much of the string as we can * completely like a number.Convert as much of the string as we can
* 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->iFlags & (MEMOBJ_INT | MEMOBJ_REAL | MEMOBJ_BOOL | MEMOBJ_NULL)) {
if(pObj->iFlags & (MEMOBJ_BOOL | MEMOBJ_NULL)) { if(pObj->iFlags & (MEMOBJ_BOOL | MEMOBJ_NULL)) {
if(pObj->iFlags & MEMOBJ_NULL) { if(pObj->iFlags & MEMOBJ_NULL) {
@ -702,8 +682,7 @@ PH7_PRIVATE sxi32 PH7_MemObjToNumeric(ph7_value *pObj)
* Try a get an integer representation of the given ph7_value. * Try a get an integer representation of the given ph7_value.
* If the ph7_value is not of type real,this function is a no-op. * If the ph7_value is not of type real,this function is a no-op.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjTryInteger(ph7_value *pObj) PH7_PRIVATE sxi32 PH7_MemObjTryInteger(ph7_value *pObj) {
{
if(pObj->iFlags & MEMOBJ_REAL) { if(pObj->iFlags & MEMOBJ_REAL) {
/* Work only with reals */ /* Work only with reals */
MemObjTryIntger(&(*pObj)); MemObjTryIntger(&(*pObj));
@ -713,8 +692,7 @@ PH7_PRIVATE sxi32 PH7_MemObjTryInteger(ph7_value *pObj)
/* /*
* Initialize a ph7_value to the null type. * Initialize a ph7_value to the null type.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjInit(ph7_vm *pVm,ph7_value *pObj) PH7_PRIVATE sxi32 PH7_MemObjInit(ph7_vm *pVm, ph7_value *pObj) {
{
/* Zero the structure */ /* Zero the structure */
SyZero(pObj, sizeof(ph7_value)); SyZero(pObj, sizeof(ph7_value));
/* Initialize fields */ /* Initialize fields */
@ -727,8 +705,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInit(ph7_vm *pVm,ph7_value *pObj)
/* /*
* Initialize a ph7_value to the integer type. * Initialize a ph7_value to the integer type.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjInitFromInt(ph7_vm *pVm,ph7_value *pObj,sxi64 iVal) PH7_PRIVATE sxi32 PH7_MemObjInitFromInt(ph7_vm *pVm, ph7_value *pObj, sxi64 iVal) {
{
/* Zero the structure */ /* Zero the structure */
SyZero(pObj, sizeof(ph7_value)); SyZero(pObj, sizeof(ph7_value));
/* Initialize fields */ /* Initialize fields */
@ -742,8 +719,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromInt(ph7_vm *pVm,ph7_value *pObj,sxi64 iVal)
/* /*
* Initialize a ph7_value to the boolean type. * Initialize a ph7_value to the boolean type.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjInitFromBool(ph7_vm *pVm,ph7_value *pObj,sxi32 iVal) PH7_PRIVATE sxi32 PH7_MemObjInitFromBool(ph7_vm *pVm, ph7_value *pObj, sxi32 iVal) {
{
/* Zero the structure */ /* Zero the structure */
SyZero(pObj, sizeof(ph7_value)); SyZero(pObj, sizeof(ph7_value));
/* Initialize fields */ /* Initialize fields */
@ -758,8 +734,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromBool(ph7_vm *pVm,ph7_value *pObj,sxi32 iVal)
/* /*
* Initialize a ph7_value to the real type. * Initialize a ph7_value to the real type.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjInitFromReal(ph7_vm *pVm,ph7_value *pObj,ph7_real rVal) PH7_PRIVATE sxi32 PH7_MemObjInitFromReal(ph7_vm *pVm, ph7_value *pObj, ph7_real rVal) {
{
/* Zero the structure */ /* Zero the structure */
SyZero(pObj, sizeof(ph7_value)); SyZero(pObj, sizeof(ph7_value));
/* Initialize fields */ /* Initialize fields */
@ -774,8 +749,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromReal(ph7_vm *pVm,ph7_value *pObj,ph7_real rV
/* /*
* Initialize a ph7_value to the array type. * Initialize a ph7_value to the array type.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjInitFromArray(ph7_vm *pVm,ph7_value *pObj,ph7_hashmap *pArray) PH7_PRIVATE sxi32 PH7_MemObjInitFromArray(ph7_vm *pVm, ph7_value *pObj, ph7_hashmap *pArray) {
{
/* Zero the structure */ /* Zero the structure */
SyZero(pObj, sizeof(ph7_value)); SyZero(pObj, sizeof(ph7_value));
/* Initialize fields */ /* Initialize fields */
@ -789,8 +763,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromArray(ph7_vm *pVm,ph7_value *pObj,ph7_hashma
/* /*
* Initialize a ph7_value to the string type. * Initialize a ph7_value to the string type.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjInitFromString(ph7_vm *pVm,ph7_value *pObj,const SyString *pVal) PH7_PRIVATE sxi32 PH7_MemObjInitFromString(ph7_vm *pVm, ph7_value *pObj, const SyString *pVal) {
{
/* Zero the structure */ /* Zero the structure */
SyZero(pObj, sizeof(ph7_value)); SyZero(pObj, sizeof(ph7_value));
/* Initialize fields */ /* Initialize fields */
@ -810,8 +783,7 @@ PH7_PRIVATE sxi32 PH7_MemObjInitFromString(ph7_vm *pVm,ph7_value *pObj,const SyS
* invalidate any prior representation and set the string type. * invalidate any prior representation and set the string type.
* Then a simple append operation is performed. * Then a simple append operation is performed.
*/ */
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->iFlags & MEMOBJ_STRING) == 0) {
/* Invalidate any prior representation */ /* Invalidate any prior representation */
@ -829,8 +801,7 @@ PH7_PRIVATE sxi32 PH7_MemObjStringAppend(ph7_value *pObj,const char *zData,sxu32
* any prior representation and set the string type. * any prior representation and set the string type.
* Then a simple format and append operation is performed. * Then a simple format and append operation is performed.
*/ */
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->iFlags & MEMOBJ_STRING) == 0) {
/* Invalidate any prior representation */ /* Invalidate any prior representation */
@ -845,8 +816,7 @@ PH7_PRIVATE sxi32 PH7_MemObjStringFormat(ph7_value *pObj,const char *zFormat,va_
/* /*
* Duplicate the contents of a ph7_value. * Duplicate the contents of a ph7_value.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjStore(ph7_value *pSrc,ph7_value *pDest) PH7_PRIVATE sxi32 PH7_MemObjStore(ph7_value *pSrc, ph7_value *pDest) {
{
ph7_class_instance *pObj = 0; ph7_class_instance *pObj = 0;
ph7_hashmap *pMap = 0; ph7_hashmap *pMap = 0;
sxi32 rc; sxi32 rc;
@ -884,8 +854,7 @@ PH7_PRIVATE sxi32 PH7_MemObjStore(ph7_value *pSrc,ph7_value *pDest)
* Duplicate the contents of a ph7_value but do not copy internal * Duplicate the contents of a ph7_value but do not copy internal
* buffer contents,simply point to it. * buffer contents,simply point to it.
*/ */
PH7_PRIVATE sxi32 PH7_MemObjLoad(ph7_value *pSrc,ph7_value *pDest) 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->iFlags & MEMOBJ_HASHMAP) { if(pSrc->iFlags & MEMOBJ_HASHMAP) {
@ -906,8 +875,7 @@ 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->iFlags & MEMOBJ_NULL) == 0) {
if(pObj->iFlags & MEMOBJ_HASHMAP) { if(pObj->iFlags & MEMOBJ_HASHMAP) {
PH7_HashmapUnref((ph7_hashmap *)pObj->x.pOther); PH7_HashmapUnref((ph7_hashmap *)pObj->x.pOther);
@ -974,8 +942,7 @@ PH7_PRIVATE sxi32 PH7_MemObjRelease(ph7_value *pObj)
* "php" FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE * "php" FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE
* "" FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE * "" FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
*/ */
PH7_PRIVATE sxi32 PH7_MemObjCmp(ph7_value *pObj1,ph7_value *pObj2,int bStrict,int iNest) PH7_PRIVATE sxi32 PH7_MemObjCmp(ph7_value *pObj1, ph7_value *pObj2, int bStrict, int iNest) {
{
sxi32 iComb; sxi32 iComb;
sxi32 rc; sxi32 rc;
if(bStrict) { if(bStrict) {
@ -1119,8 +1086,7 @@ Numeric:
* be ignored. * be ignored.
* 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->iFlags | pObj2->iFlags) & MEMOBJ_HASHMAP) == 0) {
/* Arithemtic operation */ /* Arithemtic operation */
PH7_MemObjToNumeric(pObj1); PH7_MemObjToNumeric(pObj1);
@ -1207,8 +1173,7 @@ PH7_PRIVATE sxi32 PH7_MemObjAdd(ph7_value *pObj1,ph7_value *pObj2,int bAddStore)
* Return a printable representation of the type of a given * Return a printable representation of the type of a given
* ph7_value. * ph7_value.
*/ */
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->iFlags & MEMOBJ_NULL) {
zType = "null"; zType = "null";
@ -1240,8 +1205,7 @@ PH7_PRIVATE sxi32 PH7_MemObjDump(
int nTab, /* # of Whitespace to insert */ int nTab, /* # of Whitespace to insert */
int nDepth, /* Nesting level */ int nDepth, /* Nesting level */
int isRef /* TRUE if referenced object */ int isRef /* TRUE if referenced object */
) ) {
{
sxi32 rc = SXRET_OK; sxi32 rc = SXRET_OK;
const char *zType; const char *zType;
int i; int i;

70
oop.c
View File

@ -19,8 +19,7 @@
* Create an empty class. * Create an empty class.
* Return a pointer to a raw class (ph7_class instance) on success. NULL otherwise. * Return a pointer to a raw class (ph7_class instance) on success. NULL otherwise.
*/ */
PH7_PRIVATE ph7_class * PH7_NewRawClass(ph7_vm *pVm,const SyString *pName,sxu32 nLine) PH7_PRIVATE ph7_class *PH7_NewRawClass(ph7_vm *pVm, const SyString *pName, sxu32 nLine) {
{
ph7_class *pClass; ph7_class *pClass;
char *zName; char *zName;
/* Allocate a new instance */ /* Allocate a new instance */
@ -50,8 +49,7 @@ PH7_PRIVATE ph7_class * PH7_NewRawClass(ph7_vm *pVm,const SyString *pName,sxu32
* Allocate and initialize a new class attribute. * Allocate and initialize a new class attribute.
* Return a pointer to the class attribute on success. NULL otherwise. * Return a pointer to the class attribute on success. NULL otherwise.
*/ */
PH7_PRIVATE ph7_class_attr * PH7_NewClassAttr(ph7_vm *pVm,const SyString *pName,sxu32 nLine,sxi32 iProtection,sxi32 iFlags) PH7_PRIVATE ph7_class_attr *PH7_NewClassAttr(ph7_vm *pVm, const SyString *pName, sxu32 nLine, sxi32 iProtection, sxi32 iFlags) {
{
ph7_class_attr *pAttr; ph7_class_attr *pAttr;
char *zName; char *zName;
pAttr = (ph7_class_attr *)SyMemBackendPoolAlloc(&pVm->sAllocator, sizeof(ph7_class_attr)); pAttr = (ph7_class_attr *)SyMemBackendPoolAlloc(&pVm->sAllocator, sizeof(ph7_class_attr));
@ -82,8 +80,7 @@ PH7_PRIVATE ph7_class_attr * PH7_NewClassAttr(ph7_vm *pVm,const SyString *pName,
* random unique name. * random unique name.
*/ */
PH7_PRIVATE ph7_class_method *PH7_NewClassMethod(ph7_vm *pVm, ph7_class *pClass, const SyString *pName, sxu32 nLine, PH7_PRIVATE ph7_class_method *PH7_NewClassMethod(ph7_vm *pVm, ph7_class *pClass, const SyString *pName, sxu32 nLine,
sxi32 iProtection,sxi32 iFlags,sxi32 iFuncFlags) sxi32 iProtection, sxi32 iFlags, sxi32 iFuncFlags) {
{
ph7_class_method *pMeth; ph7_class_method *pMeth;
SyHashEntry *pEntry; SyHashEntry *pEntry;
SyString *pNamePtr; SyString *pNamePtr;
@ -140,8 +137,7 @@ PH7_PRIVATE ph7_class_method * PH7_NewClassMethod(ph7_vm *pVm,ph7_class *pClass,
* Check if the given name have a class method associated with it. * Check if the given name have a class method associated with it.
* Return the desired method [i.e: ph7_class_method instance] on success. NULL otherwise. * Return the desired method [i.e: ph7_class_method instance] on success. NULL otherwise.
*/ */
PH7_PRIVATE ph7_class_method * PH7_ClassExtractMethod(ph7_class *pClass,const char *zName,sxu32 nByte) PH7_PRIVATE ph7_class_method *PH7_ClassExtractMethod(ph7_class *pClass, const char *zName, sxu32 nByte) {
{
SyHashEntry *pEntry; SyHashEntry *pEntry;
/* Perform a hash lookup */ /* Perform a hash lookup */
pEntry = SyHashGet(&pClass->hMethod, (const void *)zName, nByte); pEntry = SyHashGet(&pClass->hMethod, (const void *)zName, nByte);
@ -156,8 +152,7 @@ PH7_PRIVATE ph7_class_method * PH7_ClassExtractMethod(ph7_class *pClass,const ch
* Check if the given name is a class attribute. * Check if the given name is a class attribute.
* Return the desired attribute [i.e: ph7_class_attr instance] on success.NULL otherwise. * Return the desired attribute [i.e: ph7_class_attr instance] on success.NULL otherwise.
*/ */
PH7_PRIVATE ph7_class_attr * PH7_ClassExtractAttribute(ph7_class *pClass,const char *zName,sxu32 nByte) PH7_PRIVATE ph7_class_attr *PH7_ClassExtractAttribute(ph7_class *pClass, const char *zName, sxu32 nByte) {
{
SyHashEntry *pEntry; SyHashEntry *pEntry;
/* Perform a hash lookup */ /* Perform a hash lookup */
pEntry = SyHashGet(&pClass->hAttr, (const void *)zName, nByte); pEntry = SyHashGet(&pClass->hAttr, (const void *)zName, nByte);
@ -172,8 +167,7 @@ PH7_PRIVATE ph7_class_attr * PH7_ClassExtractAttribute(ph7_class *pClass,const c
* Install a class attribute in the corresponding container. * Install a class attribute in the corresponding container.
* Return SXRET_OK on success. Any other return value indicates failure. * Return SXRET_OK on success. Any other return value indicates failure.
*/ */
PH7_PRIVATE sxi32 PH7_ClassInstallAttr(ph7_class *pClass,ph7_class_attr *pAttr) PH7_PRIVATE sxi32 PH7_ClassInstallAttr(ph7_class *pClass, ph7_class_attr *pAttr) {
{
SyString *pName = &pAttr->sName; SyString *pName = &pAttr->sName;
sxi32 rc; sxi32 rc;
rc = SyHashInsert(&pClass->hAttr, (const void *)pName->zString, pName->nByte, pAttr); rc = SyHashInsert(&pClass->hAttr, (const void *)pName->zString, pName->nByte, pAttr);
@ -183,8 +177,7 @@ PH7_PRIVATE sxi32 PH7_ClassInstallAttr(ph7_class *pClass,ph7_class_attr *pAttr)
* Install a class method in the corresponding container. * Install a class method in the corresponding container.
* Return SXRET_OK on success. Any other return value indicates failure. * Return SXRET_OK on success. Any other return value indicates failure.
*/ */
PH7_PRIVATE sxi32 PH7_ClassInstallMethod(ph7_class *pClass,ph7_class_method *pMeth) PH7_PRIVATE sxi32 PH7_ClassInstallMethod(ph7_class *pClass, ph7_class_method *pMeth) {
{
SyString *pName = &pMeth->sFunc.sName; SyString *pName = &pMeth->sFunc.sName;
sxi32 rc; sxi32 rc;
rc = SyHashInsert(&pClass->hMethod, (const void *)pName->zString, pName->nByte, pMeth); rc = SyHashInsert(&pClass->hMethod, (const void *)pName->zString, pName->nByte, pMeth);
@ -231,8 +224,7 @@ PH7_PRIVATE sxi32 PH7_ClassInstallMethod(ph7_class *pClass,ph7_class_method *pMe
* Any other return value indicates failure and the upper layer must generate an appropriate * Any other return value indicates failure and the upper layer must generate an appropriate
* error message. * error message.
*/ */
PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_gen_state *pGen,ph7_class *pSub,ph7_class *pBase) PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_gen_state *pGen, ph7_class *pSub, ph7_class *pBase) {
{
ph7_class_method *pMeth; ph7_class_method *pMeth;
ph7_class_attr *pAttr; ph7_class_attr *pAttr;
SyHashEntry *pEntry; SyHashEntry *pEntry;
@ -256,7 +248,6 @@ PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_gen_state *pGen,ph7_class *pSub,ph7_class
PH7_GenCompileError(&(*pGen), E_WARNING, ((ph7_class_attr *)pEntry->pUserData)->nLine, PH7_GenCompileError(&(*pGen), E_WARNING, ((ph7_class_attr *)pEntry->pUserData)->nLine,
"Private attribute '%z::%z' redeclared inside child class '%z'", "Private attribute '%z::%z' redeclared inside child class '%z'",
&pBase->sName, pName, &pSub->sName); &pBase->sName, pName, &pSub->sName);
} }
continue; continue;
} }
@ -319,8 +310,7 @@ PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_gen_state *pGen,ph7_class *pSub,ph7_class
* Any other return value indicates failure and the upper layer must generate an appropriate * Any other return value indicates failure and the upper layer must generate an appropriate
* error message. * error message.
*/ */
PH7_PRIVATE sxi32 PH7_ClassInterfaceInherit(ph7_class *pSub,ph7_class *pBase) PH7_PRIVATE sxi32 PH7_ClassInterfaceInherit(ph7_class *pSub, ph7_class *pBase) {
{
ph7_class_method *pMeth; ph7_class_method *pMeth;
ph7_class_attr *pAttr; ph7_class_attr *pAttr;
SyHashEntry *pEntry; SyHashEntry *pEntry;
@ -374,8 +364,7 @@ PH7_PRIVATE sxi32 PH7_ClassInterfaceInherit(ph7_class *pSub,ph7_class *pBase)
* Any other return value indicates failure and the upper layer must generate an appropriate * Any other return value indicates failure and the upper layer must generate an appropriate
* error message. * error message.
*/ */
PH7_PRIVATE sxi32 PH7_ClassImplement(ph7_class *pMain,ph7_class *pInterface) PH7_PRIVATE sxi32 PH7_ClassImplement(ph7_class *pMain, ph7_class *pInterface) {
{
ph7_class_attr *pAttr; ph7_class_attr *pAttr;
SyHashEntry *pEntry; SyHashEntry *pEntry;
SyString *pName; SyString *pName;
@ -482,8 +471,7 @@ PH7_PRIVATE sxi32 PH7_ClassImplement(ph7_class *pMain,ph7_class *pInterface)
* }; * };
* Refer to the official documentation for more information. * Refer to the official documentation for more information.
*/ */
static ph7_class_instance * NewClassInstance(ph7_vm *pVm,ph7_class *pClass) static ph7_class_instance *NewClassInstance(ph7_vm *pVm, ph7_class *pClass) {
{
ph7_class_instance *pThis; ph7_class_instance *pThis;
/* Allocate a new instance */ /* Allocate a new instance */
pThis = (ph7_class_instance *)SyMemBackendPoolAlloc(&pVm->sAllocator, sizeof(ph7_class_instance)); pThis = (ph7_class_instance *)SyMemBackendPoolAlloc(&pVm->sAllocator, sizeof(ph7_class_instance));
@ -503,8 +491,7 @@ static ph7_class_instance * NewClassInstance(ph7_vm *pVm,ph7_class *pClass)
* Wrapper around the NewClassInstance() function defined above. * Wrapper around the NewClassInstance() function defined above.
* See the block comment above for more information. * See the block comment above for more information.
*/ */
PH7_PRIVATE ph7_class_instance * PH7_NewClassInstance(ph7_vm *pVm,ph7_class *pClass) PH7_PRIVATE ph7_class_instance *PH7_NewClassInstance(ph7_vm *pVm, ph7_class *pClass) {
{
ph7_class_instance *pNew; ph7_class_instance *pNew;
sxi32 rc; sxi32 rc;
pNew = NewClassInstance(&(*pVm), &(*pClass)); pNew = NewClassInstance(&(*pVm), &(*pClass));
@ -523,8 +510,7 @@ PH7_PRIVATE ph7_class_instance * PH7_NewClassInstance(ph7_vm *pVm,ph7_class *pCl
* Extract the value of a class instance [i.e: Object in the PHP jargon] attribute. * Extract the value of a class instance [i.e: Object in the PHP jargon] attribute.
* This function never fail. * This function never fail.
*/ */
static ph7_value * ExtractClassAttrValue(ph7_vm *pVm,VmClassAttr *pAttr) static ph7_value *ExtractClassAttrValue(ph7_vm *pVm, VmClassAttr *pAttr) {
{
/* Extract the value */ /* Extract the value */
ph7_value *pValue; ph7_value *pValue;
pValue = (ph7_value *)SySetAt(&pVm->aMemObj, pAttr->nIdx); pValue = (ph7_value *)SySetAt(&pVm->aMemObj, pAttr->nIdx);
@ -614,8 +600,7 @@ static ph7_value * ExtractClassAttrValue(ph7_vm *pVm,VmClassAttr *pAttr)
* ) * )
* ) * )
*/ */
PH7_PRIVATE ph7_class_instance * PH7_CloneClassInstance(ph7_class_instance *pSrc) PH7_PRIVATE ph7_class_instance *PH7_CloneClassInstance(ph7_class_instance *pSrc) {
{
ph7_class_instance *pClone; ph7_class_instance *pClone;
ph7_class_method *pMethod; ph7_class_method *pMethod;
SyHashEntry *pEntry2; SyHashEntry *pEntry2;
@ -672,8 +657,7 @@ PH7_PRIVATE ph7_class_instance * PH7_CloneClassInstance(ph7_class_instance *pSrc
* This routine is invoked as soon as there are no other references to a particular * This routine is invoked as soon as there are no other references to a particular
* class instance. * class instance.
*/ */
static void PH7_ClassInstanceRelease(ph7_class_instance *pThis) static void PH7_ClassInstanceRelease(ph7_class_instance *pThis) {
{
ph7_class_method *pDestr; ph7_class_method *pDestr;
SyHashEntry *pEntry; SyHashEntry *pEntry;
ph7_class *pClass; ph7_class *pClass;
@ -713,8 +697,7 @@ static void PH7_ClassInstanceRelease(ph7_class_instance *pThis)
* Decrement the reference count of a class instance [i.e Object in the PHP jargon]. * Decrement the reference count of a class instance [i.e Object in the PHP jargon].
* If the reference count reaches zero,release the whole instance. * If the reference count reaches zero,release the whole instance.
*/ */
PH7_PRIVATE void PH7_ClassInstanceUnref(ph7_class_instance *pThis) PH7_PRIVATE void PH7_ClassInstanceUnref(ph7_class_instance *pThis) {
{
pThis->iRef--; pThis->iRef--;
if(pThis->iRef < 1) { if(pThis->iRef < 1) {
/* No more reference to this instance */ /* No more reference to this instance */
@ -798,8 +781,7 @@ PH7_PRIVATE void PH7_ClassInstanceUnref(ph7_class_instance *pThis)
* This function return 0 if the objects are equals according to the comprison rules defined above. * This function return 0 if the objects are equals according to the comprison rules defined above.
* Any other return values indicates difference. * Any other return values indicates difference.
*/ */
PH7_PRIVATE sxi32 PH7_ClassInstanceCmp(ph7_class_instance *pLeft,ph7_class_instance *pRight,int bStrict,int iNest) PH7_PRIVATE sxi32 PH7_ClassInstanceCmp(ph7_class_instance *pLeft, ph7_class_instance *pRight, int bStrict, int iNest) {
{
SyHashEntry *pEntry, *pEntry2; SyHashEntry *pEntry, *pEntry2;
ph7_value sV1, sV2; ph7_value sV1, sV2;
sxi32 rc; sxi32 rc;
@ -871,8 +853,7 @@ PH7_PRIVATE sxi32 PH7_ClassInstanceCmp(ph7_class_instance *pLeft,ph7_class_insta
* This function SXRET_OK on success. Any other return value including * This function SXRET_OK on success. Any other return value including
* SXERR_LIMIT(infinite recursion) indicates failure. * SXERR_LIMIT(infinite recursion) indicates failure.
*/ */
PH7_PRIVATE sxi32 PH7_ClassInstanceDump(SyBlob *pOut,ph7_class_instance *pThis,int ShowType,int nTab,int nDepth) PH7_PRIVATE sxi32 PH7_ClassInstanceDump(SyBlob *pOut, ph7_class_instance *pThis, int ShowType, int nTab, int nDepth) {
{
SyHashEntry *pEntry; SyHashEntry *pEntry;
ph7_value *pValue; ph7_value *pValue;
sxi32 rc; sxi32 rc;
@ -975,8 +956,7 @@ PH7_PRIVATE sxi32 PH7_ClassInstanceCallMagicMethod(
const char *zMethod, /* Magic method name [i.e: __toString()]*/ const char *zMethod, /* Magic method name [i.e: __toString()]*/
sxu32 nByte, /* zMethod length*/ sxu32 nByte, /* zMethod length*/
const SyString *pAttrName /* Attribute name */ const SyString *pAttrName /* Attribute name */
) ) {
{
ph7_value *apArg[2] = { 0, 0 }; ph7_value *apArg[2] = { 0, 0 };
ph7_class_method *pMeth; ph7_class_method *pMeth;
ph7_value sAttr; /* cc warning */ ph7_value sAttr; /* cc warning */
@ -1008,8 +988,7 @@ PH7_PRIVATE sxi32 PH7_ClassInstanceCallMagicMethod(
* Extract the value of a class instance [i.e: Object in the PHP jargon]. * Extract the value of a class instance [i.e: Object in the PHP jargon].
* This function is simply a wrapper on ExtractClassAttrValue(). * This function is simply a wrapper on ExtractClassAttrValue().
*/ */
PH7_PRIVATE ph7_value * PH7_ClassInstanceExtractAttrValue(ph7_class_instance *pThis,VmClassAttr *pAttr) PH7_PRIVATE ph7_value *PH7_ClassInstanceExtractAttrValue(ph7_class_instance *pThis, VmClassAttr *pAttr) {
{
/* Extract the attribute value */ /* Extract the attribute value */
ph7_value *pValue; ph7_value *pValue;
pValue = ExtractClassAttrValue(pThis->pVm, pAttr); pValue = ExtractClassAttrValue(pThis->pVm, pAttr);
@ -1044,8 +1023,7 @@ PH7_PRIVATE ph7_value * PH7_ClassInstanceExtractAttrValue(ph7_class_instance *pT
* value unlike the standard PHP engine. * value unlike the standard PHP engine.
* This is a very powerful feature that you have to look at. * This is a very powerful feature that you have to look at.
*/ */
PH7_PRIVATE sxi32 PH7_ClassInstanceToHashmap(ph7_class_instance *pThis,ph7_hashmap *pMap) PH7_PRIVATE sxi32 PH7_ClassInstanceToHashmap(ph7_class_instance *pThis, ph7_hashmap *pMap) {
{
SyHashEntry *pEntry; SyHashEntry *pEntry;
SyString *pAttrName; SyString *pAttrName;
VmClassAttr *pAttr; VmClassAttr *pAttr;
@ -1085,8 +1063,7 @@ PH7_PRIVATE sxi32 PH7_ClassInstanceWalk(
ph7_class_instance *pThis, /* Target object */ ph7_class_instance *pThis, /* Target object */
int (*xWalk)(const char *, ph7_value *, void *), /* Walker callback */ int (*xWalk)(const char *, ph7_value *, void *), /* Walker callback */
void *pUserData /* Last argument to xWalk() */ void *pUserData /* Last argument to xWalk() */
) ) {
{
SyHashEntry *pEntry; /* Hash entry */ SyHashEntry *pEntry; /* Hash entry */
VmClassAttr *pAttr; /* Pointer to the attribute */ VmClassAttr *pAttr; /* Pointer to the attribute */
ph7_value *pValue; /* Attribute value */ ph7_value *pValue; /* Attribute value */
@ -1123,8 +1100,7 @@ PH7_PRIVATE sxi32 PH7_ClassInstanceWalk(
* will return NULL in case someone (host-application code) try to extract * will return NULL in case someone (host-application code) try to extract
* a static/constant attribute. * a static/constant attribute.
*/ */
PH7_PRIVATE ph7_value * PH7_ClassInstanceFetchAttr(ph7_class_instance *pThis,const SyString *pName) PH7_PRIVATE ph7_value *PH7_ClassInstanceFetchAttr(ph7_class_instance *pThis, const SyString *pName) {
{
SyHashEntry *pEntry; SyHashEntry *pEntry;
VmClassAttr *pAttr; VmClassAttr *pAttr;
/* Query the attribute hashtable */ /* Query the attribute hashtable */

View File

@ -259,8 +259,7 @@ static const ph7_expr_op sFCallOp = {{"(",sizeof(char)}, EXPR_OP_FUNC_CALL, 2, E
* Note that the function take care of handling ambiguity [i.e: whether we are dealing with * Note that the function take care of handling ambiguity [i.e: whether we are dealing with
* a binary minus or unary minus.] * a binary minus or unary minus.]
*/ */
PH7_PRIVATE const ph7_expr_op * PH7_ExprExtractOperator(SyString *pStr,SyToken *pLast) PH7_PRIVATE const ph7_expr_op *PH7_ExprExtractOperator(SyString *pStr, SyToken *pLast) {
{
sxu32 n = 0; sxu32 n = 0;
sxi32 rc; sxi32 rc;
/* Do a linear lookup on the operators table */ /* Do a linear lookup on the operators table */
@ -291,7 +290,6 @@ PH7_PRIVATE const ph7_expr_op * PH7_ExprExtractOperator(SyString *pStr,SyToken
/* Unary opertors have prcedence here over binary operators */ /* Unary opertors have prcedence here over binary operators */
return &aOpTable[n]; return &aOpTable[n];
} }
} }
} }
++n; /* Next operator in the table */ ++n; /* Next operator in the table */
@ -304,8 +302,7 @@ PH7_PRIVATE const ph7_expr_op * PH7_ExprExtractOperator(SyString *pStr,SyToken
* This function take care of handling the nesting level and stops when it hit * This function take care of handling the nesting level and stops when it hit
* the end of the input or the ending token is found and the nesting level is zero. * the end of the input or the ending token is found and the nesting level is zero.
*/ */
PH7_PRIVATE void PH7_DelimitNestedTokens(SyToken *pIn,SyToken *pEnd,sxu32 nTokStart,sxu32 nTokEnd,SyToken **ppEnd) PH7_PRIVATE void PH7_DelimitNestedTokens(SyToken *pIn, SyToken *pEnd, sxu32 nTokStart, sxu32 nTokEnd, SyToken **ppEnd) {
{
SyToken *pCur = pIn; SyToken *pCur = pIn;
sxi32 iNest = 1; sxi32 iNest = 1;
for(;;) { for(;;) {
@ -337,8 +334,7 @@ PH7_PRIVATE void PH7_DelimitNestedTokens(SyToken *pIn,SyToken *pEnd,sxu32 nTokSt
* constructs. You cannot use any of the following words as constants, class names, function * constructs. You cannot use any of the following words as constants, class names, function
* or method names. Using them as variable names is generally OK, but could lead to confusion. * or method names. Using them as variable names is generally OK, but could lead to confusion.
*/ */
PH7_PRIVATE int PH7_IsLangConstruct(sxu32 nKeyID,sxu8 bCheckFunc) PH7_PRIVATE int PH7_IsLangConstruct(sxu32 nKeyID, sxu8 bCheckFunc) {
{
if(nKeyID == PH7_TKWRD_ECHO || nKeyID == PH7_TKWRD_PRINT || nKeyID == PH7_TKWRD_INCLUDE if(nKeyID == PH7_TKWRD_ECHO || nKeyID == PH7_TKWRD_PRINT || nKeyID == PH7_TKWRD_INCLUDE
|| nKeyID == PH7_TKWRD_INCONCE || nKeyID == PH7_TKWRD_REQUIRE || nKeyID == PH7_TKWRD_REQONCE || nKeyID == PH7_TKWRD_INCONCE || nKeyID == PH7_TKWRD_REQUIRE || nKeyID == PH7_TKWRD_REQONCE
) { ) {
@ -360,11 +356,9 @@ PH7_PRIVATE int PH7_IsLangConstruct(sxu32 nKeyID,sxu8 bCheckFunc)
* When errors,PH7 take care of generating the appropriate error message. * When errors,PH7 take care of generating the appropriate error message.
* Return SXRET_OK on success. Any other return value indicates syntax error. * Return SXRET_OK on success. Any other return value indicates syntax error.
*/ */
static sxi32 ExprVerifyNodes(ph7_gen_state *pGen,ph7_expr_node **apNode,sxi32 nNode) static sxi32 ExprVerifyNodes(ph7_gen_state *pGen, ph7_expr_node **apNode, sxi32 nNode) {
{
sxi32 iParen, iSquare, iQuesty, iBraces; sxi32 iParen, iSquare, iQuesty, iBraces;
sxi32 i, rc; sxi32 i, rc;
if(nNode > 0 && apNode[0]->pOp && (apNode[0]->pOp->iOp == EXPR_OP_ADD || apNode[0]->pOp->iOp == EXPR_OP_SUB)) { if(nNode > 0 && apNode[0]->pOp && (apNode[0]->pOp->iOp == EXPR_OP_ADD || apNode[0]->pOp->iOp == EXPR_OP_SUB)) {
/* Fix and mark as an unary not binary plus/minus operator */ /* Fix and mark as an unary not binary plus/minus operator */
apNode[0]->pOp = PH7_ExprExtractOperator(&apNode[0]->pStart->sData, 0); apNode[0]->pOp = PH7_ExprExtractOperator(&apNode[0]->pStart->sData, 0);
@ -451,7 +445,6 @@ static sxi32 ExprVerifyNodes(ph7_gen_state *pGen,ph7_expr_node **apNode,sxi32 nN
apNode[j]->pStart->nType &= ~PH7_TK_CCB /*'}'*/; apNode[j]->pStart->nType &= ~PH7_TK_CCB /*'}'*/;
apNode[j]->pStart->nType |= PH7_TK_CSB /*']'*/; apNode[j]->pStart->nType |= PH7_TK_CSB /*']'*/;
} }
} }
} else if(apNode[i]->pStart->nType & PH7_TK_CCB /*'}'*/) { } else if(apNode[i]->pStart->nType & PH7_TK_CCB /*'}'*/) {
if(iBraces <= 0) { if(iBraces <= 0) {
@ -510,8 +503,7 @@ static sxi32 ExprVerifyNodes(ph7_gen_state *pGen,ph7_expr_node **apNode,sxi32 nN
* Collect and assemble tokens holding a namespace path [i.e: namespace\to\const] * Collect and assemble tokens holding a namespace path [i.e: namespace\to\const]
* or a simple literal [i.e: PHP_EOL]. * or a simple literal [i.e: PHP_EOL].
*/ */
static void ExprAssembleLiteral(SyToken **ppCur,SyToken *pEnd) static void ExprAssembleLiteral(SyToken **ppCur, SyToken *pEnd) {
{
SyToken *pIn = *ppCur; SyToken *pIn = *ppCur;
/* Jump the first literal seen */ /* Jump the first literal seen */
if((pIn->nType & PH7_TK_NSSEP) == 0) { if((pIn->nType & PH7_TK_NSSEP) == 0) {
@ -563,8 +555,7 @@ static void ExprAssembleLiteral(SyToken **ppCur,SyToken *pEnd)
* $new_numbers = array_map($double, $numbers); * $new_numbers = array_map($double, $numbers);
* print implode(' ', $new_numbers); * print implode(' ', $new_numbers);
*/ */
static sxi32 ExprAssembleAnnon(ph7_gen_state *pGen,SyToken **ppCur,SyToken *pEnd) static sxi32 ExprAssembleAnnon(ph7_gen_state *pGen, SyToken **ppCur, SyToken *pEnd) {
{
SyToken *pIn = *ppCur; SyToken *pIn = *ppCur;
sxu32 nLine; sxu32 nLine;
sxi32 rc; sxi32 rc;
@ -654,8 +645,7 @@ Synchronize:
* quoted string, a literal [i.e: PHP_EOL],a namespace path * quoted string, a literal [i.e: PHP_EOL],a namespace path
* [i.e: namespaces\path\to..],a array/list [i.e: array(4,5,6)] and so on. * [i.e: namespaces\path\to..],a array/list [i.e: array(4,5,6)] and so on.
*/ */
static sxi32 ExprExtractNode(ph7_gen_state *pGen,ph7_expr_node **ppNode) static sxi32 ExprExtractNode(ph7_gen_state *pGen, ph7_expr_node **ppNode) {
{
ph7_expr_node *pNode; ph7_expr_node *pNode;
SyToken *pCur; SyToken *pCur;
sxi32 rc; sxi32 rc;
@ -799,8 +789,7 @@ static sxi32 ExprExtractNode(ph7_gen_state *pGen,ph7_expr_node **ppNode)
* The cursor stops when it hit a comma ',' or a semi-colon and the nesting * The cursor stops when it hit a comma ',' or a semi-colon and the nesting
* level is zero. * level is zero.
*/ */
PH7_PRIVATE sxi32 PH7_GetNextExpr(SyToken *pStart,SyToken *pEnd,SyToken **ppNext) PH7_PRIVATE sxi32 PH7_GetNextExpr(SyToken *pStart, SyToken *pEnd, SyToken **ppNext) {
{
SyToken *pCur = pStart; SyToken *pCur = pStart;
sxi32 iNest = 0; sxi32 iNest = 0;
if(pCur >= pEnd || (pCur->nType & PH7_TK_SEMI/*';'*/)) { if(pCur >= pEnd || (pCur->nType & PH7_TK_SEMI/*';'*/)) {
@ -824,8 +813,7 @@ PH7_PRIVATE sxi32 PH7_GetNextExpr(SyToken *pStart,SyToken *pEnd,SyToken **ppNext
/* /*
* Free an expression tree. * Free an expression tree.
*/ */
static void ExprFreeTree(ph7_gen_state *pGen,ph7_expr_node *pNode) static void ExprFreeTree(ph7_gen_state *pGen, ph7_expr_node *pNode) {
{
if(pNode->pLeft) { if(pNode->pLeft) {
/* Release the left tree */ /* Release the left tree */
ExprFreeTree(&(*pGen), pNode->pLeft); ExprFreeTree(&(*pGen), pNode->pLeft);
@ -855,8 +843,7 @@ static void ExprFreeTree(ph7_gen_state *pGen,ph7_expr_node *pNode)
* Free an expression tree. * Free an expression tree.
* This function is a wrapper around ExprFreeTree() defined above. * This function is a wrapper around ExprFreeTree() defined above.
*/ */
PH7_PRIVATE sxi32 PH7_ExprFreeTree(ph7_gen_state *pGen,SySet *pNodeSet) PH7_PRIVATE sxi32 PH7_ExprFreeTree(ph7_gen_state *pGen, SySet *pNodeSet) {
{
ph7_expr_node **apNode; ph7_expr_node **apNode;
sxu32 n; sxu32 n;
apNode = (ph7_expr_node **)SySetBasePtr(pNodeSet); apNode = (ph7_expr_node **)SySetBasePtr(pNodeSet);
@ -871,8 +858,7 @@ PH7_PRIVATE sxi32 PH7_ExprFreeTree(ph7_gen_state *pGen,SySet *pNodeSet)
* Check if the given node is a modifialbe l/r-value. * Check if the given node is a modifialbe l/r-value.
* Return TRUE if modifiable.FALSE otherwise. * Return TRUE if modifiable.FALSE otherwise.
*/ */
static int ExprIsModifiableValue(ph7_expr_node *pNode,sxu8 bFunc) static int ExprIsModifiableValue(ph7_expr_node *pNode, sxu8 bFunc) {
{
sxi32 iExprOp; sxi32 iExprOp;
if(pNode->pOp == 0) { if(pNode->pOp == 0) {
return pNode->xCode == PH7_CompileVariable ? TRUE : FALSE; return pNode->xCode == PH7_CompileVariable ? TRUE : FALSE;
@ -906,8 +892,7 @@ static sxi32 ExprMakeTree(ph7_gen_state *pGen,ph7_expr_node **apNode,sxi32 nToke
* Buid an expression tree for each given function argument. * Buid an expression tree for each given function argument.
* When errors,PH7 take care of generating the appropriate error message. * When errors,PH7 take care of generating the appropriate error message.
*/ */
static sxi32 ExprProcessFuncArguments(ph7_gen_state *pGen,ph7_expr_node *pOp,ph7_expr_node **apNode,sxi32 nToken) static sxi32 ExprProcessFuncArguments(ph7_gen_state *pGen, ph7_expr_node *pOp, ph7_expr_node **apNode, sxi32 nToken) {
{
sxi32 iNest, iCur, iNode; sxi32 iNest, iCur, iNode;
sxi32 rc; sxi32 rc;
/* Process function arguments from left to right */ /* Process function arguments from left to right */
@ -978,8 +963,7 @@ static sxi32 ExprProcessFuncArguments(ph7_gen_state *pGen,ph7_expr_node *pOp,ph7
* If successful, the root of the tree is stored in apNode[0]. * If successful, the root of the tree is stored in apNode[0].
* When errors,PH7 take care of generating the appropriate error message. * When errors,PH7 take care of generating the appropriate error message.
*/ */
static sxi32 ExprMakeTree(ph7_gen_state *pGen,ph7_expr_node **apNode,sxi32 nToken) static sxi32 ExprMakeTree(ph7_gen_state *pGen, ph7_expr_node **apNode, sxi32 nToken) {
{
sxi32 i, iLeft, iRight; sxi32 i, iLeft, iRight;
ph7_expr_node *pNode; ph7_expr_node *pNode;
sxi32 iCur; sxi32 iCur;
@ -1573,8 +1557,7 @@ static sxi32 ExprProcessFuncArguments(ph7_gen_state *pGen,ph7_expr_node *pOp,ph7
* When errors,PH7 take care of generating the appropriate error message. * When errors,PH7 take care of generating the appropriate error message.
* This is the public interface used by the most code generator routines. * This is the public interface used by the most code generator routines.
*/ */
PH7_PRIVATE sxi32 PH7_ExprMakeTree(ph7_gen_state *pGen,SySet *pExprNode,ph7_expr_node **ppRoot) PH7_PRIVATE sxi32 PH7_ExprMakeTree(ph7_gen_state *pGen, SySet *pExprNode, ph7_expr_node **ppRoot) {
{
ph7_expr_node **apNode; ph7_expr_node **apNode;
ph7_expr_node *pNode; ph7_expr_node *pNode;
sxi32 rc; sxi32 rc;

28
ph7.h
View File

@ -95,10 +95,6 @@
* contact@symisc.net * contact@symisc.net
*/ */
#define PH7_COPYRIGHT "Copyright (C) Symisc Systems 2011-2012, http://ph7.symisc.net/" #define PH7_COPYRIGHT "Copyright (C) Symisc Systems 2011-2012, http://ph7.symisc.net/"
/* Make sure we can call this stuff from C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* Forward declaration to public objects */ /* Forward declaration to public objects */
typedef struct ph7_io_stream ph7_io_stream; typedef struct ph7_io_stream ph7_io_stream;
typedef struct ph7_context ph7_context; typedef struct ph7_context ph7_context;
@ -207,8 +203,7 @@ typedef struct syiovec syiovec;
typedef struct SyMutex SyMutex; typedef struct SyMutex SyMutex;
typedef struct Sytm Sytm; typedef struct Sytm Sytm;
/* Scatter and gather array. */ /* Scatter and gather array. */
struct syiovec struct syiovec {
{
#if defined (__WINNT__) #if defined (__WINNT__)
/* Same fields type and offset as WSABUF structure defined one winsock2 header */ /* Same fields type and offset as WSABUF structure defined one winsock2 header */
unsigned long nLen; unsigned long nLen;
@ -218,14 +213,12 @@ struct syiovec
unsigned long nLen; unsigned long nLen;
#endif #endif
}; };
struct SyString struct SyString {
{
const char *zString; /* Raw string (may not be null terminated) */ const char *zString; /* Raw string (may not be null terminated) */
unsigned int nByte; /* Raw string length */ unsigned int nByte; /* Raw string length */
}; };
/* Time structure. */ /* Time structure. */
struct Sytm struct Sytm {
{
int tm_sec; /* seconds (0 - 60) */ int tm_sec; /* seconds (0 - 60) */
int tm_min; /* minutes (0 - 59) */ int tm_min; /* minutes (0 - 59) */
int tm_hour; /* hours (0 - 23) */ int tm_hour; /* hours (0 - 23) */
@ -267,8 +260,7 @@ struct Sytm
(pSYTM)->tm_zone = 0; (pSYTM)->tm_zone = 0;
/* Dynamic memory allocation methods. */ /* Dynamic memory allocation methods. */
struct SyMemMethods struct SyMemMethods {
{
void *(*xAlloc)(unsigned int); /* [Required:] Allocate a memory chunk */ void *(*xAlloc)(unsigned int); /* [Required:] Allocate a memory chunk */
void *(*xRealloc)(void *, unsigned int); /* [Required:] Re-allocate a memory chunk */ void *(*xRealloc)(void *, unsigned int); /* [Required:] Re-allocate a memory chunk */
void (*xFree)(void *); /* [Required:] Release a memory chunk */ void (*xFree)(void *); /* [Required:] Release a memory chunk */
@ -280,8 +272,7 @@ struct SyMemMethods
/* Out of memory callback signature. */ /* Out of memory callback signature. */
typedef int (*ProcMemError)(void *); typedef int (*ProcMemError)(void *);
/* Mutex methods. */ /* Mutex methods. */
struct SyMutexMethods struct SyMutexMethods {
{
int (*xGlobalInit)(void); /* [Optional:] Global mutex initialization */ int (*xGlobalInit)(void); /* [Optional:] Global mutex initialization */
void (*xGlobalRelease)(void); /* [Optional:] Global Release callback () */ void (*xGlobalRelease)(void); /* [Optional:] Global Release callback () */
SyMutex *(*xNew)(int); /* [Required:] Request a new mutex */ SyMutex *(*xNew)(int); /* [Required:] Request a new mutex */
@ -492,8 +483,7 @@ typedef sxi64 ph7_int64;
* Developers wishing to implement the vfs methods can contact symisc systems to obtain * Developers wishing to implement the vfs methods can contact symisc systems to obtain
* the PH7 VFS C/C++ Specification manual. * the PH7 VFS C/C++ Specification manual.
*/ */
struct ph7_vfs struct ph7_vfs {
{
const char *zName; /* Underlying VFS name [i.e: FreeBSD/Linux/Windows...] */ const char *zName; /* Underlying VFS name [i.e: FreeBSD/Linux/Windows...] */
int iVersion; /* Current VFS structure version [default 2] */ int iVersion; /* Current VFS structure version [default 2] */
/* Directory functions */ /* Directory functions */
@ -587,8 +577,7 @@ struct ph7_vfs
* Developers wishing to implement their own IO stream devices must understand and follow * Developers wishing to implement their own IO stream devices must understand and follow
* The PH7 IO Stream C/C++ specification manual (http://ph7.symisc.net/io_stream_spec.html). * The PH7 IO Stream C/C++ specification manual (http://ph7.symisc.net/io_stream_spec.html).
*/ */
struct ph7_io_stream struct ph7_io_stream {
{
const char *zName; /* Underlying stream name [i.e: file/http/zip/php,..] */ const char *zName; /* Underlying stream name [i.e: file/http/zip/php,..] */
int iVersion; /* IO stream structure version [default 1]*/ int iVersion; /* IO stream structure version [default 1]*/
int (*xOpen)(const char *, int, ph7_value *, void **); /* Open handle*/ int (*xOpen)(const char *, int, ph7_value *, void **); /* Open handle*/
@ -712,7 +701,4 @@ PH7_APIEXPORT const char * ph7_lib_version(void);
PH7_APIEXPORT const char *ph7_lib_signature(void); PH7_APIEXPORT const char *ph7_lib_signature(void);
PH7_APIEXPORT const char *ph7_lib_ident(void); PH7_APIEXPORT const char *ph7_lib_ident(void);
PH7_APIEXPORT const char *ph7_lib_copyright(void); PH7_APIEXPORT const char *ph7_lib_copyright(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _PH7_H_ */ #endif /* _PH7_H_ */

150
ph7int.h
View File

@ -177,8 +177,7 @@ typedef sxi32 (*ProcSort)(void *,sxu32,sxu32,ProcCmp);
/* /*
* A generic dynamic set. * A generic dynamic set.
*/ */
struct SySet struct SySet {
{
SyMemBackend *pAllocator; /* Memory backend */ SyMemBackend *pAllocator; /* Memory backend */
void *pBase; /* Base pointer */ void *pBase; /* Base pointer */
sxu32 nUsed; /* Total number of used slots */ sxu32 nUsed; /* Total number of used slots */
@ -199,8 +198,7 @@ struct SySet
/* /*
* A variable length containers for generic data. * A variable length containers for generic data.
*/ */
struct SyBlob struct SyBlob {
{
SyMemBackend *pAllocator; /* Memory backend */ SyMemBackend *pAllocator; /* Memory backend */
void *pBlob; /* Base pointer */ void *pBlob; /* Base pointer */
sxu32 nByte; /* Total number of used bytes */ sxu32 nByte; /* Total number of used bytes */
@ -227,8 +225,7 @@ struct SyBlob
/* A memory backend subsystem is defined by an instance of the following structures */ /* A memory backend subsystem is defined by an instance of the following structures */
typedef union SyMemHeader SyMemHeader; typedef union SyMemHeader SyMemHeader;
typedef struct SyMemBlock SyMemBlock; typedef struct SyMemBlock SyMemBlock;
struct SyMemBlock struct SyMemBlock {
{
SyMemBlock *pNext, *pPrev; /* Chain of allocated memory blocks */ SyMemBlock *pNext, *pPrev; /* Chain of allocated memory blocks */
#ifdef UNTRUST #ifdef UNTRUST
sxu32 nGuard; /* magic number associated with each valid block,so we sxu32 nGuard; /* magic number associated with each valid block,so we
@ -239,13 +236,11 @@ struct SyMemBlock
/* /*
* Header associated with each valid memory pool block. * Header associated with each valid memory pool block.
*/ */
union SyMemHeader union SyMemHeader {
{
SyMemHeader *pNext; /* Next chunk of size 1 << (nBucket + SXMEM_POOL_INCR) in the list */ SyMemHeader *pNext; /* Next chunk of size 1 << (nBucket + SXMEM_POOL_INCR) in the list */
sxu32 nBucket; /* Bucket index in aPool[] */ sxu32 nBucket; /* Bucket index in aPool[] */
}; };
struct SyMemBackend struct SyMemBackend {
{
const SyMutexMethods *pMutexMethods; /* Mutex methods */ const SyMutexMethods *pMutexMethods; /* Mutex methods */
const SyMemMethods *pMethods; /* Memory allocation methods */ const SyMemMethods *pMethods; /* Memory allocation methods */
SyMemBlock *pBlocks; /* List of valid memory blocks */ SyMemBlock *pBlocks; /* List of valid memory blocks */
@ -348,8 +343,7 @@ typedef struct SyHash SyHash;
* Each public hashtable entry is represented by an instance * Each public hashtable entry is represented by an instance
* of the following structure. * of the following structure.
*/ */
struct SyHashEntry struct SyHashEntry {
{
const void *pKey; /* Hash key */ const void *pKey; /* Hash key */
sxu32 nKeyLen; /* Key length */ sxu32 nKeyLen; /* Key length */
void *pUserData; /* User private data */ void *pUserData; /* User private data */
@ -357,8 +351,7 @@ struct SyHashEntry
#define SyHashEntryGetUserData(ENTRY) ((ENTRY)->pUserData) #define SyHashEntryGetUserData(ENTRY) ((ENTRY)->pUserData)
#define SyHashEntryGetKey(ENTRY) ((ENTRY)->pKey) #define SyHashEntryGetKey(ENTRY) ((ENTRY)->pKey)
/* Each active hashtable is identified by an instance of the following structure */ /* Each active hashtable is identified by an instance of the following structure */
struct SyHash struct SyHash {
{
SyMemBackend *pAllocator; /* Memory backend */ SyMemBackend *pAllocator; /* Memory backend */
ProcHash xHash; /* Hash function */ ProcHash xHash; /* Hash function */
ProcCmp xCmp; /* Comparison function */ ProcCmp xCmp; /* Comparison function */
@ -384,8 +377,7 @@ struct SyHash
* This implementation is taken from the SQLite3 source tree. * This implementation is taken from the SQLite3 source tree.
*/ */
typedef struct SyPRNGCtx SyPRNGCtx; typedef struct SyPRNGCtx SyPRNGCtx;
struct SyPRNGCtx struct SyPRNGCtx {
{
sxu8 i, j; /* State variables */ sxu8 i, j; /* State variables */
unsigned char s[256]; /* State variables */ unsigned char s[256]; /* State variables */
sxu16 nMagic; /* Sanity check */ sxu16 nMagic; /* Sanity check */
@ -393,8 +385,7 @@ struct SyPRNGCtx
typedef sxi32(*ProcRandomSeed)(void *, unsigned int, void *); typedef sxi32(*ProcRandomSeed)(void *, unsigned int, void *);
/* High resolution timer.*/ /* High resolution timer.*/
typedef struct sytime sytime; typedef struct sytime sytime;
struct sytime struct sytime {
{
long tm_sec; /* seconds */ long tm_sec; /* seconds */
long tm_usec; /* microseconds */ long tm_usec; /* microseconds */
}; };
@ -410,8 +401,7 @@ typedef sxi32 (*ProcTokenizer)(SyStream *,SyToken *,void *,void *);
* Each token in the input is represented by an instance * Each token in the input is represented by an instance
* of the following structure. * of the following structure.
*/ */
struct SyToken struct SyToken {
{
SyString sData; /* Token text and length */ SyString sData; /* Token text and length */
sxu32 nType; /* Token type */ sxu32 nType; /* Token type */
sxu32 nLine; /* Token line number */ sxu32 nLine; /* Token line number */
@ -421,8 +411,7 @@ struct SyToken
* During tokenization, information about the state of the input * During tokenization, information about the state of the input
* stream is held in an instance of the following structure. * stream is held in an instance of the following structure.
*/ */
struct SyStream struct SyStream {
{
const unsigned char *zInput; /* Complete text of the input */ const unsigned char *zInput; /* Complete text of the input */
const unsigned char *zText; /* Current input we are processing */ const unsigned char *zText; /* Current input we are processing */
const unsigned char *zEnd; /* End of input marker */ const unsigned char *zEnd; /* End of input marker */
@ -433,8 +422,7 @@ struct SyStream
/* /*
* Each lexer is represented by an instance of the following structure. * Each lexer is represented by an instance of the following structure.
*/ */
struct SyLex struct SyLex {
{
SyStream sStream; /* Input stream */ SyStream sStream; /* Input stream */
ProcTokenizer xTokenizer; /* Tokenizer callback */ ProcTokenizer xTokenizer; /* Tokenizer callback */
void *pUserData; /* Third argument to xTokenizer() */ void *pUserData; /* Third argument to xTokenizer() */
@ -545,8 +533,7 @@ struct SyLex
* in an instance of the following structure. * in an instance of the following structure.
*/ */
typedef struct SyXMLRawStr SyXMLRawStr; typedef struct SyXMLRawStr SyXMLRawStr;
struct SyXMLRawStr struct SyXMLRawStr {
{
const char *zString; /* Raw text [UTF-8 ENCODED EXCEPT CDATA] [NOT NULL TERMINATED] */ const char *zString; /* Raw text [UTF-8 ENCODED EXCEPT CDATA] [NOT NULL TERMINATED] */
sxu32 nByte; /* Text length */ sxu32 nByte; /* Text length */
sxu32 nLine; /* Line number this text occurs */ sxu32 nLine; /* Line number this text occurs */
@ -600,8 +587,7 @@ enum xml_err_code{
* of the following structure. * of the following structure.
*/ */
typedef struct SyXMLParser SyXMLParser; typedef struct SyXMLParser SyXMLParser;
struct SyXMLParser struct SyXMLParser {
{
SyMemBackend *pAllocator; /* Memory backend */ SyMemBackend *pAllocator; /* Memory backend */
void *pUserData; /* User private data forwarded varbatim by the XML parser void *pUserData; /* User private data forwarded varbatim by the XML parser
* as the last argument to the users callbacks. * as the last argument to the users callbacks.
@ -634,8 +620,7 @@ struct SyXMLParser
*/ */
typedef struct SyArchiveEntry SyArchiveEntry; typedef struct SyArchiveEntry SyArchiveEntry;
typedef struct SyArchive SyArchive; typedef struct SyArchive SyArchive;
struct SyArchive struct SyArchive {
{
SyMemBackend *pAllocator; /* Memory backend */ SyMemBackend *pAllocator; /* Memory backend */
SyArchiveEntry *pCursor; /* Cursor for linear traversal of archive entries */ SyArchiveEntry *pCursor; /* Cursor for linear traversal of archive entries */
SyArchiveEntry *pList; /* Pointer to the List of the loaded archive */ SyArchiveEntry *pList; /* Pointer to the List of the loaded archive */
@ -662,8 +647,7 @@ struct SyXMLParser
* Each loaded archive record is identified by an instance * Each loaded archive record is identified by an instance
* of the following structure. * of the following structure.
*/ */
struct SyArchiveEntry struct SyArchiveEntry {
{
sxu32 nByte; /* Contents size before compression */ sxu32 nByte; /* Contents size before compression */
sxu32 nByteCompr; /* Contents size after compression */ sxu32 nByteCompr; /* Contents size after compression */
sxu32 nReadCount; /* Read counter */ sxu32 nReadCount; /* Read counter */
@ -710,8 +694,7 @@ struct SHA1Context {
* Each ph7_values struct may cache multiple representations (string, integer etc.) * Each ph7_values struct may cache multiple representations (string, integer etc.)
* of the same value. * of the same value.
*/ */
struct ph7_value struct ph7_value {
{
ph7_real rVal; /* Real value */ ph7_real rVal; /* Real value */
union { union {
sxi64 iVal; /* Integer value */ sxi64 iVal; /* Integer value */
@ -761,8 +744,7 @@ typedef struct ph7_conf ph7_conf;
* Please refer to the official documentation for more information * Please refer to the official documentation for more information
* on how to register an output consumer callback. * on how to register an output consumer callback.
*/ */
struct ph7_output_consumer struct ph7_output_consumer {
{
ProcConsumer xConsumer; /* VM output consumer routine */ ProcConsumer xConsumer; /* VM output consumer routine */
void *pUserData; /* Third argument to xConsumer() */ void *pUserData; /* Third argument to xConsumer() */
ProcConsumer xDef; /* Default output consumer routine */ ProcConsumer xDef; /* Default output consumer routine */
@ -774,8 +756,7 @@ struct ph7_output_consumer
* Please refer to the official documentation for more information * Please refer to the official documentation for more information
* on how to configure your ph7 engine instance. * on how to configure your ph7 engine instance.
*/ */
struct ph7_conf struct ph7_conf {
{
ProcConsumer xErr; /* Compile-time error consumer callback */ ProcConsumer xErr; /* Compile-time error consumer callback */
void *pErrData; /* Third argument to xErr() */ void *pErrData; /* Third argument to xErr() */
SyBlob sErrConsumer; /* Default error consumer */ SyBlob sErrConsumer; /* Default error consumer */
@ -791,8 +772,7 @@ typedef void (*ProcConstant)(ph7_value *,void *);
* on how to create/install foreign constants. * on how to create/install foreign constants.
*/ */
typedef struct ph7_constant ph7_constant; typedef struct ph7_constant ph7_constant;
struct ph7_constant struct ph7_constant {
{
SyString sName; /* Constant name */ SyString sName; /* Constant name */
ProcConstant xExpand; /* Function responsible of expanding constant value */ ProcConstant xExpand; /* Function responsible of expanding constant value */
void *pUserData; /* Last argument to xExpand() */ void *pUserData; /* Last argument to xExpand() */
@ -804,8 +784,7 @@ typedef struct ph7_aux_data ph7_aux_data;
* Note that automatic tracked chunks are also stored in an instance * Note that automatic tracked chunks are also stored in an instance
* of this structure. * of this structure.
*/ */
struct ph7_aux_data struct ph7_aux_data {
{
void *pAuxData; /* Aux data */ void *pAuxData; /* Aux data */
}; };
/* Foreign functions signature */ /* Foreign functions signature */
@ -816,8 +795,7 @@ typedef int (*ProchHostFunction)(ph7_context *,int,ph7_value **);
* Please refer to the official documentation for more information on how * Please refer to the official documentation for more information on how
* to create/install foreign functions. * to create/install foreign functions.
*/ */
struct ph7_user_func struct ph7_user_func {
{
ph7_vm *pVm; /* VM that own this instance */ ph7_vm *pVm; /* VM that own this instance */
SyString sName; /* Foreign function name */ SyString sName; /* Foreign function name */
ProchHostFunction xFunc; /* Implementation of the foreign function */ ProchHostFunction xFunc; /* Implementation of the foreign function */
@ -829,8 +807,7 @@ struct ph7_user_func
* instance of this structure is the first argument to the routines used * instance of this structure is the first argument to the routines used
* implement the foreign functions. * implement the foreign functions.
*/ */
struct ph7_context struct ph7_context {
{
ph7_user_func *pFunc; /* Function information. */ ph7_user_func *pFunc; /* Function information. */
ph7_value *pRet; /* Return value is stored here. */ ph7_value *pRet; /* Return value is stored here. */
SySet sVar; /* Container of dynamically allocated ph7_values SySet sVar; /* Container of dynamically allocated ph7_values
@ -846,8 +823,7 @@ struct ph7_context
* Each hashmap entry [i.e: array(4,5,6)] is recorded in an instance * Each hashmap entry [i.e: array(4,5,6)] is recorded in an instance
* of the following structure. * of the following structure.
*/ */
struct ph7_hashmap_node struct ph7_hashmap_node {
{
ph7_hashmap *pMap; /* Hashmap that own this instance */ ph7_hashmap *pMap; /* Hashmap that own this instance */
sxi32 iType; /* Node type */ sxi32 iType; /* Node type */
union { union {
@ -864,8 +840,7 @@ struct ph7_hashmap_node
* Each active hashmap aka array in the PHP jargon is represented * Each active hashmap aka array in the PHP jargon is represented
* by an instance of the following structure. * by an instance of the following structure.
*/ */
struct ph7_hashmap struct ph7_hashmap {
{
ph7_vm *pVm; /* VM that own this instance */ ph7_vm *pVm; /* VM that own this instance */
ph7_hashmap_node **apBucket; /* Hash bucket */ ph7_hashmap_node **apBucket; /* Hash bucket */
ph7_hashmap_node *pFirst; /* First inserted entry */ ph7_hashmap_node *pFirst; /* First inserted entry */
@ -885,15 +860,13 @@ struct ph7_hashmap
* This structure is made available to these instructions * This structure is made available to these instructions
* as the P3 operand. * as the P3 operand.
*/ */
struct ph7_foreach_info struct ph7_foreach_info {
{
SyString sKey; /* Key name. Empty otherwise*/ SyString sKey; /* Key name. Empty otherwise*/
SyString sValue; /* Value name */ SyString sValue; /* Value name */
sxi32 iFlags; /* Control flags */ sxi32 iFlags; /* Control flags */
SySet aStep; /* Stack of steps [i.e: ph7_foreach_step instance] */ SySet aStep; /* Stack of steps [i.e: ph7_foreach_step instance] */
}; };
struct ph7_foreach_step struct ph7_foreach_step {
{
sxi32 iFlags; /* Control flags (see below) */ sxi32 iFlags; /* Control flags (see below) */
/* Iterate on those values */ /* Iterate on those values */
union { union {
@ -913,8 +886,7 @@ struct ph7_foreach_step
* Please refer to the official documentation for more information * Please refer to the official documentation for more information
* on how to configure your PH7 engine instance. * on how to configure your PH7 engine instance.
*/ */
struct ph7 struct ph7 {
{
SyMemBackend sAllocator; /* Low level memory allocation subsystem */ SyMemBackend sAllocator; /* Low level memory allocation subsystem */
const ph7_vfs *pVfs; /* Underlying Virtual File System */ const ph7_vfs *pVfs; /* Underlying Virtual File System */
ph7_conf xConf; /* Configuration */ ph7_conf xConf; /* Configuration */
@ -942,8 +914,7 @@ typedef sxi32 (*ProcNodeConstruct)(ph7_gen_state *,sxi32);
* That is, the PH7 parser is thread-safe ,full reentrant, produce consistant * That is, the PH7 parser is thread-safe ,full reentrant, produce consistant
* compile-time errrors and at least 7 times faster than the standard PHP parser. * compile-time errrors and at least 7 times faster than the standard PHP parser.
*/ */
struct ph7_expr_op struct ph7_expr_op {
{
SyString sOp; /* String representation of the operator [i.e: "+","*","=="...] */ SyString sOp; /* String representation of the operator [i.e: "+","*","=="...] */
sxi32 iOp; /* Operator ID */ sxi32 iOp; /* Operator ID */
sxi32 iPrec; /* Operator precedence: 1 == Highest */ sxi32 iPrec; /* Operator precedence: 1 == Highest */
@ -954,8 +925,7 @@ struct ph7_expr_op
* Each expression node is parsed out and recorded * Each expression node is parsed out and recorded
* in an instance of the following structure. * in an instance of the following structure.
*/ */
struct ph7_expr_node struct ph7_expr_node {
{
const ph7_expr_op *pOp; /* Operator ID or NULL if literal, constant, variable, function or class method call */ const ph7_expr_op *pOp; /* Operator ID or NULL if literal, constant, variable, function or class method call */
ph7_expr_node *pLeft; /* Left expression tree */ ph7_expr_node *pLeft; /* Left expression tree */
ph7_expr_node *pRight; /* Right expression tree */ ph7_expr_node *pRight; /* Right expression tree */
@ -973,8 +943,7 @@ struct ph7_expr_node
* This structure is used only during compile-time and have no meaning * This structure is used only during compile-time and have no meaning
* during bytecode execution. * during bytecode execution.
*/ */
struct GenBlock struct GenBlock {
{
ph7_gen_state *pGen; /* State of the code generator */ ph7_gen_state *pGen; /* State of the code generator */
GenBlock *pParent; /* Upper block or NULL if global */ GenBlock *pParent; /* Upper block or NULL if global */
sxu32 nFirstInstr; /* First instruction to execute */ sxu32 nFirstInstr; /* First instruction to execute */
@ -996,8 +965,7 @@ struct GenBlock
* This structure is used only during compile-time and have no meaning * This structure is used only during compile-time and have no meaning
* during bytecode execution. * during bytecode execution.
*/ */
struct ph7_gen_state struct ph7_gen_state {
{
ph7_vm *pVm; /* VM that own this instance */ ph7_vm *pVm; /* VM that own this instance */
SyHash hLiteral; /* Constant string Literals table */ SyHash hLiteral; /* Constant string Literals table */
SyHash hNumLiteral; /* Numeric literals table */ SyHash hNumLiteral; /* Numeric literals table */
@ -1041,8 +1009,7 @@ typedef struct VmFrame VmFrame;
* Refer to the official documentation for more information on this * Refer to the official documentation for more information on this
* mechanism and other extension introduced by the PH7 engine. * mechanism and other extension introduced by the PH7 engine.
*/ */
struct ph7_vm_func_arg struct ph7_vm_func_arg {
{
SyString sName; /* Argument name */ SyString sName; /* Argument name */
SySet aByteCode; /* Compiled default value associated with this argument */ SySet aByteCode; /* Compiled default value associated with this argument */
sxu32 nType; /* Type of this argument [i.e: array, int, string, float, object, etc.] */ sxu32 nType; /* Type of this argument [i.e: array, int, string, float, object, etc.] */
@ -1062,8 +1029,7 @@ struct ph7_vm_func_arg
* //You should see something like this * //You should see something like this
* string(6 'PH7awt'); * string(6 'PH7awt');
*/ */
struct ph7_vm_func_static_var struct ph7_vm_func_static_var {
{
SyString sName; /* Static variable name */ SyString sName; /* Static variable name */
SySet aByteCode; /* Compiled initialization expression */ SySet aByteCode; /* Compiled initialization expression */
sxu32 nIdx; /* Object index in the global memory object container */ sxu32 nIdx; /* Object index in the global memory object container */
@ -1072,8 +1038,7 @@ struct ph7_vm_func_static_var
* Each imported variable from the outside closure environnment is recoded * Each imported variable from the outside closure environnment is recoded
* in an instance of the following structure. * in an instance of the following structure.
*/ */
struct ph7_vm_func_closure_env struct ph7_vm_func_closure_env {
{
SyString sName; /* Imported variable name */ SyString sName; /* Imported variable name */
int iFlags; /* Control flags */ int iFlags; /* Control flags */
ph7_value sValue; /* Imported variable value */ ph7_value sValue; /* Imported variable value */
@ -1100,8 +1065,7 @@ struct ph7_vm_func_closure_env
* arguments values and many more. * arguments values and many more.
* Please refer to the official documentation for more information. * Please refer to the official documentation for more information.
*/ */
struct ph7_vm_func struct ph7_vm_func {
{
SySet aArgs; /* Expected arguments (ph7_vm_func_arg instance) */ SySet aArgs; /* Expected arguments (ph7_vm_func_arg instance) */
SySet aStatic; /* Static variable (ph7_vm_func_static_var instance) */ SySet aStatic; /* Static variable (ph7_vm_func_static_var instance) */
SyString sName; /* Function name */ SyString sName; /* Function name */
@ -1124,8 +1088,7 @@ typedef struct ph7_builtin_func ph7_builtin_func;
* Please refer to the official documentation for more information * Please refer to the official documentation for more information
* on how to create/install foreign functions. * on how to create/install foreign functions.
*/ */
struct ph7_builtin_func struct ph7_builtin_func {
{
const char *zName; /* Function name [i.e: strlen(), rand(), array_merge(), etc.]*/ const char *zName; /* Function name [i.e: strlen(), rand(), array_merge(), etc.]*/
ProchHostFunction xFunc; /* C routine performing the computation */ ProchHostFunction xFunc; /* C routine performing the computation */
}; };
@ -1135,8 +1098,7 @@ struct ph7_builtin_func
* Please refer to the official documentation for more information * Please refer to the official documentation for more information
* on how to create/install foreign constants. * on how to create/install foreign constants.
*/ */
struct ph7_builtin_constant struct ph7_builtin_constant {
{
const char *zName; /* Constant name */ const char *zName; /* Constant name */
ProcConstant xExpand; /* C routine responsible of expanding constant value*/ ProcConstant xExpand; /* C routine responsible of expanding constant value*/
}; };
@ -1148,8 +1110,7 @@ typedef struct ph7_class_attr ph7_class_attr;
* PH7 introduced powerfull extensions to the PHP 5 OO subsystems. * PH7 introduced powerfull extensions to the PHP 5 OO subsystems.
* Please refer to the official documentation for more information. * Please refer to the official documentation for more information.
*/ */
struct ph7_class struct ph7_class {
{
ph7_class *pBase; /* Base class if any */ ph7_class *pBase; /* Base class if any */
SyHash hDerived; /* Derived [child] classes */ SyHash hDerived; /* Derived [child] classes */
SyString sName; /* Class full qualified name */ SyString sName; /* Class full qualified name */
@ -1172,8 +1133,7 @@ struct ph7_class
* each class attribute (variable, constants) is parsed out and stored * each class attribute (variable, constants) is parsed out and stored
* in an instance of the following structure. * in an instance of the following structure.
*/ */
struct ph7_class_attr struct ph7_class_attr {
{
SyString sName; /* Atrribute name */ SyString sName; /* Atrribute name */
sxi32 iFlags; /* Attribute configuration [i.e: static, variable, constant, etc.] */ sxi32 iFlags; /* Attribute configuration [i.e: static, variable, constant, etc.] */
sxi32 iProtection; /* Protection level [i.e: public, private, protected] */ sxi32 iProtection; /* Protection level [i.e: public, private, protected] */
@ -1194,8 +1154,7 @@ struct ph7_class_attr
* arguments and many more. * arguments and many more.
* Please refer to the official documentation for more information. * Please refer to the official documentation for more information.
*/ */
struct ph7_class_method struct ph7_class_method {
{
ph7_vm_func sFunc; /* Compiled method body */ ph7_vm_func sFunc; /* Compiled method body */
SyString sVmName; /* Automatically generated name assigned to this method. SyString sVmName; /* Automatically generated name assigned to this method.
* Typically this is "[class_name__method_name@random_string]" * Typically this is "[class_name__method_name@random_string]"
@ -1209,8 +1168,7 @@ struct ph7_class_method
* Each active object (class instance) is represented by an instance of * Each active object (class instance) is represented by an instance of
* the following structure. * the following structure.
*/ */
struct ph7_class_instance struct ph7_class_instance {
{
ph7_vm *pVm; /* VM that own this instance */ ph7_vm *pVm; /* VM that own this instance */
ph7_class *pClass; /* Object is an instance of this class */ ph7_class *pClass; /* Object is an instance of this class */
SyHash hAttr; /* Hashtable of active class members */ SyHash hAttr; /* Hashtable of active class members */
@ -1224,8 +1182,7 @@ struct ph7_class_instance
* is stored in an instance of the following structure. * is stored in an instance of the following structure.
*/ */
typedef struct VmInstr VmInstr; typedef struct VmInstr VmInstr;
struct VmInstr struct VmInstr {
{
sxu8 iOp; /* Operation to preform */ sxu8 iOp; /* Operation to preform */
sxi32 iP1; /* First operand */ sxi32 iP1; /* First operand */
sxu32 iP2; /* Second operand (Often the jump destination) */ sxu32 iP2; /* Second operand (Often the jump destination) */
@ -1235,8 +1192,7 @@ struct VmInstr
* of the following structure. * of the following structure.
*/ */
typedef struct VmClassAttr VmClassAttr; typedef struct VmClassAttr VmClassAttr;
struct VmClassAttr struct VmClassAttr {
{
ph7_class_attr *pAttr; /* Class attribute */ ph7_class_attr *pAttr; /* Class attribute */
sxu32 nIdx; /* Memory object index */ sxu32 nIdx; /* Memory object index */
}; };
@ -1248,8 +1204,7 @@ typedef struct VmRefObj VmRefObj;
*/ */
typedef struct ph7_exception_block ph7_exception_block; typedef struct ph7_exception_block ph7_exception_block;
typedef struct ph7_exception ph7_exception; typedef struct ph7_exception ph7_exception;
struct ph7_exception_block struct ph7_exception_block {
{
SyString sClass; /* Exception class name [i.e: Exception,MyException...] */ SyString sClass; /* Exception class name [i.e: Exception,MyException...] */
SyString sThis; /* Instance name [i.e: $e..] */ SyString sThis; /* Instance name [i.e: $e..] */
SySet sByteCode; /* Block compiled instructions */ SySet sByteCode; /* Block compiled instructions */
@ -1257,8 +1212,7 @@ struct ph7_exception_block
/* /*
* Context for the exception mechanism. * Context for the exception mechanism.
*/ */
struct ph7_exception struct ph7_exception {
{
ph7_vm *pVm; /* VM that own this exception */ ph7_vm *pVm; /* VM that own this exception */
SySet sEntry; /* Compiled 'catch' blocks (ph7_exception_block instance) SySet sEntry; /* Compiled 'catch' blocks (ph7_exception_block instance)
* container. * container.
@ -1272,8 +1226,7 @@ typedef struct ph7_switch ph7_switch;
* Each compiled case block in a swicth statement is compiled * Each compiled case block in a swicth statement is compiled
* and stored in an instance of the following structure. * and stored in an instance of the following structure.
*/ */
struct ph7_case_expr struct ph7_case_expr {
{
SySet aByteCode; /* Compiled body of the case block */ SySet aByteCode; /* Compiled body of the case block */
sxu32 nStart; /* First instruction to execute */ sxu32 nStart; /* First instruction to execute */
}; };
@ -1281,8 +1234,7 @@ struct ph7_case_expr
* Each compiled switch statement is parsed out and stored * Each compiled switch statement is parsed out and stored
* in an instance of the following structure. * in an instance of the following structure.
*/ */
struct ph7_switch struct ph7_switch {
{
SySet aCaseExpr; /* Compile case block */ SySet aCaseExpr; /* Compile case block */
sxu32 nOut; /* First instruction to execute after this statement */ sxu32 nOut; /* First instruction to execute after this statement */
sxu32 nDefault; /* First instruction to execute in the default block */ sxu32 nDefault; /* First instruction to execute in the default block */
@ -1304,8 +1256,7 @@ typedef void (*ProcErrLog)(const char *,int,const char *,const char *);
* resulting from compiling a PHP script. * resulting from compiling a PHP script.
* This structure contains the complete state of the virtual machine. * This structure contains the complete state of the virtual machine.
*/ */
struct ph7_vm struct ph7_vm {
{
SyMemBackend sAllocator; /* Memory backend */ SyMemBackend sAllocator; /* Memory backend */
#if defined(PH7_ENABLE_THREADS) #if defined(PH7_ENABLE_THREADS)
SyMutex *pMutex; /* Recursive mutex associated with VM. */ SyMutex *pMutex; /* Recursive mutex associated with VM. */
@ -1377,8 +1328,7 @@ struct ph7_vm
/* /*
* Error codes according to the PHP language reference manual. * Error codes according to the PHP language reference manual.
*/ */
enum iErrCode enum iErrCode {
{
E_ERROR = 1, /* Fatal run-time errors. These indicate errors that can not be recovered E_ERROR = 1, /* Fatal run-time errors. These indicate errors that can not be recovered
* from, such as a memory allocation problem. Execution of the script is * from, such as a memory allocation problem. Execution of the script is
* halted. * halted.

771
vfs.c

File diff suppressed because it is too large Load Diff

1175
vm.c

File diff suppressed because it is too large Load Diff