zig-pug 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +346 -0
  3. package/binding.c +375 -0
  4. package/binding.gyp +28 -0
  5. package/common.gypi +5 -0
  6. package/include/zigpug.h +135 -0
  7. package/index.js +205 -0
  8. package/package.json +87 -0
  9. package/vendor/mujs/COPYING +16 -0
  10. package/vendor/mujs/README +50 -0
  11. package/vendor/mujs/astnames.h +92 -0
  12. package/vendor/mujs/jsarray.c +832 -0
  13. package/vendor/mujs/jsboolean.c +38 -0
  14. package/vendor/mujs/jsbuiltin.c +249 -0
  15. package/vendor/mujs/jscompile.c +1428 -0
  16. package/vendor/mujs/jsdate.c +861 -0
  17. package/vendor/mujs/jsdtoa.c +749 -0
  18. package/vendor/mujs/jserror.c +139 -0
  19. package/vendor/mujs/jsfunction.c +231 -0
  20. package/vendor/mujs/jsgc.c +284 -0
  21. package/vendor/mujs/jsi.h +870 -0
  22. package/vendor/mujs/jsintern.c +137 -0
  23. package/vendor/mujs/jslex.c +878 -0
  24. package/vendor/mujs/jsmath.c +194 -0
  25. package/vendor/mujs/jsnumber.c +198 -0
  26. package/vendor/mujs/jsobject.c +560 -0
  27. package/vendor/mujs/json.c +422 -0
  28. package/vendor/mujs/jsparse.c +1065 -0
  29. package/vendor/mujs/jsproperty.c +341 -0
  30. package/vendor/mujs/jsregexp.c +232 -0
  31. package/vendor/mujs/jsrepr.c +285 -0
  32. package/vendor/mujs/jsrun.c +2096 -0
  33. package/vendor/mujs/jsstate.c +334 -0
  34. package/vendor/mujs/jsstring.c +852 -0
  35. package/vendor/mujs/jsvalue.c +708 -0
  36. package/vendor/mujs/libmujs.a +0 -0
  37. package/vendor/mujs/main.c +396 -0
  38. package/vendor/mujs/mujs.h +253 -0
  39. package/vendor/mujs/one.c +25 -0
  40. package/vendor/mujs/opnames.h +85 -0
  41. package/vendor/mujs/pp.c +980 -0
  42. package/vendor/mujs/regexp.c +1277 -0
  43. package/vendor/mujs/regexp.h +46 -0
  44. package/vendor/mujs/utf.c +305 -0
  45. package/vendor/mujs/utf.h +52 -0
  46. package/vendor/mujs/utfdata.h +2209 -0
