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.

1891 lines
89 KiB

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