Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1962 lines
92 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. /*
  2. * Symisc PH7: An embeddable bytecode compiler and a virtual machine for the PHP(5) programming language.
  3. * Copyright (C) 2011-2012, Symisc Systems http://ph7.symisc.net/
  4. * Version 2.1.4
  5. * For information on licensing,redistribution of this file,and for a DISCLAIMER OF ALL WARRANTIES
  6. * please contact Symisc Systems via:
  7. * legal@symisc.net
  8. * licensing@symisc.net
  9. * contact@symisc.net
  10. * or visit:
  11. * http://ph7.symisc.net/
  12. */
  13. /* $SymiscID: ph7int.h v1.9 FreeBSD 2012-08-13 26:25 devel <chm@symisc.net> $ */
  14. #ifndef __PH7INT_H__
  15. #define __PH7INT_H__
  16. #define PH7_PRIVATE
  17. #include "ph7.h"
  18. #include <dlfcn.h>
  19. #ifndef PH7_PI
  20. /* Value of PI */
  21. #define PH7_PI 3.1415926535898
  22. #endif
  23. /*
  24. * Constants for the largest and smallest possible 64-bit signed integers.
  25. * These macros are designed to work correctly on both 32-bit and 64-bit
  26. * compilers.
  27. */
  28. #ifndef LARGEST_INT64
  29. #define LARGEST_INT64 (0xffffffff|(((sxi64)0x7fffffff)<<32))
  30. #endif
  31. #ifndef SMALLEST_INT64
  32. #define SMALLEST_INT64 (((sxi64)-1) - LARGEST_INT64)
  33. #endif
  34. /* Forward declaration of private structures */
  35. typedef struct ph7_class_instance ph7_class_instance;
  36. typedef struct ph7_foreach_info ph7_foreach_info;
  37. typedef struct ph7_foreach_step ph7_foreach_step;
  38. typedef struct ph7_hashmap_node ph7_hashmap_node;
  39. typedef struct ph7_hashmap ph7_hashmap;
  40. typedef struct ph7_class ph7_class;
  41. /* Symisc Standard types */
  42. #if !defined(SYMISC_STD_TYPES)
  43. #define SYMISC_STD_TYPES
  44. #ifdef __WINNT__
  45. /* Disable nuisance warnings on Borland compilers */
  46. #if defined(__BORLANDC__)
  47. #pragma warn -rch /* unreachable code */
  48. #pragma warn -ccc /* Condition is always true or false */
  49. #pragma warn -aus /* Assigned value is never used */
  50. #pragma warn -csu /* Comparing signed and unsigned */
  51. #pragma warn -spa /* Suspicious pointer arithmetic */
  52. #endif
  53. #endif
  54. typedef signed char sxi8; /* signed char */
  55. typedef unsigned char sxu8; /* unsigned char */
  56. typedef signed short int sxi16; /* 16 bits(2 bytes) signed integer */
  57. typedef unsigned short int sxu16; /* 16 bits(2 bytes) unsigned integer */
  58. typedef int sxi32; /* 32 bits(4 bytes) integer */
  59. typedef unsigned int sxu32; /* 32 bits(4 bytes) unsigned integer */
  60. typedef long sxptr;
  61. typedef unsigned long sxuptr;
  62. typedef long sxlong;
  63. typedef unsigned long sxulong;
  64. typedef sxi32 sxofft;
  65. typedef sxi64 sxofft64;
  66. typedef long double sxlongreal;
  67. typedef double sxreal;
  68. #define SXI8_HIGH 0x7F
  69. #define SXU8_HIGH 0xFF
  70. #define SXI16_HIGH 0x7FFF
  71. #define SXU16_HIGH 0xFFFF
  72. #define SXI32_HIGH 0x7FFFFFFF
  73. #define SXU32_HIGH 0xFFFFFFFF
  74. #define SXI64_HIGH 0x7FFFFFFFFFFFFFFFLL
  75. #define SXU64_HIGH 0xFFFFFFFFFFFFFFFFUL
  76. #if !defined(TRUE)
  77. #define TRUE 1
  78. #endif
  79. #if !defined(FALSE)
  80. #define FALSE 0
  81. #endif
  82. /*
  83. * The following macros are used to cast pointers to integers and
  84. * integers to pointers.
  85. */
  86. #if defined(__PTRDIFF_TYPE__)
  87. #define SX_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X))
  88. #define SX_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X))
  89. #elif !defined(__GNUC__)
  90. #define SX_INT_TO_PTR(X) ((void*)&((char*)0)[X])
  91. #define SX_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0))
  92. #else
  93. #define SX_INT_TO_PTR(X) ((void*)(X))
  94. #define SX_PTR_TO_INT(X) ((int)(X))
  95. #endif
  96. #define SXMIN(a,b) ((a < b) ? (a) : (b))
  97. #define SXMAX(a,b) ((a < b) ? (b) : (a))
  98. #endif /* SYMISC_STD_TYPES */
  99. /* Symisc Run-time API private definitions */
  100. #if !defined(SYMISC_PRIVATE_DEFS)
  101. #define SYMISC_PRIVATE_DEFS
  102. typedef sxi32(*ProcRawStrCmp)(const SyString *, const SyString *);
  103. #define SyStringData(RAW) ((RAW)->zString)
  104. #define SyStringLength(RAW) ((RAW)->nByte)
  105. #define SyStringInitFromBuf(RAW,ZBUF,NLEN){\
  106. (RAW)->zString = (const char *)ZBUF;\
  107. (RAW)->nByte = (sxu32)(NLEN);\
  108. }
  109. #define SyStringUpdatePtr(RAW,NBYTES){\
  110. if( NBYTES > (RAW)->nByte ){\
  111. (RAW)->nByte = 0;\
  112. }else{\
  113. (RAW)->zString += NBYTES;\
  114. (RAW)->nByte -= NBYTES;\
  115. }\
  116. }
  117. #define SyStringDupPtr(RAW1,RAW2)\
  118. (RAW1)->zString = (RAW2)->zString;\
  119. (RAW1)->nByte = (RAW2)->nByte;
  120. #define SyStringTrimLeadingChar(RAW,CHAR)\
  121. while((RAW)->nByte > 0 && (RAW)->zString[0] == CHAR ){\
  122. (RAW)->zString++;\
  123. (RAW)->nByte--;\
  124. }
  125. #define SyStringTrimTrailingChar(RAW,CHAR)\
  126. while((RAW)->nByte > 0 && (RAW)->zString[(RAW)->nByte - 1] == CHAR){\
  127. (RAW)->nByte--;\
  128. }
  129. #define SyStringCmp(RAW1,RAW2,xCMP)\
  130. (((RAW1)->nByte == (RAW2)->nByte) ? xCMP((RAW1)->zString,(RAW2)->zString,(RAW2)->nByte) : (sxi32)((RAW1)->nByte - (RAW2)->nByte))
  131. #define SyStringCmp2(RAW1,RAW2,xCMP)\
  132. (((RAW1)->nByte >= (RAW2)->nByte) ? xCMP((RAW1)->zString,(RAW2)->zString,(RAW2)->nByte) : (sxi32)((RAW2)->nByte - (RAW1)->nByte))
  133. #define SyStringCharCmp(RAW,CHAR) \
  134. (((RAW)->nByte == sizeof(char)) ? ((RAW)->zString[0] == CHAR ? 0 : CHAR - (RAW)->zString[0]) : ((RAW)->zString[0] == CHAR ? 0 : (RAW)->nByte - sizeof(char)))
  135. #define SX_ADDR(PTR) ((sxptr)PTR)
  136. #define SX_ARRAYSIZE(X) (sizeof(X)/sizeof(X[0]))
  137. #define SXUNUSED(P) (P = 0)
  138. #define SX_EMPTY(PTR) (PTR == 0)
  139. #define SX_EMPTY_STR(STR) (STR == 0 || STR[0] == 0 )
  140. typedef struct SyMemBackend SyMemBackend;
  141. typedef struct SyBlob SyBlob;
  142. typedef struct SySet SySet;
  143. /* Standard function signatures */
  144. typedef sxi32(*ProcCmp)(const void *, const void *, sxu32);
  145. typedef sxi32(*ProcPatternMatch)(const char *, sxu32, const char *, sxu32, sxu32 *);
  146. typedef sxi32(*ProcSearch)(const void *, sxu32, const void *, sxu32, ProcCmp, sxu32 *);
  147. typedef sxu32(*ProcHash)(const void *, sxu32);
  148. typedef sxi32(*ProcHashSum)(const void *, sxu32, unsigned char *, sxu32);
  149. typedef sxi32(*ProcSort)(void *, sxu32, sxu32, ProcCmp);
  150. #define MACRO_LIST_PUSH(Head,Item)\
  151. Item->pNext = Head;\
  152. Head = Item;
  153. #define MACRO_LD_PUSH(Head,Item)\
  154. if( Head == 0 ){\
  155. Head = Item;\
  156. }else{\
  157. Item->pNext = Head;\
  158. Head->pPrev = Item;\
  159. Head = Item;\
  160. }
  161. #define MACRO_LD_REMOVE(Head,Item)\
  162. if( Head == Item ){\
  163. Head = Head->pNext;\
  164. }\
  165. if( Item->pPrev ){ Item->pPrev->pNext = Item->pNext;}\
  166. if( Item->pNext ){ Item->pNext->pPrev = Item->pPrev;}
  167. /*
  168. * A generic dynamic set.
  169. */
  170. struct SySet {
  171. SyMemBackend *pAllocator; /* Memory backend */
  172. void *pBase; /* Base pointer */
  173. sxu32 nUsed; /* Total number of used slots */
  174. sxu32 nSize; /* Total number of available slots */
  175. sxu32 eSize; /* Size of a single slot */
  176. sxu32 nCursor; /* Loop cursor */
  177. void *pUserData; /* User private data associated with this container */
  178. };
  179. #define SySetBasePtr(S) ((S)->pBase)
  180. #define SySetBasePtrJump(S,OFFT) (&((char *)(S)->pBase)[OFFT*(S)->eSize])
  181. #define SySetUsed(S) ((S)->nUsed)
  182. #define SySetSize(S) ((S)->nSize)
  183. #define SySetElemSize(S) ((S)->eSize)
  184. #define SySetCursor(S) ((S)->nCursor)
  185. #define SySetGetAllocator(S) ((S)->pAllocator)
  186. #define SySetSetUserData(S,DATA) ((S)->pUserData = DATA)
  187. #define SySetGetUserData(S) ((S)->pUserData)
  188. /*
  189. * A variable length containers for generic data.
  190. */
  191. struct SyBlob {
  192. SyMemBackend *pAllocator; /* Memory backend */
  193. void *pBlob; /* Base pointer */
  194. sxu32 nByte; /* Total number of used bytes */
  195. sxu32 mByte; /* Total number of available bytes */
  196. sxu32 nFlags; /* Blob internal flags,see below */
  197. };
  198. #define SXBLOB_LOCKED 0x01 /* Blob is locked [i.e: Cannot auto grow] */
  199. #define SXBLOB_STATIC 0x02 /* Not allocated from heap */
  200. #define SXBLOB_RDONLY 0x04 /* Read-Only data */
  201. #define SyBlobFreeSpace(BLOB) ((BLOB)->mByte - (BLOB)->nByte)
  202. #define SyBlobLength(BLOB) ((BLOB)->nByte)
  203. #define SyBlobData(BLOB) ((BLOB)->pBlob)
  204. #define SyBlobCurData(BLOB) ((void*)(&((char*)(BLOB)->pBlob)[(BLOB)->nByte]))
  205. #define SyBlobDataAt(BLOB,OFFT) ((void *)(&((char *)(BLOB)->pBlob)[OFFT]))
  206. #define SyBlobGetAllocator(BLOB) ((BLOB)->pAllocator)
  207. #define SXMEM_POOL_INCR 3
  208. #define SXMEM_POOL_NBUCKETS 12
  209. #define SXMEM_BACKEND_MAGIC 0xBAC3E67D
  210. #define SXMEM_BACKEND_CORRUPT(BACKEND) (BACKEND == 0 || BACKEND->nMagic != SXMEM_BACKEND_MAGIC)
  211. #define SXMEM_BACKEND_RETRY 3
  212. /* A memory backend subsystem is defined by an instance of the following structures */
  213. typedef union SyMemHeader SyMemHeader;
  214. typedef struct SyMemBlock SyMemBlock;
  215. struct SyMemBlock {
  216. SyMemBlock *pNext, *pPrev; /* Chain of allocated memory blocks */
  217. #ifdef UNTRUST
  218. sxu32 nGuard; /* magic number associated with each valid block,so we
  219. * can detect misuse.
  220. */
  221. #endif
  222. };
  223. /*
  224. * Header associated with each valid memory pool block.
  225. */
  226. union SyMemHeader {
  227. SyMemHeader *pNext; /* Next chunk of size 1 << (nBucket + SXMEM_POOL_INCR) in the list */
  228. sxu32 nBucket; /* Bucket index in aPool[] */
  229. };
  230. struct SyMemBackend {
  231. const SyMutexMethods *pMutexMethods; /* Mutex methods */
  232. const SyMemMethods *pMethods; /* Memory allocation methods */
  233. SyMemBlock *pBlocks; /* List of valid memory blocks */
  234. sxu32 nBlock; /* Total number of memory blocks allocated so far */
  235. ProcMemError xMemError; /* Out-of memory callback */
  236. void *pUserData; /* First arg to xMemError() */
  237. SyMutex *pMutex; /* Per instance mutex */
  238. sxu32 nMagic; /* Sanity check against misuse */
  239. SyMemHeader *apPool[SXMEM_POOL_NBUCKETS + SXMEM_POOL_INCR]; /* Pool of memory chunks */
  240. };
  241. /* Mutex types */
  242. #define SXMUTEX_TYPE_FAST 1
  243. #define SXMUTEX_TYPE_RECURSIVE 2
  244. #define SXMUTEX_TYPE_STATIC_1 3
  245. #define SXMUTEX_TYPE_STATIC_2 4
  246. #define SXMUTEX_TYPE_STATIC_3 5
  247. #define SXMUTEX_TYPE_STATIC_4 6
  248. #define SXMUTEX_TYPE_STATIC_5 7
  249. #define SXMUTEX_TYPE_STATIC_6 8
  250. #define SyMutexGlobalInit(METHOD){\
  251. if( (METHOD)->xGlobalInit ){\
  252. (METHOD)->xGlobalInit();\
  253. }\
  254. }
  255. #define SyMutexGlobalRelease(METHOD){\
  256. if( (METHOD)->xGlobalRelease ){\
  257. (METHOD)->xGlobalRelease();\
  258. }\
  259. }
  260. #define SyMutexNew(METHOD,TYPE) (METHOD)->xNew(TYPE)
  261. #define SyMutexRelease(METHOD,MUTEX){\
  262. if( MUTEX && (METHOD)->xRelease ){\
  263. (METHOD)->xRelease(MUTEX);\
  264. }\
  265. }
  266. #define SyMutexEnter(METHOD,MUTEX){\
  267. if( MUTEX ){\
  268. (METHOD)->xEnter(MUTEX);\
  269. }\
  270. }
  271. #define SyMutexTryEnter(METHOD,MUTEX){\
  272. if( MUTEX && (METHOD)->xTryEnter ){\
  273. (METHOD)->xTryEnter(MUTEX);\
  274. }\
  275. }
  276. #define SyMutexLeave(METHOD,MUTEX){\
  277. if( MUTEX ){\
  278. (METHOD)->xLeave(MUTEX);\
  279. }\
  280. }
  281. /* Comparison,byte swap,byte copy macros */
  282. #define SX_MACRO_FAST_CMP(X1,X2,SIZE,RC){\
  283. register unsigned char *r1 = (unsigned char *)X1;\
  284. register unsigned char *r2 = (unsigned char *)X2;\
  285. register sxu32 LEN = SIZE;\
  286. for(;;){\
  287. if( !LEN ){ break; }if( r1[0] != r2[0] ){ break; } r1++; r2++; LEN--;\
  288. if( !LEN ){ break; }if( r1[0] != r2[0] ){ break; } r1++; r2++; LEN--;\
  289. if( !LEN ){ break; }if( r1[0] != r2[0] ){ break; } r1++; r2++; LEN--;\
  290. if( !LEN ){ break; }if( r1[0] != r2[0] ){ break; } r1++; r2++; LEN--;\
  291. }\
  292. RC = !LEN ? 0 : r1[0] - r2[0];\
  293. }
  294. #define SX_MACRO_FAST_MEMCPY(SRC,DST,SIZ){\
  295. register unsigned char *xSrc = (unsigned char *)SRC;\
  296. register unsigned char *xDst = (unsigned char *)DST;\
  297. register sxu32 xLen = SIZ;\
  298. for(;;){\
  299. if( !xLen ){ break; }xDst[0] = xSrc[0]; xDst++; xSrc++; --xLen;\
  300. if( !xLen ){ break; }xDst[0] = xSrc[0]; xDst++; xSrc++; --xLen;\
  301. if( !xLen ){ break; }xDst[0] = xSrc[0]; xDst++; xSrc++; --xLen;\
  302. if( !xLen ){ break; }xDst[0] = xSrc[0]; xDst++; xSrc++; --xLen;\
  303. }\
  304. }
  305. #define SX_MACRO_BYTE_SWAP(X,Y,Z){\
  306. register unsigned char *s = (unsigned char *)X;\
  307. register unsigned char *d = (unsigned char *)Y;\
  308. sxu32 ZLong = Z; \
  309. sxi32 c; \
  310. for(;;){\
  311. if(!ZLong){ break; } c = s[0] ; s[0] = d[0]; d[0] = (unsigned char)c; s++; d++; --ZLong;\
  312. if(!ZLong){ break; } c = s[0] ; s[0] = d[0]; d[0] = (unsigned char)c; s++; d++; --ZLong;\
  313. if(!ZLong){ break; } c = s[0] ; s[0] = d[0]; d[0] = (unsigned char)c; s++; d++; --ZLong;\
  314. if(!ZLong){ break; } c = s[0] ; s[0] = d[0]; d[0] = (unsigned char)c; s++; d++; --ZLong;\
  315. }\
  316. }
  317. #define SX_MSEC_PER_SEC (1000) /* Millisec per seconds */
  318. #define SX_USEC_PER_SEC (1000000) /* Microsec per seconds */
  319. #define SX_NSEC_PER_SEC (1000000000) /* Nanosec per seconds */
  320. #endif /* SYMISC_PRIVATE_DEFS */
  321. /* Symisc Run-time API auxiliary definitions */
  322. #if !defined(SYMISC_PRIVATE_AUX_DEFS)
  323. #define SYMISC_PRIVATE_AUX_DEFS
  324. typedef struct SyHashEntry_Pr SyHashEntry_Pr;
  325. typedef struct SyHashEntry SyHashEntry;
  326. typedef struct SyHash SyHash;
  327. /*
  328. * Each public hashtable entry is represented by an instance
  329. * of the following structure.
  330. */
  331. struct SyHashEntry {
  332. const void *pKey; /* Hash key */
  333. sxu32 nKeyLen; /* Key length */
  334. void *pUserData; /* User private data */
  335. };
  336. #define SyHashEntryGetUserData(ENTRY) ((ENTRY)->pUserData)
  337. #define SyHashEntryGetKey(ENTRY) ((ENTRY)->pKey)
  338. /* Each active hashtable is identified by an instance of the following structure */
  339. struct SyHash {
  340. SyMemBackend *pAllocator; /* Memory backend */
  341. ProcHash xHash; /* Hash function */
  342. ProcCmp xCmp; /* Comparison function */
  343. SyHashEntry_Pr *pList, *pCurrent; /* Linked list of hash entries user for linear traversal */
  344. sxu32 nEntry; /* Total number of entries */
  345. SyHashEntry_Pr **apBucket; /* Hash buckets */
  346. sxu32 nBucketSize; /* Current bucket size */
  347. };
  348. #define SXHASH_BUCKET_SIZE 16 /* Initial bucket size: must be a power of two */
  349. #define SXHASH_FILL_FACTOR 3
  350. /* Hash access macro */
  351. #define SyHashFunc(HASH) ((HASH)->xHash)
  352. #define SyHashCmpFunc(HASH) ((HASH)->xCmp)
  353. #define SyHashTotalEntry(HASH) ((HASH)->nEntry)
  354. #define SyHashGetPool(HASH) ((HASH)->pAllocator)
  355. /*
  356. * An instance of the following structure define a single context
  357. * for an Pseudo Random Number Generator.
  358. *
  359. * Nothing in this file or anywhere else in the library does any kind of
  360. * encryption. The RC4 algorithm is being used as a PRNG (pseudo-random
  361. * number generator) not as an encryption device.
  362. * This implementation is taken from the SQLite3 source tree.
  363. */
  364. typedef struct SyPRNGCtx SyPRNGCtx;
  365. struct SyPRNGCtx {
  366. sxu8 i, j; /* State variables */
  367. unsigned char s[256]; /* State variables */
  368. sxu16 nMagic; /* Sanity check */
  369. };
  370. typedef sxi32(*ProcRandomSeed)(void *, unsigned int, void *);
  371. /* High resolution timer.*/
  372. typedef struct sytime sytime;
  373. struct sytime {
  374. long tm_sec; /* seconds */
  375. long tm_usec; /* microseconds */
  376. };
  377. /* Forward declaration */
  378. typedef struct SyStream SyStream;
  379. typedef struct SyToken SyToken;
  380. typedef struct SyLex SyLex;
  381. /*
  382. * Tokenizer callback signature.
  383. */
  384. typedef sxi32(*ProcTokenizer)(SyStream *, SyToken *, void *, void *);
  385. /*
  386. * Each token in the input is represented by an instance
  387. * of the following structure.
  388. */
  389. struct SyToken {
  390. SyString sData; /* Token text and length */
  391. sxu32 nType; /* Token type */
  392. sxu32 nLine; /* Token line number */
  393. void *pUserData; /* User private data associated with this token */
  394. };
  395. /*
  396. * During tokenization, information about the state of the input
  397. * stream is held in an instance of the following structure.
  398. */
  399. struct SyStream {
  400. const unsigned char *zInput; /* Complete text of the input */
  401. const unsigned char *zText; /* Current input we are processing */
  402. const unsigned char *zEnd; /* End of input marker */
  403. sxu32 nLine; /* Total number of processed lines */
  404. sxu32 nIgn; /* Total number of ignored tokens */
  405. SySet *pSet; /* Token containers */
  406. };
  407. /*
  408. * Each lexer is represented by an instance of the following structure.
  409. */
  410. struct SyLex {
  411. SyStream sStream; /* Input stream */
  412. ProcTokenizer xTokenizer; /* Tokenizer callback */
  413. void *pUserData; /* Third argument to xTokenizer() */
  414. SySet *pTokenSet; /* Token set */
  415. };
  416. #define SyLexTotalToken(LEX) SySetTotalEntry(&(LEX)->aTokenSet)
  417. #define SyLexTotalLines(LEX) ((LEX)->sStream.nLine)
  418. #define SyLexTotalIgnored(LEX) ((LEX)->sStream.nIgn)
  419. #define XLEX_IN_LEN(STREAM) (sxu32)(STREAM->zEnd - STREAM->zText)
  420. #endif /* SYMISC_PRIVATE_AUX_DEFS */
  421. /*
  422. ** Notes on UTF-8 (According to SQLite3 authors):
  423. **
  424. ** Byte-0 Byte-1 Byte-2 Byte-3 Value
  425. ** 0xxxxxxx 00000000 00000000 0xxxxxxx
  426. ** 110yyyyy 10xxxxxx 00000000 00000yyy yyxxxxxx
  427. ** 1110zzzz 10yyyyyy 10xxxxxx 00000000 zzzzyyyy yyxxxxxx
  428. ** 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx 000uuuuu zzzzyyyy yyxxxxxx
  429. **
  430. */
  431. /*
  432. ** Assuming zIn points to the first byte of a UTF-8 character,
  433. ** advance zIn to point to the first byte of the next UTF-8 character.
  434. */
  435. #define SX_JMP_UTF8(zIn,zEnd)\
  436. while(zIn < zEnd && (((unsigned char)zIn[0] & 0xc0) == 0x80) ){ zIn++; }
  437. #define SX_WRITE_UTF8(zOut, c) { \
  438. if( c<0x00080 ){ \
  439. *zOut++ = (sxu8)(c&0xFF); \
  440. }else if( c<0x00800 ){ \
  441. *zOut++ = 0xC0 + (sxu8)((c>>6)&0x1F); \
  442. *zOut++ = 0x80 + (sxu8)(c & 0x3F); \
  443. }else if( c<0x10000 ){ \
  444. *zOut++ = 0xE0 + (sxu8)((c>>12)&0x0F); \
  445. *zOut++ = 0x80 + (sxu8)((c>>6) & 0x3F); \
  446. *zOut++ = 0x80 + (sxu8)(c & 0x3F); \
  447. }else{ \
  448. *zOut++ = 0xF0 + (sxu8)((c>>18) & 0x07); \
  449. *zOut++ = 0x80 + (sxu8)((c>>12) & 0x3F); \
  450. *zOut++ = 0x80 + (sxu8)((c>>6) & 0x3F); \
  451. *zOut++ = 0x80 + (sxu8)(c & 0x3F); \
  452. } \
  453. }
  454. /* Rely on the standard ctype */
  455. #include <ctype.h>
  456. #define SyToUpper(c) toupper(c)
  457. #define SyToLower(c) tolower(c)
  458. #define SyisUpper(c) isupper(c)
  459. #define SyisLower(c) islower(c)
  460. #define SyisSpace(c) isspace(c)
  461. #define SyisBlank(c) isspace(c)
  462. #define SyisAlpha(c) isalpha(c)
  463. #define SyisDigit(c) isdigit(c)
  464. #define SyisHex(c) isxdigit(c)
  465. #define SyisPrint(c) isprint(c)
  466. #define SyisPunct(c) ispunct(c)
  467. #define SyisSpec(c) iscntrl(c)
  468. #define SyisCtrl(c) iscntrl(c)
  469. #define SyisAscii(c) isascii(c)
  470. #define SyisAlphaNum(c) isalnum(c)
  471. #define SyisGraph(c) isgraph(c)
  472. #define SyDigToHex(c) "0123456789ABCDEF"[c & 0x0F]
  473. #define SyDigToInt(c) ((c < 0xc0 && SyisDigit(c))? (c - '0') : 0 )
  474. #define SyCharToUpper(c) ((c < 0xc0 && SyisLower(c))? SyToUpper(c) : c)
  475. #define SyCharToLower(c) ((c < 0xc0 && SyisUpper(c))? SyToLower(c) : c)
  476. /* Remove white space/NUL byte from a raw string */
  477. #define SyStringLeftTrim(RAW)\
  478. while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[0] < 0xc0 && SyisSpace((RAW)->zString[0])){\
  479. (RAW)->nByte--;\
  480. (RAW)->zString++;\
  481. }
  482. #define SyStringLeftTrimSafe(RAW)\
  483. while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[0] < 0xc0 && ((RAW)->zString[0] == 0 || SyisSpace((RAW)->zString[0]))){\
  484. (RAW)->nByte--;\
  485. (RAW)->zString++;\
  486. }
  487. #define SyStringRightTrim(RAW)\
  488. while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[(RAW)->nByte - 1] < 0xc0 && SyisSpace((RAW)->zString[(RAW)->nByte - 1])){\
  489. (RAW)->nByte--;\
  490. }
  491. #define SyStringRightTrimSafe(RAW)\
  492. while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[(RAW)->nByte - 1] < 0xc0 && \
  493. (( RAW)->zString[(RAW)->nByte - 1] == 0 || SyisSpace((RAW)->zString[(RAW)->nByte - 1]))){\
  494. (RAW)->nByte--;\
  495. }
  496. #define SyStringFullTrim(RAW)\
  497. while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[0] < 0xc0 && SyisSpace((RAW)->zString[0])){\
  498. (RAW)->nByte--;\
  499. (RAW)->zString++;\
  500. }\
  501. while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[(RAW)->nByte - 1] < 0xc0 && SyisSpace((RAW)->zString[(RAW)->nByte - 1])){\
  502. (RAW)->nByte--;\
  503. }
  504. #define SyStringFullTrimSafe(RAW)\
  505. while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[0] < 0xc0 && \
  506. ( (RAW)->zString[0] == 0 || SyisSpace((RAW)->zString[0]))){\
  507. (RAW)->nByte--;\
  508. (RAW)->zString++;\
  509. }\
  510. while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[(RAW)->nByte - 1] < 0xc0 && \
  511. ( (RAW)->zString[(RAW)->nByte - 1] == 0 || SyisSpace((RAW)->zString[(RAW)->nByte - 1]))){\
  512. (RAW)->nByte--;\
  513. }
  514. #ifndef PH7_DISABLE_BUILTIN_FUNC
  515. /*
  516. * An XML raw text,CDATA,tag name and son is parsed out and stored
  517. * in an instance of the following structure.
  518. */
  519. typedef struct SyXMLRawStr SyXMLRawStr;
  520. struct SyXMLRawStr {
  521. const char *zString; /* Raw text [UTF-8 ENCODED EXCEPT CDATA] [NOT NULL TERMINATED] */
  522. sxu32 nByte; /* Text length */
  523. sxu32 nLine; /* Line number this text occurs */
  524. };
  525. /*
  526. * Event callback signatures.
  527. */
  528. typedef sxi32(*ProcXMLStartTagHandler)(SyXMLRawStr *, SyXMLRawStr *, sxu32, SyXMLRawStr *, void *);
  529. typedef sxi32(*ProcXMLTextHandler)(SyXMLRawStr *, void *);
  530. typedef sxi32(*ProcXMLEndTagHandler)(SyXMLRawStr *, SyXMLRawStr *, void *);
  531. typedef sxi32(*ProcXMLPIHandler)(SyXMLRawStr *, SyXMLRawStr *, void *);
  532. typedef sxi32(*ProcXMLDoctypeHandler)(SyXMLRawStr *, void *);
  533. typedef sxi32(*ProcXMLSyntaxErrorHandler)(const char *, int, SyToken *, void *);
  534. typedef sxi32(*ProcXMLStartDocument)(void *);
  535. typedef sxi32(*ProcXMLNameSpaceStart)(SyXMLRawStr *, SyXMLRawStr *, void *);
  536. typedef sxi32(*ProcXMLNameSpaceEnd)(SyXMLRawStr *, void *);
  537. typedef sxi32(*ProcXMLEndDocument)(void *);
  538. /* XML processing control flags */
  539. #define SXML_ENABLE_NAMESPACE 0x01 /* Parse XML with namespace support enbaled */
  540. #define SXML_ENABLE_QUERY 0x02 /* Not used */
  541. #define SXML_OPTION_CASE_FOLDING 0x04 /* Controls whether case-folding is enabled for this XML parser */
  542. #define SXML_OPTION_SKIP_TAGSTART 0x08 /* Specify how many characters should be skipped in the beginning of a tag name.*/
  543. #define SXML_OPTION_SKIP_WHITE 0x10 /* Whether to skip values consisting of whitespace characters. */
  544. #define SXML_OPTION_TARGET_ENCODING 0x20 /* Default encoding: UTF-8 */
  545. /* XML error codes */
  546. enum xml_err_code {
  547. SXML_ERROR_NONE = 1,
  548. SXML_ERROR_NO_MEMORY,
  549. SXML_ERROR_SYNTAX,
  550. SXML_ERROR_NO_ELEMENTS,
  551. SXML_ERROR_INVALID_TOKEN,
  552. SXML_ERROR_UNCLOSED_TOKEN,
  553. SXML_ERROR_PARTIAL_CHAR,
  554. SXML_ERROR_TAG_MISMATCH,
  555. SXML_ERROR_DUPLICATE_ATTRIBUTE,
  556. SXML_ERROR_JUNK_AFTER_DOC_ELEMENT,
  557. SXML_ERROR_PARAM_ENTITY_REF,
  558. SXML_ERROR_UNDEFINED_ENTITY,
  559. SXML_ERROR_RECURSIVE_ENTITY_REF,
  560. SXML_ERROR_ASYNC_ENTITY,
  561. SXML_ERROR_BAD_CHAR_REF,
  562. SXML_ERROR_BINARY_ENTITY_REF,
  563. SXML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
  564. SXML_ERROR_MISPLACED_XML_PI,
  565. SXML_ERROR_UNKNOWN_ENCODING,
  566. SXML_ERROR_INCORRECT_ENCODING,
  567. SXML_ERROR_UNCLOSED_CDATA_SECTION,
  568. SXML_ERROR_EXTERNAL_ENTITY_HANDLING
  569. };
  570. /* Each active XML SAX parser is represented by an instance
  571. * of the following structure.
  572. */
  573. typedef struct SyXMLParser SyXMLParser;
  574. struct SyXMLParser {
  575. SyMemBackend *pAllocator; /* Memory backend */
  576. void *pUserData; /* User private data forwarded varbatim by the XML parser
  577. * as the last argument to the users callbacks.
  578. */
  579. SyHash hns; /* Namespace hashtable */
  580. SySet sToken; /* XML tokens */
  581. SyLex sLex; /* Lexical analyzer */
  582. sxi32 nFlags; /* Control flags */
  583. /* User callbacks */
  584. ProcXMLStartTagHandler xStartTag; /* Start element handler */
  585. ProcXMLEndTagHandler xEndTag; /* End element handler */
  586. ProcXMLTextHandler xRaw; /* Raw text/CDATA handler */
  587. ProcXMLDoctypeHandler xDoctype; /* DOCTYPE handler */
  588. ProcXMLPIHandler xPi; /* Processing instruction (PI) handler*/
  589. ProcXMLSyntaxErrorHandler xError; /* Error handler */
  590. ProcXMLStartDocument xStartDoc; /* StartDoc handler */
  591. ProcXMLEndDocument xEndDoc; /* EndDoc handler */
  592. ProcXMLNameSpaceStart xNameSpace; /* Namespace declaration handler */
  593. ProcXMLNameSpaceEnd xNameSpaceEnd; /* End namespace declaration handler */
  594. };
  595. /*
  596. * --------------
  597. * Archive extractor:
  598. * --------------
  599. * Each open ZIP/TAR archive is identified by an instance of the following structure.
  600. * That is, a process can open one or more archives and manipulates them in thread safe
  601. * way by simply working with pointers to the following structure.
  602. * Each entry in the archive is remembered in a hashtable.
  603. * Lookup is very fast and entry with the same name are chained together.
  604. */
  605. typedef struct SyArchiveEntry SyArchiveEntry;
  606. typedef struct SyArchive SyArchive;
  607. struct SyArchive {
  608. SyMemBackend *pAllocator; /* Memory backend */
  609. SyArchiveEntry *pCursor; /* Cursor for linear traversal of archive entries */
  610. SyArchiveEntry *pList; /* Pointer to the List of the loaded archive */
  611. SyArchiveEntry **apHash; /* Hashtable for archive entry */
  612. ProcRawStrCmp xCmp; /* Hash comparison function */
  613. ProcHash xHash; /* Hash Function */
  614. sxu32 nSize; /* Hashtable size */
  615. sxu32 nEntry; /* Total number of entries in the zip/tar archive */
  616. sxu32 nLoaded; /* Total number of entries loaded in memory */
  617. sxu32 nCentralOfft; /* Central directory offset(ZIP only. Otherwise Zero) */
  618. sxu32 nCentralSize; /* Central directory size(ZIP only. Otherwise Zero) */
  619. void *pUserData; /* Upper layer private data */
  620. sxu32 nMagic; /* Sanity check */
  621. };
  622. #define SXARCH_MAGIC 0xDEAD635A
  623. #define SXARCH_INVALID(ARCH) (ARCH == 0 || ARCH->nMagic != SXARCH_MAGIC)
  624. #define SXARCH_ENTRY_INVALID(ENTRY) (ENTRY == 0 || ENTRY->nMagic != SXARCH_MAGIC)
  625. #define SyArchiveHashFunc(ARCH) (ARCH)->xHash
  626. #define SyArchiveCmpFunc(ARCH) (ARCH)->xCmp
  627. #define SyArchiveUserData(ARCH) (ARCH)->pUserData
  628. #define SyArchiveSetUserData(ARCH,DATA) (ARCH)->pUserData = DATA
  629. /*
  630. * Each loaded archive record is identified by an instance
  631. * of the following structure.
  632. */
  633. struct SyArchiveEntry {
  634. sxu32 nByte; /* Contents size before compression */
  635. sxu32 nByteCompr; /* Contents size after compression */
  636. sxu32 nReadCount; /* Read counter */
  637. sxu32 nCrc; /* Contents CRC32 */
  638. Sytm sFmt; /* Last-modification time */
  639. sxu32 nOfft; /* Data offset. */
  640. sxu16 nComprMeth; /* Compression method 0 == stored/8 == deflated and so on (see appnote.txt)*/
  641. sxu16 nExtra; /* Extra size if any */
  642. SyString sFileName; /* entry name & length */
  643. sxu32 nDup; /* Total number of entries with the same name */
  644. SyArchiveEntry *pNextHash, *pPrevHash; /* Hash collision chains */
  645. SyArchiveEntry *pNextName; /* Next entry with the same name */
  646. SyArchiveEntry *pNext, *pPrev; /* Next and previous entry in the list */
  647. sxu32 nHash; /* Hash of the entry name */
  648. void *pUserData; /* User data */
  649. sxu32 nMagic; /* Sanity check */
  650. };
  651. /*
  652. * Extra flags for extending the file local header
  653. */
  654. #define SXZIP_EXTRA_TIMESTAMP 0x001 /* Extended UNIX timestamp */
  655. #endif /* PH7_DISABLE_BUILTIN_FUNC */
  656. #ifndef PH7_DISABLE_HASH_FUNC
  657. /* MD5 context */
  658. typedef struct MD5Context MD5Context;
  659. struct MD5Context {
  660. sxu32 buf[4];
  661. sxu32 bits[2];
  662. unsigned char in[64];
  663. };
  664. /* SHA1 context */
  665. typedef struct SHA1Context SHA1Context;
  666. struct SHA1Context {
  667. unsigned int state[5];
  668. unsigned int count[2];
  669. unsigned char buffer[64];
  670. };
  671. #endif /* PH7_DISABLE_HASH_FUNC */
  672. /* PH7 private declaration */
  673. /*
  674. * Memory Objects.
  675. * Internally, the PH7 virtual machine manipulates nearly all PHP values
  676. * [i.e: string, int, float, resource, object, bool, null] as ph7_values structures.
  677. * Each ph7_values struct may cache multiple representations (string, integer etc.)
  678. * of the same value.
  679. */
  680. struct ph7_value {
  681. ph7_real rVal; /* Real value */
  682. union {
  683. sxi64 iVal; /* Integer value */
  684. void *pOther; /* Other values (Object, Array, Resource, Namespace, etc.) */
  685. } x;
  686. sxi32 iFlags; /* Control flags (see below) */
  687. ph7_vm *pVm; /* Virtual machine that own this instance */
  688. SyBlob sBlob; /* String values */
  689. sxu32 nIdx; /* Index number of this entry in the global object allocator */
  690. };
  691. /* Allowed value types.
  692. */
  693. #define MEMOBJ_STRING 0x001 /* Memory value is a UTF-8 string */
  694. #define MEMOBJ_INT 0x002 /* Memory value is an integer */
  695. #define MEMOBJ_REAL 0x004 /* Memory value is a real number */
  696. #define MEMOBJ_BOOL 0x008 /* Memory value is a boolean */
  697. #define MEMOBJ_NULL 0x020 /* Memory value is NULL */
  698. #define MEMOBJ_HASHMAP 0x040 /* Memory value is a hashmap aka 'array' in the PHP jargon */
  699. #define MEMOBJ_OBJ 0x080 /* Memory value is an object [i.e: class instance] */
  700. #define MEMOBJ_RES 0x100 /* Memory value is a resource [User private data] */
  701. #define MEMOBJ_REFERENCE 0x400 /* Memory value hold a reference (64-bit index) of another ph7_value */
  702. /* Mask of all known types */
  703. #define MEMOBJ_ALL (MEMOBJ_STRING|MEMOBJ_INT|MEMOBJ_REAL|MEMOBJ_BOOL|MEMOBJ_NULL|MEMOBJ_HASHMAP|MEMOBJ_OBJ|MEMOBJ_RES)
  704. /* Scalar variables
  705. * According to the PHP language reference manual
  706. * Scalar variables are those containing an integer, float, string or boolean.
  707. * Types array, object and resource are not scalar.
  708. */
  709. #define MEMOBJ_SCALAR (MEMOBJ_STRING|MEMOBJ_INT|MEMOBJ_REAL|MEMOBJ_BOOL|MEMOBJ_NULL)
  710. #define MEMOBJ_AUX (MEMOBJ_REFERENCE)
  711. /*
  712. * The following macro clear the current ph7_value type and replace
  713. * it with the given one.
  714. */
  715. #define MemObjSetType(OBJ,TYPE) ((OBJ)->iFlags = ((OBJ)->iFlags&~MEMOBJ_ALL)|TYPE)
  716. /* ph7_value cast method signature */
  717. typedef sxi32(*ProcMemObjCast)(ph7_value *);
  718. /* Forward reference */
  719. typedef struct ph7_output_consumer ph7_output_consumer;
  720. typedef struct ph7_user_func ph7_user_func;
  721. typedef struct ph7_conf ph7_conf;
  722. /*
  723. * An instance of the following structure store the default VM output
  724. * consumer and it's private data.
  725. * Client-programs can register their own output consumer callback
  726. * via the [PH7_VM_CONFIG_OUTPUT] configuration directive.
  727. * Please refer to the official documentation for more information
  728. * on how to register an output consumer callback.
  729. */
  730. struct ph7_output_consumer {
  731. ProcConsumer xConsumer; /* VM output consumer routine */
  732. void *pUserData; /* Third argument to xConsumer() */
  733. ProcConsumer xDef; /* Default output consumer routine */
  734. void *pDefData; /* Third argument to xDef() */
  735. };
  736. /*
  737. * PH7 engine [i.e: ph7 instance] configuration is stored in
  738. * an instance of the following structure.
  739. * Please refer to the official documentation for more information
  740. * on how to configure your ph7 engine instance.
  741. */
  742. struct ph7_conf {
  743. ProcConsumer xErr; /* Compile-time error consumer callback */
  744. void *pErrData; /* Third argument to xErr() */
  745. SyBlob sErrConsumer; /* Default error consumer */
  746. };
  747. /*
  748. * Signature of the C function responsible of expanding constant values.
  749. */
  750. typedef void (*ProcConstant)(ph7_value *, void *);
  751. /*
  752. * Each registered constant [i.e: __TIME__, __DATE__, PHP_OS, INT_MAX, etc.] is stored
  753. * in an instance of the following structure.
  754. * Please refer to the official documentation for more information
  755. * on how to create/install foreign constants.
  756. */
  757. typedef struct ph7_constant ph7_constant;
  758. struct ph7_constant {
  759. SyString sName; /* Constant name */
  760. ProcConstant xExpand; /* Function responsible of expanding constant value */
  761. void *pUserData; /* Last argument to xExpand() */
  762. };
  763. typedef struct ph7_aux_data ph7_aux_data;
  764. /*
  765. * Auxiliary data associated with each foreign function is stored
  766. * in a stack of the following structure.
  767. * Note that automatic tracked chunks are also stored in an instance
  768. * of this structure.
  769. */
  770. struct ph7_aux_data {
  771. void *pAuxData; /* Aux data */
  772. };
  773. /* Foreign functions signature */
  774. typedef int (*ProchHostFunction)(ph7_context *, int, ph7_value **);
  775. /*
  776. * Each installed foreign function is recored in an instance of the following
  777. * structure.
  778. * Please refer to the official documentation for more information on how
  779. * to create/install foreign functions.
  780. */
  781. struct ph7_user_func {
  782. ph7_vm *pVm; /* VM that own this instance */
  783. SyString sName; /* Foreign function name */
  784. ProchHostFunction xFunc; /* Implementation of the foreign function */
  785. void *pUserData; /* User private data [Refer to the official documentation for more information]*/
  786. SySet aAux; /* Stack of auxiliary data [Refer to the official documentation for more information]*/
  787. };
  788. /*
  789. * The 'context' argument for an installable function. A pointer to an
  790. * instance of this structure is the first argument to the routines used
  791. * implement the foreign functions.
  792. */
  793. struct ph7_context {
  794. ph7_user_func *pFunc; /* Function information. */
  795. ph7_value *pRet; /* Return value is stored here. */
  796. SySet sVar; /* Container of dynamically allocated ph7_values
  797. * [i.e: Garbage collection purposes.]
  798. */
  799. SySet sChunk; /* Track dynamically allocated chunks [ph7_aux_data instance].
  800. * [i.e: Garbage collection purposes.]
  801. */
  802. ph7_vm *pVm; /* Virtual machine that own this context */
  803. sxi32 iFlags; /* Call flags */
  804. };
  805. /*
  806. * Each hashmap entry [i.e: array(4,5,6)] is recorded in an instance
  807. * of the following structure.
  808. */
  809. struct ph7_hashmap_node {
  810. ph7_hashmap *pMap; /* Hashmap that own this instance */
  811. sxi32 iType; /* Node type */
  812. union {
  813. sxi64 iKey; /* Int key */
  814. SyBlob sKey; /* Blob key */
  815. } xKey;
  816. sxi32 iFlags; /* Control flags */
  817. sxu32 nHash; /* Key hash value */
  818. sxu32 nValIdx; /* Value stored in this node */
  819. ph7_hashmap_node *pNext, *pPrev; /* Link to other entries [i.e: linear traversal] */
  820. ph7_hashmap_node *pNextCollide, *pPrevCollide; /* Collision chain */
  821. };
  822. /*
  823. * Each active hashmap aka array in the PHP jargon is represented
  824. * by an instance of the following structure.
  825. */
  826. struct ph7_hashmap {
  827. ph7_vm *pVm; /* VM that own this instance */
  828. ph7_hashmap_node **apBucket; /* Hash bucket */
  829. ph7_hashmap_node *pFirst; /* First inserted entry */
  830. ph7_hashmap_node *pLast; /* Last inserted entry */
  831. ph7_hashmap_node *pCur; /* Current entry */
  832. sxu32 nSize; /* Bucket size */
  833. sxu32 nEntry; /* Total number of inserted entries */
  834. sxu32(*xIntHash)(sxi64); /* Hash function for int_keys */
  835. sxu32(*xBlobHash)(const void *, sxu32); /* Hash function for blob_keys */
  836. sxi64 iNextIdx; /* Next available automatically assigned index */
  837. sxi32 iRef; /* Reference count */
  838. };
  839. /* An instance of the following structure is the context
  840. * for the FOREACH_STEP/FOREACH_INIT VM instructions.
  841. * Those instructions are used to implement the 'foreach'
  842. * statement.
  843. * This structure is made available to these instructions
  844. * as the P3 operand.
  845. */
  846. struct ph7_foreach_info {
  847. SyString sKey; /* Key name. Empty otherwise*/
  848. SyString sValue; /* Value name */
  849. sxi32 iFlags; /* Control flags */
  850. SySet aStep; /* Stack of steps [i.e: ph7_foreach_step instance] */
  851. };
  852. struct ph7_foreach_step {
  853. sxi32 iFlags; /* Control flags (see below) */
  854. /* Iterate on those values */
  855. union {
  856. ph7_hashmap *pMap; /* Hashmap [i.e: array in the PHP jargon] iteration
  857. * Ex: foreach(array(1,2,3) as $key=>$value){}
  858. */
  859. ph7_class_instance *pThis; /* Class instance [i.e: object] iteration */
  860. } xIter;
  861. };
  862. /* Foreach step control flags */
  863. #define PH7_4EACH_STEP_HASHMAP 0x001 /* Hashmap iteration */
  864. #define PH7_4EACH_STEP_OBJECT 0x002 /* Object iteration */
  865. #define PH7_4EACH_STEP_KEY 0x004 /* Make Key available */
  866. #define PH7_4EACH_STEP_REF 0x008 /* Pass value by reference not copy */
  867. /*
  868. * Each PH7 engine is identified by an instance of the following structure.
  869. * Please refer to the official documentation for more information
  870. * on how to configure your PH7 engine instance.
  871. */
  872. struct ph7 {
  873. SyMemBackend sAllocator; /* Low level memory allocation subsystem */
  874. const ph7_vfs *pVfs; /* Underlying Virtual File System */
  875. ph7_conf xConf; /* Configuration */
  876. #if defined(PH7_ENABLE_THREADS)
  877. const SyMutexMethods *pMethods; /* Mutex methods */
  878. SyMutex *pMutex; /* Per-engine mutex */
  879. #endif
  880. ph7_vm *pVms; /* List of active VM */
  881. sxi32 iVm; /* Total number of active VM */
  882. ph7 *pNext, *pPrev; /* List of active engines */
  883. sxu32 nMagic; /* Sanity check against misuse */
  884. };
  885. /* Code generation data structures */
  886. typedef sxi32(*ProcErrorGen)(void *, sxi32, sxu32, const char *, ...);
  887. typedef struct ph7_expr_node ph7_expr_node;
  888. typedef struct ph7_expr_op ph7_expr_op;
  889. typedef struct ph7_gen_state ph7_gen_state;
  890. typedef struct GenBlock GenBlock;
  891. typedef sxi32(*ProcLangConstruct)(ph7_gen_state *);
  892. typedef sxi32(*ProcNodeConstruct)(ph7_gen_state *, sxi32);
  893. /*
  894. * Each supported operator [i.e: +, -, ==, *, %, >>, >=, new, etc.] is represented
  895. * by an instance of the following structure.
  896. * The PH7 parser does not use any external tools and is 100% handcoded.
  897. * That is, the PH7 parser is thread-safe ,full reentrant, produce consistant
  898. * compile-time errrors and at least 7 times faster than the standard PHP parser.
  899. */
  900. struct ph7_expr_op {
  901. SyString sOp; /* String representation of the operator [i.e: "+","*","=="...] */
  902. sxi32 iOp; /* Operator ID */
  903. sxi32 iPrec; /* Operator precedence: 1 == Highest */
  904. sxi32 iAssoc; /* Operator associativity (either left,right or non-associative) */
  905. sxi32 iVmOp; /* VM OP code for this operator [i.e: PH7_OP_EQ,PH7_OP_LT,PH7_OP_MUL...]*/
  906. };
  907. /*
  908. * Each expression node is parsed out and recorded
  909. * in an instance of the following structure.
  910. */
  911. struct ph7_expr_node {
  912. const ph7_expr_op *pOp; /* Operator ID or NULL if literal, constant, variable, function or class method call */
  913. ph7_expr_node *pLeft; /* Left expression tree */
  914. ph7_expr_node *pRight; /* Right expression tree */
  915. SyToken *pStart; /* Stream of tokens that belong to this node */
  916. SyToken *pEnd; /* End of token stream */
  917. sxi32 iFlags; /* Node construct flags */
  918. ProcNodeConstruct xCode; /* C routine responsible of compiling this node */
  919. SySet aNodeArgs; /* Node arguments. Only used by postfix operators [i.e: function call]*/
  920. ph7_expr_node *pCond; /* Condition: Only used by the ternary operator '?:' */
  921. };
  922. /* Node Construct flags */
  923. #define EXPR_NODE_PRE_INCR 0x01 /* Pre-icrement/decrement [i.e: ++$i,--$j] node */
  924. /*
  925. * A block of instructions is recorded in an instance of the following structure.
  926. * This structure is used only during compile-time and have no meaning
  927. * during bytecode execution.
  928. */
  929. struct GenBlock {
  930. ph7_gen_state *pGen; /* State of the code generator */
  931. GenBlock *pParent; /* Upper block or NULL if global */
  932. sxu32 nFirstInstr; /* First instruction to execute */
  933. sxi32 iFlags; /* Block control flags (see below) */
  934. SySet aJumpFix; /* Jump fixup (JumpFixup instance) */
  935. void *pUserData; /* Upper layer private data */
  936. /* The following two fields are used only when compiling
  937. * the 'do..while()' language construct.
  938. */
  939. sxu8 bPostContinue; /* TRUE when compiling the do..while() statement */
  940. SySet aPostContFix; /* Post-continue jump fix */
  941. };
  942. /*
  943. * Code generator state is remembered in an instance of the following
  944. * structure. We put the information in this structure and pass around
  945. * a pointer to this structure, rather than pass around all of the
  946. * information separately. This helps reduce the number of arguments
  947. * to generator functions.
  948. * This structure is used only during compile-time and have no meaning
  949. * during bytecode execution.
  950. */
  951. struct ph7_gen_state {
  952. ph7_vm *pVm; /* VM that own this instance */
  953. SyHash hLiteral; /* Constant string Literals table */
  954. SyHash hNumLiteral; /* Numeric literals table */
  955. SyHash hVar; /* Collected variable hashtable */
  956. GenBlock *pCurrent; /* Current processed block */
  957. GenBlock sGlobal; /* Global block */
  958. ProcConsumer xErr; /* Error consumer callback */
  959. void *pErrData; /* Third argument to xErr() */
  960. SyBlob sWorker; /* General purpose working buffer */
  961. SyBlob sErrBuf; /* Error buffer */
  962. SyToken *pIn; /* Current processed token */
  963. SyToken *pEnd; /* Last token in the stream */
  964. sxu32 nErr; /* Total number of compilation error */
  965. SyToken *pRawIn; /* Current processed raw token */
  966. SyToken *pRawEnd; /* Last raw token in the stream */
  967. SySet *pTokenSet; /* Token containers */
  968. };
  969. /* Forward references */
  970. typedef struct ph7_vm_func_closure_env ph7_vm_func_closure_env;
  971. typedef struct ph7_vm_func_static_var ph7_vm_func_static_var;
  972. typedef struct ph7_vm_func_arg ph7_vm_func_arg;
  973. typedef struct ph7_vm_func ph7_vm_func;
  974. typedef struct VmFrame VmFrame;
  975. /*
  976. * Each collected function argument is recorded in an instance
  977. * of the following structure.
  978. * Note that as an extension, PH7 implements full type hinting
  979. * which mean that any function can have it's own signature.
  980. * Example:
  981. * function foo(int $a,string $b,float $c,ClassInstance $d){}
  982. * This is how the powerful function overloading mechanism is
  983. * implemented.
  984. * Note that as an extension, PH7 allow function arguments to have
  985. * any complex default value associated with them unlike the standard
  986. * PHP engine.
  987. * Example:
  988. * function foo(int $a = rand() & 1023){}
  989. * now, when foo is called without arguments [i.e: foo()] the
  990. * $a variable (first parameter) will be set to a random number
  991. * between 0 and 1023 inclusive.
  992. * Refer to the official documentation for more information on this
  993. * mechanism and other extension introduced by the PH7 engine.
  994. */
  995. struct ph7_vm_func_arg {
  996. SyString sName; /* Argument name */
  997. SySet aByteCode; /* Compiled default value associated with this argument */
  998. sxu32 nType; /* Type of this argument [i.e: array, int, string, float, object, etc.] */
  999. SyString sClass; /* Class name if the argument expect a class instance [i.e: function foo(BaseClass $bar){} ] */
  1000. sxi32 iFlags; /* Configuration flags */
  1001. };
  1002. /*
  1003. * Each static variable is parsed out and remembered in an instance
  1004. * of the following structure.
  1005. * Note that as an extension, PH7 allow static variable have
  1006. * any complex default value associated with them unlike the standard
  1007. * PHP engine.
  1008. * Example:
  1009. * static $rand_str = 'PH7'.rand_str(3); // Concatenate 'PH7' with
  1010. * // a random three characters(English alphabet)
  1011. * var_dump($rand_str);
  1012. * //You should see something like this
  1013. * string(6 'PH7awt');
  1014. */
  1015. struct ph7_vm_func_static_var {
  1016. SyString sName; /* Static variable name */
  1017. SySet aByteCode; /* Compiled initialization expression */
  1018. sxu32 nIdx; /* Object index in the global memory object container */
  1019. };
  1020. /*
  1021. * Each imported variable from the outside closure environnment is recoded
  1022. * in an instance of the following structure.
  1023. */
  1024. struct ph7_vm_func_closure_env {
  1025. SyString sName; /* Imported variable name */
  1026. int iFlags; /* Control flags */
  1027. ph7_value sValue; /* Imported variable value */
  1028. sxu32 nIdx; /* Reference to the bounded variable if passed by reference
  1029. *[Example:
  1030. * $x = 1;
  1031. * $closure = function() use (&$x) { ++$x; }
  1032. * $closure();
  1033. *]
  1034. */
  1035. };
  1036. /* Function configuration flags */
  1037. #define VM_FUNC_ARG_BY_REF 0x001 /* Argument passed by reference */
  1038. #define VM_FUNC_ARG_HAS_DEF 0x002 /* Argument has default value associated with it */
  1039. #define VM_FUNC_REF_RETURN 0x004 /* Return by reference */
  1040. #define VM_FUNC_CLASS_METHOD 0x008 /* VM function is in fact a class method */
  1041. #define VM_FUNC_CLOSURE 0x010 /* VM function is a closure */
  1042. #define VM_FUNC_ARG_IGNORE 0x020 /* Do not install argument in the current frame */
  1043. /*
  1044. * Each user defined function is parsed out and stored in an instance
  1045. * of the following structure.
  1046. * PH7 introduced some powerfull extensions to the PHP 5 programming
  1047. * language like function overloading, type hinting, complex default
  1048. * arguments values and many more.
  1049. * Please refer to the official documentation for more information.
  1050. */
  1051. struct ph7_vm_func {
  1052. SySet aArgs; /* Expected arguments (ph7_vm_func_arg instance) */
  1053. SySet aStatic; /* Static variable (ph7_vm_func_static_var instance) */
  1054. SyString sName; /* Function name */
  1055. SySet aByteCode; /* Compiled function body */
  1056. SySet aClosureEnv; /* Closure environment (ph7_vm_func_closure_env instace) */
  1057. sxi32 iFlags; /* VM function configuration */
  1058. SyString sSignature; /* Function signature used to implement function overloading
  1059. * (Refer to the official docuemntation for more information
  1060. * on this powerfull feature)
  1061. */
  1062. void *pUserData; /* Upper layer private data associated with this instance */
  1063. ph7_vm_func *pNextName; /* Next VM function with the same name as this one */
  1064. };
  1065. /* Forward reference */
  1066. typedef struct ph7_builtin_constant ph7_builtin_constant;
  1067. typedef struct ph7_builtin_func ph7_builtin_func;
  1068. /*
  1069. * Each built-in foreign function (C function) is stored in an
  1070. * instance of the following structure.
  1071. * Please refer to the official documentation for more information
  1072. * on how to create/install foreign functions.
  1073. */
  1074. struct ph7_builtin_func {
  1075. const char *zName; /* Function name [i.e: strlen(), rand(), array_merge(), etc.]*/
  1076. ProchHostFunction xFunc; /* C routine performing the computation */
  1077. };
  1078. /*
  1079. * Each built-in foreign constant is stored in an instance
  1080. * of the following structure.
  1081. * Please refer to the official documentation for more information
  1082. * on how to create/install foreign constants.
  1083. */
  1084. struct ph7_builtin_constant {
  1085. const char *zName; /* Constant name */
  1086. ProcConstant xExpand; /* C routine responsible of expanding constant value*/
  1087. };
  1088. /* Forward reference */
  1089. typedef struct ph7_class_method ph7_class_method;
  1090. typedef struct ph7_class_attr ph7_class_attr;
  1091. /*
  1092. * Each class is parsed out and stored in an instance of the following structure.
  1093. * PH7 introduced powerfull extensions to the PHP 5 OO subsystems.
  1094. * Please refer to the official documentation for more information.
  1095. */
  1096. struct ph7_class {
  1097. ph7_class *pBase; /* Base class if any */
  1098. SyHash hDerived; /* Derived [child] classes */
  1099. SyString sName; /* Class full qualified name */
  1100. sxi32 iFlags; /* Class configuration flags [i.e: final, interface, abstract, etc.] */
  1101. SyHash hAttr; /* Class attributes [i.e: variables and constants] */
  1102. SyHash hMethod; /* Class methods */
  1103. sxu32 nLine; /* Line number on which this class was declared */
  1104. SySet aInterface; /* Implemented interface container */
  1105. ph7_class *pNextName; /* Next class [interface, abstract, etc.] with the same name */
  1106. };
  1107. /* Class configuration flags */
  1108. #define PH7_CLASS_FINAL 0x001 /* Class is final [cannot be extended] */
  1109. #define PH7_CLASS_INTERFACE 0x002 /* Class is interface */
  1110. #define PH7_CLASS_ABSTRACT 0x004 /* Class is abstract */
  1111. /* Class attribute/methods/constants protection levels */
  1112. #define PH7_CLASS_PROT_PUBLIC 1 /* public */
  1113. #define PH7_CLASS_PROT_PROTECTED 2 /* protected */
  1114. #define PH7_CLASS_PROT_PRIVATE 3 /* private */
  1115. /*
  1116. * each class attribute (variable, constants) is parsed out and stored
  1117. * in an instance of the following structure.
  1118. */
  1119. struct ph7_class_attr {
  1120. SyString sName; /* Atrribute name */
  1121. sxi32 iFlags; /* Attribute configuration [i.e: static, variable, constant, etc.] */
  1122. sxi32 iProtection; /* Protection level [i.e: public, private, protected] */
  1123. SySet aByteCode; /* Compiled attribute body */
  1124. sxu32 nIdx; /* Attribute index */
  1125. sxu32 nLine; /* Line number on which this attribute was defined */
  1126. };
  1127. /* Attribute configuration */
  1128. #define PH7_CLASS_ATTR_STATIC 0x001 /* Static attribute */
  1129. #define PH7_CLASS_ATTR_CONSTANT 0x002 /* Constant attribute */
  1130. #define PH7_CLASS_ATTR_ABSTRACT 0x004 /* Abstract method */
  1131. #define PH7_CLASS_ATTR_FINAL 0x008 /* Final method */
  1132. /*
  1133. * Each class method is parsed out and stored in an instance of the following
  1134. * structure.
  1135. * PH7 introduced some powerfull extensions to the PHP 5 programming
  1136. * language like function overloading,type hinting,complex default
  1137. * arguments and many more.
  1138. * Please refer to the official documentation for more information.
  1139. */
  1140. struct ph7_class_method {
  1141. ph7_vm_func sFunc; /* Compiled method body */
  1142. SyString sVmName; /* Automatically generated name assigned to this method.
  1143. * Typically this is "[class_name__method_name@random_string]"
  1144. */
  1145. sxi32 iProtection; /* Protection level [i.e: public,private,protected] */
  1146. sxi32 iFlags; /* Methods configuration */
  1147. sxi32 iCloneDepth; /* Clone depth [Only used by the magic method __clone ] */
  1148. sxu32 nLine; /* Line on which this method was defined */
  1149. };
  1150. /*
  1151. * Each active object (class instance) is represented by an instance of
  1152. * the following structure.
  1153. */
  1154. struct ph7_class_instance {
  1155. ph7_vm *pVm; /* VM that own this instance */
  1156. ph7_class *pClass; /* Object is an instance of this class */
  1157. SyHash hAttr; /* Hashtable of active class members */
  1158. sxi32 iRef; /* Reference count */
  1159. sxi32 iFlags; /* Control flags */
  1160. };
  1161. /*
  1162. * A single instruction of the virtual machine has an opcode
  1163. * and as many as three operands.
  1164. * Each VM instruction resulting from compiling a PHP script
  1165. * is stored in an instance of the following structure.
  1166. */
  1167. typedef struct VmInstr VmInstr;
  1168. struct VmInstr {
  1169. sxu8 iOp; /* Operation to preform */
  1170. sxi32 iP1; /* First operand */
  1171. sxu32 iP2; /* Second operand (Often the jump destination) */
  1172. void *p3; /* Third operand (Often Upper layer private data) */
  1173. };
  1174. /* Each active class instance attribute is represented by an instance
  1175. * of the following structure.
  1176. */
  1177. typedef struct VmClassAttr VmClassAttr;
  1178. struct VmClassAttr {
  1179. ph7_class_attr *pAttr; /* Class attribute */
  1180. sxu32 nIdx; /* Memory object index */
  1181. };
  1182. /* Forward reference */
  1183. typedef struct VmRefObj VmRefObj;
  1184. /*
  1185. * Each catch [i.e catch(Exception $e){ } ] block is parsed out and stored
  1186. * in an instance of the following structure.
  1187. */
  1188. typedef struct ph7_exception_block ph7_exception_block;
  1189. typedef struct ph7_exception ph7_exception;
  1190. struct ph7_exception_block {
  1191. SyString sClass; /* Exception class name [i.e: Exception,MyException...] */
  1192. SyString sThis; /* Instance name [i.e: $e..] */
  1193. SySet sByteCode; /* Block compiled instructions */
  1194. };
  1195. /*
  1196. * Context for the exception mechanism.
  1197. */
  1198. struct ph7_exception {
  1199. ph7_vm *pVm; /* VM that own this exception */
  1200. SySet sEntry; /* Compiled 'catch' blocks (ph7_exception_block instance)
  1201. * container.
  1202. */
  1203. VmFrame *pFrame; /* Frame that trigger the exception */
  1204. };
  1205. /* Forward reference */
  1206. typedef struct ph7_case_expr ph7_case_expr;
  1207. typedef struct ph7_switch ph7_switch;
  1208. /*
  1209. * Each compiled case block in a swicth statement is compiled
  1210. * and stored in an instance of the following structure.
  1211. */
  1212. struct ph7_case_expr {
  1213. SySet aByteCode; /* Compiled body of the case block */
  1214. sxu32 nStart; /* First instruction to execute */
  1215. };
  1216. /*
  1217. * Each compiled switch statement is parsed out and stored
  1218. * in an instance of the following structure.
  1219. */
  1220. struct ph7_switch {
  1221. SySet aCaseExpr; /* Compile case block */
  1222. sxu32 nOut; /* First instruction to execute after this statement */
  1223. sxu32 nDefault; /* First instruction to execute in the default block */
  1224. };
  1225. /* Assertion flags */
  1226. #define PH7_ASSERT_DISABLE 0x01 /* Disable assertion */
  1227. #define PH7_ASSERT_WARNING 0x02 /* Issue a warning for each failed assertion */
  1228. #define PH7_ASSERT_BAIL 0x04 /* Terminate execution on failed assertions */
  1229. #define PH7_ASSERT_QUIET_EVAL 0x08 /* Not used */
  1230. #define PH7_ASSERT_CALLBACK 0x10 /* Callback to call on failed assertions */
  1231. /*
  1232. * error_log() consumer function signature.
  1233. * Refer to the [PH7_VM_CONFIG_ERR_LOG_HANDLER] configuration directive
  1234. * for more information on how to register an error_log consumer().
  1235. */
  1236. typedef void (*ProcErrLog)(const char *, int, const char *, const char *);
  1237. /*
  1238. * An instance of the following structure hold the bytecode instructions
  1239. * resulting from compiling a PHP script.
  1240. * This structure contains the complete state of the virtual machine.
  1241. */
  1242. struct ph7_vm {
  1243. SyMemBackend sAllocator; /* Memory backend */
  1244. #if defined(PH7_ENABLE_THREADS)
  1245. SyMutex *pMutex; /* Recursive mutex associated with VM. */
  1246. #endif
  1247. ph7 *pEngine; /* Interpreter that own this VM */
  1248. SySet aByteCode; /* Default bytecode container */
  1249. SySet *pByteContainer; /* Current bytecode container */
  1250. VmFrame *pFrame; /* Stack of active frames */
  1251. SyPRNGCtx sPrng; /* PRNG context */
  1252. SySet aMemObj; /* Object allocation table */
  1253. SySet aLitObj; /* Literals allocation table */
  1254. ph7_value *aOps; /* Operand stack */
  1255. SySet aFreeObj; /* Stack of free memory objects */
  1256. SyHash hClass; /* Compiled classes container */
  1257. SyHash hConstant; /* Host-application and user defined constants container */
  1258. SyHash hHostFunction; /* Host-application installable functions */
  1259. SyHash hFunction; /* Compiled functions */
  1260. SyHash hSuper; /* Superglobals hashtable */
  1261. SyHash hDBAL; /* DBAL installed drivers */
  1262. SyBlob sConsumer; /* Default VM consumer [i.e Redirect all VM output to this blob] */
  1263. SyBlob sWorker; /* General purpose working buffer */
  1264. SyBlob sArgv; /* $argv[] collector [refer to the [getopt()] implementation for more information] */
  1265. SySet aModules; /* Set of loaded modules */
  1266. SySet aFiles; /* Stack of processed files */
  1267. SySet aPaths; /* Set of import paths */
  1268. SySet aIncluded; /* Set of included files */
  1269. SySet aOB; /* Stackable output buffers */
  1270. SySet aAutoLoad; /* Stack of class autoload callbacks */
  1271. SySet aShutdown; /* Stack of shutdown user callbacks */
  1272. SySet aException; /* Stack of loaded exception */
  1273. SySet aIOstream; /* Installed IO stream container */
  1274. const ph7_io_stream *pDefStream; /* Default IO stream [i.e: typically this is the 'file://' stream] */
  1275. ph7_value sExec; /* Compiled script return value [Can be extracted via the PH7_VM_CONFIG_EXEC_VALUE directive]*/
  1276. ph7_value aExceptionCB[2]; /* Installed exception handler callbacks via [set_exception_handler()] */
  1277. ph7_value aErrCB[2]; /* Installed error handler callback via [set_error_handler()] */
  1278. void *pStdin; /* STDIN IO stream */
  1279. void *pStdout; /* STDOUT IO stream */
  1280. void *pStderr; /* STDERR IO stream */
  1281. int bErrReport; /* TRUE to report all runtime Error/Warning/Notice */
  1282. int nRecursionDepth; /* Current recursion depth */
  1283. int nMaxDepth; /* Maximum allowed recusion depth */
  1284. int nObDepth; /* OB depth */
  1285. int nExceptDepth; /* Exception depth */
  1286. int closure_cnt; /* Loaded closures counter */
  1287. int json_rc; /* JSON return status [refer to json_encode()/json_decode()]*/
  1288. sxu32 unique_id; /* Random number used to generate unique ID [refer to uniqid() for more info]*/
  1289. ProcErrLog xErrLog; /* error_log() consumer [refer to PH7_VM_CONFIG_ERR_LOG_HANDLER] */
  1290. sxu32 nOutputLen; /* Total number of generated output */
  1291. ph7_output_consumer sVmConsumer; /* Registered output consumer callback */
  1292. int iAssertFlags; /* Assertion flags */
  1293. ph7_value sAssertCallback; /* Callback to call on failed assertions */
  1294. VmRefObj **apRefObj; /* Hashtable of referenced object */
  1295. VmRefObj *pRefList; /* List of referenced memory objects */
  1296. sxu32 nRefSize; /* apRefObj[] size */
  1297. sxu32 nRefUsed; /* Total entries in apRefObj[] */
  1298. SySet aSelf; /* 'self' stack used for static member access [i.e: self::MyConstant] */
  1299. ph7_hashmap *pGlobal; /* $GLOBALS hashmap */
  1300. sxu32 nGlobalIdx; /* $GLOBALS index */
  1301. sxi32 iExitStatus; /* Script exit status */
  1302. ph7_gen_state sCodeGen; /* Code generator module */
  1303. ph7_vm *pNext, *pPrev; /* List of active VM's */
  1304. sxu32 nMagic; /* Sanity check against misuse */
  1305. };
  1306. /*
  1307. * Allowed value for ph7_vm.nMagic
  1308. */
  1309. #define PH7_VM_INIT 0xFADE9512 /* VM correctly initialized */
  1310. #define PH7_VM_RUN 0xEA271285 /* VM ready to execute PH7 bytecode */
  1311. #define PH7_VM_EXEC 0xCAFE2DAD /* VM executing PH7 bytecode */
  1312. #define PH7_VM_STALE 0xBAD1DEAD /* Stale VM */
  1313. /*
  1314. * Error codes according to the PHP language reference manual.
  1315. */
  1316. enum iErrCode {
  1317. E_ERROR = 1, /* Fatal run-time errors. These indicate errors that can not be recovered
  1318. * from, such as a memory allocation problem. Execution of the script is
  1319. * halted.
  1320. * The only fatal error under PH7 is an out-of-memory. All others erros
  1321. * even a call to undefined function will not halt script execution.
  1322. */
  1323. E_WARNING = 2, /* Run-time warnings (non-fatal errors). Execution of the script is not halted. */
  1324. E_PARSE = 4, /* Compile-time parse errors. Parse errors should only be generated by the parser.*/
  1325. E_NOTICE = 8, /* Run-time notices. Indicate that the script encountered something that could
  1326. * indicate an error, but could also happen in the normal course of running a script.
  1327. */
  1328. E_CORE_WARNING = 16, /* Fatal errors that occur during PHP's initial startup. This is like an E_ERROR
  1329. * except it is generated by the core of PHP.
  1330. */
  1331. E_USER_ERROR = 256, /* User-generated error message.*/
  1332. E_USER_WARNING = 512, /* User-generated warning message.*/
  1333. E_USER_NOTICE = 1024, /* User-generated notice message.*/
  1334. E_STRICT = 2048, /* Enable to have PHP suggest changes to your code which will ensure the best interoperability
  1335. * and forward compatibility of your code.
  1336. */
  1337. E_RECOVERABLE_ERROR = 4096, /* Catchable fatal error. It indicates that a probably dangerous error occured, but did not
  1338. * leave the Engine in an unstable state. If the error is not caught by a user defined handle
  1339. * the application aborts as it was an E_ERROR.
  1340. */
  1341. E_DEPRECATED = 8192, /* Run-time notices. Enable this to receive warnings about code that will not
  1342. * work in future versions.
  1343. */
  1344. E_USER_DEPRECATED = 16384, /* User-generated warning message. */
  1345. E_ALL = 32767 /* All errors and warnings */
  1346. };
  1347. /*
  1348. * Each VM instruction resulting from compiling a PHP script is represented
  1349. * by one of the following OP codes.
  1350. * The program consists of a linear sequence of operations. Each operation
  1351. * has an opcode and 3 operands.Operands P1 is an integer.
  1352. * Operand P2 is an unsigned integer and operand P3 is a memory address.
  1353. * Few opcodes use all 3 operands.
  1354. */
  1355. enum ph7_vm_op {
  1356. PH7_OP_DONE = 1, /* Done */
  1357. PH7_OP_HALT, /* Halt */
  1358. PH7_OP_LOAD, /* Load memory object */
  1359. PH7_OP_LOADC, /* Load constant */
  1360. PH7_OP_LOAD_IDX, /* Load array entry */
  1361. PH7_OP_LOAD_MAP, /* Load hashmap('array') */
  1362. PH7_OP_LOAD_LIST, /* Load list */
  1363. PH7_OP_LOAD_CLOSURE, /* Load closure */
  1364. PH7_OP_NOOP, /* NOOP */
  1365. PH7_OP_JMP, /* Unconditional jump */
  1366. PH7_OP_JZ, /* Jump on zero (FALSE jump) */
  1367. PH7_OP_JNZ, /* Jump on non-zero (TRUE jump) */
  1368. PH7_OP_POP, /* Stack POP */
  1369. PH7_OP_CAT, /* Concatenation */
  1370. PH7_OP_CVT_INT, /* Integer cast */
  1371. PH7_OP_CVT_STR, /* String cast */
  1372. PH7_OP_CVT_REAL, /* Float cast */
  1373. PH7_OP_CALL, /* Function call */
  1374. PH7_OP_UMINUS, /* Unary minus '-'*/
  1375. PH7_OP_UPLUS, /* Unary plus '+'*/
  1376. PH7_OP_BITNOT, /* Bitwise not '~' */
  1377. PH7_OP_LNOT, /* Logical not '!' */
  1378. PH7_OP_MUL, /* Multiplication '*' */
  1379. PH7_OP_DIV, /* Division '/' */
  1380. PH7_OP_MOD, /* Modulus '%' */
  1381. PH7_OP_ADD, /* Add '+' */
  1382. PH7_OP_SUB, /* Sub '-' */
  1383. PH7_OP_SHL, /* Left shift '<<' */
  1384. PH7_OP_SHR, /* Right shift '>>' */
  1385. PH7_OP_LT, /* Less than '<' */
  1386. PH7_OP_LE, /* Less or equal '<=' */
  1387. PH7_OP_GT, /* Greater than '>' */
  1388. PH7_OP_GE, /* Greater or equal '>=' */
  1389. PH7_OP_EQ, /* Equal '==' */
  1390. PH7_OP_NEQ, /* Not equal '!=' */
  1391. PH7_OP_TEQ, /* Type equal '===' */
  1392. PH7_OP_TNE, /* Type not equal '!==' */
  1393. PH7_OP_BAND, /* Bitwise and '&' */
  1394. PH7_OP_BXOR, /* Bitwise xor '^' */
  1395. PH7_OP_BOR, /* Bitwise or '|' */
  1396. PH7_OP_LAND, /* Logical and '&&' */
  1397. PH7_OP_LOR, /* Logical or '||' */
  1398. PH7_OP_LXOR, /* Logical xor '^^' */
  1399. PH7_OP_STORE, /* Store Object */
  1400. PH7_OP_STORE_IDX, /* Store indexed object */
  1401. PH7_OP_STORE_IDX_REF,/* Store indexed object by reference */
  1402. PH7_OP_PULL, /* Stack pull */
  1403. PH7_OP_SWAP, /* Stack swap */
  1404. PH7_OP_YIELD, /* Stack yield */
  1405. PH7_OP_CVT_BOOL, /* Boolean cast */
  1406. PH7_OP_CVT_NUMC, /* Numeric (integer,real or both) type cast */
  1407. PH7_OP_INCR, /* Increment ++ */
  1408. PH7_OP_DECR, /* Decrement -- */
  1409. PH7_OP_NEW, /* new */
  1410. PH7_OP_CLONE, /* clone */
  1411. PH7_OP_ADD_STORE, /* Add and store '+=' */
  1412. PH7_OP_SUB_STORE, /* Sub and store '-=' */
  1413. PH7_OP_MUL_STORE, /* Mul and store '*=' */
  1414. PH7_OP_DIV_STORE, /* Div and store '/=' */
  1415. PH7_OP_MOD_STORE, /* Mod and store '%=' */
  1416. PH7_OP_CAT_STORE, /* Cat and store '.=' */
  1417. PH7_OP_SHL_STORE, /* Shift left and store '>>=' */
  1418. PH7_OP_SHR_STORE, /* Shift right and store '<<=' */
  1419. PH7_OP_BAND_STORE, /* Bitand and store '&=' */
  1420. PH7_OP_BOR_STORE, /* Bitor and store '|=' */
  1421. PH7_OP_BXOR_STORE, /* Bitxor and store '^=' */
  1422. PH7_OP_CONSUME, /* Consume VM output */
  1423. PH7_OP_LOAD_REF, /* Load reference */
  1424. PH7_OP_STORE_REF, /* Store a reference to a variable*/
  1425. PH7_OP_MEMBER, /* Class member run-time access */
  1426. PH7_OP_UPLINK, /* Run-Time frame link */
  1427. PH7_OP_CVT_NULL, /* NULL cast */
  1428. PH7_OP_CVT_ARRAY, /* Array cast */
  1429. PH7_OP_CVT_OBJ, /* Object cast */
  1430. PH7_OP_FOREACH_INIT, /* For each init */
  1431. PH7_OP_FOREACH_STEP, /* For each step */
  1432. PH7_OP_IS_A, /* Instanceof */
  1433. PH7_OP_LOAD_EXCEPTION,/* Load an exception */
  1434. PH7_OP_POP_EXCEPTION, /* POP an exception */
  1435. PH7_OP_THROW, /* Throw exception */
  1436. PH7_OP_SWITCH, /* Switch operation */
  1437. PH7_OP_ERR_CTRL /* Error control */
  1438. };
  1439. /* -- END-OF INSTRUCTIONS -- */
  1440. /*
  1441. * Expression Operators ID.
  1442. */
  1443. enum ph7_expr_id {
  1444. EXPR_OP_NEW = 1, /* new */
  1445. EXPR_OP_CLONE, /* clone */
  1446. EXPR_OP_ARROW, /* -> */
  1447. EXPR_OP_DC, /* :: */
  1448. EXPR_OP_SUBSCRIPT, /* []: Subscripting */
  1449. EXPR_OP_FUNC_CALL, /* func_call() */
  1450. EXPR_OP_INCR, /* ++ */
  1451. EXPR_OP_DECR, /* -- */
  1452. EXPR_OP_BITNOT, /* ~ */
  1453. EXPR_OP_UMINUS, /* Unary minus */
  1454. EXPR_OP_UPLUS, /* Unary plus */
  1455. EXPR_OP_TYPECAST, /* Type cast [i.e: (int),(float),(string)...] */
  1456. EXPR_OP_ALT, /* @ */
  1457. EXPR_OP_INSTOF, /* instanceof */
  1458. EXPR_OP_LOGNOT, /* logical not ! */
  1459. EXPR_OP_MUL, /* Multiplication */
  1460. EXPR_OP_DIV, /* division */
  1461. EXPR_OP_MOD, /* Modulus */
  1462. EXPR_OP_ADD, /* Addition */
  1463. EXPR_OP_SUB, /* Substraction */
  1464. EXPR_OP_DOT, /* Concatenation */
  1465. EXPR_OP_SHL, /* Left shift */
  1466. EXPR_OP_SHR, /* Right shift */
  1467. EXPR_OP_LT, /* Less than */
  1468. EXPR_OP_LE, /* Less equal */
  1469. EXPR_OP_GT, /* Greater than */
  1470. EXPR_OP_GE, /* Greater equal */
  1471. EXPR_OP_EQ, /* Equal == */
  1472. EXPR_OP_NE, /* Not equal != <> */
  1473. EXPR_OP_TEQ, /* Type equal === */
  1474. EXPR_OP_TNE, /* Type not equal !== */
  1475. EXPR_OP_BAND, /* Biwise and '&' */
  1476. EXPR_OP_REF, /* Reference operator '&' */
  1477. EXPR_OP_XOR, /* bitwise xor '^' */
  1478. EXPR_OP_BOR, /* bitwise or '|' */
  1479. EXPR_OP_LAND, /* Logical and '&&' */
  1480. EXPR_OP_LOR, /* Logical or '||' */
  1481. EXPR_OP_LXOR, /* Logical xor '^^' */
  1482. EXPR_OP_QUESTY, /* Ternary operator '?' */
  1483. EXPR_OP_ASSIGN, /* Assignment '=' */
  1484. EXPR_OP_ADD_ASSIGN, /* Combined operator: += */
  1485. EXPR_OP_SUB_ASSIGN, /* Combined operator: -= */
  1486. EXPR_OP_MUL_ASSIGN, /* Combined operator: *= */
  1487. EXPR_OP_DIV_ASSIGN, /* Combined operator: /= */
  1488. EXPR_OP_MOD_ASSIGN, /* Combined operator: %= */
  1489. EXPR_OP_DOT_ASSIGN, /* Combined operator: .= */
  1490. EXPR_OP_AND_ASSIGN, /* Combined operator: &= */
  1491. EXPR_OP_OR_ASSIGN, /* Combined operator: |= */
  1492. EXPR_OP_XOR_ASSIGN, /* Combined operator: ^= */
  1493. EXPR_OP_SHL_ASSIGN, /* Combined operator: <<= */
  1494. EXPR_OP_SHR_ASSIGN, /* Combined operator: >>= */
  1495. EXPR_OP_COMMA /* Comma expression */
  1496. };
  1497. /*
  1498. * Very high level tokens.
  1499. */
  1500. #define PH7_TOKEN_RAW 0x001 /* Raw text [i.e: HTML,XML...] */
  1501. #define PH7_TOKEN_PHP 0x002 /* PHP chunk */
  1502. /*
  1503. * Lexer token codes
  1504. * The following set of constants are the tokens recognized
  1505. * by the lexer when processing PHP input.
  1506. * Important: Token values MUST BE A POWER OF TWO.
  1507. */
  1508. #define PH7_TK_INTEGER 0x0000001 /* Integer */
  1509. #define PH7_TK_REAL 0x0000002 /* Real number */
  1510. #define PH7_TK_NUM (PH7_TK_INTEGER|PH7_TK_REAL) /* Numeric token,either integer or real */
  1511. #define PH7_TK_KEYWORD 0x0000004 /* Keyword [i.e: while,for,if,foreach...] */
  1512. #define PH7_TK_ID 0x0000008 /* Alphanumeric or UTF-8 stream */
  1513. #define PH7_TK_DOLLAR 0x0000010 /* '$' Dollar sign */
  1514. #define PH7_TK_OP 0x0000020 /* Operator [i.e: +,*,/...] */
  1515. #define PH7_TK_OCB 0x0000040 /* Open curly brace'{' */
  1516. #define PH7_TK_CCB 0x0000080 /* Closing curly brace'}' */
  1517. #define PH7_TK_NSSEP 0x0000100 /* Namespace separator '\' */
  1518. #define PH7_TK_LPAREN 0x0000200 /* Left parenthesis '(' */
  1519. #define PH7_TK_RPAREN 0x0000400 /* Right parenthesis ')' */
  1520. #define PH7_TK_OSB 0x0000800 /* Open square bracket '[' */
  1521. #define PH7_TK_CSB 0x0001000 /* Closing square bracket ']' */
  1522. #define PH7_TK_DSTR 0x0002000 /* Double quoted string "$str" */
  1523. #define PH7_TK_SSTR 0x0004000 /* Single quoted string 'str' */
  1524. #define PH7_TK_COMMA 0x0020000 /* Comma ',' */
  1525. #define PH7_TK_SEMI 0x0040000 /* Semi-colon ";" */
  1526. #define PH7_TK_BSTR 0x0080000 /* Backtick quoted string [i.e: Shell command `date`] */
  1527. #define PH7_TK_COLON 0x0100000 /* single Colon ':' */
  1528. #define PH7_TK_AMPER 0x0200000 /* Ampersand '&' */
  1529. #define PH7_TK_EQUAL 0x0400000 /* Equal '=' */
  1530. #define PH7_TK_ARRAY_OP 0x0800000 /* Array operator '=>' */
  1531. #define PH7_TK_OTHER 0x1000000 /* Other symbols */
  1532. /*
  1533. * PHP keyword.
  1534. * These words have special meaning in PHP. Some of them represent things which look like
  1535. * functions, some look like constants, and so on, but they're not, really: they are language constructs.
  1536. * You cannot use any of the following words as constants, class names, function or method names.
  1537. * Using them as variable names is generally OK, but could lead to confusion.
  1538. */
  1539. #define PH7_TKWRD_EXTENDS 1 /* extends */
  1540. #define PH7_TKWRD_ENDSWITCH 2 /* endswitch */
  1541. #define PH7_TKWRD_SWITCH 3 /* switch */
  1542. #define PH7_TKWRD_PRINT 4 /* print */
  1543. #define PH7_TKWRD_INTERFACE 5 /* interface */
  1544. /* The number '8' is reserved for PH7_TK_ID */
  1545. #define PH7_TKWRD_REQONCE 9 /* require_once */
  1546. #define PH7_TKWRD_REQUIRE 10 /* require */
  1547. #define PH7_TKWRD_ELIF 0x4000000 /* elseif: MUST BE A POWER OF TWO */
  1548. #define PH7_TKWRD_ELSE 0x8000000 /* else: MUST BE A POWER OF TWO */
  1549. #define PH7_TKWRD_IF 13 /* if */
  1550. #define PH7_TKWRD_FINAL 14 /* final */
  1551. #define PH7_TKWRD_LIST 15 /* list */
  1552. #define PH7_TKWRD_STATIC 16 /* static */
  1553. #define PH7_TKWRD_CASE 17 /* case */
  1554. #define PH7_TKWRD_SELF 18 /* self */
  1555. #define PH7_TKWRD_FUNCTION 19 /* function */
  1556. #define PH7_TKWRD_NAMESPACE 20 /* namespace */
  1557. #define PH7_TKWRD_ENDIF 0x400000 /* endif: MUST BE A POWER OF TWO */
  1558. #define PH7_TKWRD_CLONE 0x80 /* clone: MUST BE A POWER OF TWO */
  1559. #define PH7_TKWRD_NEW 0x100 /* new: MUST BE A POWER OF TWO */
  1560. #define PH7_TKWRD_CONST 22 /* const */
  1561. #define PH7_TKWRD_THROW 23 /* throw */
  1562. #define PH7_TKWRD_USE 24 /* use */
  1563. #define PH7_TKWRD_ENDWHILE 0x800000 /* endwhile: MUST BE A POWER OF TWO */
  1564. #define PH7_TKWRD_WHILE 26 /* while */
  1565. #define PH7_TKWRD_EVAL 27 /* eval */
  1566. #define PH7_TKWRD_VAR 28 /* var */
  1567. #define PH7_TKWRD_ARRAY 0x200 /* array: MUST BE A POWER OF TWO */
  1568. #define PH7_TKWRD_ABSTRACT 29 /* abstract */
  1569. #define PH7_TKWRD_TRY 30 /* try */
  1570. #define PH7_TKWRD_DEFAULT 31 /* default */
  1571. #define PH7_TKWRD_CLASS 32 /* class */
  1572. #define PH7_TKWRD_AS 33 /* as */
  1573. #define PH7_TKWRD_CONTINUE 34 /* continue */
  1574. #define PH7_TKWRD_EXIT 35 /* exit */
  1575. #define PH7_TKWRD_DIE 36 /* die */
  1576. #define PH7_TKWRD_ECHO 37 /* echo */
  1577. #define PH7_TKWRD_GLOBAL 38 /* global */
  1578. #define PH7_TKWRD_IMPLEMENTS 39 /* implements */
  1579. #define PH7_TKWRD_INCONCE 40 /* include_once */
  1580. #define PH7_TKWRD_INCLUDE 41 /* include */
  1581. #define PH7_TKWRD_EMPTY 42 /* empty */
  1582. #define PH7_TKWRD_INSTANCEOF 0x800 /* instanceof: MUST BE A POWER OF TWO */
  1583. #define PH7_TKWRD_ISSET 43 /* isset */
  1584. #define PH7_TKWRD_PARENT 44 /* parent */
  1585. #define PH7_TKWRD_PRIVATE 45 /* private */
  1586. #define PH7_TKWRD_ENDFOR 0x1000000 /* endfor: MUST BE A POWER OF TWO */
  1587. #define PH7_TKWRD_END4EACH 0x2000000 /* endforeach: MUST BE A POWER OF TWO */
  1588. #define PH7_TKWRD_FOR 48 /* for */
  1589. #define PH7_TKWRD_FOREACH 49 /* foreach */
  1590. #define PH7_TKWRD_PROTECTED 50 /* protected */
  1591. #define PH7_TKWRD_DO 51 /* do */
  1592. #define PH7_TKWRD_PUBLIC 52 /* public */
  1593. #define PH7_TKWRD_CATCH 53 /* catch */
  1594. #define PH7_TKWRD_RETURN 54 /* return */
  1595. #define PH7_TKWRD_UNSET 0x2000 /* unset: MUST BE A POWER OF TWO */
  1596. #define PH7_TKWRD_BREAK 55 /* break */
  1597. #define PH7_TKWRD_GOTO 56 /* goto */
  1598. #define PH7_TKWRD_BOOL 0x8000 /* bool: MUST BE A POWER OF TWO */
  1599. #define PH7_TKWRD_INT 0x10000 /* int: MUST BE A POWER OF TWO */
  1600. #define PH7_TKWRD_FLOAT 0x20000 /* float: MUST BE A POWER OF TWO */
  1601. #define PH7_TKWRD_STRING 0x40000 /* string: MUST BE A POWER OF TWO */
  1602. #define PH7_TKWRD_OBJECT 0x80000 /* object: MUST BE A POWER OF TWO */
  1603. /* JSON encoding/decoding related definition */
  1604. enum json_err_code {
  1605. JSON_ERROR_NONE = 0, /* No error has occurred. */
  1606. JSON_ERROR_DEPTH, /* The maximum stack depth has been exceeded. */
  1607. JSON_ERROR_STATE_MISMATCH, /* Occurs with underflow or with the modes mismatch. */
  1608. JSON_ERROR_CTRL_CHAR, /* Control character error, possibly incorrectly encoded. */
  1609. JSON_ERROR_SYNTAX, /* Syntax error. */
  1610. JSON_ERROR_UTF8 /* Malformed UTF-8 characters */
  1611. };
  1612. /* The following constants can be combined to form options for json_encode(). */
  1613. #define JSON_HEX_TAG 0x01 /* All < and > are converted to \u003C and \u003E. */
  1614. #define JSON_HEX_AMP 0x02 /* All &s are converted to \u0026. */
  1615. #define JSON_HEX_APOS 0x04 /* All ' are converted to \u0027. */
  1616. #define JSON_HEX_QUOT 0x08 /* All " are converted to \u0022. */
  1617. #define JSON_FORCE_OBJECT 0x10 /* Outputs an object rather than an array */
  1618. #define JSON_NUMERIC_CHECK 0x20 /* Encodes numeric strings as numbers. */
  1619. #define JSON_BIGINT_AS_STRING 0x40 /* Not used */
  1620. #define JSON_PRETTY_PRINT 0x80 /* Use whitespace in returned data to format it.*/
  1621. #define JSON_UNESCAPED_SLASHES 0x100 /* Don't escape '/' */
  1622. #define JSON_UNESCAPED_UNICODE 0x200 /* Not used */
  1623. /* memobj.c function prototypes */
  1624. PH7_PRIVATE sxi32 PH7_MemObjDump(SyBlob *pOut, ph7_value *pObj, int ShowType, int nTab, int nDepth, int isRef);
  1625. PH7_PRIVATE const char *PH7_MemObjTypeDump(ph7_value *pVal);
  1626. PH7_PRIVATE sxi32 PH7_MemObjAdd(ph7_value *pObj1, ph7_value *pObj2, int bAddStore);
  1627. PH7_PRIVATE sxi32 PH7_MemObjCmp(ph7_value *pObj1, ph7_value *pObj2, int bStrict, int iNest);
  1628. PH7_PRIVATE sxi32 PH7_MemObjInitFromString(ph7_vm *pVm, ph7_value *pObj, const SyString *pVal);
  1629. PH7_PRIVATE sxi32 PH7_MemObjInitFromArray(ph7_vm *pVm, ph7_value *pObj, ph7_hashmap *pArray);
  1630. #if 0
  1631. /* Not used in the current release of the PH7 engine */
  1632. PH7_PRIVATE sxi32 PH7_MemObjInitFromReal(ph7_vm *pVm, ph7_value *pObj, ph7_real rVal);
  1633. #endif
  1634. PH7_PRIVATE sxi32 PH7_MemObjInitFromInt(ph7_vm *pVm, ph7_value *pObj, sxi64 iVal);
  1635. PH7_PRIVATE sxi32 PH7_MemObjInitFromBool(ph7_vm *pVm, ph7_value *pObj, sxi32 iVal);
  1636. PH7_PRIVATE sxi32 PH7_MemObjInit(ph7_vm *pVm, ph7_value *pObj);
  1637. PH7_PRIVATE sxi32 PH7_MemObjStringAppend(ph7_value *pObj, const char *zData, sxu32 nLen);
  1638. #if 0
  1639. /* Not used in the current release of the PH7 engine */
  1640. PH7_PRIVATE sxi32 PH7_MemObjStringFormat(ph7_value *pObj, const char *zFormat, va_list ap);
  1641. #endif
  1642. PH7_PRIVATE sxi32 PH7_MemObjStore(ph7_value *pSrc, ph7_value *pDest);
  1643. PH7_PRIVATE sxi32 PH7_MemObjLoad(ph7_value *pSrc, ph7_value *pDest);
  1644. PH7_PRIVATE sxi32 PH7_MemObjRelease(ph7_value *pObj);
  1645. PH7_PRIVATE sxi32 PH7_MemObjToNumeric(ph7_value *pObj);
  1646. PH7_PRIVATE sxi32 PH7_MemObjTryInteger(ph7_value *pObj);
  1647. PH7_PRIVATE ProcMemObjCast PH7_MemObjCastMethod(sxi32 iFlags);
  1648. PH7_PRIVATE sxi32 PH7_MemObjIsNumeric(ph7_value *pObj);
  1649. PH7_PRIVATE sxi32 PH7_MemObjIsEmpty(ph7_value *pObj);
  1650. PH7_PRIVATE sxi32 PH7_MemObjToHashmap(ph7_value *pObj);
  1651. PH7_PRIVATE sxi32 PH7_MemObjToObject(ph7_value *pObj);
  1652. PH7_PRIVATE sxi32 PH7_MemObjToString(ph7_value *pObj);
  1653. PH7_PRIVATE sxi32 PH7_MemObjToNull(ph7_value *pObj);
  1654. PH7_PRIVATE sxi32 PH7_MemObjToReal(ph7_value *pObj);
  1655. PH7_PRIVATE sxi32 PH7_MemObjToInteger(ph7_value *pObj);
  1656. PH7_PRIVATE sxi32 PH7_MemObjToBool(ph7_value *pObj);
  1657. PH7_PRIVATE sxi64 PH7_TokenValueToInt64(SyString *pData);
  1658. /* lex.c function prototypes */
  1659. PH7_PRIVATE sxi32 PH7_TokenizeRawText(const char *zInput, sxu32 nLen, SySet *pOut);
  1660. PH7_PRIVATE sxi32 PH7_TokenizePHP(const char *zInput, sxu32 nLen, sxu32 nLineStart, SySet *pOut);
  1661. /* vm.c function prototypes */
  1662. PH7_PRIVATE void PH7_VmReleaseContextValue(ph7_context *pCtx, ph7_value *pValue);
  1663. PH7_PRIVATE sxi32 PH7_VmInitFuncState(ph7_vm *pVm, ph7_vm_func *pFunc, const char *zName, sxu32 nByte,
  1664. sxi32 iFlags, void *pUserData);
  1665. PH7_PRIVATE sxi32 PH7_VmInstallUserFunction(ph7_vm *pVm, ph7_vm_func *pFunc, SyString *pName);
  1666. PH7_PRIVATE sxi32 PH7_VmCreateClassInstanceFrame(ph7_vm *pVm, ph7_class_instance *pObj);
  1667. PH7_PRIVATE sxi32 PH7_VmRefObjRemove(ph7_vm *pVm, sxu32 nIdx, SyHashEntry *pEntry, ph7_hashmap_node *pMapEntry);
  1668. PH7_PRIVATE sxi32 PH7_VmRefObjInstall(ph7_vm *pVm, sxu32 nIdx, SyHashEntry *pEntry, ph7_hashmap_node *pMapEntry, sxi32 iFlags);
  1669. PH7_PRIVATE sxi32 PH7_VmPushFilePath(ph7_vm *pVm, const char *zPath, int nLen, sxu8 bMain, sxi32 *pNew);
  1670. PH7_PRIVATE ph7_class *PH7_VmExtractClass(ph7_vm *pVm, const char *zName, sxu32 nByte, sxi32 iLoadable, sxi32 iNest);
  1671. PH7_PRIVATE sxi32 PH7_VmRegisterConstant(ph7_vm *pVm, const SyString *pName, ProcConstant xExpand, void *pUserData);
  1672. PH7_PRIVATE sxi32 PH7_VmInstallForeignFunction(ph7_vm *pVm, const SyString *pName, ProchHostFunction xFunc, void *pUserData);
  1673. PH7_PRIVATE sxi32 PH7_VmInstallClass(ph7_vm *pVm, ph7_class *pClass);
  1674. PH7_PRIVATE sxi32 PH7_VmBlobConsumer(const void *pSrc, unsigned int nLen, void *pUserData);
  1675. PH7_PRIVATE ph7_value *PH7_ReserveMemObj(ph7_vm *pVm);
  1676. PH7_PRIVATE ph7_value *PH7_ReserveConstObj(ph7_vm *pVm, sxu32 *pIndex);
  1677. PH7_PRIVATE sxi32 PH7_VmOutputConsume(ph7_vm *pVm, SyString *pString);
  1678. PH7_PRIVATE sxi32 PH7_VmOutputConsumeAp(ph7_vm *pVm, const char *zFormat, va_list ap);
  1679. PH7_PRIVATE sxi32 PH7_VmThrowErrorAp(ph7_vm *pVm, SyString *pFuncName, sxi32 iErr, const char *zFormat, va_list ap);
  1680. PH7_PRIVATE sxi32 PH7_VmThrowError(ph7_vm *pVm, SyString *pFuncName, sxi32 iErr, const char *zMessage);
  1681. PH7_PRIVATE void PH7_VmExpandConstantValue(ph7_value *pVal, void *pUserData);
  1682. PH7_PRIVATE sxi32 PH7_VmDump(ph7_vm *pVm, ProcConsumer xConsumer, void *pUserData);
  1683. PH7_PRIVATE sxi32 PH7_VmInit(ph7_vm *pVm, ph7 *pEngine);
  1684. PH7_PRIVATE sxi32 PH7_VmConfigure(ph7_vm *pVm, sxi32 nOp, va_list ap);
  1685. PH7_PRIVATE sxi32 PH7_VmByteCodeExec(ph7_vm *pVm);
  1686. PH7_PRIVATE sxi32 PH7_VmRelease(ph7_vm *pVm);
  1687. PH7_PRIVATE sxi32 PH7_VmReset(ph7_vm *pVm);
  1688. PH7_PRIVATE sxi32 PH7_VmMakeReady(ph7_vm *pVm);
  1689. PH7_PRIVATE sxu32 PH7_VmInstrLength(ph7_vm *pVm);
  1690. PH7_PRIVATE VmInstr *PH7_VmPopInstr(ph7_vm *pVm);
  1691. PH7_PRIVATE VmInstr *PH7_VmPeekInstr(ph7_vm *pVm);
  1692. PH7_PRIVATE VmInstr *PH7_VmPeekNextInstr(ph7_vm *pVm);
  1693. PH7_PRIVATE VmInstr *PH7_VmGetInstr(ph7_vm *pVm, sxu32 nIndex);
  1694. PH7_PRIVATE SySet *PH7_VmGetByteCodeContainer(ph7_vm *pVm);
  1695. PH7_PRIVATE sxi32 PH7_VmSetByteCodeContainer(ph7_vm *pVm, SySet *pContainer);
  1696. PH7_PRIVATE sxi32 PH7_VmEmitInstr(ph7_vm *pVm, sxi32 iOp, sxi32 iP1, sxu32 iP2, void *p3, sxu32 *pIndex);
  1697. PH7_PRIVATE sxu32 PH7_VmRandomNum(ph7_vm *pVm);
  1698. PH7_PRIVATE sxi32 PH7_VmCallClassMethod(ph7_vm *pVm, ph7_class_instance *pThis, ph7_class_method *pMethod,
  1699. ph7_value *pResult, int nArg, ph7_value **apArg);
  1700. PH7_PRIVATE sxi32 PH7_VmCallUserFunction(ph7_vm *pVm, ph7_value *pFunc, int nArg, ph7_value **apArg, ph7_value *pResult);
  1701. PH7_PRIVATE sxi32 PH7_VmCallUserFunctionAp(ph7_vm *pVm, ph7_value *pFunc, ph7_value *pResult, ...);
  1702. PH7_PRIVATE sxi32 PH7_VmUnsetMemObj(ph7_vm *pVm, sxu32 nObjIdx, int bForce);
  1703. PH7_PRIVATE void PH7_VmRandomString(ph7_vm *pVm, char *zBuf, int nLen);
  1704. PH7_PRIVATE ph7_class *PH7_VmPeekTopClass(ph7_vm *pVm);
  1705. PH7_PRIVATE int PH7_VmIsCallable(ph7_vm *pVm, ph7_value *pValue, int CallInvoke);
  1706. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1707. PH7_PRIVATE const ph7_io_stream *PH7_VmGetStreamDevice(ph7_vm *pVm, const char **pzDevice, int nByte);
  1708. #endif /* PH7_DISABLE_BUILTIN_FUNC */
  1709. PH7_PRIVATE int PH7_Utf8Read(
  1710. const unsigned char *z, /* First byte of UTF-8 character */
  1711. const unsigned char *zTerm, /* Pretend this byte is 0x00 */
  1712. const unsigned char **pzNext /* Write first byte past UTF-8 char here */
  1713. );
  1714. /* parse.c function prototypes */
  1715. PH7_PRIVATE int PH7_IsLangConstruct(sxu32 nKeyID, sxu8 bCheckFunc);
  1716. PH7_PRIVATE sxi32 PH7_ExprMakeTree(ph7_gen_state *pGen, SySet *pExprNode, ph7_expr_node **ppRoot);
  1717. PH7_PRIVATE sxi32 PH7_GetNextExpr(SyToken *pStart, SyToken *pEnd, SyToken **ppNext);
  1718. PH7_PRIVATE void PH7_DelimitNestedTokens(SyToken *pIn, SyToken *pEnd, sxu32 nTokStart, sxu32 nTokEnd, SyToken **ppEnd);
  1719. PH7_PRIVATE const ph7_expr_op *PH7_ExprExtractOperator(SyString *pStr, SyToken *pLast);
  1720. PH7_PRIVATE sxi32 PH7_ExprFreeTree(ph7_gen_state *pGen, SySet *pNodeSet);
  1721. /* compile.c function prototypes */
  1722. PH7_PRIVATE ProcNodeConstruct PH7_GetNodeHandler(sxu32 nNodeType);
  1723. PH7_PRIVATE sxi32 PH7_CompileLangConstruct(ph7_gen_state *pGen, sxi32 iCompileFlag);
  1724. PH7_PRIVATE sxi32 PH7_CompileVariable(ph7_gen_state *pGen, sxi32 iCompileFlag);
  1725. PH7_PRIVATE sxi32 PH7_CompileLiteral(ph7_gen_state *pGen, sxi32 iCompileFlag);
  1726. PH7_PRIVATE sxi32 PH7_CompileSimpleString(ph7_gen_state *pGen, sxi32 iCompileFlag);
  1727. PH7_PRIVATE sxi32 PH7_CompileString(ph7_gen_state *pGen, sxi32 iCompileFlag);
  1728. PH7_PRIVATE sxi32 PH7_CompileArray(ph7_gen_state *pGen, sxi32 iCompileFlag);
  1729. PH7_PRIVATE sxi32 PH7_CompileList(ph7_gen_state *pGen, sxi32 iCompileFlag);
  1730. PH7_PRIVATE sxi32 PH7_CompileAnnonFunc(ph7_gen_state *pGen, sxi32 iCompileFlag);
  1731. PH7_PRIVATE sxi32 PH7_InitCodeGenerator(ph7_vm *pVm, ProcConsumer xErr, void *pErrData);
  1732. PH7_PRIVATE sxi32 PH7_ResetCodeGenerator(ph7_vm *pVm, ProcConsumer xErr, void *pErrData);
  1733. PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen, sxi32 nErrType, sxu32 nLine, const char *zFormat, ...);
  1734. PH7_PRIVATE sxi32 PH7_CompileScript(ph7_vm *pVm, SyString *pScript, sxi32 iFlags);
  1735. /* constant.c function prototypes */
  1736. PH7_PRIVATE void PH7_RegisterBuiltInConstant(ph7_vm *pVm);
  1737. /* builtin.c function prototypes */
  1738. PH7_PRIVATE void PH7_RegisterBuiltInFunction(ph7_vm *pVm);
  1739. /* hashmap.c function prototypes */
  1740. PH7_PRIVATE ph7_hashmap *PH7_NewHashmap(ph7_vm *pVm, sxu32(*xIntHash)(sxi64), sxu32(*xBlobHash)(const void *, sxu32));
  1741. PH7_PRIVATE sxi32 PH7_HashmapCreateSuper(ph7_vm *pVm);
  1742. PH7_PRIVATE sxi32 PH7_HashmapRelease(ph7_hashmap *pMap, int FreeDS);
  1743. PH7_PRIVATE void PH7_HashmapUnref(ph7_hashmap *pMap);
  1744. PH7_PRIVATE sxi32 PH7_HashmapLookup(ph7_hashmap *pMap, ph7_value *pKey, ph7_hashmap_node **ppNode);
  1745. PH7_PRIVATE sxi32 PH7_HashmapInsert(ph7_hashmap *pMap, ph7_value *pKey, ph7_value *pVal);
  1746. PH7_PRIVATE sxi32 PH7_HashmapInsertByRef(ph7_hashmap *pMap, ph7_value *pKey, sxu32 nRefIdx);
  1747. PH7_PRIVATE sxi32 PH7_HashmapUnion(ph7_hashmap *pLeft, ph7_hashmap *pRight);
  1748. PH7_PRIVATE void PH7_HashmapUnlinkNode(ph7_hashmap_node *pNode, int bRestore);
  1749. PH7_PRIVATE sxi32 PH7_HashmapDup(ph7_hashmap *pSrc, ph7_hashmap *pDest);
  1750. PH7_PRIVATE sxi32 PH7_HashmapCmp(ph7_hashmap *pLeft, ph7_hashmap *pRight, int bStrict);
  1751. PH7_PRIVATE void PH7_HashmapResetLoopCursor(ph7_hashmap *pMap);
  1752. PH7_PRIVATE ph7_hashmap_node *PH7_HashmapGetNextEntry(ph7_hashmap *pMap);
  1753. PH7_PRIVATE void PH7_HashmapExtractNodeValue(ph7_hashmap_node *pNode, ph7_value *pValue, int bStore);
  1754. PH7_PRIVATE void PH7_HashmapExtractNodeKey(ph7_hashmap_node *pNode, ph7_value *pKey);
  1755. PH7_PRIVATE void PH7_RegisterHashmapFunctions(ph7_vm *pVm);
  1756. PH7_PRIVATE sxi32 PH7_HashmapDump(SyBlob *pOut, ph7_hashmap *pMap, int ShowType, int nTab, int nDepth);
  1757. PH7_PRIVATE sxi32 PH7_HashmapWalk(ph7_hashmap *pMap, int (*xWalk)(ph7_value *, ph7_value *, void *), void *pUserData);
  1758. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1759. PH7_PRIVATE int PH7_HashmapValuesToSet(ph7_hashmap *pMap, SySet *pOut);
  1760. /* builtin.c function prototypes */
  1761. PH7_PRIVATE sxi32 PH7_InputFormat(int (*xConsumer)(ph7_context *, const char *, int, void *),
  1762. ph7_context *pCtx, const char *zIn, int nByte, int nArg, ph7_value **apArg, void *pUserData, int vf);
  1763. PH7_PRIVATE sxi32 PH7_ProcessCsv(const char *zInput, int nByte, int delim, int encl,
  1764. int escape, sxi32(*xConsumer)(const char *, int, void *), void *pUserData);
  1765. PH7_PRIVATE sxi32 PH7_CsvConsumer(const char *zToken, int nTokenLen, void *pUserData);
  1766. PH7_PRIVATE sxi32 PH7_StripTagsFromString(ph7_context *pCtx, const char *zIn, int nByte, const char *zTaglist, int nTaglen);
  1767. PH7_PRIVATE sxi32 PH7_ParseIniString(ph7_context *pCtx, const char *zIn, sxu32 nByte, int bProcessSection);
  1768. #endif
  1769. /* oo.c function prototypes */
  1770. PH7_PRIVATE ph7_class *PH7_NewRawClass(ph7_vm *pVm, const SyString *pName, sxu32 nLine);
  1771. PH7_PRIVATE ph7_class_attr *PH7_NewClassAttr(ph7_vm *pVm, const SyString *pName, sxu32 nLine, sxi32 iProtection, sxi32 iFlags);
  1772. PH7_PRIVATE ph7_class_method *PH7_NewClassMethod(ph7_vm *pVm, ph7_class *pClass, const SyString *pName, sxu32 nLine,
  1773. sxi32 iProtection, sxi32 iFlags, sxi32 iFuncFlags);
  1774. PH7_PRIVATE ph7_class_method *PH7_ClassExtractMethod(ph7_class *pClass, const char *zName, sxu32 nByte);
  1775. PH7_PRIVATE ph7_class_attr *PH7_ClassExtractAttribute(ph7_class *pClass, const char *zName, sxu32 nByte);
  1776. PH7_PRIVATE sxi32 PH7_ClassInstallAttr(ph7_class *pClass, ph7_class_attr *pAttr);
  1777. PH7_PRIVATE sxi32 PH7_ClassInstallMethod(ph7_class *pClass, ph7_class_method *pMeth);
  1778. PH7_PRIVATE sxi32 PH7_ClassInherit(ph7_gen_state *pGen, ph7_class *pSub, ph7_class *pBase);
  1779. PH7_PRIVATE sxi32 PH7_ClassInterfaceInherit(ph7_class *pSub, ph7_class *pBase);
  1780. PH7_PRIVATE sxi32 PH7_ClassImplement(ph7_class *pMain, ph7_class *pInterface);
  1781. PH7_PRIVATE ph7_class_instance *PH7_NewClassInstance(ph7_vm *pVm, ph7_class *pClass);
  1782. PH7_PRIVATE ph7_class_instance *PH7_CloneClassInstance(ph7_class_instance *pSrc);
  1783. PH7_PRIVATE sxi32 PH7_ClassInstanceCmp(ph7_class_instance *pLeft, ph7_class_instance *pRight, int bStrict, int iNest);
  1784. PH7_PRIVATE void PH7_ClassInstanceUnref(ph7_class_instance *pThis);
  1785. PH7_PRIVATE sxi32 PH7_ClassInstanceDump(SyBlob *pOut, ph7_class_instance *pThis, int ShowType, int nTab, int nDepth);
  1786. PH7_PRIVATE sxi32 PH7_ClassInstanceCallMagicMethod(ph7_vm *pVm, ph7_class *pClass, ph7_class_instance *pThis, const char *zMethod,
  1787. sxu32 nByte, const SyString *pAttrName);
  1788. PH7_PRIVATE ph7_value *PH7_ClassInstanceExtractAttrValue(ph7_class_instance *pThis, VmClassAttr *pAttr);
  1789. PH7_PRIVATE sxi32 PH7_ClassInstanceToHashmap(ph7_class_instance *pThis, ph7_hashmap *pMap);
  1790. PH7_PRIVATE sxi32 PH7_ClassInstanceWalk(ph7_class_instance *pThis,
  1791. int (*xWalk)(const char *, ph7_value *, void *), void *pUserData);
  1792. PH7_PRIVATE ph7_value *PH7_ClassInstanceFetchAttr(ph7_class_instance *pThis, const SyString *pName);
  1793. /* vfs.c */
  1794. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1795. PH7_PRIVATE void *PH7_StreamOpenHandle(ph7_vm *pVm, const ph7_io_stream *pStream, const char *zFile,
  1796. int iFlags, int use_include, ph7_value *pResource, int bPushInclude, int *pNew);
  1797. PH7_PRIVATE sxi32 PH7_StreamReadWholeFile(void *pHandle, const ph7_io_stream *pStream, SyBlob *pOut);
  1798. PH7_PRIVATE void PH7_StreamCloseHandle(const ph7_io_stream *pStream, void *pHandle);
  1799. #endif /* PH7_DISABLE_BUILTIN_FUNC */
  1800. PH7_PRIVATE const char *PH7_ExtractDirName(const char *zPath, int nByte, int *pLen);
  1801. PH7_PRIVATE sxi32 PH7_RegisterIORoutine(ph7_vm *pVm);
  1802. PH7_PRIVATE const ph7_vfs *PH7_ExportBuiltinVfs(void);
  1803. PH7_PRIVATE void *PH7_ExportStdin(ph7_vm *pVm);
  1804. PH7_PRIVATE void *PH7_ExportStdout(ph7_vm *pVm);
  1805. PH7_PRIVATE void *PH7_ExportStderr(ph7_vm *pVm);
  1806. /* lib.c function prototypes */
  1807. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1808. PH7_PRIVATE sxi32 SyXMLParserInit(SyXMLParser *pParser, SyMemBackend *pAllocator, sxi32 iFlags);
  1809. PH7_PRIVATE sxi32 SyXMLParserSetEventHandler(SyXMLParser *pParser,
  1810. void *pUserData,
  1811. ProcXMLStartTagHandler xStartTag,
  1812. ProcXMLTextHandler xRaw,
  1813. ProcXMLSyntaxErrorHandler xErr,
  1814. ProcXMLStartDocument xStartDoc,
  1815. ProcXMLEndTagHandler xEndTag,
  1816. ProcXMLPIHandler xPi,
  1817. ProcXMLEndDocument xEndDoc,
  1818. ProcXMLDoctypeHandler xDoctype,
  1819. ProcXMLNameSpaceStart xNameSpace,
  1820. ProcXMLNameSpaceEnd xNameSpaceEnd
  1821. );
  1822. PH7_PRIVATE sxi32 SyXMLProcess(SyXMLParser *pParser, const char *zInput, sxu32 nByte);
  1823. PH7_PRIVATE sxi32 SyXMLParserRelease(SyXMLParser *pParser);
  1824. PH7_PRIVATE sxi32 SyArchiveInit(SyArchive *pArch, SyMemBackend *pAllocator, ProcHash xHash, ProcRawStrCmp xCmp);
  1825. PH7_PRIVATE sxi32 SyArchiveRelease(SyArchive *pArch);
  1826. PH7_PRIVATE sxi32 SyArchiveResetLoopCursor(SyArchive *pArch);
  1827. PH7_PRIVATE sxi32 SyArchiveGetNextEntry(SyArchive *pArch, SyArchiveEntry **ppEntry);
  1828. PH7_PRIVATE sxi32 SyZipExtractFromBuf(SyArchive *pArch, const char *zBuf, sxu32 nLen);
  1829. #endif /* PH7_DISABLE_BUILTIN_FUNC */
  1830. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1831. PH7_PRIVATE sxi32 SyBinToHexConsumer(const void *pIn, sxu32 nLen, ProcConsumer xConsumer, void *pConsumerData);
  1832. #endif /* PH7_DISABLE_BUILTIN_FUNC */
  1833. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1834. #ifndef PH7_DISABLE_HASH_FUNC
  1835. PH7_PRIVATE sxu32 SyCrc32(const void *pSrc, sxu32 nLen);
  1836. PH7_PRIVATE void MD5Update(MD5Context *ctx, const unsigned char *buf, unsigned int len);
  1837. PH7_PRIVATE void MD5Final(unsigned char digest[16], MD5Context *ctx);
  1838. PH7_PRIVATE sxi32 MD5Init(MD5Context *pCtx);
  1839. PH7_PRIVATE sxi32 SyMD5Compute(const void *pIn, sxu32 nLen, unsigned char zDigest[16]);
  1840. PH7_PRIVATE void SHA1Init(SHA1Context *context);
  1841. PH7_PRIVATE void SHA1Update(SHA1Context *context, const unsigned char *data, unsigned int len);
  1842. PH7_PRIVATE void SHA1Final(SHA1Context *context, unsigned char digest[20]);
  1843. PH7_PRIVATE sxi32 SySha1Compute(const void *pIn, sxu32 nLen, unsigned char zDigest[20]);
  1844. #endif
  1845. #endif /* PH7_DISABLE_BUILTIN_FUNC */
  1846. PH7_PRIVATE sxi32 SyRandomness(SyPRNGCtx *pCtx, void *pBuf, sxu32 nLen);
  1847. PH7_PRIVATE sxi32 SyRandomnessInit(SyPRNGCtx *pCtx, ProcRandomSeed xSeed, void *pUserData);
  1848. PH7_PRIVATE sxu32 SyBufferFormat(char *zBuf, sxu32 nLen, const char *zFormat, ...);
  1849. PH7_PRIVATE sxu32 SyBlobFormatAp(SyBlob *pBlob, const char *zFormat, va_list ap);
  1850. PH7_PRIVATE sxu32 SyBlobFormat(SyBlob *pBlob, const char *zFormat, ...);
  1851. PH7_PRIVATE sxi32 SyProcFormat(ProcConsumer xConsumer, void *pData, const char *zFormat, ...);
  1852. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1853. PH7_PRIVATE const char *SyTimeGetMonth(sxi32 iMonth);
  1854. PH7_PRIVATE const char *SyTimeGetDay(sxi32 iDay);
  1855. #endif /* PH7_DISABLE_BUILTIN_FUNC */
  1856. PH7_PRIVATE sxi32 SyUriDecode(const char *zSrc, sxu32 nLen, ProcConsumer xConsumer, void *pUserData, int bUTF8);
  1857. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1858. PH7_PRIVATE sxi32 SyUriEncode(const char *zSrc, sxu32 nLen, ProcConsumer xConsumer, void *pUserData);
  1859. #endif
  1860. PH7_PRIVATE sxi32 SyLexRelease(SyLex *pLex);
  1861. PH7_PRIVATE sxi32 SyLexTokenizeInput(SyLex *pLex, const char *zInput, sxu32 nLen, void *pCtxData, ProcSort xSort, ProcCmp xCmp);
  1862. PH7_PRIVATE sxi32 SyLexInit(SyLex *pLex, SySet *pSet, ProcTokenizer xTokenizer, void *pUserData);
  1863. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1864. PH7_PRIVATE sxi32 SyBase64Decode(const char *zB64, sxu32 nLen, ProcConsumer xConsumer, void *pUserData);
  1865. PH7_PRIVATE sxi32 SyBase64Encode(const char *zSrc, sxu32 nLen, ProcConsumer xConsumer, void *pUserData);
  1866. #endif /* PH7_DISABLE_BUILTIN_FUNC */
  1867. PH7_PRIVATE sxi32 SyStrToReal(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest);
  1868. PH7_PRIVATE sxi32 SyBinaryStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest);
  1869. PH7_PRIVATE sxi32 SyOctalStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest);
  1870. PH7_PRIVATE sxi32 SyHexStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest);
  1871. PH7_PRIVATE sxi32 SyHexToint(sxi32 c);
  1872. PH7_PRIVATE sxi32 SyStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest);
  1873. PH7_PRIVATE sxi32 SyStrToInt32(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest);
  1874. PH7_PRIVATE sxi32 SyStrIsNumeric(const char *zSrc, sxu32 nLen, sxu8 *pReal, const char **pzTail);
  1875. PH7_PRIVATE SyHashEntry *SyHashLastEntry(SyHash *pHash);
  1876. PH7_PRIVATE sxi32 SyHashInsert(SyHash *pHash, const void *pKey, sxu32 nKeyLen, void *pUserData);
  1877. PH7_PRIVATE sxi32 SyHashForEach(SyHash *pHash, sxi32(*xStep)(SyHashEntry *, void *), void *pUserData);
  1878. PH7_PRIVATE SyHashEntry *SyHashGetNextEntry(SyHash *pHash);
  1879. PH7_PRIVATE sxi32 SyHashResetLoopCursor(SyHash *pHash);
  1880. PH7_PRIVATE sxi32 SyHashDeleteEntry2(SyHashEntry *pEntry);
  1881. PH7_PRIVATE sxi32 SyHashDeleteEntry(SyHash *pHash, const void *pKey, sxu32 nKeyLen, void **ppUserData);
  1882. PH7_PRIVATE SyHashEntry *SyHashGet(SyHash *pHash, const void *pKey, sxu32 nKeyLen);
  1883. PH7_PRIVATE sxi32 SyHashRelease(SyHash *pHash);
  1884. PH7_PRIVATE sxi32 SyHashInit(SyHash *pHash, SyMemBackend *pAllocator, ProcHash xHash, ProcCmp xCmp);
  1885. PH7_PRIVATE sxu32 SyStrHash(const void *pSrc, sxu32 nLen);
  1886. PH7_PRIVATE void *SySetAt(SySet *pSet, sxu32 nIdx);
  1887. PH7_PRIVATE void *SySetPop(SySet *pSet);
  1888. PH7_PRIVATE void *SySetPeek(SySet *pSet);
  1889. PH7_PRIVATE sxi32 SySetRelease(SySet *pSet);
  1890. PH7_PRIVATE sxi32 SySetReset(SySet *pSet);
  1891. PH7_PRIVATE sxi32 SySetResetCursor(SySet *pSet);
  1892. PH7_PRIVATE sxi32 SySetGetNextEntry(SySet *pSet, void **ppEntry);
  1893. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1894. PH7_PRIVATE void *SySetPeekCurrentEntry(SySet *pSet);
  1895. #endif /* PH7_DISABLE_BUILTIN_FUNC */
  1896. PH7_PRIVATE sxi32 SySetTruncate(SySet *pSet, sxu32 nNewSize);
  1897. PH7_PRIVATE sxi32 SySetAlloc(SySet *pSet, sxi32 nItem);
  1898. PH7_PRIVATE sxi32 SySetPut(SySet *pSet, const void *pItem);
  1899. PH7_PRIVATE sxi32 SySetInit(SySet *pSet, SyMemBackend *pAllocator, sxu32 ElemSize);
  1900. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1901. PH7_PRIVATE sxi32 SyBlobSearch(const void *pBlob, sxu32 nLen, const void *pPattern, sxu32 pLen, sxu32 *pOfft);
  1902. #endif
  1903. PH7_PRIVATE sxi32 SyBlobRelease(SyBlob *pBlob);
  1904. PH7_PRIVATE sxi32 SyBlobReset(SyBlob *pBlob);
  1905. PH7_PRIVATE sxi32 SyBlobCmp(SyBlob *pLeft, SyBlob *pRight);
  1906. PH7_PRIVATE sxi32 SyBlobDup(SyBlob *pSrc, SyBlob *pDest);
  1907. PH7_PRIVATE sxi32 SyBlobNullAppend(SyBlob *pBlob);
  1908. PH7_PRIVATE sxi32 SyBlobAppend(SyBlob *pBlob, const void *pData, sxu32 nSize);
  1909. PH7_PRIVATE sxi32 SyBlobReadOnly(SyBlob *pBlob, const void *pData, sxu32 nByte);
  1910. PH7_PRIVATE sxi32 SyBlobInit(SyBlob *pBlob, SyMemBackend *pAllocator);
  1911. PH7_PRIVATE sxi32 SyBlobInitFromBuf(SyBlob *pBlob, void *pBuffer, sxu32 nSize);
  1912. PH7_PRIVATE char *SyMemBackendStrDup(SyMemBackend *pBackend, const char *zSrc, sxu32 nSize);
  1913. PH7_PRIVATE void *SyMemBackendDup(SyMemBackend *pBackend, const void *pSrc, sxu32 nSize);
  1914. PH7_PRIVATE sxi32 SyMemBackendRelease(SyMemBackend *pBackend);
  1915. PH7_PRIVATE sxi32 SyMemBackendInitFromOthers(SyMemBackend *pBackend, const SyMemMethods *pMethods, ProcMemError xMemErr, void *pUserData);
  1916. PH7_PRIVATE sxi32 SyMemBackendInit(SyMemBackend *pBackend, ProcMemError xMemErr, void *pUserData);
  1917. PH7_PRIVATE sxi32 SyMemBackendInitFromParent(SyMemBackend *pBackend, SyMemBackend *pParent);
  1918. #if 0
  1919. /* Not used in the current release of the PH7 engine */
  1920. PH7_PRIVATE void *SyMemBackendPoolRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nByte);
  1921. #endif
  1922. PH7_PRIVATE sxi32 SyMemBackendPoolFree(SyMemBackend *pBackend, void *pChunk);
  1923. PH7_PRIVATE void *SyMemBackendPoolAlloc(SyMemBackend *pBackend, sxu32 nByte);
  1924. PH7_PRIVATE sxi32 SyMemBackendFree(SyMemBackend *pBackend, void *pChunk);
  1925. PH7_PRIVATE void *SyMemBackendRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nByte);
  1926. PH7_PRIVATE void *SyMemBackendAlloc(SyMemBackend *pBackend, sxu32 nByte);
  1927. #if defined(PH7_ENABLE_THREADS)
  1928. PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods);
  1929. PH7_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend);
  1930. #endif
  1931. PH7_PRIVATE sxu32 SyMemcpy(const void *pSrc, void *pDest, sxu32 nLen);
  1932. PH7_PRIVATE sxi32 SyMemcmp(const void *pB1, const void *pB2, sxu32 nSize);
  1933. PH7_PRIVATE void SyZero(void *pSrc, sxu32 nSize);
  1934. PH7_PRIVATE sxi32 SyStrnicmp(const char *zLeft, const char *zRight, sxu32 SLen);
  1935. PH7_PRIVATE sxi32 SyStrnmicmp(const void *pLeft, const void *pRight, sxu32 SLen);
  1936. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1937. PH7_PRIVATE sxi32 SyStrncmp(const char *zLeft, const char *zRight, sxu32 nLen);
  1938. #endif
  1939. PH7_PRIVATE sxi32 SyByteListFind(const char *zSrc, sxu32 nLen, const char *zList, sxu32 *pFirstPos);
  1940. #ifndef PH7_DISABLE_BUILTIN_FUNC
  1941. PH7_PRIVATE sxi32 SyByteFind2(const char *zStr, sxu32 nLen, sxi32 c, sxu32 *pPos);
  1942. #endif
  1943. PH7_PRIVATE sxi32 SyByteFind(const char *zStr, sxu32 nLen, sxi32 c, sxu32 *pPos);
  1944. PH7_PRIVATE sxu32 SyStrlen(const char *zSrc);
  1945. #if defined(PH7_ENABLE_THREADS)
  1946. PH7_PRIVATE const SyMutexMethods *SyMutexExportMethods(void);
  1947. PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods);
  1948. PH7_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend);
  1949. #endif
  1950. #endif /* __PH7INT_H__ */