forked from bellard/mquickjs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmquickjs_priv.h
More file actions
268 lines (237 loc) · 12.2 KB
/
mquickjs_priv.h
File metadata and controls
268 lines (237 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/* microj private definitions */
#ifndef MICROJS_PRIV_H
#define MICROJS_PRIV_H
#include "mquickjs.h"
#include "libm.h"
#define JS_DUMP /* 2.6 kB */
//#define DUMP_EXEC
//#define DUMP_FUNC_BYTECODE /* dump the bytecode of each compiled function */
//#define DUMP_REOP /* dump regexp bytecode */
//#define DUMP_GC
//#define DUMP_TOKEN /* dump parsed tokens */
/* run GC before at each malloc() and modify the allocated data pointers */
//#define DEBUG_GC
#if defined(DUMP_FUNC_BYTECODE) || defined(DUMP_EXEC)
#define DUMP_BYTECODE /* include the dump_byte_code() function */
#endif
#define JS_VALUE_TO_PTR(v) (void *)((uintptr_t)(v) - 1)
#define JS_VALUE_FROM_PTR(ptr) (JSWord)((uintptr_t)(ptr) + 1)
#define JS_IS_ROM_PTR(ctx, ptr) ((uintptr_t)(ptr) < (uintptr_t)ctx || (uintptr_t)(ptr) >= (uintptr_t)ctx->stack_top)
enum {
JS_MTAG_FREE,
/* javascript values */
JS_MTAG_OBJECT,
JS_MTAG_FLOAT64,
JS_MTAG_STRING,
/* other special memory blocks */
JS_MTAG_FUNCTION_BYTECODE,
JS_MTAG_VALUE_ARRAY,
JS_MTAG_BYTE_ARRAY,
JS_MTAG_VARREF,
JS_MTAG_COUNT,
};
/* JS_MTAG_BITS bits are reserved at the start of every memory block */
#define JS_MTAG_BITS 4
#define JS_MB_HEADER \
JSWord gc_mark: 1; \
JSWord mtag: (JS_MTAG_BITS - 1)
typedef enum {
JS_PROP_NORMAL,
JS_PROP_GETSET, /* value is a two element JSValueArray */
JS_PROP_VARREF, /* value is a JSVarRef (used for global variables) */
JS_PROP_SPECIAL, /* for the prototype and constructor properties in ROM */
} JSPropTypeEnum;
#define JS_MB_HEADER_DEF(tag) ((tag) << 1)
#define JS_VALUE_ARRAY_HEADER(size) (JS_MB_HEADER_DEF(JS_MTAG_VALUE_ARRAY) | ((size) << JS_MTAG_BITS))
#define JS_ROM_VALUE(offset) JS_VALUE_FROM_PTR(&js_stdlib_table[offset])
/* runtime helpers */
JSValue js_function_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_function_get_prototype(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_function_set_prototype(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_function_get_length_name(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int is_name);
JSValue js_function_toString(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_function_call(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_function_apply(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_function_bind(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_function_bound(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, JSValue params);
JSValue js_array_get_length(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_set_length(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_number_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_number_toString(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_number_toFixed(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_number_toExponential(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_number_toPrecision(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_number_parseInt(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_number_parseFloat(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_boolean_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_get_length(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_set_length(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_slice(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_substring(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
enum {
magic_internalAt,
magic_charAt,
magic_charCodeAt,
magic_codePointAt,
};
JSValue js_string_charAt(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int magic);
JSValue js_string_concat(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_indexOf(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int lastIndexOf);
JSValue js_string_match(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_replace(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int is_replaceAll);
JSValue js_string_search(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_split(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_toLowerCase(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int to_lower);
JSValue js_string_trim(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int magic);
JSValue js_string_toString(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_repeat(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_object_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_object_defineProperty(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_object_getPrototypeOf(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_object_setPrototypeOf(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_object_create(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_object_keys(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_object_hasOwnProperty(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_object_toString(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_string_fromCharCode(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int is_fromCodePoint);
JSValue js_error_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int magic);
JSValue js_error_toString(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_error_get_message(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int magic);
JSValue js_array_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_push(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int is_unshift);
JSValue js_array_pop(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_shift(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_join(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_toString(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_isArray(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_reverse(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_concat(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_indexOf(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int is_lastIndexOf);
JSValue js_array_slice(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_splice(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_sort(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
#define js_special_every 0
#define js_special_some 1
#define js_special_forEach 2
#define js_special_map 3
#define js_special_filter 4
JSValue js_array_every(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int special);
#define js_special_reduce 0
#define js_special_reduceRight 1
JSValue js_array_reduce(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int special);
JSValue js_math_min_max(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int magic);
double js_math_sign(double a);
double js_math_fround(double a);
JSValue js_math_imul(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_math_clz32(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_math_atan2(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_math_pow(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_math_random(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_buffer_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_array_buffer_get_byteLength(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_typed_array_base_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_typed_array_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int magic);
JSValue js_typed_array_get_length(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int magic);
JSValue js_typed_array_subarray(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_typed_array_set(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_date_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_global_eval(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_global_isNaN(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_global_isFinite(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_json_parse(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_json_stringify(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_regexp_constructor(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_regexp_get_lastIndex(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_regexp_set_lastIndex(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_regexp_get_source(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_regexp_get_flags(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv);
JSValue js_regexp_exec(JSContext *ctx, JSValue *this_val,
int argc, JSValue *argv, int is_test);
#endif /* MICROJS_PRIV_H */