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.

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