@@ -0,0 +1,870 @@
1
+ #ifndef jsi_h
2
+ #define jsi_h
3
+
4
+ #include "mujs.h"
5
+
6
+ #include <stdio.h>
7
+ #include <stdlib.h>
8
+ #include <stddef.h>
9
+ #include <stdarg.h>
10
+ #include <string.h>
11
+ #include <setjmp.h>
12
+ #include <math.h>
13
+ #include <float.h>
14
+ #include <limits.h>
15
+
16
+ /* NOTE: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103052 */
17
+ #ifdef __GNUC__
18
+ #if (__GNUC__ >= 6)
19
+ #pragma GCC optimize ("no-ipa-pure-const")
20
+ #endif
21
+ #endif
22
+
23
+ /* Microsoft Visual C */
24
+ #ifdef _MSC_VER
25
+ #pragma warning(disable:4996) /* _CRT_SECURE_NO_WARNINGS */
26
+ #pragma warning(disable:4244) /* implicit conversion from double to int */
27
+ #pragma warning(disable:4267) /* implicit conversion of int to smaller int */
28
+ #pragma warning(disable:4090) /* broken const warnings */
29
+ #define inline __inline
30
+ #if _MSC_VER < 1900 /* MSVC 2015 */
31
+ #define snprintf jsW_snprintf
32
+ #define vsnprintf jsW_vsnprintf
33
+ static int jsW_vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
34
+ {
35
+ int n;
36
+ n = _vsnprintf(str, size, fmt, ap);
37
+ str[size-1] = 0;
38
+ return n;
39
+ }
40
+ static int jsW_snprintf(char *str, size_t size, const char *fmt, ...)
41
+ {
42
+ int n;
43
+ va_list ap;
44
+ va_start(ap, fmt);
45
+ n = jsW_vsnprintf(str, size, fmt, ap);
46
+ va_end(ap);
47
+ return n;
48
+ }
49
+ #endif
50
+ #if _MSC_VER <= 1700 /* <= MSVC 2012 */
51
+ #define isnan(x) _isnan(x)
52
+ #define isinf(x) (!_finite(x))
53
+ #define isfinite(x) _finite(x)
54
+ static __inline int signbit(double x) { __int64 i; memcpy(&i, &x, 8); return i>>63; }
55
+ #define INFINITY (DBL_MAX+DBL_MAX)
56
+ #define NAN (INFINITY-INFINITY)
57
+ #endif
58
+ #endif
59
+
60
+ #define soffsetof(x,y) ((int)offsetof(x,y))
61
+ #define nelem(a) (int)(sizeof (a) / sizeof (a)[0])
62
+
63
+ void *js_malloc(js_State *J, int size);
64
+ void *js_realloc(js_State *J, void *ptr, int size);
65
+ void js_free(js_State *J, void *ptr);
66
+
67
+ typedef union js_Value js_Value;
68
+ typedef struct js_Regexp js_Regexp;
69
+ typedef struct js_Object js_Object;
70
+ typedef struct js_String js_String;
71
+ typedef struct js_Ast js_Ast;
72
+ typedef struct js_Function js_Function;
73
+ typedef struct js_Environment js_Environment;
74
+ typedef struct js_StringNode js_StringNode;
75
+ typedef struct js_Jumpbuf js_Jumpbuf;
76
+ typedef struct js_StackTrace js_StackTrace;
77
+
78
+ /* Limits */
79
+
80
+ #ifndef JS_STACKSIZE
81
+ #define JS_STACKSIZE 4096 /* value stack size */
82
+ #endif
83
+ #ifndef JS_ENVLIMIT
84
+ #define JS_ENVLIMIT 1024 /* environment stack size */
85
+ #endif
86
+ #ifndef JS_TRYLIMIT
87
+ #define JS_TRYLIMIT 64 /* exception stack size */
88
+ #endif
89
+
90
+ #ifndef JS_ARRAYLIMIT
91
+ #define JS_ARRAYLIMIT (1<<26) /* limit arrays to 64M entries (1G of flat array data) */
92
+ #endif
93
+
94
+ #ifndef JS_GCFACTOR
95
+ /*
96
+ * GC will try to trigger when memory usage is this value times the minimum
97
+ * needed memory. E.g. if there are 100 remaining objects after GC and this
98
+ * value is 5.0, then the next GC will trigger when the overall number is 500.
99
+ * I.e. a value of 5.0 aims at 80% garbage, 20% remain-used on each GC.
100
+ * The bigger the value the less impact GC has on overall performance, but more
101
+ * memory is used and individual GC pauses are longer (but fewer).
102
+ */
103
+ #define JS_GCFACTOR 5.0 /* memory overhead factor >= 1.0 */
104
+ #endif
105
+
106
+ #ifndef JS_ASTLIMIT
107
+ #define JS_ASTLIMIT 400 /* max nested expressions */
108
+ #endif
109
+
110
+ #ifndef JS_STRLIMIT
111
+ #define JS_STRLIMIT (1<<28) /* max string length */
112
+ #endif
113
+
114
+ /* instruction size -- change to int if you get integer overflow syntax errors */
115
+
116
+ #ifdef JS_INSTRUCTION
117
+ typedef JS_INSTRUCTION js_Instruction;
118
+ #else
119
+ typedef unsigned short js_Instruction;
120
+ #endif
121
+
122
+ /* String interning */
123
+
124
+ char *js_strdup(js_State *J, const char *s);
125
+ const char *js_intern(js_State *J, const char *s);
126
+ void jsS_dumpstrings(js_State *J);
127
+ void jsS_freestrings(js_State *J);
128
+
129
+ /* Portable strtod and printf float formatting */
130
+
131
+ void js_fmtexp(char *p, int e);
132
+ int js_grisu2(double v, char *buffer, int *K);
133
+ double js_strtod(const char *as, char **aas);
134
+
135
+ double js_strtol(const char *s, char **ep, int radix);
136
+
137
+ /* Private stack functions */
138
+
139
+ void js_newarguments(js_State *J);
140
+ void js_newfunction(js_State *J, js_Function *function, js_Environment *scope);
141
+ void js_newscript(js_State *J, js_Function *function, js_Environment *scope);
142
+ void js_loadeval(js_State *J, const char *filename, const char *source);
143
+
144
+ js_Regexp *js_toregexp(js_State *J, int idx);
145
+ int js_isarrayindex(js_State *J, const char *str, int *idx);
146
+ int js_runeat(js_State *J, const char *s, int i);
147
+ int js_utflen(const char *s);
148
+ int js_utfptrtoidx(const char *s, const char *p);
149
+
150
+ void js_dup(js_State *J);
151
+ void js_dup2(js_State *J);
152
+ void js_rot2(js_State *J);
153
+ void js_rot3(js_State *J);
154
+ void js_rot4(js_State *J);
155
+ void js_rot2pop1(js_State *J);
156
+ void js_rot3pop2(js_State *J);
157
+ void js_dup1rot3(js_State *J);
158
+ void js_dup1rot4(js_State *J);
159
+
160
+ void js_RegExp_prototype_exec(js_State *J, js_Regexp *re, const char *text);
161
+
162
+ void js_trap(js_State *J, int pc); /* dump stack and environment to stdout */
163
+
164
+ struct js_StackTrace
165
+ {
166
+ const char *name;
167
+ const char *file;
168
+ int line;
169
+ };
170
+
171
+ /* Exception handling */
172
+
173
+ struct js_Jumpbuf
174
+ {
175
+ jmp_buf buf;
176
+ js_Environment *E;
177
+ int envtop;
178
+ int tracetop;
179
+ int top, bot;
180
+ int strict;
181
+ js_Instruction *pc;
182
+ };
183
+
184
+ void *js_savetrypc(js_State *J, js_Instruction *pc);
185
+
186
+ #define js_trypc(J, PC) \
187
+ setjmp(js_savetrypc(J, PC))
188
+
189
+ /* String buffer */
190
+
191
+ typedef struct js_Buffer { int n, m; char s[64]; } js_Buffer;
192
+
193
+ void js_putc(js_State *J, js_Buffer **sbp, int c);
194
+ void js_puts(js_State *J, js_Buffer **sb, const char *s);
195
+ void js_putm(js_State *J, js_Buffer **sb, const char *s, const char *e);
196
+
197
+ /* State struct */
198
+
199
+ struct js_State
200
+ {
201
+ void *actx;
202
+ void *uctx;
203
+ js_Alloc alloc;
204
+ js_Report report;
205
+ js_Panic panic;
206
+
207
+ js_StringNode *strings;
208
+
209
+ int default_strict;
210
+ int strict;
211
+
212
+ /* parser input source */
213
+ const char *filename;
214
+ const char *source;
215
+ int line;
216
+
217
+ /* lexer state */
218
+ struct { char *text; int len, cap; } lexbuf;
219
+ int lexline;
220
+ int lexchar;
221
+ int lasttoken;
222
+ int newline;
223
+
224
+ /* parser state */
225
+ int astdepth;
226
+ int lookahead;
227
+ const char *text;
228
+ double number;
229
+ js_Ast *gcast; /* list of allocated nodes to free after parsing */
230
+
231
+ /* runtime environment */
232
+ js_Object *Object_prototype;
233
+ js_Object *Array_prototype;
234
+ js_Object *Function_prototype;
235
+ js_Object *Boolean_prototype;
236
+ js_Object *Number_prototype;
237
+ js_Object *String_prototype;
238
+ js_Object *RegExp_prototype;
239
+ js_Object *Date_prototype;
240
+
241
+ js_Object *Error_prototype;
242
+ js_Object *EvalError_prototype;
243
+ js_Object *RangeError_prototype;
244
+ js_Object *ReferenceError_prototype;
245
+ js_Object *SyntaxError_prototype;
246
+ js_Object *TypeError_prototype;
247
+ js_Object *URIError_prototype;
248
+
249
+ unsigned int seed; /* Math.random seed */
250
+
251
+ char scratch[12]; /* scratch buffer for iterating over array indices */
252
+
253
+ int nextref; /* for js_ref use */
254
+ js_Object *R; /* registry of hidden values */
255
+ js_Object *G; /* the global object */
256
+ js_Environment *E; /* current environment scope */
257
+ js_Environment *GE; /* global environment scope (at the root) */
258
+
259
+ /* execution stack */
260
+ int top, bot;
261
+ js_Value *stack;
262
+
263
+ /* garbage collector list */
264
+ int gcmark;
265
+ unsigned int gccounter, gcthresh;
266
+ js_Environment *gcenv;
267
+ js_Function *gcfun;
268
+ js_Object *gcobj;
269
+ js_String *gcstr;
270
+
271
+ js_Object *gcroot; /* gc scan list */
272
+
273
+ int runlimit;
274
+ int memlimit;
275
+
276
+ /* environments on the call stack but currently not in scope */
277
+ int envtop;
278
+ js_Environment *envstack[JS_ENVLIMIT];
279
+
280
+ /* debug info stack trace */
281
+ int tracetop;
282
+ js_StackTrace trace[JS_ENVLIMIT];
283
+
284
+ /* exception stack */
285
+ int trytop;
286
+ js_Jumpbuf trybuf[JS_TRYLIMIT];
287
+ };
288
+
289
+ /* Values */
290
+
291
+ typedef struct js_Property js_Property;
292
+ typedef struct js_Iterator js_Iterator;
293
+
294
+ /* Hint to ToPrimitive() */
295
+ enum {
296
+ JS_HNONE,
297
+ JS_HNUMBER,
298
+ JS_HSTRING
299
+ };
300
+
301
+ enum js_Type {
302
+ JS_TSHRSTR, /* type tag doubles as string zero-terminator */
303
+ JS_TUNDEFINED,
304
+ JS_TNULL,
305
+ JS_TBOOLEAN,
306
+ JS_TNUMBER,
307
+ JS_TLITSTR,
308
+ JS_TMEMSTR,
309
+ JS_TOBJECT,
310
+ };
311
+
312
+ enum js_Class {
313
+ JS_COBJECT,
314
+ JS_CARRAY,
315
+ JS_CFUNCTION,
316
+ JS_CSCRIPT, /* function created from global/eval code */
317
+ JS_CCFUNCTION, /* built-in function */
318
+ JS_CERROR,
319
+ JS_CBOOLEAN,
320
+ JS_CNUMBER,
321
+ JS_CSTRING,
322
+ JS_CREGEXP,
323
+ JS_CDATE,
324
+ JS_CMATH,
325
+ JS_CJSON,
326
+ JS_CARGUMENTS,
327
+ JS_CITERATOR,
328
+ JS_CUSERDATA,
329
+ };
330
+
331
+ /*
332
+ Short strings abuse the js_Value struct. By putting the type tag in the
333
+ last byte, and using 0 as the tag for short strings, we can use the
334
+ entire js_Value as string storage by letting the type tag serve double
335
+ purpose as the string zero terminator.
336
+ */
337
+
338
+ union js_Value
339
+ {
340
+ struct {
341
+ char pad[15];
342
+ char type; /* type tag overlaps with final byte of shrstr */
343
+ } t;
344
+ union {
345
+ char shrstr[16];
346
+ int boolean;
347
+ double number;
348
+ const char *litstr;
349
+ js_String *memstr;
350
+ js_Object *object;
351
+ } u;
352
+ };
353
+
354
+ struct js_String
355
+ {
356
+ js_String *gcnext;
357
+ char gcmark;
358
+ char p[1];
359
+ };
360
+
361
+ struct js_Regexp
362
+ {
363
+ void *prog;
364
+ char *source;
365
+ unsigned short flags;
366
+ unsigned short last;
367
+ };
368
+
369
+ struct js_Object
370
+ {
371
+ enum js_Class type;
372
+ int extensible;
373
+ js_Property *properties;
374
+ int count; /* number of properties, for array sparseness check */
375
+ js_Object *prototype;
376
+ union {
377
+ int boolean;
378
+ double number;
379
+ struct {
380
+ int length;
381
+ char *string;
382
+ char shrstr[16];
383
+ } s;
384
+ struct {
385
+ int length; /* actual length */
386
+ int simple; /* true if array has only non-sparse array properties */
387
+ int flat_length; /* used length of simple array part */
388
+ int flat_capacity; /* allocated length of simple array part */
389
+ js_Value *array;
390
+ } a;
391
+ struct {
392
+ js_Function *function;
393
+ js_Environment *scope;
394
+ } f;
395
+ struct {
396
+ const char *name;
397
+ js_CFunction function;
398
+ js_CFunction constructor;
399
+ int length;
400
+ void *data;
401
+ js_Finalize finalize;
402
+ } c;
403
+ js_Regexp r;
404
+ struct {
405
+ js_Object *target;
406
+ int i, n; /* for array part */
407
+ js_Iterator *head, *current; /* for object part */
408
+ } iter;
409
+ struct {
410
+ const char *tag;
411
+ void *data;
412
+ js_HasProperty has;
413
+ js_Put put;
414
+ js_Delete delete;
415
+ js_Finalize finalize;
416
+ } user;
417
+ } u;
418
+ js_Object *gcnext; /* allocation list */
419
+ js_Object *gcroot; /* scan list */
420
+ int gcmark;
421
+ };
422
+
423
+ struct js_Property
424
+ {
425
+ js_Property *left, *right;
426
+ int level;
427
+ int atts;
428
+ js_Value value;
429
+ js_Object *getter;
430
+ js_Object *setter;
431
+ char name[1];
432
+ };
433
+
434
+ struct js_Iterator
435
+ {
436
+ js_Iterator *next;
437
+ char name[1];
438
+ };
439
+
440
+ struct js_Environment
441
+ {
442
+ js_Environment *outer;
443
+ js_Object *variables;
444
+
445
+ js_Environment *gcnext;
446
+ int gcmark;
447
+ };
448
+
449
+ /* jsrun.c */
450
+ js_Environment *jsR_newenvironment(js_State *J, js_Object *variables, js_Environment *outer);
451
+ js_String *jsV_newmemstring(js_State *J, const char *s, int n);
452
+ js_Value *js_tovalue(js_State *J, int idx);
453
+ void js_toprimitive(js_State *J, int idx, int hint);
454
+ js_Object *js_toobject(js_State *J, int idx);
455
+ void js_pushvalue(js_State *J, js_Value v);
456
+ void js_pushobject(js_State *J, js_Object *v);
457
+ void jsR_unflattenarray(js_State *J, js_Object *obj);
458
+
459
+ /* jsvalue.c */
460
+ int jsV_toboolean(js_State *J, js_Value *v);
461
+ double jsV_tonumber(js_State *J, js_Value *v);
462
+ double jsV_tointeger(js_State *J, js_Value *v);
463
+ const char *jsV_tostring(js_State *J, js_Value *v);
464
+ js_Object *jsV_toobject(js_State *J, js_Value *v);
465
+ void jsV_toprimitive(js_State *J, js_Value *v, int preferred);
466
+
467
+ const char *js_itoa(char *buf, int a);
468
+ double js_stringtofloat(const char *s, char **ep);
469
+ int jsV_numbertointeger(double n);
470
+ int jsV_numbertoint32(double n);
471
+ unsigned int jsV_numbertouint32(double n);
472
+ short jsV_numbertoint16(double n);
473
+ unsigned short jsV_numbertouint16(double n);
474
+ const char *jsV_numbertostring(js_State *J, char buf[32], double number);
475
+ double jsV_stringtonumber(js_State *J, const char *string);
476
+
477
+ /* jsproperty.c */
478
+ js_Object *jsV_newobject(js_State *J, enum js_Class type, js_Object *prototype);
479
+ js_Property *jsV_getownproperty(js_State *J, js_Object *obj, const char *name);
480
+ js_Property *jsV_getpropertyx(js_State *J, js_Object *obj, const char *name, int *own);
481
+ js_Property *jsV_getproperty(js_State *J, js_Object *obj, const char *name);
482
+ js_Property *jsV_setproperty(js_State *J, js_Object *obj, const char *name);
483
+ js_Property *jsV_nextproperty(js_State *J, js_Object *obj, const char *name);
484
+ void jsV_delproperty(js_State *J, js_Object *obj, const char *name);
485
+
486
+ js_Object *jsV_newiterator(js_State *J, js_Object *obj, int own);
487
+ const char *jsV_nextiterator(js_State *J, js_Object *iter);
488
+
489
+ void jsV_resizearray(js_State *J, js_Object *obj, int newlen);
490
+
491
+ void jsV_unflattenarray(js_State *J, js_Object *obj);
492
+ void jsV_growarray(js_State *J, js_Object *obj);
493
+
494
+ /* Lexer */
495
+
496
+ enum
497
+ {
498
+ TK_IDENTIFIER = 256,
499
+ TK_NUMBER,
500
+ TK_STRING,
501
+ TK_REGEXP,
502
+
503
+ /* multi-character punctuators */
504
+ TK_LE,
505
+ TK_GE,
506
+ TK_EQ,
507
+ TK_NE,
508
+ TK_STRICTEQ,
509
+ TK_STRICTNE,
510
+ TK_SHL,
511
+ TK_SHR,
512
+ TK_USHR,
513
+ TK_AND,
514
+ TK_OR,
515
+ TK_ADD_ASS,
516
+ TK_SUB_ASS,
517
+ TK_MUL_ASS,
518
+ TK_DIV_ASS,
519
+ TK_MOD_ASS,
520
+ TK_SHL_ASS,
521
+ TK_SHR_ASS,
522
+ TK_USHR_ASS,
523
+ TK_AND_ASS,
524
+ TK_OR_ASS,
525
+ TK_XOR_ASS,
526
+ TK_INC,
527
+ TK_DEC,
528
+
529
+ /* keywords */
530
+ TK_BREAK,
531
+ TK_CASE,
532
+ TK_CATCH,
533
+ TK_CONTINUE,
534
+ TK_DEBUGGER,
535
+ TK_DEFAULT,
536
+ TK_DELETE,
537
+ TK_DO,
538
+ TK_ELSE,
539
+ TK_FALSE,
540
+ TK_FINALLY,
541
+ TK_FOR,
542
+ TK_FUNCTION,
543
+ TK_IF,
544
+ TK_IN,
545
+ TK_INSTANCEOF,
546
+ TK_NEW,
547
+ TK_NULL,
548
+ TK_RETURN,
549
+ TK_SWITCH,
550
+ TK_THIS,
551
+ TK_THROW,
552
+ TK_TRUE,
553
+ TK_TRY,
554
+ TK_TYPEOF,
555
+ TK_VAR,
556
+ TK_VOID,
557
+ TK_WHILE,
558
+ TK_WITH,
559
+ };
560
+
561
+ int jsY_iswhite(int c);
562
+ int jsY_isnewline(int c);
563
+ int jsY_ishex(int c);
564
+ int jsY_tohex(int c);
565
+
566
+ const char *jsY_tokenstring(int token);
567
+ int jsY_findword(const char *s, const char **list, int num);
568
+
569
+ void jsY_initlex(js_State *J, const char *filename, const char *source);
570
+ int jsY_lex(js_State *J);
571
+ int jsY_lexjson(js_State *J);
572
+
573
+ /* Parser */
574
+
575
+ enum js_AstType
576
+ {
577
+ AST_LIST,
578
+ AST_FUNDEC,
579
+ AST_IDENTIFIER,
580
+
581
+ EXP_IDENTIFIER,
582
+ EXP_NUMBER,
583
+ EXP_STRING,
584
+ EXP_REGEXP,
585
+
586
+ /* literals */
587
+ EXP_ELISION, /* for array elisions */
588
+ EXP_NULL,
589
+ EXP_TRUE,
590
+ EXP_FALSE,
591
+ EXP_THIS,
592
+
593
+ EXP_ARRAY,
594
+ EXP_OBJECT,
595
+ EXP_PROP_VAL,
596
+ EXP_PROP_GET,
597
+ EXP_PROP_SET,
598
+
599
+ EXP_FUN,
600
+
601
+ /* expressions */
602
+ EXP_INDEX,
603
+ EXP_MEMBER,
604
+ EXP_CALL,
605
+ EXP_NEW,
606
+
607
+ EXP_POSTINC,
608
+ EXP_POSTDEC,
609
+
610
+ EXP_DELETE,
611
+ EXP_VOID,
612
+ EXP_TYPEOF,
613
+ EXP_PREINC,
614
+ EXP_PREDEC,
615
+ EXP_POS,
616
+ EXP_NEG,
617
+ EXP_BITNOT,
618
+ EXP_LOGNOT,
619
+
620
+ EXP_MOD,
621
+ EXP_DIV,
622
+ EXP_MUL,
623
+ EXP_SUB,
624
+ EXP_ADD,
625
+ EXP_USHR,
626
+ EXP_SHR,
627
+ EXP_SHL,
628
+ EXP_IN,
629
+ EXP_INSTANCEOF,
630
+ EXP_GE,
631
+ EXP_LE,
632
+ EXP_GT,
633
+ EXP_LT,
634
+ EXP_STRICTNE,
635
+ EXP_STRICTEQ,
636
+ EXP_NE,
637
+ EXP_EQ,
638
+ EXP_BITAND,
639
+ EXP_BITXOR,
640
+ EXP_BITOR,
641
+ EXP_LOGAND,
642
+ EXP_LOGOR,
643
+
644
+ EXP_COND,
645
+
646
+ EXP_ASS,
647
+ EXP_ASS_MUL,
648
+ EXP_ASS_DIV,
649
+ EXP_ASS_MOD,
650
+ EXP_ASS_ADD,
651
+ EXP_ASS_SUB,
652
+ EXP_ASS_SHL,
653
+ EXP_ASS_SHR,
654
+ EXP_ASS_USHR,
655
+ EXP_ASS_BITAND,
656
+ EXP_ASS_BITXOR,
657
+ EXP_ASS_BITOR,
658
+
659
+ EXP_COMMA,
660
+
661
+ EXP_VAR, /* var initializer */
662
+
663
+ /* statements */
664
+ STM_BLOCK,
665
+ STM_EMPTY,
666
+ STM_VAR,
667
+ STM_IF,
668
+ STM_DO,
669
+ STM_WHILE,
670
+ STM_FOR,
671
+ STM_FOR_VAR,
672
+ STM_FOR_IN,
673
+ STM_FOR_IN_VAR,
674
+ STM_CONTINUE,
675
+ STM_BREAK,
676
+ STM_RETURN,
677
+ STM_WITH,
678
+ STM_SWITCH,
679
+ STM_THROW,
680
+ STM_TRY,
681
+ STM_DEBUGGER,
682
+
683
+ STM_LABEL,
684
+ STM_CASE,
685
+ STM_DEFAULT,
686
+ };
687
+
688
+ typedef struct js_JumpList js_JumpList;
689
+
690
+ struct js_JumpList
691
+ {
692
+ enum js_AstType type;
693
+ int inst;
694
+ js_JumpList *next;
695
+ };
696
+
697
+ struct js_Ast
698
+ {
699
+ enum js_AstType type;
700
+ int line;
701
+ js_Ast *parent, *a, *b, *c, *d;
702
+ double number;
703
+ const char *string;
704
+ js_JumpList *jumps; /* list of break/continue jumps to patch */
705
+ int casejump; /* for switch case clauses */
706
+ js_Ast *gcnext; /* next in alloc list */
707
+ };
708
+
709
+ js_Ast *jsP_parsefunction(js_State *J, const char *filename, const char *params, const char *body);
710
+ js_Ast *jsP_parse(js_State *J, const char *filename, const char *source);
711
+ void jsP_freeparse(js_State *J);
712
+
713
+ /* Compiler */
714
+
715
+ enum js_OpCode
716
+ {
717
+ OP_POP, /* A -- */
718
+ OP_DUP, /* A -- A A */
719
+ OP_DUP2, /* A B -- A B A B */
720
+ OP_ROT2, /* A B -- B A */
721
+ OP_ROT3, /* A B C -- C A B */
722
+ OP_ROT4, /* A B C D -- D A B C */
723
+
724
+ OP_INTEGER, /* -K- (number-32768) */
725
+ OP_NUMBER, /* -N- <number> */
726
+ OP_STRING, /* -S- <string> */
727
+ OP_CLOSURE, /* -F- <closure> */
728
+
729
+ OP_NEWARRAY,
730
+ OP_NEWOBJECT,
731
+ OP_NEWREGEXP, /* -S,opts- <regexp> */
732
+
733
+ OP_UNDEF,
734
+ OP_NULL,
735
+ OP_TRUE,
736
+ OP_FALSE,
737
+
738
+ OP_THIS,
739
+ OP_CURRENT, /* currently executing function object */
740
+
741
+ OP_GETLOCAL, /* -K- <value> */
742
+ OP_SETLOCAL, /* <value> -K- <value> */
743
+ OP_DELLOCAL, /* -K- false */
744
+
745
+ OP_HASVAR, /* -S- ( <value> | undefined ) */
746
+ OP_GETVAR, /* -S- <value> */
747
+ OP_SETVAR, /* <value> -S- <value> */
748
+ OP_DELVAR, /* -S- <success> */
749
+
750
+ OP_IN, /* <name> <obj> -- <exists?> */
751
+
752
+ OP_SKIPARRAY, /* <obj> -- <obj> */
753
+ OP_INITARRAY, /* <obj> <val> -- <obj> */
754
+ OP_INITPROP, /* <obj> <key> <val> -- <obj> */
755
+ OP_INITGETTER, /* <obj> <key> <closure> -- <obj> */
756
+ OP_INITSETTER, /* <obj> <key> <closure> -- <obj> */
757
+
758
+ OP_GETPROP, /* <obj> <name> -- <value> */
759
+ OP_GETPROP_S, /* <obj> -S- <value> */
760
+ OP_SETPROP, /* <obj> <name> <value> -- <value> */
761
+ OP_SETPROP_S, /* <obj> <value> -S- <value> */
762
+ OP_DELPROP, /* <obj> <name> -- <success> */
763
+ OP_DELPROP_S, /* <obj> -S- <success> */
764
+
765
+ OP_ITERATOR, /* <obj> -- <iobj> */
766
+ OP_NEXTITER, /* <iobj> -- ( <iobj> <name> true | false ) */
767
+
768
+ OP_EVAL, /* <args...> -(numargs)- <returnvalue> */
769
+ OP_CALL, /* <closure> <this> <args...> -(numargs)- <returnvalue> */
770
+ OP_NEW, /* <closure> <args...> -(numargs)- <returnvalue> */
771
+
772
+ OP_TYPEOF,
773
+ OP_POS,
774
+ OP_NEG,
775
+ OP_BITNOT,
776
+ OP_LOGNOT,
777
+ OP_INC, /* <x> -- ToNumber(x)+1 */
778
+ OP_DEC, /* <x> -- ToNumber(x)-1 */
779
+ OP_POSTINC, /* <x> -- ToNumber(x)+1 ToNumber(x) */
780
+ OP_POSTDEC, /* <x> -- ToNumber(x)-1 ToNumber(x) */
781
+
782
+ OP_MUL,
783
+ OP_DIV,
784
+ OP_MOD,
785
+ OP_ADD,
786
+ OP_SUB,
787
+ OP_SHL,
788
+ OP_SHR,
789
+ OP_USHR,
790
+ OP_LT,
791
+ OP_GT,
792
+ OP_LE,
793
+ OP_GE,
794
+ OP_EQ,
795
+ OP_NE,
796
+ OP_STRICTEQ,
797
+ OP_STRICTNE,
798
+ OP_JCASE,
799
+ OP_BITAND,
800
+ OP_BITXOR,
801
+ OP_BITOR,
802
+
803
+ OP_INSTANCEOF,
804
+
805
+ OP_THROW,
806
+
807
+ OP_TRY, /* -ADDR- /jump/ or -ADDR- <exception> */
808
+ OP_ENDTRY,
809
+
810
+ OP_CATCH, /* push scope chain with exception variable */
811
+ OP_ENDCATCH,
812
+
813
+ OP_WITH,
814
+ OP_ENDWITH,
815
+
816
+ OP_DEBUGGER,
817
+ OP_JUMP,
818
+ OP_JTRUE,
819
+ OP_JFALSE,
820
+ OP_RETURN,
821
+ };
822
+
823
+ struct js_Function
824
+ {
825
+ const char *name;
826
+ int script;
827
+ int lightweight;
828
+ int strict;
829
+ int arguments;
830
+ int numparams;
831
+
832
+ js_Instruction *code;
833
+ int codecap, codelen;
834
+
835
+ js_Function **funtab;
836
+ int funcap, funlen;
837
+
838
+ const char **vartab;
839
+ int varcap, varlen;
840
+
841
+ const char *filename;
842
+ int line, lastline;
843
+
844
+ js_Function *gcnext;
845
+ int gcmark;
846
+ };
847
+
848
+ js_Function *jsC_compilefunction(js_State *J, js_Ast *prog);
849
+ js_Function *jsC_compilescript(js_State *J, js_Ast *prog, int default_strict);
850
+
851
+ /* Builtins */
852
+
853
+ void jsB_init(js_State *J);
854
+ void jsB_initobject(js_State *J);
855
+ void jsB_initarray(js_State *J);
856
+ void jsB_initfunction(js_State *J);
857
+ void jsB_initboolean(js_State *J);
858
+ void jsB_initnumber(js_State *J);
859
+ void jsB_initstring(js_State *J);
860
+ void jsB_initregexp(js_State *J);
861
+ void jsB_initerror(js_State *J);
862
+ void jsB_initmath(js_State *J);
863
+ void jsB_initjson(js_State *J);
864
+ void jsB_initdate(js_State *J);
865
+
866
+ void jsB_propf(js_State *J, const char *name, js_CFunction cfun, int n);
867
+ void jsB_propn(js_State *J, const char *name, double number);
868
+ void jsB_props(js_State *J, const char *name, const char *string);
869
+
870
+ #endif