diff options
Diffstat (limited to 'common/unqlite/jx9Int.h')
-rw-r--r-- | common/unqlite/jx9Int.h | 1705 |
1 files changed, 1705 insertions, 0 deletions
diff --git a/common/unqlite/jx9Int.h b/common/unqlite/jx9Int.h new file mode 100644 index 0000000..3b2350a --- /dev/null +++ b/common/unqlite/jx9Int.h | |||
@@ -0,0 +1,1705 @@ | |||
1 | /* | ||
2 | * Symisc JX9: A Highly Efficient Embeddable Scripting Engine Based on JSON. | ||
3 | * Copyright (C) 2012-2013, Symisc Systems http://jx9.symisc.net/ | ||
4 | * Version 1.7.2 | ||
5 | * For information on licensing, redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES | ||
6 | * please contact Symisc Systems via: | ||
7 | * legal@symisc.net | ||
8 | * licensing@symisc.net | ||
9 | * contact@symisc.net | ||
10 | * or visit: | ||
11 | * http://jx9.symisc.net/ | ||
12 | */ | ||
13 | /* $SymiscID: jx9Int.h v1.9 FreeBSD 2012-08-13 23:25 devel <chm@symisc.net> $ */ | ||
14 | #ifndef __JX9INT_H__ | ||
15 | #define __JX9INT_H__ | ||
16 | /* Internal interface definitions for JX9. */ | ||
17 | #ifdef JX9_AMALGAMATION | ||
18 | #ifndef JX9_PRIVATE | ||
19 | /* Marker for routines not intended for external use */ | ||
20 | #define JX9_PRIVATE static | ||
21 | #endif /* JX9_PRIVATE */ | ||
22 | #else | ||
23 | #define JX9_PRIVATE | ||
24 | #include "jx9.h" | ||
25 | #endif | ||
26 | #ifndef JX9_PI | ||
27 | /* Value of PI */ | ||
28 | #define JX9_PI 3.1415926535898 | ||
29 | #endif | ||
30 | /* | ||
31 | * Constants for the largest and smallest possible 64-bit signed integers. | ||
32 | * These macros are designed to work correctly on both 32-bit and 64-bit | ||
33 | * compilers. | ||
34 | */ | ||
35 | #ifndef LARGEST_INT64 | ||
36 | #define LARGEST_INT64 (0xffffffff|(((sxi64)0x7fffffff)<<32)) | ||
37 | #endif | ||
38 | #ifndef SMALLEST_INT64 | ||
39 | #define SMALLEST_INT64 (((sxi64)-1) - LARGEST_INT64) | ||
40 | #endif | ||
41 | /* Forward declaration of private structures */ | ||
42 | typedef struct jx9_foreach_info jx9_foreach_info; | ||
43 | typedef struct jx9_foreach_step jx9_foreach_step; | ||
44 | typedef struct jx9_hashmap_node jx9_hashmap_node; | ||
45 | typedef struct jx9_hashmap jx9_hashmap; | ||
46 | /* Symisc Standard types */ | ||
47 | #if !defined(SYMISC_STD_TYPES) | ||
48 | #define SYMISC_STD_TYPES | ||
49 | #ifdef __WINNT__ | ||
50 | /* Disable nuisance warnings on Borland compilers */ | ||
51 | #if defined(__BORLANDC__) | ||
52 | #pragma warn -rch /* unreachable code */ | ||
53 | #pragma warn -ccc /* Condition is always true or false */ | ||
54 | #pragma warn -aus /* Assigned value is never used */ | ||
55 | #pragma warn -csu /* Comparing signed and unsigned */ | ||
56 | #pragma warn -spa /* Suspicious pointer arithmetic */ | ||
57 | #endif | ||
58 | #endif | ||
59 | typedef signed char sxi8; /* signed char */ | ||
60 | typedef unsigned char sxu8; /* unsigned char */ | ||
61 | typedef signed short int sxi16; /* 16 bits(2 bytes) signed integer */ | ||
62 | typedef unsigned short int sxu16; /* 16 bits(2 bytes) unsigned integer */ | ||
63 | typedef int sxi32; /* 32 bits(4 bytes) integer */ | ||
64 | typedef unsigned int sxu32; /* 32 bits(4 bytes) unsigned integer */ | ||
65 | typedef long sxptr; | ||
66 | typedef unsigned long sxuptr; | ||
67 | typedef long sxlong; | ||
68 | typedef unsigned long sxulong; | ||
69 | typedef sxi32 sxofft; | ||
70 | typedef sxi64 sxofft64; | ||
71 | typedef long double sxlongreal; | ||
72 | typedef double sxreal; | ||
73 | #define SXI8_HIGH 0x7F | ||
74 | #define SXU8_HIGH 0xFF | ||
75 | #define SXI16_HIGH 0x7FFF | ||
76 | #define SXU16_HIGH 0xFFFF | ||
77 | #define SXI32_HIGH 0x7FFFFFFF | ||
78 | #define SXU32_HIGH 0xFFFFFFFF | ||
79 | #define SXI64_HIGH 0x7FFFFFFFFFFFFFFF | ||
80 | #define SXU64_HIGH 0xFFFFFFFFFFFFFFFF | ||
81 | #if !defined(TRUE) | ||
82 | #define TRUE 1 | ||
83 | #endif | ||
84 | #if !defined(FALSE) | ||
85 | #define FALSE 0 | ||
86 | #endif | ||
87 | /* | ||
88 | * The following macros are used to cast pointers to integers and | ||
89 | * integers to pointers. | ||
90 | */ | ||
91 | #if defined(__PTRDIFF_TYPE__) | ||
92 | # define SX_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X)) | ||
93 | # define SX_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X)) | ||
94 | #elif !defined(__GNUC__) | ||
95 | # define SX_INT_TO_PTR(X) ((void*)&((char*)0)[X]) | ||
96 | # define SX_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) | ||
97 | #else | ||
98 | # define SX_INT_TO_PTR(X) ((void*)(X)) | ||
99 | # define SX_PTR_TO_INT(X) ((int)(X)) | ||
100 | #endif | ||
101 | #define SXMIN(a, b) ((a < b) ? (a) : (b)) | ||
102 | #define SXMAX(a, b) ((a < b) ? (b) : (a)) | ||
103 | #endif /* SYMISC_STD_TYPES */ | ||
104 | /* Symisc Run-time API private definitions */ | ||
105 | #if !defined(SYMISC_PRIVATE_DEFS) | ||
106 | #define SYMISC_PRIVATE_DEFS | ||
107 | |||
108 | typedef sxi32 (*ProcRawStrCmp)(const SyString *, const SyString *); | ||
109 | #define SyStringData(RAW) ((RAW)->zString) | ||
110 | #define SyStringLength(RAW) ((RAW)->nByte) | ||
111 | #define SyStringInitFromBuf(RAW, ZBUF, NLEN){\ | ||
112 | (RAW)->zString = (const char *)ZBUF;\ | ||
113 | (RAW)->nByte = (sxu32)(NLEN);\ | ||
114 | } | ||
115 | #define SyStringUpdatePtr(RAW, NBYTES){\ | ||
116 | if( NBYTES > (RAW)->nByte ){\ | ||
117 | (RAW)->nByte = 0;\ | ||
118 | }else{\ | ||
119 | (RAW)->zString += NBYTES;\ | ||
120 | (RAW)->nByte -= NBYTES;\ | ||
121 | }\ | ||
122 | } | ||
123 | #define SyStringDupPtr(RAW1, RAW2)\ | ||
124 | (RAW1)->zString = (RAW2)->zString;\ | ||
125 | (RAW1)->nByte = (RAW2)->nByte; | ||
126 | |||
127 | #define SyStringTrimLeadingChar(RAW, CHAR)\ | ||
128 | while((RAW)->nByte > 0 && (RAW)->zString[0] == CHAR ){\ | ||
129 | (RAW)->zString++;\ | ||
130 | (RAW)->nByte--;\ | ||
131 | } | ||
132 | #define SyStringTrimTrailingChar(RAW, CHAR)\ | ||
133 | while((RAW)->nByte > 0 && (RAW)->zString[(RAW)->nByte - 1] == CHAR){\ | ||
134 | (RAW)->nByte--;\ | ||
135 | } | ||
136 | #define SyStringCmp(RAW1, RAW2, xCMP)\ | ||
137 | (((RAW1)->nByte == (RAW2)->nByte) ? xCMP((RAW1)->zString, (RAW2)->zString, (RAW2)->nByte) : (sxi32)((RAW1)->nByte - (RAW2)->nByte)) | ||
138 | |||
139 | #define SyStringCmp2(RAW1, RAW2, xCMP)\ | ||
140 | (((RAW1)->nByte >= (RAW2)->nByte) ? xCMP((RAW1)->zString, (RAW2)->zString, (RAW2)->nByte) : (sxi32)((RAW2)->nByte - (RAW1)->nByte)) | ||
141 | |||
142 | #define SyStringCharCmp(RAW, CHAR) \ | ||
143 | (((RAW)->nByte == sizeof(char)) ? ((RAW)->zString[0] == CHAR ? 0 : CHAR - (RAW)->zString[0]) : ((RAW)->zString[0] == CHAR ? 0 : (RAW)->nByte - sizeof(char))) | ||
144 | |||
145 | #define SX_ADDR(PTR) ((sxptr)PTR) | ||
146 | #define SX_ARRAYSIZE(X) (sizeof(X)/sizeof(X[0])) | ||
147 | #define SXUNUSED(P) (P = 0) | ||
148 | #define SX_EMPTY(PTR) (PTR == 0) | ||
149 | #define SX_EMPTY_STR(STR) (STR == 0 || STR[0] == 0 ) | ||
150 | typedef struct SyMemBackend SyMemBackend; | ||
151 | typedef struct SyBlob SyBlob; | ||
152 | typedef struct SySet SySet; | ||
153 | /* Standard function signatures */ | ||
154 | typedef sxi32 (*ProcCmp)(const void *, const void *, sxu32); | ||
155 | typedef sxi32 (*ProcPatternMatch)(const char *, sxu32, const char *, sxu32, sxu32 *); | ||
156 | typedef sxi32 (*ProcSearch)(const void *, sxu32, const void *, sxu32, ProcCmp, sxu32 *); | ||
157 | typedef sxu32 (*ProcHash)(const void *, sxu32); | ||
158 | typedef sxi32 (*ProcHashSum)(const void *, sxu32, unsigned char *, sxu32); | ||
159 | typedef sxi32 (*ProcSort)(void *, sxu32, sxu32, ProcCmp); | ||
160 | #define MACRO_LIST_PUSH(Head, Item)\ | ||
161 | Item->pNext = Head;\ | ||
162 | Head = Item; | ||
163 | #define MACRO_LD_PUSH(Head, Item)\ | ||
164 | if( Head == 0 ){\ | ||
165 | Head = Item;\ | ||
166 | }else{\ | ||
167 | Item->pNext = Head;\ | ||
168 | Head->pPrev = Item;\ | ||
169 | Head = Item;\ | ||
170 | } | ||
171 | #define MACRO_LD_REMOVE(Head, Item)\ | ||
172 | if( Head == Item ){\ | ||
173 | Head = Head->pNext;\ | ||
174 | }\ | ||
175 | if( Item->pPrev ){ Item->pPrev->pNext = Item->pNext;}\ | ||
176 | if( Item->pNext ){ Item->pNext->pPrev = Item->pPrev;} | ||
177 | /* | ||
178 | * A generic dynamic set. | ||
179 | */ | ||
180 | struct SySet | ||
181 | { | ||
182 | SyMemBackend *pAllocator; /* Memory backend */ | ||
183 | void *pBase; /* Base pointer */ | ||
184 | sxu32 nUsed; /* Total number of used slots */ | ||
185 | sxu32 nSize; /* Total number of available slots */ | ||
186 | sxu32 eSize; /* Size of a single slot */ | ||
187 | sxu32 nCursor; /* Loop cursor */ | ||
188 | void *pUserData; /* User private data associated with this container */ | ||
189 | }; | ||
190 | #define SySetBasePtr(S) ((S)->pBase) | ||
191 | #define SySetBasePtrJump(S, OFFT) (&((char *)(S)->pBase)[OFFT*(S)->eSize]) | ||
192 | #define SySetUsed(S) ((S)->nUsed) | ||
193 | #define SySetSize(S) ((S)->nSize) | ||
194 | #define SySetElemSize(S) ((S)->eSize) | ||
195 | #define SySetCursor(S) ((S)->nCursor) | ||
196 | #define SySetGetAllocator(S) ((S)->pAllocator) | ||
197 | #define SySetSetUserData(S, DATA) ((S)->pUserData = DATA) | ||
198 | #define SySetGetUserData(S) ((S)->pUserData) | ||
199 | /* | ||
200 | * A variable length containers for generic data. | ||
201 | */ | ||
202 | struct SyBlob | ||
203 | { | ||
204 | SyMemBackend *pAllocator; /* Memory backend */ | ||
205 | void *pBlob; /* Base pointer */ | ||
206 | sxu32 nByte; /* Total number of used bytes */ | ||
207 | sxu32 mByte; /* Total number of available bytes */ | ||
208 | sxu32 nFlags; /* Blob internal flags, see below */ | ||
209 | }; | ||
210 | #define SXBLOB_LOCKED 0x01 /* Blob is locked [i.e: Cannot auto grow] */ | ||
211 | #define SXBLOB_STATIC 0x02 /* Not allocated from heap */ | ||
212 | #define SXBLOB_RDONLY 0x04 /* Read-Only data */ | ||
213 | |||
214 | #define SyBlobFreeSpace(BLOB) ((BLOB)->mByte - (BLOB)->nByte) | ||
215 | #define SyBlobLength(BLOB) ((BLOB)->nByte) | ||
216 | #define SyBlobData(BLOB) ((BLOB)->pBlob) | ||
217 | #define SyBlobCurData(BLOB) ((void*)(&((char*)(BLOB)->pBlob)[(BLOB)->nByte])) | ||
218 | #define SyBlobDataAt(BLOB, OFFT) ((void *)(&((char *)(BLOB)->pBlob)[OFFT])) | ||
219 | #define SyBlobGetAllocator(BLOB) ((BLOB)->pAllocator) | ||
220 | |||
221 | #define SXMEM_POOL_INCR 3 | ||
222 | #define SXMEM_POOL_NBUCKETS 12 | ||
223 | #define SXMEM_BACKEND_MAGIC 0xBAC3E67D | ||
224 | #define SXMEM_BACKEND_CORRUPT(BACKEND) (BACKEND == 0 || BACKEND->nMagic != SXMEM_BACKEND_MAGIC) | ||
225 | |||
226 | #define SXMEM_BACKEND_RETRY 3 | ||
227 | /* A memory backend subsystem is defined by an instance of the following structures */ | ||
228 | typedef union SyMemHeader SyMemHeader; | ||
229 | typedef struct SyMemBlock SyMemBlock; | ||
230 | struct SyMemBlock | ||
231 | { | ||
232 | SyMemBlock *pNext, *pPrev; /* Chain of allocated memory blocks */ | ||
233 | #ifdef UNTRUST | ||
234 | sxu32 nGuard; /* magic number associated with each valid block, so we | ||
235 | * can detect misuse. | ||
236 | */ | ||
237 | #endif | ||
238 | }; | ||
239 | /* | ||
240 | * Header associated with each valid memory pool block. | ||
241 | */ | ||
242 | union SyMemHeader | ||
243 | { | ||
244 | SyMemHeader *pNext; /* Next chunk of size 1 << (nBucket + SXMEM_POOL_INCR) in the list */ | ||
245 | sxu32 nBucket; /* Bucket index in aPool[] */ | ||
246 | }; | ||
247 | struct SyMemBackend | ||
248 | { | ||
249 | const SyMutexMethods *pMutexMethods; /* Mutex methods */ | ||
250 | const SyMemMethods *pMethods; /* Memory allocation methods */ | ||
251 | SyMemBlock *pBlocks; /* List of valid memory blocks */ | ||
252 | sxu32 nBlock; /* Total number of memory blocks allocated so far */ | ||
253 | ProcMemError xMemError; /* Out-of memory callback */ | ||
254 | void *pUserData; /* First arg to xMemError() */ | ||
255 | SyMutex *pMutex; /* Per instance mutex */ | ||
256 | sxu32 nMagic; /* Sanity check against misuse */ | ||
257 | SyMemHeader *apPool[SXMEM_POOL_NBUCKETS+SXMEM_POOL_INCR]; /* Pool of memory chunks */ | ||
258 | }; | ||
259 | /* Mutex types */ | ||
260 | #define SXMUTEX_TYPE_FAST 1 | ||
261 | #define SXMUTEX_TYPE_RECURSIVE 2 | ||
262 | #define SXMUTEX_TYPE_STATIC_1 3 | ||
263 | #define SXMUTEX_TYPE_STATIC_2 4 | ||
264 | #define SXMUTEX_TYPE_STATIC_3 5 | ||
265 | #define SXMUTEX_TYPE_STATIC_4 6 | ||
266 | #define SXMUTEX_TYPE_STATIC_5 7 | ||
267 | #define SXMUTEX_TYPE_STATIC_6 8 | ||
268 | |||
269 | #define SyMutexGlobalInit(METHOD){\ | ||
270 | if( (METHOD)->xGlobalInit ){\ | ||
271 | (METHOD)->xGlobalInit();\ | ||
272 | }\ | ||
273 | } | ||
274 | #define SyMutexGlobalRelease(METHOD){\ | ||
275 | if( (METHOD)->xGlobalRelease ){\ | ||
276 | (METHOD)->xGlobalRelease();\ | ||
277 | }\ | ||
278 | } | ||
279 | #define SyMutexNew(METHOD, TYPE) (METHOD)->xNew(TYPE) | ||
280 | #define SyMutexRelease(METHOD, MUTEX){\ | ||
281 | if( MUTEX && (METHOD)->xRelease ){\ | ||
282 | (METHOD)->xRelease(MUTEX);\ | ||
283 | }\ | ||
284 | } | ||
285 | #define SyMutexEnter(METHOD, MUTEX){\ | ||
286 | if( MUTEX ){\ | ||
287 | (METHOD)->xEnter(MUTEX);\ | ||
288 | }\ | ||
289 | } | ||
290 | #define SyMutexTryEnter(METHOD, MUTEX){\ | ||
291 | if( MUTEX && (METHOD)->xTryEnter ){\ | ||
292 | (METHOD)->xTryEnter(MUTEX);\ | ||
293 | }\ | ||
294 | } | ||
295 | #define SyMutexLeave(METHOD, MUTEX){\ | ||
296 | if( MUTEX ){\ | ||
297 | (METHOD)->xLeave(MUTEX);\ | ||
298 | }\ | ||
299 | } | ||
300 | /* Comparison, byte swap, byte copy macros */ | ||
301 | #define SX_MACRO_FAST_CMP(X1, X2, SIZE, RC){\ | ||
302 | register unsigned char *r1 = (unsigned char *)X1;\ | ||
303 | register unsigned char *r2 = (unsigned char *)X2;\ | ||
304 | register sxu32 LEN = SIZE;\ | ||
305 | for(;;){\ | ||
306 | if( !LEN ){ break; }if( r1[0] != r2[0] ){ break; } r1++; r2++; LEN--;\ | ||
307 | if( !LEN ){ break; }if( r1[0] != r2[0] ){ break; } r1++; r2++; LEN--;\ | ||
308 | if( !LEN ){ break; }if( r1[0] != r2[0] ){ break; } r1++; r2++; LEN--;\ | ||
309 | if( !LEN ){ break; }if( r1[0] != r2[0] ){ break; } r1++; r2++; LEN--;\ | ||
310 | }\ | ||
311 | RC = !LEN ? 0 : r1[0] - r2[0];\ | ||
312 | } | ||
313 | #define SX_MACRO_FAST_MEMCPY(SRC, DST, SIZ){\ | ||
314 | register unsigned char *xSrc = (unsigned char *)SRC;\ | ||
315 | register unsigned char *xDst = (unsigned char *)DST;\ | ||
316 | register sxu32 xLen = SIZ;\ | ||
317 | for(;;){\ | ||
318 | if( !xLen ){ break; }xDst[0] = xSrc[0]; xDst++; xSrc++; --xLen;\ | ||
319 | if( !xLen ){ break; }xDst[0] = xSrc[0]; xDst++; xSrc++; --xLen;\ | ||
320 | if( !xLen ){ break; }xDst[0] = xSrc[0]; xDst++; xSrc++; --xLen;\ | ||
321 | if( !xLen ){ break; }xDst[0] = xSrc[0]; xDst++; xSrc++; --xLen;\ | ||
322 | }\ | ||
323 | } | ||
324 | #define SX_MACRO_BYTE_SWAP(X, Y, Z){\ | ||
325 | register unsigned char *s = (unsigned char *)X;\ | ||
326 | register unsigned char *d = (unsigned char *)Y;\ | ||
327 | sxu32 ZLong = Z; \ | ||
328 | sxi32 c; \ | ||
329 | for(;;){\ | ||
330 | if(!ZLong){ break; } c = s[0] ; s[0] = d[0]; d[0] = (unsigned char)c; s++; d++; --ZLong;\ | ||
331 | if(!ZLong){ break; } c = s[0] ; s[0] = d[0]; d[0] = (unsigned char)c; s++; d++; --ZLong;\ | ||
332 | if(!ZLong){ break; } c = s[0] ; s[0] = d[0]; d[0] = (unsigned char)c; s++; d++; --ZLong;\ | ||
333 | if(!ZLong){ break; } c = s[0] ; s[0] = d[0]; d[0] = (unsigned char)c; s++; d++; --ZLong;\ | ||
334 | }\ | ||
335 | } | ||
336 | #define SX_MSEC_PER_SEC (1000) /* Millisec per seconds */ | ||
337 | #define SX_USEC_PER_SEC (1000000) /* Microsec per seconds */ | ||
338 | #define SX_NSEC_PER_SEC (1000000000) /* Nanosec per seconds */ | ||
339 | #endif /* SYMISC_PRIVATE_DEFS */ | ||
340 | /* Symisc Run-time API auxiliary definitions */ | ||
341 | #if !defined(SYMISC_PRIVATE_AUX_DEFS) | ||
342 | #define SYMISC_PRIVATE_AUX_DEFS | ||
343 | |||
344 | typedef struct SyHashEntry_Pr SyHashEntry_Pr; | ||
345 | typedef struct SyHashEntry SyHashEntry; | ||
346 | typedef struct SyHash SyHash; | ||
347 | /* | ||
348 | * Each public hashtable entry is represented by an instance | ||
349 | * of the following structure. | ||
350 | */ | ||
351 | struct SyHashEntry | ||
352 | { | ||
353 | const void *pKey; /* Hash key */ | ||
354 | sxu32 nKeyLen; /* Key length */ | ||
355 | void *pUserData; /* User private data */ | ||
356 | }; | ||
357 | #define SyHashEntryGetUserData(ENTRY) ((ENTRY)->pUserData) | ||
358 | #define SyHashEntryGetKey(ENTRY) ((ENTRY)->pKey) | ||
359 | /* Each active hashtable is identified by an instance of the following structure */ | ||
360 | struct SyHash | ||
361 | { | ||
362 | SyMemBackend *pAllocator; /* Memory backend */ | ||
363 | ProcHash xHash; /* Hash function */ | ||
364 | ProcCmp xCmp; /* Comparison function */ | ||
365 | SyHashEntry_Pr *pList, *pCurrent; /* Linked list of hash entries user for linear traversal */ | ||
366 | sxu32 nEntry; /* Total number of entries */ | ||
367 | SyHashEntry_Pr **apBucket; /* Hash buckets */ | ||
368 | sxu32 nBucketSize; /* Current bucket size */ | ||
369 | }; | ||
370 | #define SXHASH_BUCKET_SIZE 16 /* Initial bucket size: must be a power of two */ | ||
371 | #define SXHASH_FILL_FACTOR 3 | ||
372 | /* Hash access macro */ | ||
373 | #define SyHashFunc(HASH) ((HASH)->xHash) | ||
374 | #define SyHashCmpFunc(HASH) ((HASH)->xCmp) | ||
375 | #define SyHashTotalEntry(HASH) ((HASH)->nEntry) | ||
376 | #define SyHashGetPool(HASH) ((HASH)->pAllocator) | ||
377 | /* | ||
378 | * An instance of the following structure define a single context | ||
379 | * for an Pseudo Random Number Generator. | ||
380 | * | ||
381 | * Nothing in this file or anywhere else in the library does any kind of | ||
382 | * encryption. The RC4 algorithm is being used as a PRNG (pseudo-random | ||
383 | * number generator) not as an encryption device. | ||
384 | * This implementation is taken from the SQLite3 source tree. | ||
385 | */ | ||
386 | typedef struct SyPRNGCtx SyPRNGCtx; | ||
387 | struct SyPRNGCtx | ||
388 | { | ||
389 | sxu8 i, j; /* State variables */ | ||
390 | unsigned char s[256]; /* State variables */ | ||
391 | sxu16 nMagic; /* Sanity check */ | ||
392 | }; | ||
393 | typedef sxi32 (*ProcRandomSeed)(void *, unsigned int, void *); | ||
394 | /* High resolution timer.*/ | ||
395 | typedef struct sytime sytime; | ||
396 | struct sytime | ||
397 | { | ||
398 | long tm_sec; /* seconds */ | ||
399 | long tm_usec; /* microseconds */ | ||
400 | }; | ||
401 | /* Forward declaration */ | ||
402 | typedef struct SyStream SyStream; | ||
403 | typedef struct SyToken SyToken; | ||
404 | typedef struct SyLex SyLex; | ||
405 | /* | ||
406 | * Tokenizer callback signature. | ||
407 | */ | ||
408 | typedef sxi32 (*ProcTokenizer)(SyStream *, SyToken *, void *, void *); | ||
409 | /* | ||
410 | * Each token in the input is represented by an instance | ||
411 | * of the following structure. | ||
412 | */ | ||
413 | struct SyToken | ||
414 | { | ||
415 | SyString sData; /* Token text and length */ | ||
416 | sxu32 nType; /* Token type */ | ||
417 | sxu32 nLine; /* Token line number */ | ||
418 | void *pUserData; /* User private data associated with this token */ | ||
419 | }; | ||
420 | /* | ||
421 | * During tokenization, information about the state of the input | ||
422 | * stream is held in an instance of the following structure. | ||
423 | */ | ||
424 | struct SyStream | ||
425 | { | ||
426 | const unsigned char *zInput; /* Complete text of the input */ | ||
427 | const unsigned char *zText; /* Current input we are processing */ | ||
428 | const unsigned char *zEnd; /* End of input marker */ | ||
429 | sxu32 nLine; /* Total number of processed lines */ | ||
430 | sxu32 nIgn; /* Total number of ignored tokens */ | ||
431 | SySet *pSet; /* Token containers */ | ||
432 | }; | ||
433 | /* | ||
434 | * Each lexer is represented by an instance of the following structure. | ||
435 | */ | ||
436 | struct SyLex | ||
437 | { | ||
438 | SyStream sStream; /* Input stream */ | ||
439 | ProcTokenizer xTokenizer; /* Tokenizer callback */ | ||
440 | void * pUserData; /* Third argument to xTokenizer() */ | ||
441 | SySet *pTokenSet; /* Token set */ | ||
442 | }; | ||
443 | #define SyLexTotalToken(LEX) SySetTotalEntry(&(LEX)->aTokenSet) | ||
444 | #define SyLexTotalLines(LEX) ((LEX)->sStream.nLine) | ||
445 | #define SyLexTotalIgnored(LEX) ((LEX)->sStream.nIgn) | ||
446 | #define XLEX_IN_LEN(STREAM) (sxu32)(STREAM->zEnd - STREAM->zText) | ||
447 | #endif /* SYMISC_PRIVATE_AUX_DEFS */ | ||
448 | /* | ||
449 | ** Notes on UTF-8 (According to SQLite3 authors): | ||
450 | ** | ||
451 | ** Byte-0 Byte-1 Byte-2 Byte-3 Value | ||
452 | ** 0xxxxxxx 00000000 00000000 0xxxxxxx | ||
453 | ** 110yyyyy 10xxxxxx 00000000 00000yyy yyxxxxxx | ||
454 | ** 1110zzzz 10yyyyyy 10xxxxxx 00000000 zzzzyyyy yyxxxxxx | ||
455 | ** 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx 000uuuuu zzzzyyyy yyxxxxxx | ||
456 | ** | ||
457 | */ | ||
458 | /* | ||
459 | ** Assuming zIn points to the first byte of a UTF-8 character, | ||
460 | ** advance zIn to point to the first byte of the next UTF-8 character. | ||
461 | */ | ||
462 | #define SX_JMP_UTF8(zIn, zEnd)\ | ||
463 | while(zIn < zEnd && (((unsigned char)zIn[0] & 0xc0) == 0x80) ){ zIn++; } | ||
464 | #define SX_WRITE_UTF8(zOut, c) { \ | ||
465 | if( c<0x00080 ){ \ | ||
466 | *zOut++ = (sxu8)(c&0xFF); \ | ||
467 | }else if( c<0x00800 ){ \ | ||
468 | *zOut++ = 0xC0 + (sxu8)((c>>6)&0x1F); \ | ||
469 | *zOut++ = 0x80 + (sxu8)(c & 0x3F); \ | ||
470 | }else if( c<0x10000 ){ \ | ||
471 | *zOut++ = 0xE0 + (sxu8)((c>>12)&0x0F); \ | ||
472 | *zOut++ = 0x80 + (sxu8)((c>>6) & 0x3F); \ | ||
473 | *zOut++ = 0x80 + (sxu8)(c & 0x3F); \ | ||
474 | }else{ \ | ||
475 | *zOut++ = 0xF0 + (sxu8)((c>>18) & 0x07); \ | ||
476 | *zOut++ = 0x80 + (sxu8)((c>>12) & 0x3F); \ | ||
477 | *zOut++ = 0x80 + (sxu8)((c>>6) & 0x3F); \ | ||
478 | *zOut++ = 0x80 + (sxu8)(c & 0x3F); \ | ||
479 | } \ | ||
480 | } | ||
481 | /* Rely on the standard ctype */ | ||
482 | #include <ctype.h> | ||
483 | #define SyToUpper(c) toupper(c) | ||
484 | #define SyToLower(c) tolower(c) | ||
485 | #define SyisUpper(c) isupper(c) | ||
486 | #define SyisLower(c) islower(c) | ||
487 | #define SyisSpace(c) isspace(c) | ||
488 | #define SyisBlank(c) isspace(c) | ||
489 | #define SyisAlpha(c) isalpha(c) | ||
490 | #define SyisDigit(c) isdigit(c) | ||
491 | #define SyisHex(c) isxdigit(c) | ||
492 | #define SyisPrint(c) isprint(c) | ||
493 | #define SyisPunct(c) ispunct(c) | ||
494 | #define SyisSpec(c) iscntrl(c) | ||
495 | #define SyisCtrl(c) iscntrl(c) | ||
496 | #define SyisAscii(c) isascii(c) | ||
497 | #define SyisAlphaNum(c) isalnum(c) | ||
498 | #define SyisGraph(c) isgraph(c) | ||
499 | #define SyDigToHex(c) "0123456789ABCDEF"[c & 0x0F] | ||
500 | #define SyDigToInt(c) ((c < 0xc0 && SyisDigit(c))? (c - '0') : 0 ) | ||
501 | #define SyCharToUpper(c) ((c < 0xc0 && SyisLower(c))? SyToUpper(c) : c) | ||
502 | #define SyCharToLower(c) ((c < 0xc0 && SyisUpper(c))? SyToLower(c) : c) | ||
503 | /* Remove white space/NUL byte from a raw string */ | ||
504 | #define SyStringLeftTrim(RAW)\ | ||
505 | while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[0] < 0xc0 && SyisSpace((RAW)->zString[0])){\ | ||
506 | (RAW)->nByte--;\ | ||
507 | (RAW)->zString++;\ | ||
508 | } | ||
509 | #define SyStringLeftTrimSafe(RAW)\ | ||
510 | while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[0] < 0xc0 && ((RAW)->zString[0] == 0 || SyisSpace((RAW)->zString[0]))){\ | ||
511 | (RAW)->nByte--;\ | ||
512 | (RAW)->zString++;\ | ||
513 | } | ||
514 | #define SyStringRightTrim(RAW)\ | ||
515 | while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[(RAW)->nByte - 1] < 0xc0 && SyisSpace((RAW)->zString[(RAW)->nByte - 1])){\ | ||
516 | (RAW)->nByte--;\ | ||
517 | } | ||
518 | #define SyStringRightTrimSafe(RAW)\ | ||
519 | while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[(RAW)->nByte - 1] < 0xc0 && \ | ||
520 | (( RAW)->zString[(RAW)->nByte - 1] == 0 || SyisSpace((RAW)->zString[(RAW)->nByte - 1]))){\ | ||
521 | (RAW)->nByte--;\ | ||
522 | } | ||
523 | |||
524 | #define SyStringFullTrim(RAW)\ | ||
525 | while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[0] < 0xc0 && SyisSpace((RAW)->zString[0])){\ | ||
526 | (RAW)->nByte--;\ | ||
527 | (RAW)->zString++;\ | ||
528 | }\ | ||
529 | while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[(RAW)->nByte - 1] < 0xc0 && SyisSpace((RAW)->zString[(RAW)->nByte - 1])){\ | ||
530 | (RAW)->nByte--;\ | ||
531 | } | ||
532 | #define SyStringFullTrimSafe(RAW)\ | ||
533 | while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[0] < 0xc0 && \ | ||
534 | ( (RAW)->zString[0] == 0 || SyisSpace((RAW)->zString[0]))){\ | ||
535 | (RAW)->nByte--;\ | ||
536 | (RAW)->zString++;\ | ||
537 | }\ | ||
538 | while((RAW)->nByte > 0 && (unsigned char)(RAW)->zString[(RAW)->nByte - 1] < 0xc0 && \ | ||
539 | ( (RAW)->zString[(RAW)->nByte - 1] == 0 || SyisSpace((RAW)->zString[(RAW)->nByte - 1]))){\ | ||
540 | (RAW)->nByte--;\ | ||
541 | } | ||
542 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
543 | /* | ||
544 | * An XML raw text, CDATA, tag name and son is parsed out and stored | ||
545 | * in an instance of the following structure. | ||
546 | */ | ||
547 | typedef struct SyXMLRawStr SyXMLRawStr; | ||
548 | struct SyXMLRawStr | ||
549 | { | ||
550 | const char *zString; /* Raw text [UTF-8 ENCODED EXCEPT CDATA] [NOT NULL TERMINATED] */ | ||
551 | sxu32 nByte; /* Text length */ | ||
552 | sxu32 nLine; /* Line number this text occurs */ | ||
553 | }; | ||
554 | /* | ||
555 | * Event callback signatures. | ||
556 | */ | ||
557 | typedef sxi32 (*ProcXMLStartTagHandler)(SyXMLRawStr *, SyXMLRawStr *, sxu32, SyXMLRawStr *, void *); | ||
558 | typedef sxi32 (*ProcXMLTextHandler)(SyXMLRawStr *, void *); | ||
559 | typedef sxi32 (*ProcXMLEndTagHandler)(SyXMLRawStr *, SyXMLRawStr *, void *); | ||
560 | typedef sxi32 (*ProcXMLPIHandler)(SyXMLRawStr *, SyXMLRawStr *, void *); | ||
561 | typedef sxi32 (*ProcXMLDoctypeHandler)(SyXMLRawStr *, void *); | ||
562 | typedef sxi32 (*ProcXMLSyntaxErrorHandler)(const char *, int, SyToken *, void *); | ||
563 | typedef sxi32 (*ProcXMLStartDocument)(void *); | ||
564 | typedef sxi32 (*ProcXMLNameSpaceStart)(SyXMLRawStr *, SyXMLRawStr *, void *); | ||
565 | typedef sxi32 (*ProcXMLNameSpaceEnd)(SyXMLRawStr *, void *); | ||
566 | typedef sxi32 (*ProcXMLEndDocument)(void *); | ||
567 | /* XML processing control flags */ | ||
568 | #define SXML_ENABLE_NAMESPACE 0x01 /* Parse XML with namespace support enbaled */ | ||
569 | #define SXML_ENABLE_QUERY 0x02 /* Not used */ | ||
570 | #define SXML_OPTION_CASE_FOLDING 0x04 /* Controls whether case-folding is enabled for this XML parser */ | ||
571 | #define SXML_OPTION_SKIP_TAGSTART 0x08 /* Specify how many characters should be skipped in the beginning of a tag name.*/ | ||
572 | #define SXML_OPTION_SKIP_WHITE 0x10 /* Whether to skip values consisting of whitespace characters. */ | ||
573 | #define SXML_OPTION_TARGET_ENCODING 0x20 /* Default encoding: UTF-8 */ | ||
574 | /* XML error codes */ | ||
575 | enum xml_err_code{ | ||
576 | SXML_ERROR_NONE = 1, | ||
577 | SXML_ERROR_NO_MEMORY, | ||
578 | SXML_ERROR_SYNTAX, | ||
579 | SXML_ERROR_NO_ELEMENTS, | ||
580 | SXML_ERROR_INVALID_TOKEN, | ||
581 | SXML_ERROR_UNCLOSED_TOKEN, | ||
582 | SXML_ERROR_PARTIAL_CHAR, | ||
583 | SXML_ERROR_TAG_MISMATCH, | ||
584 | SXML_ERROR_DUPLICATE_ATTRIBUTE, | ||
585 | SXML_ERROR_JUNK_AFTER_DOC_ELEMENT, | ||
586 | SXML_ERROR_PARAM_ENTITY_REF, | ||
587 | SXML_ERROR_UNDEFINED_ENTITY, | ||
588 | SXML_ERROR_RECURSIVE_ENTITY_REF, | ||
589 | SXML_ERROR_ASYNC_ENTITY, | ||
590 | SXML_ERROR_BAD_CHAR_REF, | ||
591 | SXML_ERROR_BINARY_ENTITY_REF, | ||
592 | SXML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, | ||
593 | SXML_ERROR_MISPLACED_XML_PI, | ||
594 | SXML_ERROR_UNKNOWN_ENCODING, | ||
595 | SXML_ERROR_INCORRECT_ENCODING, | ||
596 | SXML_ERROR_UNCLOSED_CDATA_SECTION, | ||
597 | SXML_ERROR_EXTERNAL_ENTITY_HANDLING | ||
598 | }; | ||
599 | /* Each active XML SAX parser is represented by an instance | ||
600 | * of the following structure. | ||
601 | */ | ||
602 | typedef struct SyXMLParser SyXMLParser; | ||
603 | struct SyXMLParser | ||
604 | { | ||
605 | SyMemBackend *pAllocator; /* Memory backend */ | ||
606 | void *pUserData; /* User private data forwarded varbatim by the XML parser | ||
607 | * as the last argument to the users callbacks. | ||
608 | */ | ||
609 | SyHash hns; /* Namespace hashtable */ | ||
610 | SySet sToken; /* XML tokens */ | ||
611 | SyLex sLex; /* Lexical analyzer */ | ||
612 | sxi32 nFlags; /* Control flags */ | ||
613 | /* User callbacks */ | ||
614 | ProcXMLStartTagHandler xStartTag; /* Start element handler */ | ||
615 | ProcXMLEndTagHandler xEndTag; /* End element handler */ | ||
616 | ProcXMLTextHandler xRaw; /* Raw text/CDATA handler */ | ||
617 | ProcXMLDoctypeHandler xDoctype; /* DOCTYPE handler */ | ||
618 | ProcXMLPIHandler xPi; /* Processing instruction (PI) handler*/ | ||
619 | ProcXMLSyntaxErrorHandler xError; /* Error handler */ | ||
620 | ProcXMLStartDocument xStartDoc; /* StartDoc handler */ | ||
621 | ProcXMLEndDocument xEndDoc; /* EndDoc handler */ | ||
622 | ProcXMLNameSpaceStart xNameSpace; /* Namespace declaration handler */ | ||
623 | ProcXMLNameSpaceEnd xNameSpaceEnd; /* End namespace declaration handler */ | ||
624 | }; | ||
625 | /* | ||
626 | * -------------- | ||
627 | * Archive extractor: | ||
628 | * -------------- | ||
629 | * Each open ZIP/TAR archive is identified by an instance of the following structure. | ||
630 | * That is, a process can open one or more archives and manipulates them in thread safe | ||
631 | * way by simply working with pointers to the following structure. | ||
632 | * Each entry in the archive is remembered in a hashtable. | ||
633 | * Lookup is very fast and entry with the same name are chained together. | ||
634 | */ | ||
635 | typedef struct SyArchiveEntry SyArchiveEntry; | ||
636 | typedef struct SyArchive SyArchive; | ||
637 | struct SyArchive | ||
638 | { | ||
639 | SyMemBackend *pAllocator; /* Memory backend */ | ||
640 | SyArchiveEntry *pCursor; /* Cursor for linear traversal of archive entries */ | ||
641 | SyArchiveEntry *pList; /* Pointer to the List of the loaded archive */ | ||
642 | SyArchiveEntry **apHash; /* Hashtable for archive entry */ | ||
643 | ProcRawStrCmp xCmp; /* Hash comparison function */ | ||
644 | ProcHash xHash; /* Hash Function */ | ||
645 | sxu32 nSize; /* Hashtable size */ | ||
646 | sxu32 nEntry; /* Total number of entries in the zip/tar archive */ | ||
647 | sxu32 nLoaded; /* Total number of entries loaded in memory */ | ||
648 | sxu32 nCentralOfft; /* Central directory offset(ZIP only. Otherwise Zero) */ | ||
649 | sxu32 nCentralSize; /* Central directory size(ZIP only. Otherwise Zero) */ | ||
650 | void *pUserData; /* Upper layer private data */ | ||
651 | sxu32 nMagic; /* Sanity check */ | ||
652 | |||
653 | }; | ||
654 | #define SXARCH_MAGIC 0xDEAD635A | ||
655 | #define SXARCH_INVALID(ARCH) (ARCH == 0 || ARCH->nMagic != SXARCH_MAGIC) | ||
656 | #define SXARCH_ENTRY_INVALID(ENTRY) (ENTRY == 0 || ENTRY->nMagic != SXARCH_MAGIC) | ||
657 | #define SyArchiveHashFunc(ARCH) (ARCH)->xHash | ||
658 | #define SyArchiveCmpFunc(ARCH) (ARCH)->xCmp | ||
659 | #define SyArchiveUserData(ARCH) (ARCH)->pUserData | ||
660 | #define SyArchiveSetUserData(ARCH, DATA) (ARCH)->pUserData = DATA | ||
661 | /* | ||
662 | * Each loaded archive record is identified by an instance | ||
663 | * of the following structure. | ||
664 | */ | ||
665 | struct SyArchiveEntry | ||
666 | { | ||
667 | sxu32 nByte; /* Contents size before compression */ | ||
668 | sxu32 nByteCompr; /* Contents size after compression */ | ||
669 | sxu32 nReadCount; /* Read counter */ | ||
670 | sxu32 nCrc; /* Contents CRC32 */ | ||
671 | Sytm sFmt; /* Last-modification time */ | ||
672 | sxu32 nOfft; /* Data offset. */ | ||
673 | sxu16 nComprMeth; /* Compression method 0 == stored/8 == deflated and so on (see appnote.txt)*/ | ||
674 | sxu16 nExtra; /* Extra size if any */ | ||
675 | SyString sFileName; /* entry name & length */ | ||
676 | sxu32 nDup; /* Total number of entries with the same name */ | ||
677 | SyArchiveEntry *pNextHash, *pPrevHash; /* Hash collision chains */ | ||
678 | SyArchiveEntry *pNextName; /* Next entry with the same name */ | ||
679 | SyArchiveEntry *pNext, *pPrev; /* Next and previous entry in the list */ | ||
680 | sxu32 nHash; /* Hash of the entry name */ | ||
681 | void *pUserData; /* User data */ | ||
682 | sxu32 nMagic; /* Sanity check */ | ||
683 | }; | ||
684 | /* | ||
685 | * Extra flags for extending the file local header | ||
686 | */ | ||
687 | #define SXZIP_EXTRA_TIMESTAMP 0x001 /* Extended UNIX timestamp */ | ||
688 | #endif /* JX9_DISABLE_BUILTIN_FUNC */ | ||
689 | #ifndef JX9_DISABLE_HASH_FUNC | ||
690 | /* MD5 context */ | ||
691 | typedef struct MD5Context MD5Context; | ||
692 | struct MD5Context { | ||
693 | sxu32 buf[4]; | ||
694 | sxu32 bits[2]; | ||
695 | unsigned char in[64]; | ||
696 | }; | ||
697 | /* SHA1 context */ | ||
698 | typedef struct SHA1Context SHA1Context; | ||
699 | struct SHA1Context { | ||
700 | unsigned int state[5]; | ||
701 | unsigned int count[2]; | ||
702 | unsigned char buffer[64]; | ||
703 | }; | ||
704 | #endif /* JX9_DISABLE_HASH_FUNC */ | ||
705 | /* JX9 private declaration */ | ||
706 | /* | ||
707 | * Memory Objects. | ||
708 | * Internally, the JX9 virtual machine manipulates nearly all JX9 values | ||
709 | * [i.e: string, int, float, resource, object, bool, null] as jx9_values structures. | ||
710 | * Each jx9_values struct may cache multiple representations (string, integer etc.) | ||
711 | * of the same value. | ||
712 | */ | ||
713 | struct jx9_value | ||
714 | { | ||
715 | union{ | ||
716 | jx9_real rVal; /* Real value */ | ||
717 | sxi64 iVal; /* Integer value */ | ||
718 | void *pOther; /* Other values (Object, Array, Resource, Namespace, etc.) */ | ||
719 | }x; | ||
720 | sxi32 iFlags; /* Control flags (see below) */ | ||
721 | jx9_vm *pVm; /* VM this instance belong */ | ||
722 | SyBlob sBlob; /* String values */ | ||
723 | sxu32 nIdx; /* Object index in the global pool */ | ||
724 | }; | ||
725 | /* Allowed value types. | ||
726 | */ | ||
727 | #define MEMOBJ_STRING 0x001 /* Memory value is a UTF-8 string */ | ||
728 | #define MEMOBJ_INT 0x002 /* Memory value is an integer */ | ||
729 | #define MEMOBJ_REAL 0x004 /* Memory value is a real number */ | ||
730 | #define MEMOBJ_BOOL 0x008 /* Memory value is a boolean */ | ||
731 | #define MEMOBJ_NULL 0x020 /* Memory value is NULL */ | ||
732 | #define MEMOBJ_HASHMAP 0x040 /* Memory value is a hashmap (JSON representation of Array and Objects) */ | ||
733 | #define MEMOBJ_RES 0x100 /* Memory value is a resource [User private data] */ | ||
734 | /* Mask of all known types */ | ||
735 | #define MEMOBJ_ALL (MEMOBJ_STRING|MEMOBJ_INT|MEMOBJ_REAL|MEMOBJ_BOOL|MEMOBJ_NULL|MEMOBJ_HASHMAP|MEMOBJ_RES) | ||
736 | /* Scalar variables | ||
737 | * According to the JX9 language reference manual | ||
738 | * Scalar variables are those containing an integer, float, string or boolean. | ||
739 | * Types array, object and resource are not scalar. | ||
740 | */ | ||
741 | #define MEMOBJ_SCALAR (MEMOBJ_STRING|MEMOBJ_INT|MEMOBJ_REAL|MEMOBJ_BOOL|MEMOBJ_NULL) | ||
742 | /* | ||
743 | * The following macro clear the current jx9_value type and replace | ||
744 | * it with the given one. | ||
745 | */ | ||
746 | #define MemObjSetType(OBJ, TYPE) ((OBJ)->iFlags = ((OBJ)->iFlags&~MEMOBJ_ALL)|TYPE) | ||
747 | /* jx9_value cast method signature */ | ||
748 | typedef sxi32 (*ProcMemObjCast)(jx9_value *); | ||
749 | /* Forward reference */ | ||
750 | typedef struct jx9_output_consumer jx9_output_consumer; | ||
751 | typedef struct jx9_user_func jx9_user_func; | ||
752 | typedef struct jx9_conf jx9_conf; | ||
753 | /* | ||
754 | * An instance of the following structure store the default VM output | ||
755 | * consumer and it's private data. | ||
756 | * Client-programs can register their own output consumer callback | ||
757 | * via the [JX9_VM_CONFIG_OUTPUT] configuration directive. | ||
758 | * Please refer to the official documentation for more information | ||
759 | * on how to register an output consumer callback. | ||
760 | */ | ||
761 | struct jx9_output_consumer | ||
762 | { | ||
763 | ProcConsumer xConsumer; /* VM output consumer routine */ | ||
764 | void *pUserData; /* Third argument to xConsumer() */ | ||
765 | ProcConsumer xDef; /* Default output consumer routine */ | ||
766 | void *pDefData; /* Third argument to xDef() */ | ||
767 | }; | ||
768 | /* | ||
769 | * JX9 engine [i.e: jx9 instance] configuration is stored in | ||
770 | * an instance of the following structure. | ||
771 | * Please refer to the official documentation for more information | ||
772 | * on how to configure your jx9 engine instance. | ||
773 | */ | ||
774 | struct jx9_conf | ||
775 | { | ||
776 | ProcConsumer xErr; /* Compile-time error consumer callback */ | ||
777 | void *pErrData; /* Third argument to xErr() */ | ||
778 | SyBlob sErrConsumer; /* Default error consumer */ | ||
779 | }; | ||
780 | /* | ||
781 | * Signature of the C function responsible of expanding constant values. | ||
782 | */ | ||
783 | typedef void (*ProcConstant)(jx9_value *, void *); | ||
784 | /* | ||
785 | * Each registered constant [i.e: __TIME__, __DATE__, JX9_OS, INT_MAX, etc.] is stored | ||
786 | * in an instance of the following structure. | ||
787 | * Please refer to the official documentation for more information | ||
788 | * on how to create/install foreign constants. | ||
789 | */ | ||
790 | typedef struct jx9_constant jx9_constant; | ||
791 | struct jx9_constant | ||
792 | { | ||
793 | SyString sName; /* Constant name */ | ||
794 | ProcConstant xExpand; /* Function responsible of expanding constant value */ | ||
795 | void *pUserData; /* Last argument to xExpand() */ | ||
796 | }; | ||
797 | typedef struct jx9_aux_data jx9_aux_data; | ||
798 | /* | ||
799 | * Auxiliary data associated with each foreign function is stored | ||
800 | * in a stack of the following structure. | ||
801 | * Note that automatic tracked chunks are also stored in an instance | ||
802 | * of this structure. | ||
803 | */ | ||
804 | struct jx9_aux_data | ||
805 | { | ||
806 | void *pAuxData; /* Aux data */ | ||
807 | }; | ||
808 | /* Foreign functions signature */ | ||
809 | typedef int (*ProcHostFunction)(jx9_context *, int, jx9_value **); | ||
810 | /* | ||
811 | * Each installed foreign function is recored in an instance of the following | ||
812 | * structure. | ||
813 | * Please refer to the official documentation for more information on how | ||
814 | * to create/install foreign functions. | ||
815 | */ | ||
816 | struct jx9_user_func | ||
817 | { | ||
818 | jx9_vm *pVm; /* VM that own this instance */ | ||
819 | SyString sName; /* Foreign function name */ | ||
820 | ProcHostFunction xFunc; /* Implementation of the foreign function */ | ||
821 | void *pUserData; /* User private data [Refer to the official documentation for more information]*/ | ||
822 | SySet aAux; /* Stack of auxiliary data [Refer to the official documentation for more information]*/ | ||
823 | }; | ||
824 | /* | ||
825 | * The 'context' argument for an installable function. A pointer to an | ||
826 | * instance of this structure is the first argument to the routines used | ||
827 | * implement the foreign functions. | ||
828 | */ | ||
829 | struct jx9_context | ||
830 | { | ||
831 | jx9_user_func *pFunc; /* Function information. */ | ||
832 | jx9_value *pRet; /* Return value is stored here. */ | ||
833 | SySet sVar; /* Container of dynamically allocated jx9_values | ||
834 | * [i.e: Garbage collection purposes.] | ||
835 | */ | ||
836 | SySet sChunk; /* Track dynamically allocated chunks [jx9_aux_data instance]. | ||
837 | * [i.e: Garbage collection purposes.] | ||
838 | */ | ||
839 | jx9_vm *pVm; /* Virtual machine that own this context */ | ||
840 | sxi32 iFlags; /* Call flags */ | ||
841 | }; | ||
842 | /* Hashmap control flags */ | ||
843 | #define HASHMAP_JSON_OBJECT 0x001 /* Hashmap represent JSON Object*/ | ||
844 | /* | ||
845 | * Each hashmap entry [i.e: array(4, 5, 6)] is recorded in an instance | ||
846 | * of the following structure. | ||
847 | */ | ||
848 | struct jx9_hashmap_node | ||
849 | { | ||
850 | jx9_hashmap *pMap; /* Hashmap that own this instance */ | ||
851 | sxi32 iType; /* Node type */ | ||
852 | union{ | ||
853 | sxi64 iKey; /* Int key */ | ||
854 | SyBlob sKey; /* Blob key */ | ||
855 | }xKey; | ||
856 | sxi32 iFlags; /* Control flags */ | ||
857 | sxu32 nHash; /* Key hash value */ | ||
858 | sxu32 nValIdx; /* Value stored in this node */ | ||
859 | jx9_hashmap_node *pNext, *pPrev; /* Link to other entries [i.e: linear traversal] */ | ||
860 | jx9_hashmap_node *pNextCollide, *pPrevCollide; /* Collision chain */ | ||
861 | }; | ||
862 | /* | ||
863 | * Each active hashmap aka array in the JX9 jargon is represented | ||
864 | * by an instance of the following structure. | ||
865 | */ | ||
866 | struct jx9_hashmap | ||
867 | { | ||
868 | jx9_vm *pVm; /* VM that own this instance */ | ||
869 | jx9_hashmap_node **apBucket; /* Hash bucket */ | ||
870 | jx9_hashmap_node *pFirst; /* First inserted entry */ | ||
871 | jx9_hashmap_node *pLast; /* Last inserted entry */ | ||
872 | jx9_hashmap_node *pCur; /* Current entry */ | ||
873 | sxu32 nSize; /* Bucket size */ | ||
874 | sxu32 nEntry; /* Total number of inserted entries */ | ||
875 | sxu32 (*xIntHash)(sxi64); /* Hash function for int_keys */ | ||
876 | sxu32 (*xBlobHash)(const void *, sxu32); /* Hash function for blob_keys */ | ||
877 | sxi32 iFlags; /* Hashmap control flags */ | ||
878 | sxi64 iNextIdx; /* Next available automatically assigned index */ | ||
879 | sxi32 iRef; /* Reference count */ | ||
880 | }; | ||
881 | /* An instance of the following structure is the context | ||
882 | * for the FOREACH_STEP/FOREACH_INIT VM instructions. | ||
883 | * Those instructions are used to implement the 'foreach' | ||
884 | * statement. | ||
885 | * This structure is made available to these instructions | ||
886 | * as the P3 operand. | ||
887 | */ | ||
888 | struct jx9_foreach_info | ||
889 | { | ||
890 | SyString sKey; /* Key name. Empty otherwise*/ | ||
891 | SyString sValue; /* Value name */ | ||
892 | sxi32 iFlags; /* Control flags */ | ||
893 | SySet aStep; /* Stack of steps [i.e: jx9_foreach_step instance] */ | ||
894 | }; | ||
895 | struct jx9_foreach_step | ||
896 | { | ||
897 | sxi32 iFlags; /* Control flags (see below) */ | ||
898 | /* Iterate on this map*/ | ||
899 | jx9_hashmap *pMap; /* Hashmap [i.e: array in the JX9 jargon] iteration | ||
900 | * Ex: foreach(array(1, 2, 3) as $key=>$value){} | ||
901 | */ | ||
902 | |||
903 | }; | ||
904 | /* Foreach step control flags */ | ||
905 | #define JX9_4EACH_STEP_KEY 0x001 /* Make Key available */ | ||
906 | /* | ||
907 | * Each JX9 engine is identified by an instance of the following structure. | ||
908 | * Please refer to the official documentation for more information | ||
909 | * on how to configure your JX9 engine instance. | ||
910 | */ | ||
911 | struct jx9 | ||
912 | { | ||
913 | SyMemBackend sAllocator; /* Low level memory allocation subsystem */ | ||
914 | const jx9_vfs *pVfs; /* Underlying Virtual File System */ | ||
915 | jx9_conf xConf; /* Configuration */ | ||
916 | #if defined(JX9_ENABLE_THREADS) | ||
917 | SyMutex *pMutex; /* Per-engine mutex */ | ||
918 | #endif | ||
919 | jx9_vm *pVms; /* List of active VM */ | ||
920 | sxi32 iVm; /* Total number of active VM */ | ||
921 | jx9 *pNext, *pPrev; /* List of active engines */ | ||
922 | sxu32 nMagic; /* Sanity check against misuse */ | ||
923 | }; | ||
924 | /* Code generation data structures */ | ||
925 | typedef sxi32 (*ProcErrorGen)(void *, sxi32, sxu32, const char *, ...); | ||
926 | typedef struct jx9_expr_node jx9_expr_node; | ||
927 | typedef struct jx9_expr_op jx9_expr_op; | ||
928 | typedef struct jx9_gen_state jx9_gen_state; | ||
929 | typedef struct GenBlock GenBlock; | ||
930 | typedef sxi32 (*ProcLangConstruct)(jx9_gen_state *); | ||
931 | typedef sxi32 (*ProcNodeConstruct)(jx9_gen_state *, sxi32); | ||
932 | /* | ||
933 | * Each supported operator [i.e: +, -, ==, *, %, >>, >=, new, etc.] is represented | ||
934 | * by an instance of the following structure. | ||
935 | * The JX9 parser does not use any external tools and is 100% handcoded. | ||
936 | * That is, the JX9 parser is thread-safe , full reentrant, produce consistant | ||
937 | * compile-time errrors and at least 7 times faster than the standard JX9 parser. | ||
938 | */ | ||
939 | struct jx9_expr_op | ||
940 | { | ||
941 | SyString sOp; /* String representation of the operator [i.e: "+", "*", "=="...] */ | ||
942 | sxi32 iOp; /* Operator ID */ | ||
943 | sxi32 iPrec; /* Operator precedence: 1 == Highest */ | ||
944 | sxi32 iAssoc; /* Operator associativity (either left, right or non-associative) */ | ||
945 | sxi32 iVmOp; /* VM OP code for this operator [i.e: JX9_OP_EQ, JX9_OP_LT, JX9_OP_MUL...]*/ | ||
946 | }; | ||
947 | /* | ||
948 | * Each expression node is parsed out and recorded | ||
949 | * in an instance of the following structure. | ||
950 | */ | ||
951 | struct jx9_expr_node | ||
952 | { | ||
953 | const jx9_expr_op *pOp; /* Operator ID or NULL if literal, constant, variable, function or object method call */ | ||
954 | jx9_expr_node *pLeft; /* Left expression tree */ | ||
955 | jx9_expr_node *pRight; /* Right expression tree */ | ||
956 | SyToken *pStart; /* Stream of tokens that belong to this node */ | ||
957 | SyToken *pEnd; /* End of token stream */ | ||
958 | sxi32 iFlags; /* Node construct flags */ | ||
959 | ProcNodeConstruct xCode; /* C routine responsible of compiling this node */ | ||
960 | SySet aNodeArgs; /* Node arguments. Only used by postfix operators [i.e: function call]*/ | ||
961 | jx9_expr_node *pCond; /* Condition: Only used by the ternary operator '?:' */ | ||
962 | }; | ||
963 | /* Node Construct flags */ | ||
964 | #define EXPR_NODE_PRE_INCR 0x01 /* Pre-icrement/decrement [i.e: ++$i, --$j] node */ | ||
965 | /* | ||
966 | * A block of instructions is recorded in an instance of the following structure. | ||
967 | * This structure is used only during compile-time and have no meaning | ||
968 | * during bytecode execution. | ||
969 | */ | ||
970 | struct GenBlock | ||
971 | { | ||
972 | jx9_gen_state *pGen; /* State of the code generator */ | ||
973 | GenBlock *pParent; /* Upper block or NULL if global */ | ||
974 | sxu32 nFirstInstr; /* First instruction to execute */ | ||
975 | sxi32 iFlags; /* Block control flags (see below) */ | ||
976 | SySet aJumpFix; /* Jump fixup (JumpFixup instance) */ | ||
977 | void *pUserData; /* Upper layer private data */ | ||
978 | /* The following two fields are used only when compiling | ||
979 | * the 'do..while()' language construct. | ||
980 | */ | ||
981 | sxu8 bPostContinue; /* TRUE when compiling the do..while() statement */ | ||
982 | SySet aPostContFix; /* Post-continue jump fix */ | ||
983 | }; | ||
984 | /* | ||
985 | * Code generator state is remembered in an instance of the following | ||
986 | * structure. We put the information in this structure and pass around | ||
987 | * a pointer to this structure, rather than pass around all of the | ||
988 | * information separately. This helps reduce the number of arguments | ||
989 | * to generator functions. | ||
990 | * This structure is used only during compile-time and have no meaning | ||
991 | * during bytecode execution. | ||
992 | */ | ||
993 | struct jx9_gen_state | ||
994 | { | ||
995 | jx9_vm *pVm; /* VM that own this instance */ | ||
996 | SyHash hLiteral; /* Constant string Literals table */ | ||
997 | SyHash hNumLiteral; /* Numeric literals table */ | ||
998 | SyHash hVar; /* Collected variable hashtable */ | ||
999 | GenBlock *pCurrent; /* Current processed block */ | ||
1000 | GenBlock sGlobal; /* Global block */ | ||
1001 | ProcConsumer xErr; /* Error consumer callback */ | ||
1002 | void *pErrData; /* Third argument to xErr() */ | ||
1003 | SyToken *pIn; /* Current processed token */ | ||
1004 | SyToken *pEnd; /* Last token in the stream */ | ||
1005 | sxu32 nErr; /* Total number of compilation error */ | ||
1006 | }; | ||
1007 | /* Forward references */ | ||
1008 | typedef struct jx9_vm_func_static_var jx9_vm_func_static_var; | ||
1009 | typedef struct jx9_vm_func_arg jx9_vm_func_arg; | ||
1010 | typedef struct jx9_vm_func jx9_vm_func; | ||
1011 | typedef struct VmFrame VmFrame; | ||
1012 | /* | ||
1013 | * Each collected function argument is recorded in an instance | ||
1014 | * of the following structure. | ||
1015 | * Note that as an extension, JX9 implements full type hinting | ||
1016 | * which mean that any function can have it's own signature. | ||
1017 | * Example: | ||
1018 | * function foo(int $a, string $b, float $c, ClassInstance $d){} | ||
1019 | * This is how the powerful function overloading mechanism is | ||
1020 | * implemented. | ||
1021 | * Note that as an extension, JX9 allow function arguments to have | ||
1022 | * any complex default value associated with them unlike the standard | ||
1023 | * JX9 engine. | ||
1024 | * Example: | ||
1025 | * function foo(int $a = rand() & 1023){} | ||
1026 | * now, when foo is called without arguments [i.e: foo()] the | ||
1027 | * $a variable (first parameter) will be set to a random number | ||
1028 | * between 0 and 1023 inclusive. | ||
1029 | * Refer to the official documentation for more information on this | ||
1030 | * mechanism and other extension introduced by the JX9 engine. | ||
1031 | */ | ||
1032 | struct jx9_vm_func_arg | ||
1033 | { | ||
1034 | SyString sName; /* Argument name */ | ||
1035 | SySet aByteCode; /* Compiled default value associated with this argument */ | ||
1036 | sxu32 nType; /* Type of this argument [i.e: array, int, string, float, object, etc.] */ | ||
1037 | sxi32 iFlags; /* Configuration flags */ | ||
1038 | }; | ||
1039 | /* | ||
1040 | * Each static variable is parsed out and remembered in an instance | ||
1041 | * of the following structure. | ||
1042 | * Note that as an extension, JX9 allow static variable have | ||
1043 | * any complex default value associated with them unlike the standard | ||
1044 | * JX9 engine. | ||
1045 | * Example: | ||
1046 | * static $rand_str = 'JX9'.rand_str(3); // Concatenate 'JX9' with | ||
1047 | * // a random three characters(English alphabet) | ||
1048 | * dump($rand_str); | ||
1049 | * //You should see something like this | ||
1050 | * string(6 'JX9awt'); | ||
1051 | */ | ||
1052 | struct jx9_vm_func_static_var | ||
1053 | { | ||
1054 | SyString sName; /* Static variable name */ | ||
1055 | SySet aByteCode; /* Compiled initialization expression */ | ||
1056 | sxu32 nIdx; /* Object index in the global memory object container */ | ||
1057 | }; | ||
1058 | /* Function configuration flags */ | ||
1059 | #define VM_FUNC_ARG_HAS_DEF 0x001 /* Argument has default value associated with it */ | ||
1060 | #define VM_FUNC_ARG_IGNORE 0x002 /* Do not install argument in the current frame */ | ||
1061 | /* | ||
1062 | * Each user defined function is parsed out and stored in an instance | ||
1063 | * of the following structure. | ||
1064 | * JX9 introduced some powerfull extensions to the JX9 5 programming | ||
1065 | * language like function overloading, type hinting, complex default | ||
1066 | * arguments values and many more. | ||
1067 | * Please refer to the official documentation for more information. | ||
1068 | */ | ||
1069 | struct jx9_vm_func | ||
1070 | { | ||
1071 | SySet aArgs; /* Expected arguments (jx9_vm_func_arg instance) */ | ||
1072 | SySet aStatic; /* Static variable (jx9_vm_func_static_var instance) */ | ||
1073 | SyString sName; /* Function name */ | ||
1074 | SySet aByteCode; /* Compiled function body */ | ||
1075 | sxi32 iFlags; /* VM function configuration */ | ||
1076 | SyString sSignature; /* Function signature used to implement function overloading | ||
1077 | * (Refer to the official docuemntation for more information | ||
1078 | * on this powerfull feature) | ||
1079 | */ | ||
1080 | void *pUserData; /* Upper layer private data associated with this instance */ | ||
1081 | jx9_vm_func *pNextName; /* Next VM function with the same name as this one */ | ||
1082 | }; | ||
1083 | /* Forward reference */ | ||
1084 | typedef struct jx9_builtin_constant jx9_builtin_constant; | ||
1085 | typedef struct jx9_builtin_func jx9_builtin_func; | ||
1086 | /* | ||
1087 | * Each built-in foreign function (C function) is stored in an | ||
1088 | * instance of the following structure. | ||
1089 | * Please refer to the official documentation for more information | ||
1090 | * on how to create/install foreign functions. | ||
1091 | */ | ||
1092 | struct jx9_builtin_func | ||
1093 | { | ||
1094 | const char *zName; /* Function name [i.e: strlen(), rand(), array_merge(), etc.]*/ | ||
1095 | ProcHostFunction xFunc; /* C routine performing the computation */ | ||
1096 | }; | ||
1097 | /* | ||
1098 | * Each built-in foreign constant is stored in an instance | ||
1099 | * of the following structure. | ||
1100 | * Please refer to the official documentation for more information | ||
1101 | * on how to create/install foreign constants. | ||
1102 | */ | ||
1103 | struct jx9_builtin_constant | ||
1104 | { | ||
1105 | const char *zName; /* Constant name */ | ||
1106 | ProcConstant xExpand; /* C routine responsible of expanding constant value*/ | ||
1107 | }; | ||
1108 | /* | ||
1109 | * A single instruction of the virtual machine has an opcode | ||
1110 | * and as many as three operands. | ||
1111 | * Each VM instruction resulting from compiling a JX9 script | ||
1112 | * is stored in an instance of the following structure. | ||
1113 | */ | ||
1114 | typedef struct VmInstr VmInstr; | ||
1115 | struct VmInstr | ||
1116 | { | ||
1117 | sxu8 iOp; /* Operation to preform */ | ||
1118 | sxi32 iP1; /* First operand */ | ||
1119 | sxu32 iP2; /* Second operand (Often the jump destination) */ | ||
1120 | void *p3; /* Third operand (Often Upper layer private data) */ | ||
1121 | }; | ||
1122 | /* Forward reference */ | ||
1123 | typedef struct jx9_case_expr jx9_case_expr; | ||
1124 | typedef struct jx9_switch jx9_switch; | ||
1125 | /* | ||
1126 | * Each compiled case block in a swicth statement is compiled | ||
1127 | * and stored in an instance of the following structure. | ||
1128 | */ | ||
1129 | struct jx9_case_expr | ||
1130 | { | ||
1131 | SySet aByteCode; /* Compiled body of the case block */ | ||
1132 | sxu32 nStart; /* First instruction to execute */ | ||
1133 | }; | ||
1134 | /* | ||
1135 | * Each compiled switch statement is parsed out and stored | ||
1136 | * in an instance of the following structure. | ||
1137 | */ | ||
1138 | struct jx9_switch | ||
1139 | { | ||
1140 | SySet aCaseExpr; /* Compile case block */ | ||
1141 | sxu32 nOut; /* First instruction to execute after this statement */ | ||
1142 | sxu32 nDefault; /* First instruction to execute in the default block */ | ||
1143 | }; | ||
1144 | /* Assertion flags */ | ||
1145 | #define JX9_ASSERT_DISABLE 0x01 /* Disable assertion */ | ||
1146 | #define JX9_ASSERT_WARNING 0x02 /* Issue a warning for each failed assertion */ | ||
1147 | #define JX9_ASSERT_BAIL 0x04 /* Terminate execution on failed assertions */ | ||
1148 | #define JX9_ASSERT_QUIET_EVAL 0x08 /* Not used */ | ||
1149 | #define JX9_ASSERT_CALLBACK 0x10 /* Callback to call on failed assertions */ | ||
1150 | /* | ||
1151 | * An instance of the following structure hold the bytecode instructions | ||
1152 | * resulting from compiling a JX9 script. | ||
1153 | * This structure contains the complete state of the virtual machine. | ||
1154 | */ | ||
1155 | struct jx9_vm | ||
1156 | { | ||
1157 | SyMemBackend sAllocator; /* Memory backend */ | ||
1158 | #if defined(JX9_ENABLE_THREADS) | ||
1159 | SyMutex *pMutex; /* Recursive mutex associated with this VM. */ | ||
1160 | #endif | ||
1161 | jx9 *pEngine; /* Interpreter that own this VM */ | ||
1162 | SySet aByteCode; /* Default bytecode container */ | ||
1163 | SySet *pByteContainer; /* Current bytecode container */ | ||
1164 | VmFrame *pFrame; /* Stack of active frames */ | ||
1165 | SyPRNGCtx sPrng; /* PRNG context */ | ||
1166 | SySet aMemObj; /* Object allocation table */ | ||
1167 | SySet aLitObj; /* Literals allocation table */ | ||
1168 | jx9_value *aOps; /* Operand stack */ | ||
1169 | SySet aFreeObj; /* Stack of free memory objects */ | ||
1170 | SyHash hConstant; /* Host-application and user defined constants container */ | ||
1171 | SyHash hHostFunction; /* Host-application installable functions */ | ||
1172 | SyHash hFunction; /* Compiled functions */ | ||
1173 | SyHash hSuper; /* Global variable */ | ||
1174 | SyBlob sConsumer; /* Default VM consumer [i.e Redirect all VM output to this blob] */ | ||
1175 | SyBlob sWorker; /* General purpose working buffer */ | ||
1176 | SyBlob sArgv; /* $argv[] collector [refer to the [getopt()] implementation for more information] */ | ||
1177 | SySet aFiles; /* Stack of processed files */ | ||
1178 | SySet aPaths; /* Set of import paths */ | ||
1179 | SySet aIncluded; /* Set of included files */ | ||
1180 | SySet aIOstream; /* Installed IO stream container */ | ||
1181 | const jx9_io_stream *pDefStream; /* Default IO stream [i.e: typically this is the 'file://' stream] */ | ||
1182 | jx9_value sExec; /* Compiled script return value [Can be extracted via the JX9_VM_CONFIG_EXEC_VALUE directive]*/ | ||
1183 | void *pStdin; /* STDIN IO stream */ | ||
1184 | void *pStdout; /* STDOUT IO stream */ | ||
1185 | void *pStderr; /* STDERR IO stream */ | ||
1186 | int bErrReport; /* TRUE to report all runtime Error/Warning/Notice */ | ||
1187 | int nRecursionDepth; /* Current recursion depth */ | ||
1188 | int nMaxDepth; /* Maximum allowed recusion depth */ | ||
1189 | sxu32 nOutputLen; /* Total number of generated output */ | ||
1190 | jx9_output_consumer sVmConsumer; /* Registered output consumer callback */ | ||
1191 | int iAssertFlags; /* Assertion flags */ | ||
1192 | jx9_value sAssertCallback; /* Callback to call on failed assertions */ | ||
1193 | sxi32 iExitStatus; /* Script exit status */ | ||
1194 | jx9_gen_state sCodeGen; /* Code generator module */ | ||
1195 | jx9_vm *pNext, *pPrev; /* List of active VM's */ | ||
1196 | sxu32 nMagic; /* Sanity check against misuse */ | ||
1197 | }; | ||
1198 | /* | ||
1199 | * Allowed value for jx9_vm.nMagic | ||
1200 | */ | ||
1201 | #define JX9_VM_INIT 0xEA12CD72 /* VM correctly initialized */ | ||
1202 | #define JX9_VM_RUN 0xBA851227 /* VM ready to execute JX9 bytecode */ | ||
1203 | #define JX9_VM_EXEC 0xCDFE1DAD /* VM executing JX9 bytecode */ | ||
1204 | #define JX9_VM_STALE 0xDEAD2BAD /* Stale VM */ | ||
1205 | /* | ||
1206 | * Error codes according to the JX9 language reference manual. | ||
1207 | */ | ||
1208 | enum iErrCode | ||
1209 | { | ||
1210 | E_ERROR = 1, /* Fatal run-time errors. These indicate errors that can not be recovered | ||
1211 | * from, such as a memory allocation problem. Execution of the script is | ||
1212 | * halted. | ||
1213 | * The only fatal error under JX9 is an out-of-memory. All others erros | ||
1214 | * even a call to undefined function will not halt script execution. | ||
1215 | */ | ||
1216 | E_WARNING , /* Run-time warnings (non-fatal errors). Execution of the script is not halted. */ | ||
1217 | E_PARSE , /* Compile-time parse errors. Parse errors should only be generated by the parser.*/ | ||
1218 | E_NOTICE , /* Run-time notices. Indicate that the script encountered something that could | ||
1219 | * indicate an error, but could also happen in the normal course of running a script. | ||
1220 | */ | ||
1221 | }; | ||
1222 | /* | ||
1223 | * Each VM instruction resulting from compiling a JX9 script is represented | ||
1224 | * by one of the following OP codes. | ||
1225 | * The program consists of a linear sequence of operations. Each operation | ||
1226 | * has an opcode and 3 operands.Operands P1 is an integer. | ||
1227 | * Operand P2 is an unsigned integer and operand P3 is a memory address. | ||
1228 | * Few opcodes use all 3 operands. | ||
1229 | */ | ||
1230 | enum jx9_vm_op { | ||
1231 | JX9_OP_DONE = 1, /* Done */ | ||
1232 | JX9_OP_HALT, /* Halt */ | ||
1233 | JX9_OP_LOAD, /* Load memory object */ | ||
1234 | JX9_OP_LOADC, /* Load constant */ | ||
1235 | JX9_OP_LOAD_IDX, /* Load array entry */ | ||
1236 | JX9_OP_LOAD_MAP, /* Load hashmap('array') */ | ||
1237 | JX9_OP_NOOP, /* NOOP */ | ||
1238 | JX9_OP_JMP, /* Unconditional jump */ | ||
1239 | JX9_OP_JZ, /* Jump on zero (FALSE jump) */ | ||
1240 | JX9_OP_JNZ, /* Jump on non-zero (TRUE jump) */ | ||
1241 | JX9_OP_POP, /* Stack POP */ | ||
1242 | JX9_OP_CAT, /* Concatenation */ | ||
1243 | JX9_OP_CVT_INT, /* Integer cast */ | ||
1244 | JX9_OP_CVT_STR, /* String cast */ | ||
1245 | JX9_OP_CVT_REAL, /* Float cast */ | ||
1246 | JX9_OP_CALL, /* Function call */ | ||
1247 | JX9_OP_UMINUS, /* Unary minus '-'*/ | ||
1248 | JX9_OP_UPLUS, /* Unary plus '+'*/ | ||
1249 | JX9_OP_BITNOT, /* Bitwise not '~' */ | ||
1250 | JX9_OP_LNOT, /* Logical not '!' */ | ||
1251 | JX9_OP_MUL, /* Multiplication '*' */ | ||
1252 | JX9_OP_DIV, /* Division '/' */ | ||
1253 | JX9_OP_MOD, /* Modulus '%' */ | ||
1254 | JX9_OP_ADD, /* Add '+' */ | ||
1255 | JX9_OP_SUB, /* Sub '-' */ | ||
1256 | JX9_OP_SHL, /* Left shift '<<' */ | ||
1257 | JX9_OP_SHR, /* Right shift '>>' */ | ||
1258 | JX9_OP_LT, /* Less than '<' */ | ||
1259 | JX9_OP_LE, /* Less or equal '<=' */ | ||
1260 | JX9_OP_GT, /* Greater than '>' */ | ||
1261 | JX9_OP_GE, /* Greater or equal '>=' */ | ||
1262 | JX9_OP_EQ, /* Equal '==' */ | ||
1263 | JX9_OP_NEQ, /* Not equal '!=' */ | ||
1264 | JX9_OP_TEQ, /* Type equal '===' */ | ||
1265 | JX9_OP_TNE, /* Type not equal '!==' */ | ||
1266 | JX9_OP_BAND, /* Bitwise and '&' */ | ||
1267 | JX9_OP_BXOR, /* Bitwise xor '^' */ | ||
1268 | JX9_OP_BOR, /* Bitwise or '|' */ | ||
1269 | JX9_OP_LAND, /* Logical and '&&','and' */ | ||
1270 | JX9_OP_LOR, /* Logical or '||','or' */ | ||
1271 | JX9_OP_LXOR, /* Logical xor 'xor' */ | ||
1272 | JX9_OP_STORE, /* Store Object */ | ||
1273 | JX9_OP_STORE_IDX, /* Store indexed object */ | ||
1274 | JX9_OP_PULL, /* Stack pull */ | ||
1275 | JX9_OP_SWAP, /* Stack swap */ | ||
1276 | JX9_OP_YIELD, /* Stack yield */ | ||
1277 | JX9_OP_CVT_BOOL, /* Boolean cast */ | ||
1278 | JX9_OP_CVT_NUMC, /* Numeric (integer, real or both) type cast */ | ||
1279 | JX9_OP_INCR, /* Increment ++ */ | ||
1280 | JX9_OP_DECR, /* Decrement -- */ | ||
1281 | JX9_OP_ADD_STORE, /* Add and store '+=' */ | ||
1282 | JX9_OP_SUB_STORE, /* Sub and store '-=' */ | ||
1283 | JX9_OP_MUL_STORE, /* Mul and store '*=' */ | ||
1284 | JX9_OP_DIV_STORE, /* Div and store '/=' */ | ||
1285 | JX9_OP_MOD_STORE, /* Mod and store '%=' */ | ||
1286 | JX9_OP_CAT_STORE, /* Cat and store '.=' */ | ||
1287 | JX9_OP_SHL_STORE, /* Shift left and store '>>=' */ | ||
1288 | JX9_OP_SHR_STORE, /* Shift right and store '<<=' */ | ||
1289 | JX9_OP_BAND_STORE, /* Bitand and store '&=' */ | ||
1290 | JX9_OP_BOR_STORE, /* Bitor and store '|=' */ | ||
1291 | JX9_OP_BXOR_STORE, /* Bitxor and store '^=' */ | ||
1292 | JX9_OP_CONSUME, /* Consume VM output */ | ||
1293 | JX9_OP_MEMBER, /* Object member run-time access */ | ||
1294 | JX9_OP_UPLINK, /* Run-Time frame link */ | ||
1295 | JX9_OP_CVT_NULL, /* NULL cast */ | ||
1296 | JX9_OP_CVT_ARRAY, /* Array cast */ | ||
1297 | JX9_OP_FOREACH_INIT, /* For each init */ | ||
1298 | JX9_OP_FOREACH_STEP, /* For each step */ | ||
1299 | JX9_OP_SWITCH /* Switch operation */ | ||
1300 | }; | ||
1301 | /* -- END-OF INSTRUCTIONS -- */ | ||
1302 | /* | ||
1303 | * Expression Operators ID. | ||
1304 | */ | ||
1305 | enum jx9_expr_id { | ||
1306 | EXPR_OP_DOT, /* Member access */ | ||
1307 | EXPR_OP_DC, /* :: */ | ||
1308 | EXPR_OP_SUBSCRIPT, /* []: Subscripting */ | ||
1309 | EXPR_OP_FUNC_CALL, /* func_call() */ | ||
1310 | EXPR_OP_INCR, /* ++ */ | ||
1311 | EXPR_OP_DECR, /* -- */ | ||
1312 | EXPR_OP_BITNOT, /* ~ */ | ||
1313 | EXPR_OP_UMINUS, /* Unary minus */ | ||
1314 | EXPR_OP_UPLUS, /* Unary plus */ | ||
1315 | EXPR_OP_TYPECAST, /* Type cast [i.e: (int), (float), (string)...] */ | ||
1316 | EXPR_OP_ALT, /* @ */ | ||
1317 | EXPR_OP_INSTOF, /* instanceof */ | ||
1318 | EXPR_OP_LOGNOT, /* logical not ! */ | ||
1319 | EXPR_OP_MUL, /* Multiplication */ | ||
1320 | EXPR_OP_DIV, /* division */ | ||
1321 | EXPR_OP_MOD, /* Modulus */ | ||
1322 | EXPR_OP_ADD, /* Addition */ | ||
1323 | EXPR_OP_SUB, /* Substraction */ | ||
1324 | EXPR_OP_DDOT, /* Concatenation */ | ||
1325 | EXPR_OP_SHL, /* Left shift */ | ||
1326 | EXPR_OP_SHR, /* Right shift */ | ||
1327 | EXPR_OP_LT, /* Less than */ | ||
1328 | EXPR_OP_LE, /* Less equal */ | ||
1329 | EXPR_OP_GT, /* Greater than */ | ||
1330 | EXPR_OP_GE, /* Greater equal */ | ||
1331 | EXPR_OP_EQ, /* Equal == */ | ||
1332 | EXPR_OP_NE, /* Not equal != <> */ | ||
1333 | EXPR_OP_TEQ, /* Type equal === */ | ||
1334 | EXPR_OP_TNE, /* Type not equal !== */ | ||
1335 | EXPR_OP_SEQ, /* String equal 'eq' */ | ||
1336 | EXPR_OP_SNE, /* String not equal 'ne' */ | ||
1337 | EXPR_OP_BAND, /* Biwise and '&' */ | ||
1338 | EXPR_OP_REF, /* Reference operator '&' */ | ||
1339 | EXPR_OP_XOR, /* bitwise xor '^' */ | ||
1340 | EXPR_OP_BOR, /* bitwise or '|' */ | ||
1341 | EXPR_OP_LAND, /* Logical and '&&','and' */ | ||
1342 | EXPR_OP_LOR, /* Logical or '||','or'*/ | ||
1343 | EXPR_OP_LXOR, /* Logical xor 'xor' */ | ||
1344 | EXPR_OP_QUESTY, /* Ternary operator '?' */ | ||
1345 | EXPR_OP_ASSIGN, /* Assignment '=' */ | ||
1346 | EXPR_OP_ADD_ASSIGN, /* Combined operator: += */ | ||
1347 | EXPR_OP_SUB_ASSIGN, /* Combined operator: -= */ | ||
1348 | EXPR_OP_MUL_ASSIGN, /* Combined operator: *= */ | ||
1349 | EXPR_OP_DIV_ASSIGN, /* Combined operator: /= */ | ||
1350 | EXPR_OP_MOD_ASSIGN, /* Combined operator: %= */ | ||
1351 | EXPR_OP_DOT_ASSIGN, /* Combined operator: .= */ | ||
1352 | EXPR_OP_AND_ASSIGN, /* Combined operator: &= */ | ||
1353 | EXPR_OP_OR_ASSIGN, /* Combined operator: |= */ | ||
1354 | EXPR_OP_XOR_ASSIGN, /* Combined operator: ^= */ | ||
1355 | EXPR_OP_SHL_ASSIGN, /* Combined operator: <<= */ | ||
1356 | EXPR_OP_SHR_ASSIGN, /* Combined operator: >>= */ | ||
1357 | EXPR_OP_COMMA /* Comma expression */ | ||
1358 | }; | ||
1359 | /* | ||
1360 | * Lexer token codes | ||
1361 | * The following set of constants are the tokens recognized | ||
1362 | * by the lexer when processing JX9 input. | ||
1363 | * Important: Token values MUST BE A POWER OF TWO. | ||
1364 | */ | ||
1365 | #define JX9_TK_INTEGER 0x0000001 /* Integer */ | ||
1366 | #define JX9_TK_REAL 0x0000002 /* Real number */ | ||
1367 | #define JX9_TK_NUM (JX9_TK_INTEGER|JX9_TK_REAL) /* Numeric token, either integer or real */ | ||
1368 | #define JX9_TK_KEYWORD 0x0000004 /* Keyword [i.e: while, for, if, foreach...] */ | ||
1369 | #define JX9_TK_ID 0x0000008 /* Alphanumeric or UTF-8 stream */ | ||
1370 | #define JX9_TK_DOLLAR 0x0000010 /* '$' Dollar sign */ | ||
1371 | #define JX9_TK_OP 0x0000020 /* Operator [i.e: +, *, /...] */ | ||
1372 | #define JX9_TK_OCB 0x0000040 /* Open curly brace'{' */ | ||
1373 | #define JX9_TK_CCB 0x0000080 /* Closing curly brace'}' */ | ||
1374 | #define JX9_TK_DOT 0x0000100 /* Dot . */ | ||
1375 | #define JX9_TK_LPAREN 0x0000200 /* Left parenthesis '(' */ | ||
1376 | #define JX9_TK_RPAREN 0x0000400 /* Right parenthesis ')' */ | ||
1377 | #define JX9_TK_OSB 0x0000800 /* Open square bracket '[' */ | ||
1378 | #define JX9_TK_CSB 0x0001000 /* Closing square bracket ']' */ | ||
1379 | #define JX9_TK_DSTR 0x0002000 /* Double quoted string "$str" */ | ||
1380 | #define JX9_TK_SSTR 0x0004000 /* Single quoted string 'str' */ | ||
1381 | #define JX9_TK_NOWDOC 0x0010000 /* Nowdoc <<< */ | ||
1382 | #define JX9_TK_COMMA 0x0020000 /* Comma ',' */ | ||
1383 | #define JX9_TK_SEMI 0x0040000 /* Semi-colon ";" */ | ||
1384 | #define JX9_TK_BSTR 0x0080000 /* Backtick quoted string [i.e: Shell command `date`] */ | ||
1385 | #define JX9_TK_COLON 0x0100000 /* single Colon ':' */ | ||
1386 | #define JX9_TK_AMPER 0x0200000 /* Ampersand '&' */ | ||
1387 | #define JX9_TK_EQUAL 0x0400000 /* Equal '=' */ | ||
1388 | #define JX9_TK_OTHER 0x1000000 /* Other symbols */ | ||
1389 | /* | ||
1390 | * JX9 keyword. | ||
1391 | * These words have special meaning in JX9. Some of them represent things which look like | ||
1392 | * functions, some look like constants, and so on, but they're not, really: they are language constructs. | ||
1393 | * You cannot use any of the following words as constants, object names, function or method names. | ||
1394 | * Using them as variable names is generally OK, but could lead to confusion. | ||
1395 | */ | ||
1396 | #define JX9_TKWRD_SWITCH 1 /* switch */ | ||
1397 | #define JX9_TKWRD_PRINT 2 /* print */ | ||
1398 | #define JX9_TKWRD_ELIF 0x4000000 /* elseif: MUST BE A POWER OF TWO */ | ||
1399 | #define JX9_TKWRD_ELSE 0x8000000 /* else: MUST BE A POWER OF TWO */ | ||
1400 | #define JX9_TKWRD_IF 3 /* if */ | ||
1401 | #define JX9_TKWRD_STATIC 4 /* static */ | ||
1402 | #define JX9_TKWRD_CASE 5 /* case */ | ||
1403 | #define JX9_TKWRD_FUNCTION 6 /* function */ | ||
1404 | #define JX9_TKWRD_CONST 7 /* const */ | ||
1405 | /* The number '8' is reserved for JX9_TK_ID */ | ||
1406 | #define JX9_TKWRD_WHILE 9 /* while */ | ||
1407 | #define JX9_TKWRD_DEFAULT 10 /* default */ | ||
1408 | #define JX9_TKWRD_AS 11 /* as */ | ||
1409 | #define JX9_TKWRD_CONTINUE 12 /* continue */ | ||
1410 | #define JX9_TKWRD_EXIT 13 /* exit */ | ||
1411 | #define JX9_TKWRD_DIE 14 /* die */ | ||
1412 | #define JX9_TKWRD_IMPORT 15 /* import */ | ||
1413 | #define JX9_TKWRD_INCLUDE 16 /* include */ | ||
1414 | #define JX9_TKWRD_FOR 17 /* for */ | ||
1415 | #define JX9_TKWRD_FOREACH 18 /* foreach */ | ||
1416 | #define JX9_TKWRD_RETURN 19 /* return */ | ||
1417 | #define JX9_TKWRD_BREAK 20 /* break */ | ||
1418 | #define JX9_TKWRD_UPLINK 21 /* uplink */ | ||
1419 | #define JX9_TKWRD_BOOL 0x8000 /* bool: MUST BE A POWER OF TWO */ | ||
1420 | #define JX9_TKWRD_INT 0x10000 /* int: MUST BE A POWER OF TWO */ | ||
1421 | #define JX9_TKWRD_FLOAT 0x20000 /* float: MUST BE A POWER OF TWO */ | ||
1422 | #define JX9_TKWRD_STRING 0x40000 /* string: MUST BE A POWER OF TWO */ | ||
1423 | |||
1424 | /* api.c */ | ||
1425 | JX9_PRIVATE sxi32 jx9EngineConfig(jx9 *pEngine, sxi32 nOp, va_list ap); | ||
1426 | JX9_PRIVATE int jx9DeleteFunction(jx9_vm *pVm,const char *zName); | ||
1427 | JX9_PRIVATE int Jx9DeleteConstant(jx9_vm *pVm,const char *zName); | ||
1428 | /* json.c function prototypes */ | ||
1429 | JX9_PRIVATE int jx9JsonSerialize(jx9_value *pValue,SyBlob *pOut); | ||
1430 | JX9_PRIVATE int jx9JsonDecode(jx9_context *pCtx,const char *zJSON,int nByte); | ||
1431 | /* memobj.c function prototypes */ | ||
1432 | JX9_PRIVATE sxi32 jx9MemObjDump(SyBlob *pOut, jx9_value *pObj); | ||
1433 | JX9_PRIVATE const char * jx9MemObjTypeDump(jx9_value *pVal); | ||
1434 | JX9_PRIVATE sxi32 jx9MemObjAdd(jx9_value *pObj1, jx9_value *pObj2, int bAddStore); | ||
1435 | JX9_PRIVATE sxi32 jx9MemObjCmp(jx9_value *pObj1, jx9_value *pObj2, int bStrict, int iNest); | ||
1436 | JX9_PRIVATE sxi32 jx9MemObjInitFromString(jx9_vm *pVm, jx9_value *pObj, const SyString *pVal); | ||
1437 | JX9_PRIVATE sxi32 jx9MemObjInitFromArray(jx9_vm *pVm, jx9_value *pObj, jx9_hashmap *pArray); | ||
1438 | #if 0 | ||
1439 | /* Not used in the current release of the JX9 engine */ | ||
1440 | JX9_PRIVATE sxi32 jx9MemObjInitFromReal(jx9_vm *pVm, jx9_value *pObj, jx9_real rVal); | ||
1441 | #endif | ||
1442 | JX9_PRIVATE sxi32 jx9MemObjInitFromInt(jx9_vm *pVm, jx9_value *pObj, sxi64 iVal); | ||
1443 | JX9_PRIVATE sxi32 jx9MemObjInitFromBool(jx9_vm *pVm, jx9_value *pObj, sxi32 iVal); | ||
1444 | JX9_PRIVATE sxi32 jx9MemObjInit(jx9_vm *pVm, jx9_value *pObj); | ||
1445 | JX9_PRIVATE sxi32 jx9MemObjStringAppend(jx9_value *pObj, const char *zData, sxu32 nLen); | ||
1446 | #if 0 | ||
1447 | /* Not used in the current release of the JX9 engine */ | ||
1448 | JX9_PRIVATE sxi32 jx9MemObjStringFormat(jx9_value *pObj, const char *zFormat, va_list ap); | ||
1449 | #endif | ||
1450 | JX9_PRIVATE sxi32 jx9MemObjStore(jx9_value *pSrc, jx9_value *pDest); | ||
1451 | JX9_PRIVATE sxi32 jx9MemObjLoad(jx9_value *pSrc, jx9_value *pDest); | ||
1452 | JX9_PRIVATE sxi32 jx9MemObjRelease(jx9_value *pObj); | ||
1453 | JX9_PRIVATE sxi32 jx9MemObjToNumeric(jx9_value *pObj); | ||
1454 | JX9_PRIVATE sxi32 jx9MemObjTryInteger(jx9_value *pObj); | ||
1455 | JX9_PRIVATE ProcMemObjCast jx9MemObjCastMethod(sxi32 iFlags); | ||
1456 | JX9_PRIVATE sxi32 jx9MemObjIsNumeric(jx9_value *pObj); | ||
1457 | JX9_PRIVATE sxi32 jx9MemObjIsEmpty(jx9_value *pObj); | ||
1458 | JX9_PRIVATE sxi32 jx9MemObjToHashmap(jx9_value *pObj); | ||
1459 | JX9_PRIVATE sxi32 jx9MemObjToString(jx9_value *pObj); | ||
1460 | JX9_PRIVATE sxi32 jx9MemObjToNull(jx9_value *pObj); | ||
1461 | JX9_PRIVATE sxi32 jx9MemObjToReal(jx9_value *pObj); | ||
1462 | JX9_PRIVATE sxi32 jx9MemObjToInteger(jx9_value *pObj); | ||
1463 | JX9_PRIVATE sxi32 jx9MemObjToBool(jx9_value *pObj); | ||
1464 | JX9_PRIVATE sxi64 jx9TokenValueToInt64(SyString *pData); | ||
1465 | /* lex.c function prototypes */ | ||
1466 | JX9_PRIVATE sxi32 jx9Tokenize(const char *zInput, sxu32 nLen, SySet *pOut); | ||
1467 | /* vm.c function prototypes */ | ||
1468 | JX9_PRIVATE void jx9VmReleaseContextValue(jx9_context *pCtx, jx9_value *pValue); | ||
1469 | JX9_PRIVATE sxi32 jx9VmInitFuncState(jx9_vm *pVm, jx9_vm_func *pFunc, const char *zName, sxu32 nByte, | ||
1470 | sxi32 iFlags, void *pUserData); | ||
1471 | JX9_PRIVATE sxi32 jx9VmInstallUserFunction(jx9_vm *pVm, jx9_vm_func *pFunc, SyString *pName); | ||
1472 | JX9_PRIVATE sxi32 jx9VmRegisterConstant(jx9_vm *pVm, const SyString *pName, ProcConstant xExpand, void *pUserData); | ||
1473 | JX9_PRIVATE sxi32 jx9VmInstallForeignFunction(jx9_vm *pVm, const SyString *pName, ProcHostFunction xFunc, void *pUserData); | ||
1474 | JX9_PRIVATE sxi32 jx9VmBlobConsumer(const void *pSrc, unsigned int nLen, void *pUserData); | ||
1475 | JX9_PRIVATE jx9_value * jx9VmReserveMemObj(jx9_vm *pVm,sxu32 *pIndex); | ||
1476 | JX9_PRIVATE jx9_value * jx9VmReserveConstObj(jx9_vm *pVm, sxu32 *pIndex); | ||
1477 | JX9_PRIVATE sxi32 jx9VmOutputConsume(jx9_vm *pVm, SyString *pString); | ||
1478 | JX9_PRIVATE sxi32 jx9VmOutputConsumeAp(jx9_vm *pVm, const char *zFormat, va_list ap); | ||
1479 | JX9_PRIVATE sxi32 jx9VmThrowErrorAp(jx9_vm *pVm, SyString *pFuncName, sxi32 iErr, const char *zFormat, va_list ap); | ||
1480 | JX9_PRIVATE sxi32 jx9VmThrowError(jx9_vm *pVm, SyString *pFuncName, sxi32 iErr, const char *zMessage); | ||
1481 | JX9_PRIVATE void jx9VmExpandConstantValue(jx9_value *pVal, void *pUserData); | ||
1482 | JX9_PRIVATE sxi32 jx9VmDump(jx9_vm *pVm, ProcConsumer xConsumer, void *pUserData); | ||
1483 | JX9_PRIVATE sxi32 jx9VmInit(jx9_vm *pVm, jx9 *pEngine); | ||
1484 | JX9_PRIVATE sxi32 jx9VmConfigure(jx9_vm *pVm, sxi32 nOp, va_list ap); | ||
1485 | JX9_PRIVATE sxi32 jx9VmByteCodeExec(jx9_vm *pVm); | ||
1486 | JX9_PRIVATE jx9_value * jx9VmExtractVariable(jx9_vm *pVm,SyString *pVar); | ||
1487 | JX9_PRIVATE sxi32 jx9VmRelease(jx9_vm *pVm); | ||
1488 | JX9_PRIVATE sxi32 jx9VmReset(jx9_vm *pVm); | ||
1489 | JX9_PRIVATE sxi32 jx9VmMakeReady(jx9_vm *pVm); | ||
1490 | JX9_PRIVATE sxu32 jx9VmInstrLength(jx9_vm *pVm); | ||
1491 | JX9_PRIVATE VmInstr * jx9VmPopInstr(jx9_vm *pVm); | ||
1492 | JX9_PRIVATE VmInstr * jx9VmPeekInstr(jx9_vm *pVm); | ||
1493 | JX9_PRIVATE VmInstr *jx9VmGetInstr(jx9_vm *pVm, sxu32 nIndex); | ||
1494 | JX9_PRIVATE SySet * jx9VmGetByteCodeContainer(jx9_vm *pVm); | ||
1495 | JX9_PRIVATE sxi32 jx9VmSetByteCodeContainer(jx9_vm *pVm, SySet *pContainer); | ||
1496 | JX9_PRIVATE sxi32 jx9VmEmitInstr(jx9_vm *pVm, sxi32 iOp, sxi32 iP1, sxu32 iP2, void *p3, sxu32 *pIndex); | ||
1497 | JX9_PRIVATE sxu32 jx9VmRandomNum(jx9_vm *pVm); | ||
1498 | JX9_PRIVATE sxi32 jx9VmCallUserFunction(jx9_vm *pVm, jx9_value *pFunc, int nArg, jx9_value **apArg, jx9_value *pResult); | ||
1499 | JX9_PRIVATE sxi32 jx9VmCallUserFunctionAp(jx9_vm *pVm, jx9_value *pFunc, jx9_value *pResult, ...); | ||
1500 | JX9_PRIVATE sxi32 jx9VmUnsetMemObj(jx9_vm *pVm, sxu32 nObjIdx); | ||
1501 | JX9_PRIVATE void jx9VmRandomString(jx9_vm *pVm, char *zBuf, int nLen); | ||
1502 | JX9_PRIVATE int jx9VmIsCallable(jx9_vm *pVm, jx9_value *pValue); | ||
1503 | JX9_PRIVATE sxi32 jx9VmPushFilePath(jx9_vm *pVm, const char *zPath, int nLen, sxu8 bMain, sxi32 *pNew); | ||
1504 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1505 | JX9_PRIVATE const jx9_io_stream * jx9VmGetStreamDevice(jx9_vm *pVm, const char **pzDevice, int nByte); | ||
1506 | #endif /* JX9_DISABLE_BUILTIN_FUNC */ | ||
1507 | JX9_PRIVATE int jx9Utf8Read( | ||
1508 | const unsigned char *z, /* First byte of UTF-8 character */ | ||
1509 | const unsigned char *zTerm, /* Pretend this byte is 0x00 */ | ||
1510 | const unsigned char **pzNext /* Write first byte past UTF-8 char here */ | ||
1511 | ); | ||
1512 | /* parse.c function prototypes */ | ||
1513 | JX9_PRIVATE int jx9IsLangConstruct(sxu32 nKeyID); | ||
1514 | JX9_PRIVATE sxi32 jx9ExprMakeTree(jx9_gen_state *pGen, SySet *pExprNode, jx9_expr_node **ppRoot); | ||
1515 | JX9_PRIVATE sxi32 jx9GetNextExpr(SyToken *pStart, SyToken *pEnd, SyToken **ppNext); | ||
1516 | JX9_PRIVATE void jx9DelimitNestedTokens(SyToken *pIn, SyToken *pEnd, sxu32 nTokStart, sxu32 nTokEnd, SyToken **ppEnd); | ||
1517 | JX9_PRIVATE const jx9_expr_op * jx9ExprExtractOperator(SyString *pStr, SyToken *pLast); | ||
1518 | JX9_PRIVATE sxi32 jx9ExprFreeTree(jx9_gen_state *pGen, SySet *pNodeSet); | ||
1519 | /* compile.c function prototypes */ | ||
1520 | JX9_PRIVATE ProcNodeConstruct jx9GetNodeHandler(sxu32 nNodeType); | ||
1521 | JX9_PRIVATE sxi32 jx9CompileLangConstruct(jx9_gen_state *pGen, sxi32 iCompileFlag); | ||
1522 | JX9_PRIVATE sxi32 jx9CompileJsonArray(jx9_gen_state *pGen, sxi32 iCompileFlag); | ||
1523 | JX9_PRIVATE sxi32 jx9CompileJsonObject(jx9_gen_state *pGen, sxi32 iCompileFlag); | ||
1524 | JX9_PRIVATE sxi32 jx9CompileVariable(jx9_gen_state *pGen, sxi32 iCompileFlag); | ||
1525 | JX9_PRIVATE sxi32 jx9CompileLiteral(jx9_gen_state *pGen, sxi32 iCompileFlag); | ||
1526 | JX9_PRIVATE sxi32 jx9CompileSimpleString(jx9_gen_state *pGen, sxi32 iCompileFlag); | ||
1527 | JX9_PRIVATE sxi32 jx9CompileString(jx9_gen_state *pGen, sxi32 iCompileFlag); | ||
1528 | JX9_PRIVATE sxi32 jx9CompileAnnonFunc(jx9_gen_state *pGen, sxi32 iCompileFlag); | ||
1529 | JX9_PRIVATE sxi32 jx9InitCodeGenerator(jx9_vm *pVm, ProcConsumer xErr, void *pErrData); | ||
1530 | JX9_PRIVATE sxi32 jx9ResetCodeGenerator(jx9_vm *pVm, ProcConsumer xErr, void *pErrData); | ||
1531 | JX9_PRIVATE sxi32 jx9GenCompileError(jx9_gen_state *pGen, sxi32 nErrType, sxu32 nLine, const char *zFormat, ...); | ||
1532 | JX9_PRIVATE sxi32 jx9CompileScript(jx9_vm *pVm, SyString *pScript, sxi32 iFlags); | ||
1533 | /* constant.c function prototypes */ | ||
1534 | JX9_PRIVATE void jx9RegisterBuiltInConstant(jx9_vm *pVm); | ||
1535 | /* builtin.c function prototypes */ | ||
1536 | JX9_PRIVATE void jx9RegisterBuiltInFunction(jx9_vm *pVm); | ||
1537 | /* hashmap.c function prototypes */ | ||
1538 | JX9_PRIVATE jx9_hashmap * jx9NewHashmap(jx9_vm *pVm, sxu32 (*xIntHash)(sxi64), sxu32 (*xBlobHash)(const void *, sxu32)); | ||
1539 | JX9_PRIVATE sxi32 jx9HashmapLoadBuiltin(jx9_vm *pVm); | ||
1540 | JX9_PRIVATE sxi32 jx9HashmapRelease(jx9_hashmap *pMap, int FreeDS); | ||
1541 | JX9_PRIVATE void jx9HashmapUnref(jx9_hashmap *pMap); | ||
1542 | JX9_PRIVATE sxi32 jx9HashmapLookup(jx9_hashmap *pMap, jx9_value *pKey, jx9_hashmap_node **ppNode); | ||
1543 | JX9_PRIVATE sxi32 jx9HashmapInsert(jx9_hashmap *pMap, jx9_value *pKey, jx9_value *pVal); | ||
1544 | JX9_PRIVATE sxi32 jx9HashmapUnion(jx9_hashmap *pLeft, jx9_hashmap *pRight); | ||
1545 | JX9_PRIVATE sxi32 jx9HashmapDup(jx9_hashmap *pSrc, jx9_hashmap *pDest); | ||
1546 | JX9_PRIVATE sxi32 jx9HashmapCmp(jx9_hashmap *pLeft, jx9_hashmap *pRight, int bStrict); | ||
1547 | JX9_PRIVATE void jx9HashmapResetLoopCursor(jx9_hashmap *pMap); | ||
1548 | JX9_PRIVATE jx9_hashmap_node * jx9HashmapGetNextEntry(jx9_hashmap *pMap); | ||
1549 | JX9_PRIVATE jx9_value * jx9HashmapGetNodeValue(jx9_hashmap_node *pNode); | ||
1550 | JX9_PRIVATE void jx9HashmapExtractNodeValue(jx9_hashmap_node *pNode, jx9_value *pValue, int bStore); | ||
1551 | JX9_PRIVATE void jx9HashmapExtractNodeKey(jx9_hashmap_node *pNode, jx9_value *pKey); | ||
1552 | JX9_PRIVATE void jx9RegisterHashmapFunctions(jx9_vm *pVm); | ||
1553 | JX9_PRIVATE sxi32 jx9HashmapWalk(jx9_hashmap *pMap, int (*xWalk)(jx9_value *, jx9_value *, void *), void *pUserData); | ||
1554 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1555 | JX9_PRIVATE int jx9HashmapValuesToSet(jx9_hashmap *pMap, SySet *pOut); | ||
1556 | /* builtin.c function prototypes */ | ||
1557 | JX9_PRIVATE sxi32 jx9InputFormat(int (*xConsumer)(jx9_context *, const char *, int, void *), | ||
1558 | jx9_context *pCtx, const char *zIn, int nByte, int nArg, jx9_value **apArg, void *pUserData, int vf); | ||
1559 | JX9_PRIVATE sxi32 jx9ProcessCsv(const char *zInput, int nByte, int delim, int encl, | ||
1560 | int escape, sxi32 (*xConsumer)(const char *, int, void *), void *pUserData); | ||
1561 | JX9_PRIVATE sxi32 jx9CsvConsumer(const char *zToken, int nTokenLen, void *pUserData); | ||
1562 | JX9_PRIVATE sxi32 jx9StripTagsFromString(jx9_context *pCtx, const char *zIn, int nByte, const char *zTaglist, int nTaglen); | ||
1563 | JX9_PRIVATE sxi32 jx9ParseIniString(jx9_context *pCtx, const char *zIn, sxu32 nByte, int bProcessSection); | ||
1564 | #endif | ||
1565 | /* vfs.c */ | ||
1566 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1567 | JX9_PRIVATE void * jx9StreamOpenHandle(jx9_vm *pVm, const jx9_io_stream *pStream, const char *zFile, | ||
1568 | int iFlags, int use_include, jx9_value *pResource, int bPushInclude, int *pNew); | ||
1569 | JX9_PRIVATE sxi32 jx9StreamReadWholeFile(void *pHandle, const jx9_io_stream *pStream, SyBlob *pOut); | ||
1570 | JX9_PRIVATE void jx9StreamCloseHandle(const jx9_io_stream *pStream, void *pHandle); | ||
1571 | #endif /* JX9_DISABLE_BUILTIN_FUNC */ | ||
1572 | JX9_PRIVATE const char * jx9ExtractDirName(const char *zPath, int nByte, int *pLen); | ||
1573 | JX9_PRIVATE sxi32 jx9RegisterIORoutine(jx9_vm *pVm); | ||
1574 | JX9_PRIVATE const jx9_vfs * jx9ExportBuiltinVfs(void); | ||
1575 | JX9_PRIVATE void * jx9ExportStdin(jx9_vm *pVm); | ||
1576 | JX9_PRIVATE void * jx9ExportStdout(jx9_vm *pVm); | ||
1577 | JX9_PRIVATE void * jx9ExportStderr(jx9_vm *pVm); | ||
1578 | /* lib.c function prototypes */ | ||
1579 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1580 | JX9_PRIVATE sxi32 SyArchiveInit(SyArchive *pArch, SyMemBackend *pAllocator, ProcHash xHash, ProcRawStrCmp xCmp); | ||
1581 | JX9_PRIVATE sxi32 SyArchiveRelease(SyArchive *pArch); | ||
1582 | JX9_PRIVATE sxi32 SyArchiveResetLoopCursor(SyArchive *pArch); | ||
1583 | JX9_PRIVATE sxi32 SyArchiveGetNextEntry(SyArchive *pArch, SyArchiveEntry **ppEntry); | ||
1584 | JX9_PRIVATE sxi32 SyZipExtractFromBuf(SyArchive *pArch, const char *zBuf, sxu32 nLen); | ||
1585 | #endif /* JX9_DISABLE_BUILTIN_FUNC */ | ||
1586 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1587 | JX9_PRIVATE sxi32 SyBinToHexConsumer(const void *pIn, sxu32 nLen, ProcConsumer xConsumer, void *pConsumerData); | ||
1588 | #endif /* JX9_DISABLE_BUILTIN_FUNC */ | ||
1589 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1590 | #ifndef JX9_DISABLE_HASH_FUNC | ||
1591 | JX9_PRIVATE sxu32 SyCrc32(const void *pSrc, sxu32 nLen); | ||
1592 | JX9_PRIVATE void MD5Update(MD5Context *ctx, const unsigned char *buf, unsigned int len); | ||
1593 | JX9_PRIVATE void MD5Final(unsigned char digest[16], MD5Context *ctx); | ||
1594 | JX9_PRIVATE sxi32 MD5Init(MD5Context *pCtx); | ||
1595 | JX9_PRIVATE sxi32 SyMD5Compute(const void *pIn, sxu32 nLen, unsigned char zDigest[16]); | ||
1596 | JX9_PRIVATE void SHA1Init(SHA1Context *context); | ||
1597 | JX9_PRIVATE void SHA1Update(SHA1Context *context, const unsigned char *data, unsigned int len); | ||
1598 | JX9_PRIVATE void SHA1Final(SHA1Context *context, unsigned char digest[20]); | ||
1599 | JX9_PRIVATE sxi32 SySha1Compute(const void *pIn, sxu32 nLen, unsigned char zDigest[20]); | ||
1600 | #endif | ||
1601 | #endif /* JX9_DISABLE_BUILTIN_FUNC */ | ||
1602 | JX9_PRIVATE sxi32 SyRandomness(SyPRNGCtx *pCtx, void *pBuf, sxu32 nLen); | ||
1603 | JX9_PRIVATE sxi32 SyRandomnessInit(SyPRNGCtx *pCtx, ProcRandomSeed xSeed, void *pUserData); | ||
1604 | JX9_PRIVATE sxu32 SyBufferFormat(char *zBuf, sxu32 nLen, const char *zFormat, ...); | ||
1605 | JX9_PRIVATE sxu32 SyBlobFormatAp(SyBlob *pBlob, const char *zFormat, va_list ap); | ||
1606 | JX9_PRIVATE sxu32 SyBlobFormat(SyBlob *pBlob, const char *zFormat, ...); | ||
1607 | JX9_PRIVATE sxi32 SyProcFormat(ProcConsumer xConsumer, void *pData, const char *zFormat, ...); | ||
1608 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1609 | JX9_PRIVATE const char *SyTimeGetMonth(sxi32 iMonth); | ||
1610 | JX9_PRIVATE const char *SyTimeGetDay(sxi32 iDay); | ||
1611 | #endif /* JX9_DISABLE_BUILTIN_FUNC */ | ||
1612 | JX9_PRIVATE sxi32 SyUriDecode(const char *zSrc, sxu32 nLen, ProcConsumer xConsumer, void *pUserData, int bUTF8); | ||
1613 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1614 | JX9_PRIVATE sxi32 SyUriEncode(const char *zSrc, sxu32 nLen, ProcConsumer xConsumer, void *pUserData); | ||
1615 | #endif | ||
1616 | JX9_PRIVATE sxi32 SyLexRelease(SyLex *pLex); | ||
1617 | JX9_PRIVATE sxi32 SyLexTokenizeInput(SyLex *pLex, const char *zInput, sxu32 nLen, void *pCtxData, ProcSort xSort, ProcCmp xCmp); | ||
1618 | JX9_PRIVATE sxi32 SyLexInit(SyLex *pLex, SySet *pSet, ProcTokenizer xTokenizer, void *pUserData); | ||
1619 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1620 | JX9_PRIVATE sxi32 SyBase64Decode(const char *zB64, sxu32 nLen, ProcConsumer xConsumer, void *pUserData); | ||
1621 | JX9_PRIVATE sxi32 SyBase64Encode(const char *zSrc, sxu32 nLen, ProcConsumer xConsumer, void *pUserData); | ||
1622 | #endif /* JX9_DISABLE_BUILTIN_FUNC */ | ||
1623 | JX9_PRIVATE sxu32 SyBinHash(const void *pSrc, sxu32 nLen); | ||
1624 | JX9_PRIVATE sxi32 SyStrToReal(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest); | ||
1625 | JX9_PRIVATE sxi32 SyBinaryStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest); | ||
1626 | JX9_PRIVATE sxi32 SyOctalStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest); | ||
1627 | JX9_PRIVATE sxi32 SyHexStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest); | ||
1628 | JX9_PRIVATE sxi32 SyHexToint(sxi32 c); | ||
1629 | JX9_PRIVATE sxi32 SyStrToInt64(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest); | ||
1630 | JX9_PRIVATE sxi32 SyStrToInt32(const char *zSrc, sxu32 nLen, void *pOutVal, const char **zRest); | ||
1631 | JX9_PRIVATE sxi32 SyStrIsNumeric(const char *zSrc, sxu32 nLen, sxu8 *pReal, const char **pzTail); | ||
1632 | JX9_PRIVATE sxi32 SyHashInsert(SyHash *pHash, const void *pKey, sxu32 nKeyLen, void *pUserData); | ||
1633 | JX9_PRIVATE sxi32 SyHashForEach(SyHash *pHash, sxi32(*xStep)(SyHashEntry *, void *), void *pUserData); | ||
1634 | JX9_PRIVATE sxi32 SyHashDeleteEntry(SyHash *pHash, const void *pKey, sxu32 nKeyLen, void **ppUserData); | ||
1635 | JX9_PRIVATE SyHashEntry *SyHashGet(SyHash *pHash, const void *pKey, sxu32 nKeyLen); | ||
1636 | JX9_PRIVATE sxi32 SyHashRelease(SyHash *pHash); | ||
1637 | JX9_PRIVATE sxi32 SyHashInit(SyHash *pHash, SyMemBackend *pAllocator, ProcHash xHash, ProcCmp xCmp); | ||
1638 | JX9_PRIVATE void *SySetAt(SySet *pSet, sxu32 nIdx); | ||
1639 | JX9_PRIVATE void *SySetPop(SySet *pSet); | ||
1640 | JX9_PRIVATE void *SySetPeek(SySet *pSet); | ||
1641 | JX9_PRIVATE sxi32 SySetRelease(SySet *pSet); | ||
1642 | JX9_PRIVATE sxi32 SySetReset(SySet *pSet); | ||
1643 | JX9_PRIVATE sxi32 SySetResetCursor(SySet *pSet); | ||
1644 | JX9_PRIVATE sxi32 SySetGetNextEntry(SySet *pSet, void **ppEntry); | ||
1645 | JX9_PRIVATE sxi32 SySetAlloc(SySet *pSet, sxi32 nItem); | ||
1646 | JX9_PRIVATE sxi32 SySetPut(SySet *pSet, const void *pItem); | ||
1647 | JX9_PRIVATE sxi32 SySetInit(SySet *pSet, SyMemBackend *pAllocator, sxu32 ElemSize); | ||
1648 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1649 | JX9_PRIVATE sxi32 SyBlobSearch(const void *pBlob, sxu32 nLen, const void *pPattern, sxu32 pLen, sxu32 *pOfft); | ||
1650 | #endif | ||
1651 | JX9_PRIVATE sxi32 SyBlobRelease(SyBlob *pBlob); | ||
1652 | JX9_PRIVATE sxi32 SyBlobReset(SyBlob *pBlob); | ||
1653 | JX9_PRIVATE sxi32 SyBlobTruncate(SyBlob *pBlob,sxu32 nNewLen); | ||
1654 | JX9_PRIVATE sxi32 SyBlobDup(SyBlob *pSrc, SyBlob *pDest); | ||
1655 | JX9_PRIVATE sxi32 SyBlobNullAppend(SyBlob *pBlob); | ||
1656 | JX9_PRIVATE sxi32 SyBlobAppend(SyBlob *pBlob, const void *pData, sxu32 nSize); | ||
1657 | JX9_PRIVATE sxi32 SyBlobReadOnly(SyBlob *pBlob, const void *pData, sxu32 nByte); | ||
1658 | JX9_PRIVATE sxi32 SyBlobInit(SyBlob *pBlob, SyMemBackend *pAllocator); | ||
1659 | JX9_PRIVATE sxi32 SyBlobInitFromBuf(SyBlob *pBlob, void *pBuffer, sxu32 nSize); | ||
1660 | JX9_PRIVATE char *SyMemBackendStrDup(SyMemBackend *pBackend, const char *zSrc, sxu32 nSize); | ||
1661 | JX9_PRIVATE void *SyMemBackendDup(SyMemBackend *pBackend, const void *pSrc, sxu32 nSize); | ||
1662 | JX9_PRIVATE sxi32 SyMemBackendRelease(SyMemBackend *pBackend); | ||
1663 | JX9_PRIVATE sxi32 SyMemBackendInitFromOthers(SyMemBackend *pBackend, const SyMemMethods *pMethods, ProcMemError xMemErr, void *pUserData); | ||
1664 | JX9_PRIVATE sxi32 SyMemBackendInit(SyMemBackend *pBackend, ProcMemError xMemErr, void *pUserData); | ||
1665 | JX9_PRIVATE sxi32 SyMemBackendInitFromParent(SyMemBackend *pBackend,const SyMemBackend *pParent); | ||
1666 | #if 0 | ||
1667 | /* Not used in the current release of the JX9 engine */ | ||
1668 | JX9_PRIVATE void *SyMemBackendPoolRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nByte); | ||
1669 | #endif | ||
1670 | JX9_PRIVATE sxi32 SyMemBackendPoolFree(SyMemBackend *pBackend, void *pChunk); | ||
1671 | JX9_PRIVATE void *SyMemBackendPoolAlloc(SyMemBackend *pBackend, sxu32 nByte); | ||
1672 | JX9_PRIVATE sxi32 SyMemBackendFree(SyMemBackend *pBackend, void *pChunk); | ||
1673 | JX9_PRIVATE void *SyMemBackendRealloc(SyMemBackend *pBackend, void *pOld, sxu32 nByte); | ||
1674 | JX9_PRIVATE void *SyMemBackendAlloc(SyMemBackend *pBackend, sxu32 nByte); | ||
1675 | JX9_PRIVATE sxu32 SyMemcpy(const void *pSrc, void *pDest, sxu32 nLen); | ||
1676 | JX9_PRIVATE sxi32 SyMemcmp(const void *pB1, const void *pB2, sxu32 nSize); | ||
1677 | JX9_PRIVATE void SyZero(void *pSrc, sxu32 nSize); | ||
1678 | JX9_PRIVATE sxi32 SyStrnicmp(const char *zLeft, const char *zRight, sxu32 SLen); | ||
1679 | JX9_PRIVATE sxu32 Systrcpy(char *zDest, sxu32 nDestLen, const char *zSrc, sxu32 nLen); | ||
1680 | #if !defined(JX9_DISABLE_BUILTIN_FUNC) || defined(__APPLE__) | ||
1681 | JX9_PRIVATE sxi32 SyStrncmp(const char *zLeft, const char *zRight, sxu32 nLen); | ||
1682 | #endif | ||
1683 | JX9_PRIVATE sxi32 SyByteListFind(const char *zSrc, sxu32 nLen, const char *zList, sxu32 *pFirstPos); | ||
1684 | #ifndef JX9_DISABLE_BUILTIN_FUNC | ||
1685 | JX9_PRIVATE sxi32 SyByteFind2(const char *zStr, sxu32 nLen, sxi32 c, sxu32 *pPos); | ||
1686 | #endif | ||
1687 | JX9_PRIVATE sxi32 SyByteFind(const char *zStr, sxu32 nLen, sxi32 c, sxu32 *pPos); | ||
1688 | JX9_PRIVATE sxu32 SyStrlen(const char *zSrc); | ||
1689 | #if defined(JX9_ENABLE_THREADS) | ||
1690 | JX9_PRIVATE const SyMutexMethods *SyMutexExportMethods(void); | ||
1691 | JX9_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods); | ||
1692 | JX9_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend); | ||
1693 | #endif | ||
1694 | JX9_PRIVATE void SyBigEndianPack32(unsigned char *buf,sxu32 nb); | ||
1695 | JX9_PRIVATE void SyBigEndianUnpack32(const unsigned char *buf,sxu32 *uNB); | ||
1696 | JX9_PRIVATE void SyBigEndianPack16(unsigned char *buf,sxu16 nb); | ||
1697 | JX9_PRIVATE void SyBigEndianUnpack16(const unsigned char *buf,sxu16 *uNB); | ||
1698 | JX9_PRIVATE void SyBigEndianPack64(unsigned char *buf,sxu64 n64); | ||
1699 | JX9_PRIVATE void SyBigEndianUnpack64(const unsigned char *buf,sxu64 *n64); | ||
1700 | JX9_PRIVATE sxi32 SyBlobAppendBig64(SyBlob *pBlob,sxu64 n64); | ||
1701 | JX9_PRIVATE sxi32 SyBlobAppendBig32(SyBlob *pBlob,sxu32 n32); | ||
1702 | JX9_PRIVATE sxi32 SyBlobAppendBig16(SyBlob *pBlob,sxu16 n16); | ||
1703 | JX9_PRIVATE void SyTimeFormatToDos(Sytm *pFmt,sxu32 *pOut); | ||
1704 | JX9_PRIVATE void SyDosTimeFormat(sxu32 nDosDate, Sytm *pOut); | ||
1705 | #endif /* __JX9INT_H__ */ | ||