15 /* Microsoft Visual C */
17 #pragma warning(disable:4996) /* _CRT_SECURE_NO_WARNINGS */
18 #pragma warning(disable:4244) /* implicit conversion from double to int */
19 #pragma warning(disable:4267) /* implicit conversion of int to smaller int */
20 #define inline __inline
21 #define snprintf _snprintf
22 #define vsnprintf _vsnprintf
24 #define round(x) floor((x) < 0 ? (x) - 0.5 : (x) + 0.5)
25 #define isnan(x) _isnan(x)
26 #define isinf(x) (!_finite(x))
27 #define isfinite(x) _finite(x)
28 static __inline int signbit(double x) {union{double d;__int64 i;}u;u.d=x;return u.i>>63;}
29 #define INFINITY (DBL_MAX+DBL_MAX)
30 #define NAN (INFINITY-INFINITY)
34 #define nelem(a) (sizeof (a) / sizeof (a)[0])
36 void *js_malloc(js_State *J, unsigned int size);
37 void *js_realloc(js_State *J, void *ptr, unsigned int size);
38 void js_free(js_State *J, void *ptr);
40 typedef struct js_Regexp js_Regexp;
41 typedef struct js_Value js_Value;
42 typedef struct js_Object js_Object;
43 typedef struct js_String js_String;
44 typedef struct js_Ast js_Ast;
45 typedef struct js_Function js_Function;
46 typedef struct js_Environment js_Environment;
47 typedef struct js_StringNode js_StringNode;
48 typedef struct js_Jumpbuf js_Jumpbuf;
49 typedef struct js_StackTrace js_StackTrace;
53 #define JS_STACKSIZE 256 /* value stack size */
54 #define JS_ENVLIMIT 64 /* environment stack size */
55 #define JS_TRYLIMIT 64 /* exception stack size */
56 #define JS_GCLIMIT 10000 /* run gc cycle every N allocations */
58 /* instruction size -- change to unsigned int if you get integer overflow syntax errors */
59 typedef unsigned short js_Instruction;
61 /* String interning */
63 const char *js_intern(js_State *J, const char *s);
64 void jsS_dumpstrings(js_State *J);
65 void jsS_freestrings(js_State *J);
67 /* Portable strtod and printf float formatting */
69 void js_fmtexp(char *p, int e);
70 void js_dtoa(double f, char *digits, int *exp, int *neg, int *ndigits);
71 double js_strtod(const char *as, char **aas);
73 /* Private stack functions */
75 void js_newfunction(js_State *J, js_Function *function, js_Environment *scope);
76 void js_newscript(js_State *J, js_Function *function, js_Environment *scope);
77 void js_loadeval(js_State *J, const char *filename, const char *source);
79 js_Regexp *js_toregexp(js_State *J, int idx);
80 int js_isarrayindex(js_State *J, const char *str, unsigned int *idx);
81 int js_runeat(js_State *J, const char *s, int i);
82 int js_utfptrtoidx(const char *s, const char *p);
83 const char *js_utfidxtoptr(const char *s, int i);
85 void js_dup(js_State *J);
86 void js_dup2(js_State *J);
87 void js_rot2(js_State *J);
88 void js_rot3(js_State *J);
89 void js_rot4(js_State *J);
90 void js_rot2pop1(js_State *J);
91 void js_rot3pop2(js_State *J);
92 void js_dup1rot3(js_State *J);
93 void js_dup1rot4(js_State *J);
95 void js_pushundefinedthis(js_State *J); /* push 'global' if non-strict, undefined if strict */
97 void js_RegExp_prototype_exec(js_State *J, js_Regexp *re, const char *text);
99 void js_trap(js_State *J, int pc); /* dump stack and environment to stdout */
108 /* Exception handling */
120 void js_savetry(js_State *J, js_Instruction *pc);
122 #define js_trypc(J, PC) \
123 (js_savetry(J, PC), setjmp(J->trybuf[J->trytop++].buf))
126 (js_savetry(J, NULL), setjmp(J->trybuf[J->trytop++].buf))
128 #define js_endtry(J) \
140 js_StringNode *strings;
144 /* parser input source */
145 const char *filename;
150 struct { char *text; unsigned int len, cap; } lexbuf;
161 js_Ast *gcast; /* list of allocated nodes to free after parsing */
163 /* runtime environment */
164 js_Object *Object_prototype;
165 js_Object *Array_prototype;
166 js_Object *Function_prototype;
167 js_Object *Boolean_prototype;
168 js_Object *Number_prototype;
169 js_Object *String_prototype;
170 js_Object *RegExp_prototype;
171 js_Object *Date_prototype;
173 js_Object *Error_prototype;
174 js_Object *EvalError_prototype;
175 js_Object *RangeError_prototype;
176 js_Object *ReferenceError_prototype;
177 js_Object *SyntaxError_prototype;
178 js_Object *TypeError_prototype;
179 js_Object *URIError_prototype;
181 int nextref; /* for js_ref use */
182 js_Object *R; /* registry of hidden values */
183 js_Object *G; /* the global object */
184 js_Environment *E; /* current environment scope */
185 js_Environment *GE; /* global environment scope (at the root) */
187 /* execution stack */
191 /* garbage collector list */
194 js_Environment *gcenv;
200 /* environments on the call stack but currently not in scope */
202 js_Environment *envstack[JS_ENVLIMIT];
204 /* debug info stack trace */
206 js_StackTrace trace[JS_ENVLIMIT];
208 /* exception stack */
210 js_Jumpbuf trybuf[JS_TRYLIMIT];