/src/moddable/xs/sources/xsCode.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2016-2025 Moddable Tech, Inc. |
3 | | * |
4 | | * This file is part of the Moddable SDK Runtime. |
5 | | * |
6 | | * The Moddable SDK Runtime is free software: you can redistribute it and/or modify |
7 | | * it under the terms of the GNU Lesser General Public License as published by |
8 | | * the Free Software Foundation, either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * The Moddable SDK Runtime is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public License |
17 | | * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>. |
18 | | * |
19 | | * This file incorporates work covered by the following copyright and |
20 | | * permission notice: |
21 | | * |
22 | | * Copyright (C) 2010-2016 Marvell International Ltd. |
23 | | * Copyright (C) 2002-2010 Kinoma, Inc. |
24 | | * |
25 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
26 | | * you may not use this file except in compliance with the License. |
27 | | * You may obtain a copy of the License at |
28 | | * |
29 | | * http://www.apache.org/licenses/LICENSE-2.0 |
30 | | * |
31 | | * Unless required by applicable law or agreed to in writing, software |
32 | | * distributed under the License is distributed on an "AS IS" BASIS, |
33 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
34 | | * See the License for the specific language governing permissions and |
35 | | * limitations under the License. |
36 | | */ |
37 | | |
38 | | #include "xsScript.h" |
39 | | |
40 | | //#define mxCodePrint 1 |
41 | | |
42 | | #define mxByteCodePart\ |
43 | | txByteCode* nextCode;\ |
44 | | txInteger id;\ |
45 | | txInteger stackLevel |
46 | | |
47 | | struct sxByteCode { |
48 | | mxByteCodePart; |
49 | | }; |
50 | | |
51 | | struct sxBigIntCode { |
52 | | mxByteCodePart; |
53 | | txBigInt bigint; |
54 | | }; |
55 | | |
56 | | struct sxBranchCode { |
57 | | mxByteCodePart; |
58 | | txTargetCode* target; |
59 | | }; |
60 | | |
61 | | struct sxIndexCode { |
62 | | mxByteCodePart; |
63 | | txInteger index; |
64 | | }; |
65 | | |
66 | | struct sxIntegerCode { |
67 | | mxByteCodePart; |
68 | | txInteger integer; |
69 | | }; |
70 | | |
71 | | struct sxNumberCode { |
72 | | mxByteCodePart; |
73 | | txNumber number; |
74 | | }; |
75 | | |
76 | | struct sxStringCode { |
77 | | mxByteCodePart; |
78 | | txInteger length; |
79 | | txString string; |
80 | | }; |
81 | | |
82 | | struct sxSymbolCode { |
83 | | mxByteCodePart; |
84 | | txSymbol* symbol; |
85 | | }; |
86 | | |
87 | | struct sxTargetCode { |
88 | | mxByteCodePart; |
89 | | txInteger index; |
90 | | txLabelNode* label; |
91 | | txTargetCode* nextTarget; |
92 | | txInteger environmentLevel; |
93 | | txInteger scopeLevel; |
94 | | txInteger offset; |
95 | | txTargetCode* original; |
96 | | txBoolean used; |
97 | | }; |
98 | | |
99 | | struct sxVariableCode { |
100 | | mxByteCodePart; |
101 | | txSymbol* symbol; |
102 | | txInteger index; |
103 | | }; |
104 | | |
105 | | struct sxCoder { |
106 | | txParser* parser; |
107 | | txByteCode* firstCode; |
108 | | txByteCode* lastCode; |
109 | | txTargetCode* firstBreakTarget; |
110 | | txTargetCode* firstContinueTarget; |
111 | | txTargetCode* returnTarget; |
112 | | txInteger environmentLevel; |
113 | | txInteger scopeLevel; |
114 | | txInteger stackLevel; |
115 | | txInteger targetIndex; |
116 | | txSymbol* path; |
117 | | txInteger line; |
118 | | txBoolean programFlag; |
119 | | txBoolean evalFlag; |
120 | | txBoolean importFlag; |
121 | | txBoolean importMetaFlag; |
122 | | txClassNode* classNode; |
123 | | txTargetCode* chainTarget; |
124 | | }; |
125 | | |
126 | | typedef struct { |
127 | | txInteger exception; |
128 | | txInteger selector; |
129 | | txTargetCode* catchTarget; |
130 | | } txUsingContext; |
131 | | |
132 | | typedef void (*txCompound)(void* it, void* param, txByte step); |
133 | | |
134 | | static void fxCoderAdd(txCoder* self, txInteger delta, void* it); |
135 | | static void fxCoderAddBigInt(txCoder* self, txInteger delta, txInteger id, txBigInt* bigint); |
136 | | static void fxCoderAddBranch(txCoder* self, txInteger delta, txInteger id, txTargetCode* target); |
137 | | static void fxCoderAddByte(txCoder* self, txInteger delta, txInteger id); |
138 | | static void fxCoderAddIndex(txCoder* self, txInteger delta, txInteger id, txInteger index); |
139 | | static void fxCoderAddInteger(txCoder* self, txInteger delta, txInteger id, txInteger integer); |
140 | | static void fxCoderAddLine(txCoder* self, txInteger delta, txInteger id, txNode* node); |
141 | | static void fxCoderAddNumber(txCoder* self, txInteger delta, txInteger id, txNumber number); |
142 | | static void fxCoderAddString(txCoder* self, txInteger delta, txInteger id, txInteger length, txString string); |
143 | | static void fxCoderAddSymbol(txCoder* self, txInteger delta, txInteger id, txSymbol* symbol); |
144 | | static void fxCoderAddVariable(txCoder* self, txInteger delta, txInteger id, txSymbol* symbol, txInteger index); |
145 | | static void fxCoderAdjustEnvironment(txCoder* self, txTargetCode* target); |
146 | | static void fxCoderAdjustScope(txCoder* self, txTargetCode* target); |
147 | | static txTargetCode* fxCoderAliasTargets(txCoder* self, txTargetCode* target); |
148 | | static txInteger fxCoderCountParameters(txCoder* self, txNode* it); |
149 | | static txTargetCode* fxCoderCreateTarget(txCoder* self); |
150 | | static txTargetCode* fxCoderFinalizeTargets(txCoder* self, txTargetCode* alias, txInteger selector, txInteger* address, txTargetCode* finallyTarget); |
151 | | static void fxCoderJumpTargets(txCoder* self, txTargetCode* target, txInteger selector, txInteger* address); |
152 | | static void fxCoderOptimize(txCoder* self); |
153 | | static txInteger fxCoderUseTemporaryVariable(txCoder* self); |
154 | | static void fxCoderUnuseTemporaryVariables(txCoder* self, txInteger count); |
155 | | |
156 | | static void fxScopeCoded(txScope* self, txCoder* coder); |
157 | | static void fxScopeCodedBody(txScope* self, txCoder* coder); |
158 | | static void fxScopeCodingBlock(txScope* self, txCoder* coder); |
159 | | static void fxScopeCodingBody(txScope* self, txCoder* coder); |
160 | | static void fxScopeCodingParams(txScope* self, txCoder* coder); |
161 | | static void fxScopeCodingProgram(txScope* self, txCoder* coder); |
162 | | static void fxScopeCodeDefineNodes(txScope* self, txCoder* coder); |
163 | | static void fxScopeCodeRefresh(txScope* self, txCoder* coder); |
164 | | static void fxScopeCodeReset(txScope* self, txCoder* coder); |
165 | | static void fxScopeCodeRetrieve(txScope* self, txCoder* coder); |
166 | | static void fxScopeCodeStore(txScope* self, txCoder* coder); |
167 | | static void fxScopeCodeStoreAll(txScope* self, txCoder* coder); |
168 | | static void fxScopeCodeUsed(txScope* self, txCoder* coder, txUsingContext* context); |
169 | | static void fxScopeCodeUsedReverse(txScope* self, txCoder* coder, txDeclareNode* node, txInteger exception, txInteger selector); |
170 | | static void fxScopeCodeUsing(txScope* self, txCoder* coder, txUsingContext* context); |
171 | | static void fxScopeCodeUsingStatement(txScope* self, txCoder* coder, txNode* statement); |
172 | | |
173 | | static void fxNodeDispatchCode(void* it, void* param); |
174 | | static void fxNodeDispatchCodeAssign(void* it, void* param, txFlag flag); |
175 | | static void fxNodeDispatchCodeDelete(void* it, void* param); |
176 | | static void fxNodeDispatchCodeReference(void* it, void* param, txFlag flag); |
177 | | static txFlag fxNodeDispatchCodeThis(void* it, void* param, txFlag flag); |
178 | | |
179 | | static txFlag fxNodeCodeName(txNode* value); |
180 | | static void fxCompoundExpressionNodeCodeName(void* it, void* param); |
181 | | static void fxSpreadNodeCode(void* it, void* param, txInteger counter); |
182 | | |
183 | | txScript* fxParserCode(txParser* parser) |
184 | 939k | { |
185 | 939k | txCoder coder; |
186 | 939k | txByteCode* code; |
187 | 939k | txScript* script; |
188 | 939k | txSize size, delta, offset; |
189 | 939k | txSymbol* symbol; |
190 | 939k | txSymbol** address; |
191 | 939k | txSize c, i; |
192 | 939k | txID id, count; |
193 | 939k | txSize total; |
194 | 939k | txByte* p; |
195 | 939k | txHostNode* node; |
196 | 939k | #ifdef mxMetering |
197 | 939k | txUnsigned meterIndex = 0; |
198 | 939k | #endif |
199 | | |
200 | 939k | c_memset(&coder, 0, sizeof(txCoder)); |
201 | 939k | coder.parser = parser; |
202 | 939k | if (parser->errorCount == 0) { |
203 | 306k | mxTryParser(parser) { |
204 | 306k | txNode* self = parser->root; |
205 | 306k | (*self->description->dispatch->code)(parser->root, &coder); |
206 | 306k | } |
207 | 306k | mxCatchParser(parser) { |
208 | 12.3k | } |
209 | 306k | } |
210 | 939k | if (parser->errorCount) { |
211 | 645k | if (parser->console) { |
212 | 645k | coder.firstCode = NULL; |
213 | 645k | coder.lastCode = NULL; |
214 | 645k | fxCoderAddByte(&coder, 1, XS_CODE_GLOBAL); |
215 | 645k | fxCoderAddSymbol(&coder, 0, XS_CODE_GET_VARIABLE, parser->errorSymbol); |
216 | 645k | fxCoderAddByte(&coder, 2, XS_CODE_NEW); |
217 | 645k | fxCoderAddString(&coder, 1, XS_CODE_STRING_1, mxStringLength(parser->errorMessage), parser->errorMessage); |
218 | 645k | fxCoderAddInteger(&coder, -3, XS_CODE_RUN_1, 1); |
219 | 645k | fxCoderAddByte(&coder, -1, XS_CODE_THROW); |
220 | 645k | } |
221 | 0 | else |
222 | 0 | return C_NULL; |
223 | 645k | } |
224 | | |
225 | 939k | fxCoderOptimize(&coder); |
226 | | |
227 | 939k | script = c_malloc(sizeof(txScript)); |
228 | 939k | if (!script) goto bail; |
229 | 939k | c_memset(script, 0, sizeof(txScript)); |
230 | | |
231 | 939k | code = coder.firstCode; |
232 | 939k | size = 0; |
233 | 939k | delta = 0; |
234 | 62.9M | while (code) { |
235 | 61.9M | txInteger value; |
236 | 61.9M | switch (code->id) { |
237 | 2.21M | case XS_NO_CODE: |
238 | 2.21M | ((txTargetCode*)code)->offset = size; |
239 | 2.21M | break; |
240 | 73.0k | case XS_CODE_BRANCH_1: |
241 | 112k | case XS_CODE_BRANCH_CHAIN_1: |
242 | 1.21M | case XS_CODE_BRANCH_COALESCE_1: |
243 | 1.24M | case XS_CODE_BRANCH_ELSE_1: |
244 | 1.45M | case XS_CODE_BRANCH_IF_1: |
245 | 1.45M | case XS_CODE_BRANCH_STATUS_1: |
246 | 1.53M | case XS_CODE_CATCH_1: |
247 | 1.67M | case XS_CODE_CODE_1: |
248 | 1.67M | size += 2; |
249 | 1.67M | delta += 3; |
250 | 1.67M | break; |
251 | | |
252 | 29.8k | case XS_CODE_ARGUMENT: |
253 | 30.3k | case XS_CODE_ARGUMENTS: |
254 | 31.2k | case XS_CODE_ARGUMENTS_SLOPPY: |
255 | 31.5k | case XS_CODE_ARGUMENTS_STRICT: |
256 | 460k | case XS_CODE_BEGIN_SLOPPY: |
257 | 465k | case XS_CODE_BEGIN_STRICT: |
258 | 468k | case XS_CODE_BEGIN_STRICT_BASE: |
259 | 468k | case XS_CODE_BEGIN_STRICT_DERIVED: |
260 | 471k | case XS_CODE_BEGIN_STRICT_FIELD: |
261 | 471k | case XS_CODE_MODULE: |
262 | 471k | size += 2; |
263 | 471k | break; |
264 | | |
265 | 1.23M | case XS_CODE_LINE: |
266 | 1.23M | size += 3; |
267 | 1.23M | break; |
268 | 1.73k | case XS_CODE_ASYNC_FUNCTION: |
269 | 1.92k | case XS_CODE_ASYNC_GENERATOR_FUNCTION: |
270 | 118k | case XS_CODE_CONSTRUCTOR_FUNCTION: |
271 | 124k | case XS_CODE_DELETE_PROPERTY: |
272 | 124k | case XS_CODE_DELETE_SUPER: |
273 | 560k | case XS_CODE_FILE: |
274 | 587k | case XS_CODE_FUNCTION: |
275 | 587k | case XS_CODE_GENERATOR_FUNCTION: |
276 | 2.00M | case XS_CODE_GET_PROPERTY: |
277 | 2.00M | case XS_CODE_GET_SUPER: |
278 | 2.04M | case XS_CODE_GET_THIS_VARIABLE: |
279 | 3.20M | case XS_CODE_GET_VARIABLE: |
280 | 3.20M | case XS_CODE_EVAL_PRIVATE: |
281 | 3.44M | case XS_CODE_EVAL_REFERENCE: |
282 | 3.44M | case XS_CODE_NAME: |
283 | 3.48M | case XS_CODE_NEW_CLOSURE: |
284 | 3.64M | case XS_CODE_NEW_LOCAL: |
285 | 3.82M | case XS_CODE_NEW_PROPERTY: |
286 | 4.23M | case XS_CODE_PROGRAM_REFERENCE: |
287 | 8.67M | case XS_CODE_SET_PROPERTY: |
288 | 8.67M | case XS_CODE_SET_SUPER: |
289 | 8.77M | case XS_CODE_SET_VARIABLE: |
290 | 8.77M | case XS_CODE_SYMBOL: |
291 | 8.92M | case XS_CODE_PROFILE: |
292 | 8.92M | size += 1 + sizeof(txID); |
293 | 8.92M | break; |
294 | | |
295 | 3.06M | case XS_CODE_STRING_1: |
296 | 3.06M | size += ((txStringCode*)code)->length; |
297 | | // continue |
298 | 3.24M | case XS_CODE_RESERVE_1: |
299 | 3.26M | case XS_CODE_RETRIEVE_1: |
300 | 4.50M | case XS_CODE_UNWIND_1: |
301 | 4.50M | value = ((txIndexCode*)code)->index; |
302 | 4.50M | if (value > 65535) { |
303 | 0 | code->id += 2; |
304 | 0 | size += 5; |
305 | 0 | } |
306 | 4.50M | else if (value > 255) { |
307 | 24.1k | code->id += 1; |
308 | 24.1k | size += 3; |
309 | 24.1k | } |
310 | 4.47M | else |
311 | 4.47M | size += 2; |
312 | 4.50M | break; |
313 | 31.3k | case XS_CODE_BIGINT_1: |
314 | 31.3k | value = fxBigIntMeasure(&((txBigIntCode*)code)->bigint); |
315 | 31.3k | if (value > 255) { |
316 | 1 | code->id += 1; |
317 | 1 | size += 3; |
318 | 1 | } |
319 | 31.3k | else |
320 | 31.3k | size += 2; |
321 | 31.3k | size += value; |
322 | 31.3k | break; |
323 | | |
324 | 19.9k | case XS_CODE_CONST_CLOSURE_1: |
325 | 115k | case XS_CODE_CONST_LOCAL_1: |
326 | 146k | case XS_CODE_GET_CLOSURE_1: |
327 | 6.44M | case XS_CODE_GET_LOCAL_1: |
328 | 6.44M | case XS_CODE_GET_PRIVATE_1: |
329 | 6.44M | case XS_CODE_HAS_PRIVATE_1: |
330 | 6.44M | case XS_CODE_LET_CLOSURE_1: |
331 | 6.45M | case XS_CODE_LET_LOCAL_1: |
332 | 6.46M | case XS_CODE_NEW_PRIVATE_1: |
333 | 6.46M | case XS_CODE_PULL_CLOSURE_1: |
334 | 6.76M | case XS_CODE_PULL_LOCAL_1: |
335 | 6.76M | case XS_CODE_REFRESH_CLOSURE_1: |
336 | 6.76M | case XS_CODE_REFRESH_LOCAL_1: |
337 | 6.76M | case XS_CODE_RESET_CLOSURE_1: |
338 | 6.76M | case XS_CODE_RESET_LOCAL_1: |
339 | 6.77M | case XS_CODE_SET_CLOSURE_1: |
340 | 9.17M | case XS_CODE_SET_LOCAL_1: |
341 | 9.17M | case XS_CODE_SET_PRIVATE_1: |
342 | 9.22M | case XS_CODE_STORE_1: |
343 | 9.22M | case XS_CODE_USED_1: |
344 | 9.23M | case XS_CODE_VAR_CLOSURE_1: |
345 | 9.30M | case XS_CODE_VAR_LOCAL_1: |
346 | 9.30M | value = ((txIndexCode*)code)->index + 1; |
347 | 9.30M | if (value > 65535) { |
348 | 0 | code->id += 2; |
349 | 0 | size += 5; |
350 | 0 | } |
351 | 9.30M | else if (value > 255) { |
352 | 6.72M | code->id += 1; |
353 | 6.72M | size += 3; |
354 | 6.72M | } |
355 | 2.57M | else |
356 | 2.57M | size += 2; |
357 | 9.30M | break; |
358 | | |
359 | 7.57M | case XS_CODE_INTEGER_1: |
360 | 9.59M | case XS_CODE_RUN_1: |
361 | 9.59M | case XS_CODE_RUN_TAIL_1: |
362 | 9.59M | value = ((txIntegerCode*)code)->integer; |
363 | 9.59M | if ((value < -32768) || (value > 32767)) { |
364 | 15.0k | code->id += 2; |
365 | 15.0k | size += 5; |
366 | 15.0k | } |
367 | 9.58M | else if ((value < -128) || (value > 127)) { |
368 | 94.0k | code->id += 1; |
369 | 94.0k | size += 3; |
370 | 94.0k | } |
371 | 9.48M | else |
372 | 9.48M | size += 2; |
373 | 9.59M | break; |
374 | 12.2k | case XS_CODE_NUMBER: |
375 | 12.2k | size += 9; |
376 | 12.2k | break; |
377 | | |
378 | 0 | case XS_CODE_HOST: |
379 | 0 | size += 3; |
380 | 0 | break; |
381 | | |
382 | 23.9M | default: |
383 | 23.9M | size++; |
384 | 23.9M | break; |
385 | 61.9M | } |
386 | 61.9M | code = code->nextCode; |
387 | 61.9M | #ifdef mxMetering |
388 | 61.9M | meterIndex++; |
389 | 61.9M | #endif |
390 | 61.9M | } |
391 | 939k | #ifdef mxMetering |
392 | 939k | fxMeterSome(parser->console, meterIndex); |
393 | 939k | #endif |
394 | | |
395 | 939k | code = coder.firstCode; |
396 | 939k | size = 0; |
397 | 62.9M | while (code) { |
398 | 61.9M | switch (code->id) { |
399 | 2.21M | case XS_NO_CODE: |
400 | 2.21M | ((txTargetCode*)code)->offset = size; |
401 | 2.21M | break; |
402 | 73.0k | case XS_CODE_BRANCH_1: |
403 | 112k | case XS_CODE_BRANCH_CHAIN_1: |
404 | 1.21M | case XS_CODE_BRANCH_COALESCE_1: |
405 | 1.24M | case XS_CODE_BRANCH_ELSE_1: |
406 | 1.45M | case XS_CODE_BRANCH_IF_1: |
407 | 1.45M | case XS_CODE_BRANCH_STATUS_1: |
408 | 1.53M | case XS_CODE_CATCH_1: |
409 | 1.67M | case XS_CODE_CODE_1: |
410 | 1.67M | offset = ((txBranchCode*)code)->target->offset - (size + 5); |
411 | 1.67M | if ((offset < -32768) || (offset + delta > 32767)) { |
412 | 712k | code->id += 2; |
413 | 712k | size += 5; |
414 | 712k | } |
415 | 965k | else if ((offset < -128) || (offset + delta > 127)) { |
416 | 742k | code->id += 1; |
417 | 742k | delta -= 2; |
418 | 742k | size += 3; |
419 | 742k | } |
420 | 223k | else { |
421 | 223k | delta -= 3; |
422 | 223k | size += 2; |
423 | 223k | } |
424 | 1.67M | break; |
425 | | |
426 | 29.8k | case XS_CODE_ARGUMENT: |
427 | 30.3k | case XS_CODE_ARGUMENTS: |
428 | 31.2k | case XS_CODE_ARGUMENTS_SLOPPY: |
429 | 31.5k | case XS_CODE_ARGUMENTS_STRICT: |
430 | 460k | case XS_CODE_BEGIN_SLOPPY: |
431 | 465k | case XS_CODE_BEGIN_STRICT: |
432 | 468k | case XS_CODE_BEGIN_STRICT_BASE: |
433 | 468k | case XS_CODE_BEGIN_STRICT_DERIVED: |
434 | 471k | case XS_CODE_BEGIN_STRICT_FIELD: |
435 | 471k | case XS_CODE_MODULE: |
436 | 471k | size += 2; |
437 | 471k | break; |
438 | 1.23M | case XS_CODE_LINE: |
439 | 1.23M | size += 3; |
440 | 1.23M | break; |
441 | 1.73k | case XS_CODE_ASYNC_FUNCTION: |
442 | 1.92k | case XS_CODE_ASYNC_GENERATOR_FUNCTION: |
443 | 118k | case XS_CODE_CONSTRUCTOR_FUNCTION: |
444 | 124k | case XS_CODE_DELETE_PROPERTY: |
445 | 124k | case XS_CODE_DELETE_SUPER: |
446 | 560k | case XS_CODE_FILE: |
447 | 587k | case XS_CODE_FUNCTION: |
448 | 587k | case XS_CODE_GENERATOR_FUNCTION: |
449 | 2.00M | case XS_CODE_GET_PROPERTY: |
450 | 2.00M | case XS_CODE_GET_SUPER: |
451 | 2.04M | case XS_CODE_GET_THIS_VARIABLE: |
452 | 3.20M | case XS_CODE_GET_VARIABLE: |
453 | 3.20M | case XS_CODE_EVAL_PRIVATE: |
454 | 3.44M | case XS_CODE_EVAL_REFERENCE: |
455 | 3.44M | case XS_CODE_NAME: |
456 | 3.48M | case XS_CODE_NEW_CLOSURE: |
457 | 3.64M | case XS_CODE_NEW_LOCAL: |
458 | 3.82M | case XS_CODE_NEW_PROPERTY: |
459 | 4.23M | case XS_CODE_PROGRAM_REFERENCE: |
460 | 8.67M | case XS_CODE_SET_PROPERTY: |
461 | 8.67M | case XS_CODE_SET_SUPER: |
462 | 8.77M | case XS_CODE_SET_VARIABLE: |
463 | 8.77M | case XS_CODE_SYMBOL: |
464 | 8.77M | symbol = ((txSymbolCode*)code)->symbol; |
465 | 8.77M | if (symbol && symbol->string) |
466 | 8.73M | symbol->usage |= 1; |
467 | 8.77M | size += 1 + sizeof(txID); |
468 | 8.77M | break; |
469 | 145k | case XS_CODE_PROFILE: |
470 | 145k | size += 1 + sizeof(txID); |
471 | 145k | break; |
472 | | |
473 | 19.9k | case XS_CODE_CONST_CLOSURE_1: |
474 | 114k | case XS_CODE_CONST_LOCAL_1: |
475 | 145k | case XS_CODE_GET_CLOSURE_1: |
476 | 1.64M | case XS_CODE_GET_LOCAL_1: |
477 | 1.64M | case XS_CODE_GET_PRIVATE_1: |
478 | 1.64M | case XS_CODE_HAS_PRIVATE_1: |
479 | 1.65M | case XS_CODE_LET_CLOSURE_1: |
480 | 1.66M | case XS_CODE_LET_LOCAL_1: |
481 | 1.66M | case XS_CODE_NEW_PRIVATE_1: |
482 | 1.66M | case XS_CODE_PULL_CLOSURE_1: |
483 | 1.96M | case XS_CODE_PULL_LOCAL_1: |
484 | 1.96M | case XS_CODE_REFRESH_CLOSURE_1: |
485 | 1.96M | case XS_CODE_REFRESH_LOCAL_1: |
486 | 2.14M | case XS_CODE_RESERVE_1: |
487 | 2.14M | case XS_CODE_RESET_CLOSURE_1: |
488 | 2.14M | case XS_CODE_RESET_LOCAL_1: |
489 | 2.16M | case XS_CODE_RETRIEVE_1: |
490 | 2.17M | case XS_CODE_SET_CLOSURE_1: |
491 | 2.65M | case XS_CODE_SET_LOCAL_1: |
492 | 2.65M | case XS_CODE_SET_PRIVATE_1: |
493 | 2.70M | case XS_CODE_STORE_1: |
494 | 3.93M | case XS_CODE_UNWIND_1: |
495 | 3.93M | case XS_CODE_USED_1: |
496 | 3.95M | case XS_CODE_VAR_CLOSURE_1: |
497 | 4.01M | case XS_CODE_VAR_LOCAL_1: |
498 | 4.01M | size += 2; |
499 | 4.01M | break; |
500 | 0 | case XS_CODE_CONST_CLOSURE_2: |
501 | 290 | case XS_CODE_CONST_LOCAL_2: |
502 | 290 | case XS_CODE_GET_CLOSURE_2: |
503 | 4.79M | case XS_CODE_GET_LOCAL_2: |
504 | 4.79M | case XS_CODE_GET_PRIVATE_2: |
505 | 4.79M | case XS_CODE_HAS_PRIVATE_2: |
506 | 4.79M | case XS_CODE_LET_CLOSURE_2: |
507 | 4.79M | case XS_CODE_LET_LOCAL_2: |
508 | 4.79M | case XS_CODE_NEW_PRIVATE_2: |
509 | 4.79M | case XS_CODE_PULL_CLOSURE_2: |
510 | 4.80M | case XS_CODE_PULL_LOCAL_2: |
511 | 4.80M | case XS_CODE_REFRESH_CLOSURE_2: |
512 | 4.80M | case XS_CODE_REFRESH_LOCAL_2: |
513 | 4.80M | case XS_CODE_RESERVE_2: |
514 | 4.80M | case XS_CODE_RESET_CLOSURE_2: |
515 | 4.80M | case XS_CODE_RESET_LOCAL_2: |
516 | 4.80M | case XS_CODE_RETRIEVE_2: |
517 | 4.80M | case XS_CODE_SET_CLOSURE_2: |
518 | 6.72M | case XS_CODE_SET_LOCAL_2: |
519 | 6.72M | case XS_CODE_SET_PRIVATE_2: |
520 | 6.72M | case XS_CODE_STORE_2: |
521 | 6.72M | case XS_CODE_UNWIND_2: |
522 | 6.72M | case XS_CODE_USED_2: |
523 | 6.72M | case XS_CODE_VAR_CLOSURE_2: |
524 | 6.72M | case XS_CODE_VAR_LOCAL_2: |
525 | 6.72M | size += 3; |
526 | 6.72M | break; |
527 | | |
528 | 7.46M | case XS_CODE_INTEGER_1: |
529 | 9.48M | case XS_CODE_RUN_1: |
530 | 9.48M | case XS_CODE_RUN_TAIL_1: |
531 | 9.48M | size += 2; |
532 | 9.48M | break; |
533 | 93.9k | case XS_CODE_INTEGER_2: |
534 | 94.0k | case XS_CODE_RUN_2: |
535 | 94.0k | case XS_CODE_RUN_TAIL_2: |
536 | 94.0k | size += 3; |
537 | 94.0k | break; |
538 | 15.0k | case XS_CODE_INTEGER_4: |
539 | 15.0k | case XS_CODE_RUN_4: |
540 | 15.0k | case XS_CODE_RUN_TAIL_4: |
541 | 15.0k | size += 5; |
542 | 15.0k | break; |
543 | 12.2k | case XS_CODE_NUMBER: |
544 | 12.2k | size += 9; |
545 | 12.2k | break; |
546 | 3.04M | case XS_CODE_STRING_1: |
547 | 3.04M | size += 2 + ((txStringCode*)code)->length; |
548 | 3.04M | break; |
549 | 23.8k | case XS_CODE_STRING_2: |
550 | 23.8k | size += 3 + ((txStringCode*)code)->length; |
551 | 23.8k | break; |
552 | 0 | case XS_CODE_STRING_4: |
553 | 0 | size += 5 + ((txStringCode*)code)->length; |
554 | 0 | break; |
555 | 31.3k | case XS_CODE_BIGINT_1: |
556 | 31.3k | size += 2 + fxBigIntMeasure(&((txBigIntCode*)code)->bigint); |
557 | 31.3k | break; |
558 | 1 | case XS_CODE_BIGINT_2: |
559 | 1 | size += 3 + fxBigIntMeasure(&((txBigIntCode*)code)->bigint); |
560 | 1 | break; |
561 | | |
562 | 0 | case XS_CODE_HOST: |
563 | 0 | size += 3; |
564 | 0 | break; |
565 | | |
566 | 23.9M | default: |
567 | 23.9M | size++; |
568 | 23.9M | break; |
569 | 61.9M | } |
570 | 61.9M | code = code->nextCode; |
571 | 61.9M | } |
572 | | |
573 | 939k | node = parser->firstHostNode; |
574 | 939k | while (node) { |
575 | 0 | if (node->symbol) |
576 | 0 | node->symbol->usage |= 1; |
577 | 0 | node = node->nextHostNode; |
578 | 0 | } |
579 | | |
580 | 939k | address = parser->symbolTable; |
581 | 939k | c = parser->symbolModulo; |
582 | 939k | id = 1; |
583 | 939k | total = sizeof(txID); |
584 | 1.87G | for (i = 0; i < c; i++) { |
585 | 1.87G | txSymbol* symbol = *address; |
586 | 1.92G | while (symbol) { |
587 | 56.7M | if (symbol->usage & 1) { |
588 | 2.74M | symbol->ID = id; |
589 | 2.74M | id++; |
590 | 2.74M | total += symbol->length; |
591 | 2.74M | } |
592 | 56.7M | symbol = symbol->next; |
593 | 56.7M | } |
594 | 1.87G | address++; |
595 | 1.87G | } |
596 | 939k | count = id; |
597 | | |
598 | 939k | script->codeBuffer = c_malloc(size); |
599 | 939k | if (!script->codeBuffer) goto bail; |
600 | 939k | script->codeSize = size; |
601 | | |
602 | 939k | code = coder.firstCode; |
603 | 939k | p = script->codeBuffer; |
604 | 62.9M | while (code) { |
605 | 61.9M | txS1 s1; txS2 s2; txS4 s4; |
606 | 61.9M | txU1 u1; txU2 u2; |
607 | 61.9M | txNumber n; |
608 | 61.9M | if (code->id) |
609 | 59.7M | *p++ = (txS1)(code->id); |
610 | 61.9M | switch (code->id) { |
611 | 31.1k | case XS_CODE_BRANCH_1: |
612 | 41.3k | case XS_CODE_BRANCH_CHAIN_1: |
613 | 45.0k | case XS_CODE_BRANCH_COALESCE_1: |
614 | 62.2k | case XS_CODE_BRANCH_ELSE_1: |
615 | 90.2k | case XS_CODE_BRANCH_IF_1: |
616 | 91.1k | case XS_CODE_BRANCH_STATUS_1: |
617 | 105k | case XS_CODE_CATCH_1: |
618 | 223k | case XS_CODE_CODE_1: |
619 | 223k | offset = mxPtrDiff(p + 1 - script->codeBuffer); |
620 | 223k | s1 = (txS1)(((txBranchCode*)code)->target->offset - offset); |
621 | 223k | *p++ = s1; |
622 | 223k | break; |
623 | 31.6k | case XS_CODE_BRANCH_2: |
624 | 45.5k | case XS_CODE_BRANCH_CHAIN_2: |
625 | 569k | case XS_CODE_BRANCH_COALESCE_2: |
626 | 579k | case XS_CODE_BRANCH_ELSE_2: |
627 | 687k | case XS_CODE_BRANCH_IF_2: |
628 | 687k | case XS_CODE_BRANCH_STATUS_2: |
629 | 722k | case XS_CODE_CATCH_2: |
630 | 742k | case XS_CODE_CODE_2: |
631 | 742k | offset = mxPtrDiff(p + 2 - script->codeBuffer); |
632 | 742k | s2 = (txS2)(((txBranchCode*)code)->target->offset - offset); |
633 | 742k | mxEncode2(p, s2); |
634 | 742k | break; |
635 | 10.2k | case XS_CODE_BRANCH_4: |
636 | 26.0k | case XS_CODE_BRANCH_CHAIN_4: |
637 | 596k | case XS_CODE_BRANCH_COALESCE_4: |
638 | 599k | case XS_CODE_BRANCH_ELSE_4: |
639 | 672k | case XS_CODE_BRANCH_IF_4: |
640 | 672k | case XS_CODE_BRANCH_STATUS_4: |
641 | 705k | case XS_CODE_CATCH_4: |
642 | 712k | case XS_CODE_CODE_4: |
643 | 712k | offset = mxPtrDiff(p + 4 - script->codeBuffer); |
644 | 712k | s4 = (txS4)(((txBranchCode*)code)->target->offset - offset); |
645 | 712k | mxEncode4(p, s4); |
646 | 712k | break; |
647 | | |
648 | 1.73k | case XS_CODE_ASYNC_FUNCTION: |
649 | 1.92k | case XS_CODE_ASYNC_GENERATOR_FUNCTION: |
650 | 118k | case XS_CODE_CONSTRUCTOR_FUNCTION: |
651 | 124k | case XS_CODE_DELETE_PROPERTY: |
652 | 124k | case XS_CODE_DELETE_SUPER: |
653 | 560k | case XS_CODE_FILE: |
654 | 587k | case XS_CODE_FUNCTION: |
655 | 587k | case XS_CODE_GENERATOR_FUNCTION: |
656 | 2.00M | case XS_CODE_GET_PROPERTY: |
657 | 2.00M | case XS_CODE_GET_SUPER: |
658 | 2.04M | case XS_CODE_GET_THIS_VARIABLE: |
659 | 3.20M | case XS_CODE_GET_VARIABLE: |
660 | 3.20M | case XS_CODE_EVAL_PRIVATE: |
661 | 3.44M | case XS_CODE_EVAL_REFERENCE: |
662 | 3.44M | case XS_CODE_NAME: |
663 | 3.48M | case XS_CODE_NEW_CLOSURE: |
664 | 3.64M | case XS_CODE_NEW_LOCAL: |
665 | 3.82M | case XS_CODE_NEW_PROPERTY: |
666 | 4.23M | case XS_CODE_PROGRAM_REFERENCE: |
667 | 8.67M | case XS_CODE_SET_PROPERTY: |
668 | 8.67M | case XS_CODE_SET_SUPER: |
669 | 8.77M | case XS_CODE_SET_VARIABLE: |
670 | 8.77M | case XS_CODE_SYMBOL: |
671 | 8.77M | symbol = ((txSymbolCode*)code)->symbol; |
672 | 8.77M | if (symbol && symbol->string) |
673 | 8.73M | id = symbol->ID; |
674 | 44.6k | else |
675 | 44.6k | id = XS_NO_ID; |
676 | 8.77M | mxEncodeID(p, id); |
677 | 8.77M | break; |
678 | 145k | case XS_CODE_PROFILE: |
679 | 145k | id = fxGenerateProfileID(parser->console); |
680 | 145k | mxEncodeID(p, id); |
681 | 145k | break; |
682 | | |
683 | 29.8k | case XS_CODE_ARGUMENT: |
684 | 30.3k | case XS_CODE_ARGUMENTS: |
685 | 31.2k | case XS_CODE_ARGUMENTS_SLOPPY: |
686 | 31.5k | case XS_CODE_ARGUMENTS_STRICT: |
687 | 460k | case XS_CODE_BEGIN_SLOPPY: |
688 | 465k | case XS_CODE_BEGIN_STRICT: |
689 | 468k | case XS_CODE_BEGIN_STRICT_BASE: |
690 | 468k | case XS_CODE_BEGIN_STRICT_DERIVED: |
691 | 471k | case XS_CODE_BEGIN_STRICT_FIELD: |
692 | 471k | case XS_CODE_MODULE: |
693 | 653k | case XS_CODE_RESERVE_1: |
694 | 672k | case XS_CODE_RETRIEVE_1: |
695 | 1.90M | case XS_CODE_UNWIND_1: |
696 | 1.90M | u1 = (txU1)(((txIndexCode*)code)->index); |
697 | 1.90M | *((txU1*)p++) = u1; |
698 | 1.90M | break; |
699 | 1.23M | case XS_CODE_LINE: |
700 | 1.23M | case XS_CODE_RESERVE_2: |
701 | 1.23M | case XS_CODE_RETRIEVE_2: |
702 | 1.23M | case XS_CODE_UNWIND_2: |
703 | 1.23M | u2 = (txU2)(((txIndexCode*)code)->index); |
704 | 1.23M | mxEncode2(p, u2); |
705 | 1.23M | break; |
706 | | |
707 | 19.9k | case XS_CODE_CONST_CLOSURE_1: |
708 | 114k | case XS_CODE_CONST_LOCAL_1: |
709 | 145k | case XS_CODE_GET_CLOSURE_1: |
710 | 1.64M | case XS_CODE_GET_LOCAL_1: |
711 | 1.64M | case XS_CODE_GET_PRIVATE_1: |
712 | 1.64M | case XS_CODE_HAS_PRIVATE_1: |
713 | 1.65M | case XS_CODE_LET_CLOSURE_1: |
714 | 1.66M | case XS_CODE_LET_LOCAL_1: |
715 | 1.66M | case XS_CODE_NEW_PRIVATE_1: |
716 | 1.66M | case XS_CODE_PULL_CLOSURE_1: |
717 | 1.96M | case XS_CODE_PULL_LOCAL_1: |
718 | 1.96M | case XS_CODE_REFRESH_CLOSURE_1: |
719 | 1.96M | case XS_CODE_REFRESH_LOCAL_1: |
720 | 1.96M | case XS_CODE_RESET_CLOSURE_1: |
721 | 1.96M | case XS_CODE_RESET_LOCAL_1: |
722 | 1.96M | case XS_CODE_SET_CLOSURE_1: |
723 | 2.45M | case XS_CODE_SET_LOCAL_1: |
724 | 2.45M | case XS_CODE_SET_PRIVATE_1: |
725 | 2.50M | case XS_CODE_STORE_1: |
726 | 2.50M | case XS_CODE_USED_1: |
727 | 2.51M | case XS_CODE_VAR_CLOSURE_1: |
728 | 2.57M | case XS_CODE_VAR_LOCAL_1: |
729 | 2.57M | u1 = (txU1)(((txIndexCode*)code)->index + 1); |
730 | 2.57M | *((txU1*)p++) = u1; |
731 | 2.57M | break; |
732 | | |
733 | 0 | case XS_CODE_CONST_CLOSURE_2: |
734 | 290 | case XS_CODE_CONST_LOCAL_2: |
735 | 290 | case XS_CODE_GET_CLOSURE_2: |
736 | 4.79M | case XS_CODE_GET_LOCAL_2: |
737 | 4.79M | case XS_CODE_GET_PRIVATE_2: |
738 | 4.79M | case XS_CODE_HAS_PRIVATE_2: |
739 | 4.79M | case XS_CODE_LET_CLOSURE_2: |
740 | 4.79M | case XS_CODE_LET_LOCAL_2: |
741 | 4.79M | case XS_CODE_NEW_PRIVATE_2: |
742 | 4.79M | case XS_CODE_PULL_CLOSURE_2: |
743 | 4.80M | case XS_CODE_PULL_LOCAL_2: |
744 | 4.80M | case XS_CODE_REFRESH_CLOSURE_2: |
745 | 4.80M | case XS_CODE_REFRESH_LOCAL_2: |
746 | 4.80M | case XS_CODE_RESET_CLOSURE_2: |
747 | 4.80M | case XS_CODE_RESET_LOCAL_2: |
748 | 4.80M | case XS_CODE_SET_CLOSURE_2: |
749 | 6.72M | case XS_CODE_SET_LOCAL_2: |
750 | 6.72M | case XS_CODE_SET_PRIVATE_2: |
751 | 6.72M | case XS_CODE_STORE_2: |
752 | 6.72M | case XS_CODE_USED_2: |
753 | 6.72M | case XS_CODE_VAR_CLOSURE_2: |
754 | 6.72M | case XS_CODE_VAR_LOCAL_2: |
755 | 6.72M | u2 = (txU2)(((txIndexCode*)code)->index + 1); |
756 | 6.72M | mxEncode2(p, u2); |
757 | 6.72M | break; |
758 | | |
759 | 7.46M | case XS_CODE_INTEGER_1: |
760 | 9.48M | case XS_CODE_RUN_1: |
761 | 9.48M | case XS_CODE_RUN_TAIL_1: |
762 | 9.48M | s1 = (txS1)(((txIntegerCode*)code)->integer); |
763 | 9.48M | *p++ = s1; |
764 | 9.48M | break; |
765 | 93.9k | case XS_CODE_INTEGER_2: |
766 | 94.0k | case XS_CODE_RUN_2: |
767 | 94.0k | case XS_CODE_RUN_TAIL_2: |
768 | 94.0k | s2 = (txS2)(((txIntegerCode*)code)->integer); |
769 | 94.0k | mxEncode2(p, s2); |
770 | 94.0k | break; |
771 | 15.0k | case XS_CODE_INTEGER_4: |
772 | 15.0k | case XS_CODE_RUN_4: |
773 | 15.0k | case XS_CODE_RUN_TAIL_4: |
774 | 15.0k | s4 = (txS4)(((txIntegerCode*)code)->integer); |
775 | 15.0k | mxEncode4(p, s4); |
776 | 15.0k | break; |
777 | 12.2k | case XS_CODE_NUMBER: |
778 | 12.2k | n = ((txNumberCode*)code)->number; |
779 | 12.2k | mxEncode8(p, n); |
780 | 12.2k | break; |
781 | 3.04M | case XS_CODE_STRING_1: |
782 | 3.04M | u1 = (txU1)(((txStringCode*)code)->length); |
783 | 3.04M | *((txU1*)p++) = u1; |
784 | 3.04M | c_memcpy(p, ((txStringCode*)code)->string, u1); |
785 | 3.04M | p += u1; |
786 | 3.04M | break; |
787 | 23.8k | case XS_CODE_STRING_2: |
788 | 23.8k | u2 = (txU2)(((txStringCode*)code)->length); |
789 | 23.8k | mxEncode2(p, u2); |
790 | 23.8k | c_memcpy(p, ((txStringCode*)code)->string, u2); |
791 | 23.8k | p += u2; |
792 | 23.8k | break; |
793 | 0 | case XS_CODE_STRING_4: |
794 | 0 | s4 = (txS4)(((txStringCode*)code)->length); |
795 | 0 | mxEncode4(p, s4); |
796 | 0 | c_memcpy(p, ((txStringCode*)code)->string, s4); |
797 | 0 | p += s4; |
798 | 0 | break; |
799 | 31.3k | case XS_CODE_BIGINT_1: |
800 | 31.3k | u1 = (txU1)fxBigIntMeasure(&((txBigIntCode*)code)->bigint); |
801 | 31.3k | *((txU1*)p++) = u1; |
802 | 31.3k | fxBigIntEncode(p, &((txBigIntCode*)code)->bigint, u1); |
803 | 31.3k | p += u1; |
804 | 31.3k | break; |
805 | 1 | case XS_CODE_BIGINT_2: |
806 | 1 | u2 = (txU2)fxBigIntMeasure(&((txBigIntCode*)code)->bigint); |
807 | 1 | mxEncode2(p, u2); |
808 | 1 | fxBigIntEncode(p, &((txBigIntCode*)code)->bigint, u2); |
809 | 1 | p += u2; |
810 | 1 | break; |
811 | | |
812 | 0 | case XS_CODE_HOST: |
813 | 0 | u2 = (txU2)(((txIndexCode*)code)->index); |
814 | 0 | mxEncode2(p, u2); |
815 | 0 | break; |
816 | 61.9M | } |
817 | 61.9M | code = code->nextCode; |
818 | 61.9M | } |
819 | | |
820 | | #ifdef mxCodePrint |
821 | | fprintf(stderr, "\n"); |
822 | | code = coder.firstCode; |
823 | | while (code) { |
824 | | txInteger tab; |
825 | | for (tab = 0; tab < code->stackLevel; tab++) |
826 | | fprintf(stderr, "\t"); |
827 | | switch (code->id) { |
828 | | case XS_NO_CODE: |
829 | | fprintf(stderr, "_%d\n", ((txTargetCode*)code)->index); |
830 | | break; |
831 | | |
832 | | case XS_CODE_BRANCH_1: |
833 | | case XS_CODE_BRANCH_2: |
834 | | case XS_CODE_BRANCH_4: |
835 | | case XS_CODE_BRANCH_CHAIN_1: |
836 | | case XS_CODE_BRANCH_CHAIN_2: |
837 | | case XS_CODE_BRANCH_CHAIN_4: |
838 | | case XS_CODE_BRANCH_COALESCE_1: |
839 | | case XS_CODE_BRANCH_COALESCE_2: |
840 | | case XS_CODE_BRANCH_COALESCE_4: |
841 | | case XS_CODE_BRANCH_ELSE_1: |
842 | | case XS_CODE_BRANCH_ELSE_2: |
843 | | case XS_CODE_BRANCH_ELSE_4: |
844 | | case XS_CODE_BRANCH_IF_1: |
845 | | case XS_CODE_BRANCH_IF_2: |
846 | | case XS_CODE_BRANCH_IF_4: |
847 | | case XS_CODE_BRANCH_STATUS_1: |
848 | | case XS_CODE_BRANCH_STATUS_2: |
849 | | case XS_CODE_BRANCH_STATUS_4: |
850 | | case XS_CODE_CATCH_1: |
851 | | case XS_CODE_CATCH_2: |
852 | | case XS_CODE_CATCH_4: |
853 | | case XS_CODE_CODE_1: |
854 | | case XS_CODE_CODE_2: |
855 | | case XS_CODE_CODE_4: |
856 | | fprintf(stderr, "%s _%d\n", gxCodeNames[code->id], ((txBranchCode*)code)->target->index); |
857 | | break; |
858 | | |
859 | | case XS_CODE_ARGUMENT: |
860 | | case XS_CODE_ARGUMENTS: |
861 | | case XS_CODE_ARGUMENTS_SLOPPY: |
862 | | case XS_CODE_ARGUMENTS_STRICT: |
863 | | case XS_CODE_BEGIN_SLOPPY: |
864 | | case XS_CODE_BEGIN_STRICT: |
865 | | case XS_CODE_BEGIN_STRICT_BASE: |
866 | | case XS_CODE_BEGIN_STRICT_DERIVED: |
867 | | case XS_CODE_BEGIN_STRICT_FIELD: |
868 | | case XS_CODE_LINE: |
869 | | case XS_CODE_MODULE: |
870 | | fprintf(stderr, "%s %d\n", gxCodeNames[code->id], ((txIndexCode*)code)->index); |
871 | | break; |
872 | | |
873 | | case XS_CODE_ASYNC_FUNCTION: |
874 | | case XS_CODE_ASYNC_GENERATOR_FUNCTION: |
875 | | case XS_CODE_CONSTRUCTOR_FUNCTION: |
876 | | case XS_CODE_DELETE_PROPERTY: |
877 | | case XS_CODE_DELETE_SUPER: |
878 | | case XS_CODE_FILE: |
879 | | case XS_CODE_FUNCTION: |
880 | | case XS_CODE_GENERATOR_FUNCTION: |
881 | | case XS_CODE_GET_PROPERTY: |
882 | | case XS_CODE_GET_SUPER: |
883 | | case XS_CODE_GET_THIS_VARIABLE: |
884 | | case XS_CODE_GET_VARIABLE: |
885 | | case XS_CODE_EVAL_PRIVATE: |
886 | | case XS_CODE_EVAL_REFERENCE: |
887 | | case XS_CODE_NAME: |
888 | | case XS_CODE_NEW_PROPERTY: |
889 | | case XS_CODE_PROGRAM_REFERENCE: |
890 | | case XS_CODE_SET_PROPERTY: |
891 | | case XS_CODE_SET_SUPER: |
892 | | case XS_CODE_SET_VARIABLE: |
893 | | case XS_CODE_SYMBOL: |
894 | | symbol = ((txSymbolCode*)code)->symbol; |
895 | | if (symbol && symbol->string) |
896 | | fprintf(stderr, "%s %s\n", gxCodeNames[code->id], symbol->string); |
897 | | else |
898 | | fprintf(stderr, "%s ?\n", gxCodeNames[code->id]); |
899 | | break; |
900 | | |
901 | | case XS_CODE_CONST_CLOSURE_1: |
902 | | case XS_CODE_CONST_CLOSURE_2: |
903 | | case XS_CODE_CONST_LOCAL_1: |
904 | | case XS_CODE_CONST_LOCAL_2: |
905 | | case XS_CODE_GET_CLOSURE_1: |
906 | | case XS_CODE_GET_CLOSURE_2: |
907 | | case XS_CODE_GET_LOCAL_1: |
908 | | case XS_CODE_GET_LOCAL_2: |
909 | | case XS_CODE_GET_PRIVATE_1: |
910 | | case XS_CODE_GET_PRIVATE_2: |
911 | | case XS_CODE_HAS_PRIVATE_1: |
912 | | case XS_CODE_HAS_PRIVATE_2: |
913 | | case XS_CODE_LET_CLOSURE_1: |
914 | | case XS_CODE_LET_CLOSURE_2: |
915 | | case XS_CODE_LET_LOCAL_1: |
916 | | case XS_CODE_LET_LOCAL_2: |
917 | | case XS_CODE_NEW_PRIVATE_1: |
918 | | case XS_CODE_NEW_PRIVATE_2: |
919 | | case XS_CODE_PULL_CLOSURE_1: |
920 | | case XS_CODE_PULL_CLOSURE_2: |
921 | | case XS_CODE_PULL_LOCAL_1: |
922 | | case XS_CODE_PULL_LOCAL_2: |
923 | | case XS_CODE_REFRESH_CLOSURE_1: |
924 | | case XS_CODE_REFRESH_CLOSURE_2: |
925 | | case XS_CODE_REFRESH_LOCAL_1: |
926 | | case XS_CODE_REFRESH_LOCAL_2: |
927 | | case XS_CODE_RESET_CLOSURE_1: |
928 | | case XS_CODE_RESET_CLOSURE_2: |
929 | | case XS_CODE_RESET_LOCAL_1: |
930 | | case XS_CODE_RESET_LOCAL_2: |
931 | | case XS_CODE_SET_CLOSURE_1: |
932 | | case XS_CODE_SET_CLOSURE_2: |
933 | | case XS_CODE_SET_LOCAL_1: |
934 | | case XS_CODE_SET_LOCAL_2: |
935 | | case XS_CODE_SET_PRIVATE_1: |
936 | | case XS_CODE_SET_PRIVATE_2: |
937 | | case XS_CODE_STORE_1: |
938 | | case XS_CODE_STORE_2: |
939 | | case XS_CODE_USED_1: |
940 | | case XS_CODE_USED_2: |
941 | | case XS_CODE_VAR_CLOSURE_1: |
942 | | case XS_CODE_VAR_CLOSURE_2: |
943 | | case XS_CODE_VAR_LOCAL_1: |
944 | | case XS_CODE_VAR_LOCAL_2: |
945 | | fprintf(stderr, "%s [%d]\n", gxCodeNames[code->id], ((txIndexCode*)code)->index); |
946 | | break; |
947 | | |
948 | | case XS_CODE_RESERVE_1: |
949 | | case XS_CODE_RESERVE_2: |
950 | | case XS_CODE_UNWIND_1: |
951 | | case XS_CODE_UNWIND_2: |
952 | | fprintf(stderr, "%s #%d\n", gxCodeNames[code->id], ((txIndexCode*)code)->index); |
953 | | break; |
954 | | case XS_CODE_NEW_CLOSURE: |
955 | | case XS_CODE_NEW_LOCAL: |
956 | | fprintf(stderr, "[%d] %s %s\n", ((txVariableCode*)code)->index, gxCodeNames[code->id], ((txSymbolCode*)code)->symbol->string); |
957 | | break; |
958 | | case XS_CODE_NEW_TEMPORARY: |
959 | | fprintf(stderr, "[%d] %s\n", ((txIndexCode*)code)->index, gxCodeNames[code->id]); |
960 | | break; |
961 | | case XS_CODE_RETRIEVE_1: |
962 | | case XS_CODE_RETRIEVE_2: |
963 | | { |
964 | | txInteger i, c = ((txIndexCode*)code)->index; |
965 | | fprintf(stderr, "[0"); |
966 | | for (i = 1; i < c; i++) |
967 | | fprintf(stderr, ",%d", i); |
968 | | fprintf(stderr, "] %s\n", gxCodeNames[code->id]); |
969 | | } |
970 | | break; |
971 | | |
972 | | case XS_CODE_INTEGER_1: |
973 | | case XS_CODE_INTEGER_2: |
974 | | case XS_CODE_INTEGER_4: |
975 | | case XS_CODE_RUN_1: |
976 | | case XS_CODE_RUN_2: |
977 | | case XS_CODE_RUN_4: |
978 | | case XS_CODE_RUN_TAIL_1: |
979 | | case XS_CODE_RUN_TAIL_2: |
980 | | case XS_CODE_RUN_TAIL_4: |
981 | | fprintf(stderr, "%s %d\n", gxCodeNames[code->id], ((txIntegerCode*)code)->integer); |
982 | | break; |
983 | | case XS_CODE_NUMBER: |
984 | | fprintf(stderr, "%s %lf\n", gxCodeNames[code->id], ((txNumberCode*)code)->number); |
985 | | break; |
986 | | case XS_CODE_STRING_1: |
987 | | case XS_CODE_STRING_2: |
988 | | case XS_CODE_STRING_4: |
989 | | fprintf(stderr, "%s %d \"%s\"\n", gxCodeNames[code->id], ((txStringCode*)code)->length, ((txStringCode*)code)->string); |
990 | | break; |
991 | | case XS_CODE_BIGINT_1: |
992 | | case XS_CODE_BIGINT_2: |
993 | | fprintf(stderr, "%s %d\n", gxCodeNames[code->id], fxBigIntMeasure(&((txBigIntCode*)code)->bigint)); |
994 | | break; |
995 | | |
996 | | case XS_CODE_HOST: |
997 | | fprintf(stderr, "%s %d\n", gxCodeNames[code->id], ((txIndexCode*)code)->index); |
998 | | break; |
999 | | |
1000 | | default: |
1001 | | fprintf(stderr, "%s\n", gxCodeNames[code->id]); |
1002 | | break; |
1003 | | } |
1004 | | code = code->nextCode; |
1005 | | } |
1006 | | #endif |
1007 | 939k | script->symbolsBuffer = c_malloc(total); |
1008 | 939k | if (!script->symbolsBuffer) goto bail; |
1009 | 939k | script->symbolsSize = total; |
1010 | | |
1011 | 939k | p = script->symbolsBuffer; |
1012 | 939k | mxEncodeID(p, count); |
1013 | | |
1014 | 939k | address = parser->symbolTable; |
1015 | 939k | c = parser->symbolModulo; |
1016 | 1.87G | for (i = 0; i < c; i++) { |
1017 | 1.87G | txSymbol* symbol = *address; |
1018 | 1.92G | while (symbol) { |
1019 | 56.7M | if (symbol->usage & 1) { |
1020 | 2.74M | c_memcpy(p, symbol->string, symbol->length); |
1021 | 2.74M | p += symbol->length; |
1022 | 2.74M | } |
1023 | 56.7M | symbol = symbol->next; |
1024 | 56.7M | } |
1025 | 1.87G | address++; |
1026 | 1.87G | } |
1027 | | |
1028 | 939k | c = (txS2)(parser->hostNodeIndex); |
1029 | 939k | if (c) { |
1030 | 0 | size = sizeof(txID); |
1031 | 0 | node = parser->firstHostNode; |
1032 | 0 | while (node) { |
1033 | 0 | size += 1 + sizeof(txID) + node->at->length + 1; |
1034 | 0 | node = node->nextHostNode; |
1035 | 0 | } |
1036 | | |
1037 | 0 | script->hostsBuffer = c_malloc(size); |
1038 | 0 | if (!script->hostsBuffer) goto bail; |
1039 | 0 | script->hostsSize = size; |
1040 | | |
1041 | 0 | p = script->hostsBuffer; |
1042 | 0 | mxEncodeID(p, c); |
1043 | 0 | node = parser->firstHostNode; |
1044 | 0 | while (node) { |
1045 | 0 | *p++ = (txS1)(node->paramsCount); |
1046 | 0 | if (node->symbol) |
1047 | 0 | c = node->symbol->ID; |
1048 | 0 | else |
1049 | 0 | c = XS_NO_ID; |
1050 | 0 | mxEncodeID(p, c); |
1051 | 0 | c_memcpy(p, node->at->value, node->at->length); |
1052 | 0 | p += node->at->length; |
1053 | 0 | *p++ = 0; |
1054 | 0 | node = node->nextHostNode; |
1055 | 0 | } |
1056 | 0 | } |
1057 | | |
1058 | 939k | return script; |
1059 | 0 | bail: |
1060 | 0 | fxDeleteScript(script); |
1061 | 0 | return C_NULL; |
1062 | 939k | } |
1063 | | |
1064 | | void fxCoderAdd(txCoder* self, txInteger delta, void* it) |
1065 | 62.3M | { |
1066 | 62.3M | txByteCode* code = it; |
1067 | 62.3M | if (self->lastCode) |
1068 | 61.4M | self->lastCode->nextCode = code; |
1069 | 952k | else |
1070 | 952k | self->firstCode = code; |
1071 | 62.3M | self->lastCode = code; |
1072 | 62.3M | self->stackLevel += delta; |
1073 | 62.3M | code->stackLevel = self->stackLevel; |
1074 | | // if (self->stackLevel < 0) |
1075 | | // c_fprintf(stderr, "# oops %d\n", code->id); //@@ |
1076 | 62.3M | } |
1077 | | |
1078 | | void fxCoderAddBigInt(txCoder* self, txInteger delta, txInteger id, txBigInt* bigint) |
1079 | 32.1k | { |
1080 | 32.1k | txBigIntCode* code = fxNewParserChunkClear(self->parser, sizeof(txBigIntCode)); |
1081 | 32.1k | fxCoderAdd(self, delta, code); |
1082 | 32.1k | code->id = id; |
1083 | 32.1k | code->bigint = *bigint; |
1084 | 32.1k | } |
1085 | | |
1086 | | void fxCoderAddBranch(txCoder* self, txInteger delta, txInteger id, txTargetCode* target) |
1087 | 1.75M | { |
1088 | 1.75M | txBranchCode* code = fxNewParserChunkClear(self->parser, sizeof(txBranchCode)); |
1089 | 1.75M | fxCoderAdd(self, delta, code); |
1090 | 1.75M | code->id = id; |
1091 | 1.75M | code->target = target; |
1092 | 1.75M | target->used = 1; |
1093 | 1.75M | } |
1094 | | |
1095 | | void fxCoderAddByte(txCoder* self, txInteger delta, txInteger id) |
1096 | 21.6M | { |
1097 | 21.6M | txByteCode* code = fxNewParserChunkClear(self->parser, sizeof(txByteCode)); |
1098 | 21.6M | fxCoderAdd(self, delta, code); |
1099 | 21.6M | code->id = id; |
1100 | 21.6M | } |
1101 | | |
1102 | | void fxCoderAddIndex(txCoder* self, txInteger delta, txInteger id, txInteger index) |
1103 | 15.1M | { |
1104 | 15.1M | txIndexCode* code = fxNewParserChunkClear(self->parser, sizeof(txIndexCode)); |
1105 | 15.1M | fxCoderAdd(self, delta, code); |
1106 | 15.1M | code->id = id; |
1107 | 15.1M | code->index = index; |
1108 | 15.1M | } |
1109 | | |
1110 | | void fxCoderAddInteger(txCoder* self, txInteger delta, txInteger id, txInteger integer) |
1111 | 9.60M | { |
1112 | 9.60M | txIntegerCode* code = fxNewParserChunkClear(self->parser, sizeof(txIntegerCode)); |
1113 | 9.60M | fxCoderAdd(self, delta, code); |
1114 | 9.60M | code->id = id; |
1115 | 9.60M | code->integer = integer; |
1116 | 9.60M | } |
1117 | | |
1118 | | void fxCoderAddLine(txCoder* self, txInteger delta, txInteger id, txNode* node) |
1119 | 5.51M | { |
1120 | 5.51M | if (self->parser->flags & mxDebugFlag) { |
1121 | 5.51M | if (self->parser->lines) { |
1122 | 0 | if (node->path != self->parser->path) { |
1123 | 0 | node->path = self->parser->path; |
1124 | 0 | node->line = self->parser->lines[node->line]; |
1125 | 0 | } |
1126 | 0 | } |
1127 | 5.51M | else if (self->parser->source) { |
1128 | 5.51M | node->path = self->parser->source; |
1129 | 5.51M | } |
1130 | 5.51M | if (self->path != node->path) { |
1131 | 454k | if (node->path) { |
1132 | 454k | fxCoderAddSymbol(self, 0, XS_CODE_FILE, node->path); |
1133 | 454k | fxCoderAddIndex(self, 0, id, node->line); |
1134 | 454k | } |
1135 | 454k | self->path = node->path; |
1136 | 454k | self->line = node->line; |
1137 | 454k | } |
1138 | 5.05M | else if (self->line != node->line) { |
1139 | 1.00M | if (self->path) { |
1140 | 1.00M | txIndexCode* code = (txIndexCode*)self->lastCode; |
1141 | 1.00M | if (code && (code->id == id) && (code->index != 0)) |
1142 | 322k | code->index = node->line; |
1143 | 684k | else |
1144 | 684k | fxCoderAddIndex(self, 0, id, node->line); |
1145 | 1.00M | } |
1146 | 1.00M | self->line = node->line; |
1147 | 1.00M | } |
1148 | 5.51M | } |
1149 | 5.51M | } |
1150 | | |
1151 | | void fxCoderAddNumber(txCoder* self, txInteger delta, txInteger id, txNumber number) |
1152 | 14.2k | { |
1153 | 14.2k | txNumberCode* code = fxNewParserChunkClear(self->parser, sizeof(txNumberCode)); |
1154 | 14.2k | fxCoderAdd(self, delta, code); |
1155 | 14.2k | code->id = id; |
1156 | 14.2k | code->number = number; |
1157 | 14.2k | } |
1158 | | |
1159 | | void fxCoderAddString(txCoder* self, txInteger delta, txInteger id, txInteger length, txString string) |
1160 | 3.06M | { |
1161 | 3.06M | txStringCode* code = fxNewParserChunkClear(self->parser, sizeof(txStringCode)); |
1162 | 3.06M | fxCoderAdd(self, delta, code); |
1163 | 3.06M | code->id = id; |
1164 | 3.06M | code->length = length + 1; |
1165 | 3.06M | code->string = string; |
1166 | 3.06M | } |
1167 | | |
1168 | | void fxCoderAddSymbol(txCoder* self, txInteger delta, txInteger id, txSymbol* symbol) |
1169 | 8.64M | { |
1170 | 8.64M | txSymbolCode* code = fxNewParserChunkClear(self->parser, sizeof(txSymbolCode)); |
1171 | 8.64M | fxCoderAdd(self, delta, code); |
1172 | 8.64M | code->id = id; |
1173 | 8.64M | code->symbol = symbol; |
1174 | 8.64M | } |
1175 | | |
1176 | | void fxCoderAddVariable(txCoder* self, txInteger delta, txInteger id, txSymbol* symbol, txInteger index) |
1177 | 220k | { |
1178 | 220k | txVariableCode* code = fxNewParserChunkClear(self->parser, sizeof(txVariableCode)); |
1179 | 220k | fxCoderAdd(self, delta, code); |
1180 | 220k | code->id = id; |
1181 | 220k | code->symbol = symbol; |
1182 | 220k | code->index = index; |
1183 | 220k | } |
1184 | | |
1185 | | void fxCoderAdjustEnvironment(txCoder* self, txTargetCode* target) |
1186 | 30.1k | { |
1187 | 30.1k | txInteger count = self->environmentLevel - target->environmentLevel; |
1188 | 36.2k | while (count) { |
1189 | 6.04k | fxCoderAddByte(self, 0, XS_CODE_WITHOUT); |
1190 | 6.04k | count--; |
1191 | 6.04k | } |
1192 | 30.1k | } |
1193 | | |
1194 | | void fxCoderAdjustScope(txCoder* self, txTargetCode* target) |
1195 | 30.1k | { |
1196 | 30.1k | txInteger count = self->scopeLevel - target->scopeLevel; |
1197 | 30.1k | if (count) |
1198 | 2.89k | fxCoderAddIndex(self, 0, XS_CODE_UNWIND_1, count); |
1199 | 30.1k | } |
1200 | | |
1201 | | txTargetCode* fxCoderAliasTargets(txCoder* self, txTargetCode* target) |
1202 | 71.5k | { |
1203 | 71.5k | txTargetCode* result = NULL; |
1204 | 71.5k | if (target) { |
1205 | 61.2k | txTargetCode* alias = result = fxNewParserChunkClear(self->parser, sizeof(txTargetCode)); |
1206 | 61.2k | alias->index = self->targetIndex++; |
1207 | 61.2k | alias->label = target->label; |
1208 | 61.2k | alias->environmentLevel = self->environmentLevel; |
1209 | 61.2k | alias->scopeLevel = self->scopeLevel; |
1210 | 61.2k | alias->stackLevel = self->stackLevel; |
1211 | 61.2k | alias->original = target; |
1212 | 61.2k | target = target->nextTarget; |
1213 | 265k | while (target) { |
1214 | 203k | alias = alias->nextTarget = fxNewParserChunkClear(self->parser, sizeof(txTargetCode)); |
1215 | 203k | alias->index = self->targetIndex++; |
1216 | 203k | alias->label = target->label; |
1217 | 203k | alias->environmentLevel = self->environmentLevel; |
1218 | 203k | alias->scopeLevel = self->scopeLevel; |
1219 | 203k | alias->stackLevel = self->stackLevel; |
1220 | 203k | alias->original = target; |
1221 | 203k | target = target->nextTarget; |
1222 | 203k | } |
1223 | 61.2k | } |
1224 | 71.5k | return result; |
1225 | 71.5k | } |
1226 | | |
1227 | | txInteger fxCoderCountParameters(txCoder* self, txNode* params) |
1228 | 151k | { |
1229 | 151k | txNode* item = ((txParamsBindingNode*)params)->items->first; |
1230 | 151k | txInteger count = 0; |
1231 | 182k | while (item) { |
1232 | 31.6k | if (item->description->token == XS_TOKEN_REST_BINDING) |
1233 | 538 | break; |
1234 | 31.0k | if ((item->description->token != XS_TOKEN_ARG) && (item->description->token != XS_TOKEN_ARRAY_BINDING) && (item->description->token != XS_TOKEN_OBJECT_BINDING)) |
1235 | 148 | break; |
1236 | 30.9k | count++; |
1237 | 30.9k | item = item->next; |
1238 | 30.9k | } |
1239 | 151k | return count; |
1240 | 151k | } |
1241 | | |
1242 | | txTargetCode* fxCoderCreateTarget(txCoder* self) |
1243 | 2.25M | { |
1244 | 2.25M | txTargetCode* result = fxNewParserChunkClear(self->parser, sizeof(txTargetCode)); |
1245 | 2.25M | result->index = self->targetIndex++; |
1246 | 2.25M | result->environmentLevel = self->environmentLevel; |
1247 | 2.25M | result->scopeLevel = self->scopeLevel; |
1248 | 2.25M | result->stackLevel = self->stackLevel; |
1249 | 2.25M | return result; |
1250 | 2.25M | } |
1251 | | |
1252 | | txTargetCode* fxCoderFinalizeTargets(txCoder* self, txTargetCode* alias, txInteger selector, txInteger* address, txTargetCode* finallyTarget) |
1253 | 68.6k | { |
1254 | 68.6k | txTargetCode* result = NULL; |
1255 | 68.6k | txInteger selection = *address; |
1256 | 68.6k | if (alias) { |
1257 | 60.2k | result = alias->original; |
1258 | 324k | while (alias) { |
1259 | 264k | if (alias->used) { |
1260 | 75 | fxCoderAdd(self, 0, alias); |
1261 | 75 | fxCoderAddInteger(self, 1, XS_CODE_INTEGER_1, selection); |
1262 | 75 | fxCoderAddIndex(self, -1, XS_CODE_PULL_LOCAL_1, selector); |
1263 | 75 | fxCoderAddBranch(self, 0, XS_CODE_BRANCH_1, finallyTarget); |
1264 | 75 | alias->original->used = 1; |
1265 | 75 | } |
1266 | 264k | alias = alias->nextTarget; |
1267 | 264k | selection++; |
1268 | 264k | } |
1269 | 60.2k | } |
1270 | 68.6k | *address = selection; |
1271 | 68.6k | return result; |
1272 | 68.6k | } |
1273 | | |
1274 | | void fxCoderJumpTargets(txCoder* self, txTargetCode* target, txInteger selector, txInteger* address) |
1275 | 68.6k | { |
1276 | 68.6k | txInteger selection = *address; |
1277 | 332k | while (target) { |
1278 | 264k | if (target->used) { |
1279 | 1.28k | txTargetCode* elseTarget = fxCoderCreateTarget(self); |
1280 | 1.28k | fxCoderAddInteger(self, 1, XS_CODE_INTEGER_1, selection); |
1281 | 1.28k | fxCoderAddIndex(self, 1, XS_CODE_GET_LOCAL_1, selector); |
1282 | 1.28k | fxCoderAddByte(self, -1, XS_CODE_STRICT_EQUAL); |
1283 | 1.28k | fxCoderAddBranch(self, -1, XS_CODE_BRANCH_ELSE_1, elseTarget); |
1284 | 1.28k | fxCoderAdjustEnvironment(self, target); |
1285 | 1.28k | fxCoderAdjustScope(self, target); |
1286 | 1.28k | fxCoderAddBranch(self, 0, XS_CODE_BRANCH_1, target); |
1287 | 1.28k | fxCoderAdd(self, 0, elseTarget); |
1288 | 1.28k | } |
1289 | 264k | target = target->nextTarget; |
1290 | 264k | selection++; |
1291 | 264k | } |
1292 | 68.6k | *address = selection; |
1293 | 68.6k | } |
1294 | | |
1295 | | void fxCoderOptimize(txCoder* self) |
1296 | 939k | { |
1297 | 939k | txByteCode** address; |
1298 | 939k | txByteCode* code; |
1299 | | |
1300 | | // branch to (target | unwind)* end => end |
1301 | 939k | address = &self->firstCode; |
1302 | 62.9M | while ((code = *address)) { |
1303 | 62.0M | if (code->id == XS_CODE_BRANCH_1) { |
1304 | 132k | txByteCode* nextCode = ((txBranchCode*)code)->target->nextCode; |
1305 | 134k | while ((nextCode->id == XS_NO_CODE) || (nextCode->id == XS_CODE_UNWIND_1)) |
1306 | 2.20k | nextCode = nextCode->nextCode; |
1307 | 132k | if ((XS_CODE_END <= nextCode->id) && (nextCode->id <= XS_CODE_END_DERIVED)) { |
1308 | 30.1k | txByteCode* end = fxNewParserChunkClear(self->parser, sizeof(txByteCode)); |
1309 | 30.1k | end->nextCode = code->nextCode; |
1310 | 30.1k | end->id = nextCode->id; |
1311 | 30.1k | end->stackLevel = code->stackLevel; |
1312 | 30.1k | *address = end; |
1313 | 30.1k | } |
1314 | 102k | else |
1315 | 102k | address = &code->nextCode; |
1316 | 132k | } |
1317 | 61.9M | else |
1318 | 61.9M | address = &code->nextCode; |
1319 | 62.0M | } |
1320 | | // unwind (target | unwind)* end => (target | unwind)* end |
1321 | 939k | address = &self->firstCode; |
1322 | 62.9M | while ((code = *address)) { |
1323 | 62.0M | if (code->id == XS_CODE_UNWIND_1) { |
1324 | 1.24M | txByteCode* nextCode = code->nextCode; |
1325 | 1.29M | while ((nextCode->id == XS_NO_CODE) || (nextCode->id == XS_CODE_UNWIND_1)) |
1326 | 45.4k | nextCode = nextCode->nextCode; |
1327 | 1.24M | if ((XS_CODE_END <= nextCode->id) && (nextCode->id <= XS_CODE_END_DERIVED)) |
1328 | 13.2k | *address = code->nextCode; |
1329 | 1.23M | else |
1330 | 1.23M | address = &code->nextCode; |
1331 | 1.24M | } |
1332 | 60.7M | else |
1333 | 60.7M | address = &code->nextCode; |
1334 | 62.0M | } |
1335 | | // end target* end => target* end |
1336 | 939k | address = &self->firstCode; |
1337 | 62.9M | while ((code = *address)) { |
1338 | 62.0M | if ((XS_CODE_END <= code->id) && (code->id <= XS_CODE_END_DERIVED)) { |
1339 | 175k | txByteCode* nextCode = code->nextCode; |
1340 | 175k | if (!nextCode) |
1341 | 257 | break; |
1342 | 346k | while (nextCode->id == XS_NO_CODE) |
1343 | 171k | nextCode = nextCode->nextCode; |
1344 | 175k | if (nextCode->id == code->id) |
1345 | 23.1k | *address = code->nextCode; |
1346 | 152k | else |
1347 | 152k | address = &code->nextCode; |
1348 | 175k | } |
1349 | 61.8M | else |
1350 | 61.8M | address = &code->nextCode; |
1351 | 62.0M | } |
1352 | | // branch to next => |
1353 | 939k | address = &self->firstCode; |
1354 | 62.9M | while ((code = *address)) { |
1355 | 61.9M | if (code->id == XS_CODE_BRANCH_1) { |
1356 | 102k | if (code->nextCode == (txByteCode*)(((txBranchCode*)code)->target)) |
1357 | 29.4k | *address = code->nextCode; |
1358 | 73.0k | else |
1359 | 73.0k | address = &code->nextCode; |
1360 | 102k | } |
1361 | 61.8M | else |
1362 | 61.8M | address = &code->nextCode; |
1363 | 61.9M | } |
1364 | 939k | } |
1365 | | |
1366 | | txInteger fxCoderUseTemporaryVariable(txCoder* self) |
1367 | 2.53M | { |
1368 | 2.53M | txInteger result = self->scopeLevel++; |
1369 | 2.53M | fxCoderAddIndex(self, 0, XS_CODE_NEW_TEMPORARY, result); |
1370 | 2.53M | return result; |
1371 | 2.53M | } |
1372 | | |
1373 | | void fxCoderUnuseTemporaryVariables(txCoder* self, txInteger count) |
1374 | 1.22M | { |
1375 | 1.22M | fxCoderAddIndex(self, 0, XS_CODE_UNWIND_1, count); |
1376 | 1.22M | self->scopeLevel -= count; |
1377 | 1.22M | } |
1378 | | |
1379 | | void fxScopeCoded(txScope* self, txCoder* coder) |
1380 | 183k | { |
1381 | 183k | if (self->declareNodeCount) { |
1382 | 18.1k | if (self->flags & mxEvalFlag) { |
1383 | 1.89k | coder->environmentLevel--; |
1384 | 1.89k | fxCoderAddByte(coder, 0, XS_CODE_WITHOUT); |
1385 | 1.89k | } |
1386 | 18.1k | fxCoderAddIndex(coder, 0, XS_CODE_UNWIND_1, self->declareNodeCount); |
1387 | 18.1k | coder->scopeLevel -= self->declareNodeCount; |
1388 | 18.1k | } |
1389 | 183k | } |
1390 | | |
1391 | | void fxScopeCodedBody(txScope* self, txCoder* coder) |
1392 | 146k | { |
1393 | 146k | txScope* functionScope = self->scope; |
1394 | 146k | if ((functionScope->node->flags & mxEvalFlag) && !(functionScope->node->flags & mxStrictFlag)) { |
1395 | 1.88k | coder->environmentLevel--; |
1396 | 1.88k | fxCoderAddByte(coder, 0, XS_CODE_WITHOUT); |
1397 | 1.88k | coder->environmentLevel--; |
1398 | 1.88k | fxCoderAddByte(coder, 0, XS_CODE_WITHOUT); |
1399 | 1.88k | fxCoderAddIndex(coder, 0, XS_CODE_UNWIND_1, self->declareNodeCount); |
1400 | 1.88k | coder->scopeLevel -= self->declareNodeCount; |
1401 | 1.88k | } |
1402 | 144k | else |
1403 | 144k | fxScopeCoded(self, coder); |
1404 | 146k | } |
1405 | | |
1406 | | void fxScopeCodingBlock(txScope* self, txCoder* coder) |
1407 | 193k | { |
1408 | 193k | if (self->declareNodeCount) { |
1409 | 21.8k | txDeclareNode* node = self->firstDeclareNode; |
1410 | 61.2k | while (node) { |
1411 | 39.3k | if (node->flags & mxDeclareNodeClosureFlag) { |
1412 | 22.1k | if (!(node->flags & mxDeclareNodeUseClosureFlag)) { |
1413 | 22.1k | node->index = coder->scopeLevel++; |
1414 | 22.1k | fxCoderAddVariable(coder, 0, XS_CODE_NEW_CLOSURE, node->symbol, node->index); |
1415 | 22.1k | if (node->description->token == XS_TOKEN_VAR) { |
1416 | 3.15k | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1417 | 3.15k | fxCoderAddIndex(coder, 0, XS_CODE_VAR_CLOSURE_1, node->index); |
1418 | 3.15k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1419 | 3.15k | } |
1420 | 22.1k | } |
1421 | 22.1k | } |
1422 | 17.1k | else { |
1423 | 17.1k | node->index = coder->scopeLevel++; |
1424 | 17.1k | if (node->symbol) |
1425 | 16.2k | fxCoderAddVariable(coder, 0, XS_CODE_NEW_LOCAL, node->symbol, node->index); |
1426 | 929 | else |
1427 | 929 | fxCoderAddIndex(coder, 0, XS_CODE_NEW_TEMPORARY, node->index); |
1428 | 17.1k | if (node->description->token == XS_TOKEN_VAR) { |
1429 | 7.33k | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1430 | 7.33k | fxCoderAddIndex(coder, 0, XS_CODE_VAR_LOCAL_1, node->index); |
1431 | 7.33k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1432 | 7.33k | } |
1433 | 17.1k | } |
1434 | 39.3k | node = node->nextDeclareNode; |
1435 | 39.3k | } |
1436 | 21.8k | if (self->flags & mxEvalFlag) { |
1437 | 1.89k | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1438 | 1.89k | fxCoderAddByte(coder, 0, XS_CODE_WITH); |
1439 | 1.89k | node = self->firstDeclareNode; |
1440 | 6.51k | while (node) { |
1441 | 4.61k | fxCoderAddIndex(coder, 0, XS_CODE_STORE_1, node->index); |
1442 | 4.61k | node = node->nextDeclareNode; |
1443 | 4.61k | } |
1444 | 1.89k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1445 | 1.89k | coder->environmentLevel++; |
1446 | 1.89k | } |
1447 | 21.8k | } |
1448 | 193k | } |
1449 | | |
1450 | | void fxScopeCodingBody(txScope* self, txCoder* coder) |
1451 | 151k | { |
1452 | 151k | if ((self->node->flags & mxEvalFlag) && !(self->node->flags & mxStrictFlag)) { |
1453 | 1.88k | txDeclareNode* node = self->firstDeclareNode; |
1454 | 2.53k | while (node) { |
1455 | 644 | if (node->description->token == XS_TOKEN_DEFINE) { |
1456 | 23 | node->index = coder->scopeLevel++; |
1457 | 23 | fxCoderAddVariable(coder, 0, XS_CODE_NEW_CLOSURE, node->symbol, node->index); |
1458 | 23 | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
1459 | 23 | fxCoderAddIndex(coder, 0, XS_CODE_VAR_CLOSURE_1, node->index); |
1460 | 23 | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1461 | 23 | } |
1462 | 621 | else if (node->description->token == XS_TOKEN_VAR) { |
1463 | 118 | node->index = coder->scopeLevel++; |
1464 | 118 | fxCoderAddVariable(coder, 0, XS_CODE_NEW_CLOSURE, node->symbol, node->index); |
1465 | 118 | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1466 | 118 | fxCoderAddIndex(coder, 0, XS_CODE_VAR_CLOSURE_1, node->index); |
1467 | 118 | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1468 | 118 | } |
1469 | 644 | node = node->nextDeclareNode; |
1470 | 644 | } |
1471 | 1.88k | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
1472 | 1.88k | fxCoderAddByte(coder, 0, XS_CODE_WITH); |
1473 | 1.88k | node = self->firstDeclareNode; |
1474 | 2.53k | while (node) { |
1475 | 644 | if ((node->description->token == XS_TOKEN_DEFINE) || (node->description->token == XS_TOKEN_VAR)) |
1476 | 141 | fxCoderAddIndex(coder, 0, XS_CODE_STORE_1, node->index); |
1477 | 644 | node = node->nextDeclareNode; |
1478 | 644 | } |
1479 | 1.88k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1480 | 1.88k | coder->environmentLevel++; |
1481 | 1.88k | node = self->firstDeclareNode; |
1482 | 2.53k | while (node) { |
1483 | 644 | if ((node->description->token != XS_TOKEN_DEFINE) && (node->description->token != XS_TOKEN_VAR)) { |
1484 | 503 | node->index = coder->scopeLevel++; |
1485 | 503 | if (node->symbol) |
1486 | 503 | fxCoderAddVariable(coder, 0, XS_CODE_NEW_CLOSURE, node->symbol, node->index); |
1487 | 0 | else |
1488 | 0 | fxCoderAddIndex(coder, 0, XS_CODE_NEW_TEMPORARY, node->index); |
1489 | 503 | } |
1490 | 644 | node = node->nextDeclareNode; |
1491 | 644 | } |
1492 | 1.88k | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1493 | 1.88k | fxCoderAddByte(coder, 0, XS_CODE_WITH); |
1494 | 1.88k | node = self->firstDeclareNode; |
1495 | 2.53k | while (node) { |
1496 | 644 | if ((node->description->token != XS_TOKEN_DEFINE) && (node->description->token != XS_TOKEN_VAR)) { |
1497 | 503 | if (node->symbol) |
1498 | 503 | fxCoderAddIndex(coder, 0, XS_CODE_STORE_1, node->index); |
1499 | 503 | } |
1500 | 644 | node = node->nextDeclareNode; |
1501 | 644 | } |
1502 | 1.88k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1503 | 1.88k | coder->environmentLevel++; |
1504 | 1.88k | } |
1505 | 149k | else |
1506 | 149k | fxScopeCodingBlock(self, coder); |
1507 | 151k | } |
1508 | | |
1509 | | void fxScopeCodingEval(txScope* self, txCoder* coder) |
1510 | 185k | { |
1511 | 185k | txProgramNode* programNode = (txProgramNode*)self->node; |
1512 | 185k | txDeclareNode* node; |
1513 | 185k | if (self->flags & mxStrictFlag) { |
1514 | 1.52k | if (programNode->scopeCount) { |
1515 | 972 | fxCoderAddIndex(coder, 0, XS_CODE_RESERVE_1, programNode->scopeCount); |
1516 | 972 | fxScopeCodingBlock(self, coder); |
1517 | 972 | node = self->firstDeclareNode; |
1518 | 1.94k | while (node) { |
1519 | 972 | if (node->description->token == XS_TOKEN_PRIVATE) { |
1520 | 0 | fxCoderAddSymbol(coder, 1, XS_CODE_EVAL_PRIVATE, node->symbol); |
1521 | 0 | fxCoderAddIndex(coder, 0, XS_CODE_CONST_CLOSURE_1, node->index); |
1522 | 0 | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1523 | 0 | } |
1524 | 972 | node = node->nextDeclareNode; |
1525 | 972 | } |
1526 | 972 | } |
1527 | 1.52k | } |
1528 | 184k | else { |
1529 | 184k | txInteger count = 0; |
1530 | 184k | node = self->firstDeclareNode; |
1531 | 204k | while (node) { |
1532 | 19.6k | if ((node->description->token == XS_TOKEN_DEFINE) || (node->description->token == XS_TOKEN_VAR)) |
1533 | 8.37k | count++; |
1534 | 19.6k | node = node->nextDeclareNode; |
1535 | 19.6k | } |
1536 | 184k | if (count) { |
1537 | 7.38k | fxCoderAddIndex(coder, 0, XS_CODE_RESERVE_1, count); |
1538 | 7.38k | node = self->firstDeclareNode; |
1539 | 16.9k | while (node) { |
1540 | 9.52k | if (node->description->token == XS_TOKEN_DEFINE) { |
1541 | 233 | node->index = coder->scopeLevel++; |
1542 | 233 | fxCoderAddVariable(coder, 0, XS_CODE_NEW_LOCAL, node->symbol, node->index); |
1543 | 233 | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
1544 | 233 | fxCoderAddIndex(coder, 0, XS_CODE_VAR_LOCAL_1, node->index); |
1545 | 233 | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1546 | 233 | } |
1547 | 9.28k | else if (node->description->token == XS_TOKEN_VAR) { |
1548 | 8.14k | node->index = coder->scopeLevel++; |
1549 | 8.14k | fxCoderAddVariable(coder, 0, XS_CODE_NEW_LOCAL, node->symbol, node->index); |
1550 | 8.14k | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1551 | 8.14k | fxCoderAddIndex(coder, 0, XS_CODE_VAR_LOCAL_1, node->index); |
1552 | 8.14k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1553 | 8.14k | } |
1554 | 9.52k | node = node->nextDeclareNode; |
1555 | 9.52k | } |
1556 | 7.38k | } |
1557 | 184k | fxCoderAddByte(coder, 0, XS_CODE_EVAL_ENVIRONMENT); |
1558 | 184k | coder->scopeLevel = 0; |
1559 | 184k | if (programNode->scopeCount) { |
1560 | 21.5k | fxCoderAddIndex(coder, 0, XS_CODE_RESERVE_1, programNode->scopeCount); |
1561 | 21.5k | if (self->declareNodeCount) { |
1562 | 10.4k | node = self->firstDeclareNode; |
1563 | 22.8k | while (node) { |
1564 | 12.4k | if ((node->description->token != XS_TOKEN_DEFINE) && (node->description->token != XS_TOKEN_VAR)) { |
1565 | 11.2k | node->index = coder->scopeLevel++; |
1566 | 11.2k | if (node->flags & mxDeclareNodeClosureFlag) { |
1567 | 652 | fxCoderAddVariable(coder, 0, XS_CODE_NEW_CLOSURE, node->symbol, node->index); |
1568 | 652 | } |
1569 | 10.6k | else { |
1570 | 10.6k | fxCoderAddVariable(coder, 0, XS_CODE_NEW_LOCAL, node->symbol, node->index); |
1571 | 10.6k | } |
1572 | 11.2k | } |
1573 | 12.4k | node = node->nextDeclareNode; |
1574 | 12.4k | } |
1575 | 10.4k | if (self->flags & mxEvalFlag) { |
1576 | 0 | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1577 | 0 | fxCoderAddByte(coder, 0, XS_CODE_WITH); |
1578 | 0 | node = self->firstDeclareNode; |
1579 | 0 | while (node) { |
1580 | 0 | if ((node->description->token != XS_TOKEN_DEFINE) && (node->description->token != XS_TOKEN_VAR)) |
1581 | 0 | fxCoderAddIndex(coder, 0, XS_CODE_STORE_1, node->index); |
1582 | 0 | node = node->nextDeclareNode; |
1583 | 0 | } |
1584 | 0 | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1585 | 0 | coder->environmentLevel++; |
1586 | 0 | } |
1587 | 10.4k | } |
1588 | 21.5k | } |
1589 | 184k | } |
1590 | 185k | } |
1591 | | |
1592 | | void fxScopeCodingParams(txScope* self, txCoder* coder) |
1593 | 151k | { |
1594 | 151k | txDeclareNode* node = self->firstDeclareNode; |
1595 | 307k | while (node) { |
1596 | 155k | txToken token = node->description->token; |
1597 | 155k | if ((token == XS_TOKEN_ARG) || (token == XS_TOKEN_VAR) || (token == XS_TOKEN_CONST)) { |
1598 | 131k | if (node->flags & mxDeclareNodeClosureFlag) { |
1599 | 10.1k | if (node->flags & mxDeclareNodeUseClosureFlag) { |
1600 | 0 | fxReportParserError(self->parser, node->line, "argument %s use closure", node->symbol->string); |
1601 | 0 | } |
1602 | 10.1k | node->index = coder->scopeLevel++; |
1603 | 10.1k | fxCoderAddVariable(coder, 0, XS_CODE_NEW_CLOSURE, node->symbol, node->index); |
1604 | 10.1k | } |
1605 | 120k | else { |
1606 | 120k | node->index = coder->scopeLevel++; |
1607 | 120k | fxCoderAddVariable(coder, 0, XS_CODE_NEW_LOCAL, node->symbol, node->index); |
1608 | 120k | } |
1609 | 131k | } |
1610 | 155k | node = node->nextDeclareNode; |
1611 | 155k | } |
1612 | 151k | if (self->flags & mxEvalFlag) { |
1613 | 4.56k | if (!(self->node->flags & mxStrictFlag)) { |
1614 | 4.24k | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
1615 | 4.24k | fxCoderAddByte(coder, 0, XS_CODE_WITH); |
1616 | 4.24k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1617 | 4.24k | coder->environmentLevel++; |
1618 | 4.24k | } |
1619 | 4.56k | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1620 | 4.56k | fxCoderAddByte(coder, 0, XS_CODE_WITH); |
1621 | 4.56k | node = self->firstDeclareNode; |
1622 | 8.19k | while (node) { |
1623 | 3.63k | txToken token = node->description->token; |
1624 | 3.63k | if ((token == XS_TOKEN_ARG) || (token == XS_TOKEN_VAR) || (token == XS_TOKEN_CONST)) |
1625 | 2.73k | fxCoderAddIndex(coder, 0, XS_CODE_STORE_1, node->index); |
1626 | 3.63k | node = node->nextDeclareNode; |
1627 | 3.63k | } |
1628 | 4.56k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1629 | 4.56k | coder->environmentLevel++; |
1630 | 4.56k | } |
1631 | 151k | } |
1632 | | |
1633 | | void fxScopeCodingProgram(txScope* self, txCoder* coder) |
1634 | 120k | { |
1635 | 120k | txProgramNode* programNode = (txProgramNode*)self->node; |
1636 | 120k | txDeclareNode* node; |
1637 | 120k | txInteger count = 0; |
1638 | 120k | if (programNode->variableCount) { |
1639 | 15.2k | fxCoderAddIndex(coder, 0, XS_CODE_RESERVE_1, programNode->variableCount); |
1640 | 15.2k | node = self->firstDeclareNode; |
1641 | 45.6k | while (node) { |
1642 | 30.3k | if ((node->description->token != XS_TOKEN_DEFINE) && (node->description->token != XS_TOKEN_VAR)) { |
1643 | 6.38k | node->index = coder->scopeLevel++; |
1644 | 6.38k | fxCoderAddVariable(coder, 0, XS_CODE_NEW_CLOSURE, node->symbol, node->index); |
1645 | 6.38k | } |
1646 | 30.3k | node = node->nextDeclareNode; |
1647 | 30.3k | } |
1648 | 15.2k | count = coder->scopeLevel; |
1649 | 15.2k | node = self->firstDeclareNode; |
1650 | 45.6k | while (node) { |
1651 | 30.3k | if (node->description->token == XS_TOKEN_DEFINE) { |
1652 | | // closure -> global property |
1653 | 1.52k | node->index = coder->scopeLevel++; |
1654 | 1.52k | fxCoderAddVariable(coder, 0, XS_CODE_NEW_LOCAL, node->symbol, node->index); |
1655 | 1.52k | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
1656 | 1.52k | fxCoderAddIndex(coder, 0, XS_CODE_VAR_LOCAL_1, node->index); |
1657 | 1.52k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1658 | 1.52k | } |
1659 | 28.8k | else if (node->description->token == XS_TOKEN_VAR) { |
1660 | | // closure -> global property |
1661 | 22.4k | node->index = coder->scopeLevel++; |
1662 | 22.4k | fxCoderAddVariable(coder, 0, XS_CODE_NEW_LOCAL, node->symbol, node->index); |
1663 | 22.4k | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1664 | 22.4k | fxCoderAddIndex(coder, 0, XS_CODE_VAR_LOCAL_1, node->index); |
1665 | 22.4k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1666 | 22.4k | } |
1667 | 30.3k | node = node->nextDeclareNode; |
1668 | 30.3k | } |
1669 | 15.2k | fxCoderAddByte(coder, 0, XS_CODE_PROGRAM_ENVIRONMENT); |
1670 | 15.2k | coder->scopeLevel = count; |
1671 | 15.2k | } |
1672 | 120k | if (programNode->scopeCount > count) |
1673 | 15.1k | fxCoderAddIndex(coder, 0, XS_CODE_RESERVE_1, programNode->scopeCount - count); |
1674 | 120k | } |
1675 | | |
1676 | | void fxScopeCodeDefineNodes(txScope* self, txCoder* coder) |
1677 | 642k | { |
1678 | 642k | txDefineNode* node = self->firstDefineNode; |
1679 | 743k | while (node) { |
1680 | 101k | fxDefineNodeCode(node, coder); |
1681 | 101k | node = node->nextDefineNode; |
1682 | 101k | } |
1683 | 642k | } |
1684 | | |
1685 | | txInteger fxScopeCodeSpecifierNodes(txScope* self, txCoder* coder) |
1686 | 257 | { |
1687 | 257 | txDeclareNode* node = self->firstDeclareNode; |
1688 | 257 | txInteger count = 0; |
1689 | 884 | while (node) { |
1690 | 627 | if (node->flags & mxDeclareNodeUseClosureFlag) { |
1691 | 627 | txSpecifierNode* specifier = node->importSpecifier; |
1692 | 627 | txInteger index = 3; |
1693 | 627 | txBoolean flag = 0; |
1694 | 627 | if (node->symbol) |
1695 | 593 | fxCoderAddSymbol(coder, 1, XS_CODE_SYMBOL, node->symbol); |
1696 | 34 | else |
1697 | 34 | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
1698 | 627 | if (specifier) { |
1699 | 152 | if (coder->parser->flags & mxDebugFlag) { |
1700 | 152 | fxCoderAddLine(coder, 0, XS_CODE_LINE, (txNode*)specifier); |
1701 | 152 | } |
1702 | 152 | fxStringNodeCode(specifier->from, coder); |
1703 | 152 | if (specifier->with) |
1704 | 0 | flag = 1; |
1705 | 152 | if (specifier->symbol) |
1706 | 105 | fxCoderAddSymbol(coder, 1, XS_CODE_SYMBOL, specifier->symbol); |
1707 | 47 | else |
1708 | 47 | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
1709 | 152 | } |
1710 | 475 | else { |
1711 | 475 | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
1712 | 475 | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
1713 | 475 | } |
1714 | 627 | specifier = node->firstExportSpecifier; |
1715 | 1.13k | while (specifier) { |
1716 | 505 | if (specifier->asSymbol) { |
1717 | 32 | fxCoderAddSymbol(coder, 1, XS_CODE_SYMBOL, specifier->asSymbol); |
1718 | 32 | index++; |
1719 | 32 | } |
1720 | 473 | else if (specifier->symbol) { |
1721 | 465 | fxCoderAddSymbol(coder, 1, XS_CODE_SYMBOL, specifier->symbol); |
1722 | 465 | index++; |
1723 | 465 | } |
1724 | 8 | else { |
1725 | 8 | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
1726 | 8 | index++; |
1727 | 8 | } |
1728 | 505 | specifier = specifier->nextSpecifier; |
1729 | 505 | } |
1730 | 627 | fxCoderAddInteger(coder, 1, XS_CODE_INTEGER_1, index); |
1731 | 627 | if (flag) |
1732 | 0 | fxCoderAddByte(coder, 0 - index, XS_CODE_TRANSFER_JSON); |
1733 | 627 | else |
1734 | 627 | fxCoderAddByte(coder, 0 - index, XS_CODE_TRANSFER); |
1735 | 627 | count++; |
1736 | 627 | } |
1737 | 627 | node = node->nextDeclareNode; |
1738 | 627 | } |
1739 | 257 | return count; |
1740 | 257 | } |
1741 | | |
1742 | | void fxScopeCodeRefresh(txScope* self, txCoder* coder) |
1743 | 17.0k | { |
1744 | 17.0k | txDeclareNode* node = self->firstDeclareNode; |
1745 | 17.4k | while (node) { |
1746 | 419 | if (node->flags & mxDeclareNodeClosureFlag) |
1747 | 14 | fxCoderAddIndex(coder, 0, XS_CODE_REFRESH_CLOSURE_1, node->index); |
1748 | 405 | else |
1749 | 405 | fxCoderAddIndex(coder, 0, XS_CODE_REFRESH_LOCAL_1, node->index); |
1750 | 419 | node = node->nextDeclareNode; |
1751 | 419 | } |
1752 | 17.0k | } |
1753 | | |
1754 | | void fxScopeCodeReset(txScope* self, txCoder* coder) |
1755 | 11.2k | { |
1756 | 11.2k | txDeclareNode* node = self->firstDeclareNode; |
1757 | 12.7k | while (node) { |
1758 | 1.47k | if (node->flags & mxDeclareNodeClosureFlag) |
1759 | 85 | fxCoderAddIndex(coder, 0, XS_CODE_RESET_CLOSURE_1, node->index); |
1760 | 1.38k | else if (node->symbol) |
1761 | 1.38k | fxCoderAddIndex(coder, 0, XS_CODE_RESET_LOCAL_1, node->index); |
1762 | 0 | else { |
1763 | 0 | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1764 | 0 | fxCoderAddIndex(coder, -1, XS_CODE_PULL_LOCAL_1, node->index); |
1765 | 0 | } |
1766 | 1.47k | node = node->nextDeclareNode; |
1767 | 1.47k | } |
1768 | 11.2k | } |
1769 | | |
1770 | | void fxScopeCodeRetrieve(txScope* self, txCoder* coder) |
1771 | 152k | { |
1772 | 152k | txDeclareNode* node; |
1773 | 152k | txInteger count = 0; |
1774 | 152k | node = self->firstDeclareNode; |
1775 | 308k | while (node) { |
1776 | 156k | if ((node->flags & mxDeclareNodeUseClosureFlag) && node->symbol) { |
1777 | 25.1k | node->index = coder->scopeLevel++; |
1778 | 25.1k | count++; |
1779 | 25.1k | } |
1780 | 156k | node = node->nextDeclareNode; |
1781 | 156k | } |
1782 | 152k | if ((self->node->flags & mxArrowFlag) && ((self->node->flags & mxDefaultFlag) || (self->flags & mxEvalFlag))) { |
1783 | 2.99k | fxCoderAddIndex(coder, 0, XS_CODE_RETRIEVE_1, count); |
1784 | 2.99k | fxCoderAddByte(coder, 0, XS_CODE_RETRIEVE_TARGET); |
1785 | 2.99k | fxCoderAddByte(coder, 0, XS_CODE_RETRIEVE_THIS); |
1786 | 2.99k | } |
1787 | 149k | else if (count) |
1788 | 17.5k | fxCoderAddIndex(coder, 0, XS_CODE_RETRIEVE_1, count); |
1789 | 152k | self->closureNodeCount = count; |
1790 | 152k | } |
1791 | | |
1792 | | void fxScopeCodeStore(txScope* self, txCoder* coder) |
1793 | 26.8k | { |
1794 | 26.8k | txDeclareNode* node = self->firstDeclareNode; |
1795 | 26.8k | txUnsigned flags = self->flags & mxEvalFlag; |
1796 | 64.4k | while (node) { |
1797 | 37.6k | if (node->flags & mxDeclareNodeUseClosureFlag) { |
1798 | 24.4k | fxCoderAddIndex(coder, 0, XS_CODE_STORE_1, node->declaration->index); |
1799 | 24.4k | node->declaration->flags |= flags; |
1800 | 24.4k | } |
1801 | 37.6k | node = node->nextDeclareNode; |
1802 | 37.6k | } |
1803 | 26.8k | if ((self->node->flags & mxArrowFlag) && ((self->node->flags & mxDefaultFlag) || (self->flags & mxEvalFlag))) |
1804 | 2.99k | fxCoderAddByte(coder, 0, XS_CODE_STORE_ARROW); |
1805 | 26.8k | if (self->flags & mxEvalFlag) |
1806 | 4.56k | fxScopeCodeStoreAll(self->scope, coder); |
1807 | 26.8k | } |
1808 | | |
1809 | | void fxScopeCodeStoreAll(txScope* self, txCoder* coder) |
1810 | 4.56k | { |
1811 | 4.56k | txScope* scope = self; |
1812 | 11.1k | while (scope) { |
1813 | 8.61k | txDeclareNode* node; |
1814 | 8.61k | if (scope->token == XS_TOKEN_WITH) |
1815 | 36 | break; |
1816 | 8.57k | node = scope->firstDeclareNode; |
1817 | 32.0k | while (node) { |
1818 | 23.4k | if (node->flags & mxEvalFlag) |
1819 | 899 | node->flags &= ~mxEvalFlag; |
1820 | 22.5k | else if ((!(node->flags & mxDeclareNodeUseClosureFlag)) && node->declaration) |
1821 | 15.7k | fxCoderAddIndex(coder, 0, XS_CODE_STORE_1, node->declaration->index); |
1822 | 23.4k | node = node->nextDeclareNode; |
1823 | 23.4k | } |
1824 | 8.57k | if ((scope->token == XS_TOKEN_FUNCTION) || (scope->token == XS_TOKEN_MODULE)) |
1825 | 1.97k | break; |
1826 | 6.60k | scope = scope->scope; |
1827 | 6.60k | } |
1828 | 4.56k | } |
1829 | | |
1830 | | void fxScopeCodeUsed(txScope* self, txCoder* coder, txUsingContext* context) |
1831 | 0 | { |
1832 | 0 | txTargetCode* normalTarget = fxCoderCreateTarget(coder); |
1833 | 0 | txTargetCode* uncatchTarget = fxCoderCreateTarget(coder); |
1834 | 0 | txTargetCode* finallyTarget = fxCoderCreateTarget(coder); |
1835 | 0 | txTargetCode* elseTarget = fxCoderCreateTarget(coder); |
1836 | 0 | txInteger selection; |
1837 | | |
1838 | 0 | fxCoderAddBranch(coder, 0, XS_CODE_BRANCH_1, normalTarget); |
1839 | 0 | fxCoderAdd(coder, 0, context->catchTarget); |
1840 | 0 | fxCoderAddByte(coder, 1, XS_CODE_EXCEPTION); |
1841 | 0 | fxCoderAddIndex(coder, 0, XS_CODE_PULL_LOCAL_1, context->exception); |
1842 | 0 | fxCoderAddInteger(coder, 1, XS_CODE_INTEGER_1, 0); |
1843 | 0 | fxCoderAddIndex(coder, -1, XS_CODE_PULL_LOCAL_1, context->selector); |
1844 | 0 | fxCoderAddBranch(coder, 0, XS_CODE_BRANCH_1, finallyTarget); |
1845 | 0 | selection = 1; |
1846 | 0 | coder->firstBreakTarget = fxCoderFinalizeTargets(coder, coder->firstBreakTarget, context->selector, &selection, uncatchTarget); |
1847 | 0 | coder->firstContinueTarget = fxCoderFinalizeTargets(coder, coder->firstContinueTarget, context->selector, &selection, uncatchTarget); |
1848 | 0 | coder->returnTarget = fxCoderFinalizeTargets(coder, coder->returnTarget, context->selector, &selection, uncatchTarget); |
1849 | 0 | fxCoderAdd(coder, 0, normalTarget); |
1850 | 0 | fxCoderAddInteger(coder, 1, XS_CODE_INTEGER_1, selection); |
1851 | 0 | fxCoderAddIndex(coder, -1, XS_CODE_PULL_LOCAL_1, context->selector); |
1852 | 0 | fxCoderAdd(coder, 0, uncatchTarget); |
1853 | 0 | fxCoderAddByte(coder, 0, XS_CODE_UNCATCH); |
1854 | 0 | fxCoderAdd(coder, 0, finallyTarget); |
1855 | | |
1856 | 0 | fxScopeCodeUsedReverse(self, coder, self->firstDeclareNode, context->exception, context->selector); |
1857 | | |
1858 | 0 | fxCoderAddIndex(coder, 1, XS_CODE_GET_LOCAL_1, context->selector); |
1859 | 0 | fxCoderAddBranch(coder, -1, XS_CODE_BRANCH_IF_1, elseTarget); |
1860 | 0 | fxCoderAddIndex(coder, 1, XS_CODE_GET_LOCAL_1, context->exception); |
1861 | 0 | fxCoderAddByte(coder, -1, XS_CODE_THROW); |
1862 | 0 | fxCoderAdd(coder, 0, elseTarget); |
1863 | 0 | selection = 1; |
1864 | 0 | fxCoderJumpTargets(coder, coder->firstBreakTarget, context->selector, &selection); |
1865 | 0 | fxCoderJumpTargets(coder, coder->firstContinueTarget, context->selector, &selection); |
1866 | 0 | fxCoderJumpTargets(coder, coder->returnTarget, context->selector, &selection); |
1867 | 0 | fxCoderUnuseTemporaryVariables(coder, 2); |
1868 | 0 | } |
1869 | | |
1870 | | void fxScopeCodeUsedReverse(txScope* self, txCoder* coder, txDeclareNode* node, txInteger exception, txInteger selector) |
1871 | 25.4k | { |
1872 | 25.4k | if (node) { |
1873 | 2.94k | fxCheckParserStack(coder->parser, node->line); |
1874 | 2.94k | fxScopeCodeUsedReverse(self, coder, node->nextDeclareNode, exception, selector); |
1875 | 2.94k | if (node->description->token == XS_TOKEN_USING) { |
1876 | 0 | txTargetCode* catchTarget = fxCoderCreateTarget(coder); |
1877 | 0 | txTargetCode* chainTarget = fxCoderCreateTarget(coder); |
1878 | 0 | txTargetCode* normalTarget = fxCoderCreateTarget(coder); |
1879 | | |
1880 | 0 | fxCoderAddIndex(coder, 1, XS_CODE_GET_LOCAL_1, node->index + 1); |
1881 | 0 | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
1882 | 0 | fxCoderAddByte(coder, -1, XS_CODE_STRICT_EQUAL); |
1883 | 0 | fxCoderAddBranch(coder, -1, XS_CODE_BRANCH_IF_1, normalTarget); |
1884 | | |
1885 | 0 | fxCoderAddBranch(coder, 0, XS_CODE_CATCH_1, catchTarget); |
1886 | | |
1887 | 0 | fxCoderAddIndex(coder, 1, (node->flags & mxDeclareNodeClosureFlag) ? XS_CODE_GET_CLOSURE_1: XS_CODE_GET_LOCAL_1, node->index); |
1888 | 0 | fxCoderAddBranch(coder, 0, XS_CODE_BRANCH_CHAIN_1, chainTarget); |
1889 | 0 | fxCoderAddIndex(coder, 1, XS_CODE_GET_LOCAL_1, node->index + 1); |
1890 | 0 | fxCoderAddByte(coder, 1, XS_CODE_CALL); |
1891 | 0 | fxCoderAddInteger(coder, -2, XS_CODE_RUN_1, 0); |
1892 | | |
1893 | 0 | fxCoderAdd(coder, 0, chainTarget); |
1894 | 0 | if (node->flags & mxAwaitingFlag) { |
1895 | 0 | fxCoderAddByte(coder, 0, XS_CODE_AWAIT); |
1896 | 0 | fxCoderAddByte(coder, 0, XS_CODE_THROW_STATUS); |
1897 | 0 | } |
1898 | 0 | fxCoderAddByte(coder, -1, XS_CODE_POP); |
1899 | | |
1900 | 0 | fxCoderAddByte(coder, 0, XS_CODE_UNCATCH); |
1901 | 0 | fxCoderAddBranch(coder, 0, XS_CODE_BRANCH_1, normalTarget); |
1902 | 0 | fxCoderAdd(coder, 0, catchTarget); |
1903 | 0 | fxCoderAddIndex(coder, 1, XS_CODE_USED_1, selector); |
1904 | | |
1905 | 0 | fxCoderAdd(coder, 0, normalTarget); |
1906 | 0 | } |
1907 | 2.94k | } |
1908 | 25.4k | } |
1909 | | |
1910 | | void fxScopeCodeUsing(txScope* self, txCoder* coder, txUsingContext* context) |
1911 | 928 | { |
1912 | 928 | context->exception = fxCoderUseTemporaryVariable(coder); |
1913 | 928 | context->selector = fxCoderUseTemporaryVariable(coder); |
1914 | 928 | coder->firstBreakTarget = fxCoderAliasTargets(coder, coder->firstBreakTarget); |
1915 | 928 | coder->firstContinueTarget = fxCoderAliasTargets(coder, coder->firstContinueTarget); |
1916 | 928 | coder->returnTarget = fxCoderAliasTargets(coder, coder->returnTarget); |
1917 | 928 | context->catchTarget = fxCoderCreateTarget(coder); |
1918 | 928 | fxCoderAddBranch(coder, 0, XS_CODE_CATCH_1, context->catchTarget); |
1919 | 928 | } |
1920 | | |
1921 | | void fxScopeCodeUsingStatement(txScope* self, txCoder* coder, txNode* statement) |
1922 | 163k | { |
1923 | 163k | if (self->disposableNodeCount) { |
1924 | 928 | txUsingContext context; |
1925 | 928 | fxScopeCodeUsing(self, coder, &context); |
1926 | 928 | fxNodeDispatchCode(statement, coder); |
1927 | 928 | fxScopeCodeUsed(self, coder, &context); |
1928 | 928 | } |
1929 | 162k | else |
1930 | 162k | fxNodeDispatchCode(statement, coder); |
1931 | 163k | } |
1932 | | |
1933 | | void fxNodeDispatchCode(void* it, void* param) |
1934 | 6.88M | { |
1935 | 6.88M | txNode* self = it; |
1936 | 6.88M | txCoder* coder = param; |
1937 | 6.88M | fxCheckParserStack(coder->parser, self->line); |
1938 | 6.88M | if (self->line >= 0) |
1939 | 4.27M | fxCoderAddLine(coder, 0, XS_CODE_LINE, self); |
1940 | 6.88M | (*self->description->dispatch->code)(it, param); |
1941 | 6.88M | } |
1942 | | |
1943 | | void fxNodeDispatchCodeAssign(void* it, void* param, txFlag flag) |
1944 | 182k | { |
1945 | 182k | txNode* self = it; |
1946 | 182k | txCoder* coder = param; |
1947 | 182k | fxCheckParserStack(coder->parser, self->line); |
1948 | 182k | if (self->line >= 0) |
1949 | 164k | fxCoderAddLine(coder, 0, XS_CODE_LINE, self); |
1950 | 182k | (*self->description->dispatch->codeAssign)(self, param, flag); |
1951 | 182k | } |
1952 | | |
1953 | | void fxNodeDispatchCodeDelete(void* it, void* param) |
1954 | 7.27k | { |
1955 | 7.27k | txNode* self = it; |
1956 | 7.27k | txCoder* coder = param; |
1957 | 7.27k | fxCheckParserStack(coder->parser, self->line); |
1958 | 7.27k | if (self->line >= 0) |
1959 | 6.36k | fxCoderAddLine(coder, 0, XS_CODE_LINE, self); |
1960 | 7.27k | (*self->description->dispatch->codeDelete)(self, param); |
1961 | 7.27k | } |
1962 | | |
1963 | | void fxNodeDispatchCodeReference(void* it, void* param, txFlag flag) |
1964 | 160k | { |
1965 | 160k | txNode* self = it; |
1966 | 160k | txCoder* coder = param; |
1967 | 160k | fxCheckParserStack(coder->parser, self->line); |
1968 | 160k | if (self->line >= 0) |
1969 | 143k | fxCoderAddLine(coder, 0, XS_CODE_LINE, self); |
1970 | 160k | (*self->description->dispatch->codeReference)(self, param, flag); |
1971 | 160k | } |
1972 | | |
1973 | | txFlag fxNodeDispatchCodeThis(void* it, void* param, txFlag flag) |
1974 | 1.25M | { |
1975 | 1.25M | txNode* self = it; |
1976 | 1.25M | txCoder* coder = param; |
1977 | 1.25M | fxCheckParserStack(coder->parser, self->line); |
1978 | 1.25M | if (self->line >= 0) |
1979 | 466k | fxCoderAddLine(coder, 0, XS_CODE_LINE, self); |
1980 | 1.25M | return (*self->description->dispatch->codeThis)(self, param, flag); |
1981 | 1.25M | } |
1982 | | |
1983 | | void fxNodeCode(void* it, void* param) |
1984 | 3 | { |
1985 | 3 | txNode* self = it; |
1986 | 3 | txCoder* coder = param; |
1987 | 3 | fxReportParserError(coder->parser, self->line, "no value"); |
1988 | 3 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
1989 | 3 | } |
1990 | | |
1991 | | void fxNodeCodeAssign(void* it, void* param, txFlag flag) |
1992 | 1 | { |
1993 | 1 | txNode* self = it; |
1994 | 1 | txCoder* coder = param; |
1995 | 1 | fxReportParserError(coder->parser, self->line, "no reference"); |
1996 | 1 | } |
1997 | | |
1998 | | void fxNodeCodeDelete(void* it, void* param) |
1999 | 494 | { |
2000 | 494 | fxNodeDispatchCode(it, param); |
2001 | 494 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2002 | 494 | fxCoderAddByte(param, 1, XS_CODE_TRUE); |
2003 | 494 | } |
2004 | | |
2005 | | void fxNodeCodeReference(void* it, void* param, txFlag flag) |
2006 | 1.37k | { |
2007 | 1.37k | } |
2008 | | |
2009 | | txFlag fxNodeCodeName(txNode* value) |
2010 | 66.5k | { |
2011 | 66.5k | txToken token = value->description->token; |
2012 | 66.5k | if (token == XS_TOKEN_EXPRESSIONS) { |
2013 | 17 | value = ((txExpressionsNode*)value)->items->first; |
2014 | 17 | if (value->next) |
2015 | 1 | return 0; |
2016 | 16 | token = value->description->token; |
2017 | 16 | } |
2018 | 66.5k | if (token == XS_TOKEN_CLASS) { |
2019 | 2 | txClassNode* node = (txClassNode*)value; |
2020 | 2 | if (node->symbol) |
2021 | 1 | return 0; |
2022 | 2 | } |
2023 | 66.5k | else if ((token == XS_TOKEN_FUNCTION) || (token == XS_TOKEN_GENERATOR) || (token == XS_TOKEN_HOST)) { |
2024 | 1.84k | txFunctionNode* node = (txFunctionNode*)value; |
2025 | 1.84k | if (node->symbol) |
2026 | 26 | return 0; |
2027 | 1.84k | } |
2028 | 64.6k | else |
2029 | 64.6k | return 0; |
2030 | 1.82k | return 1; |
2031 | 66.5k | } |
2032 | | |
2033 | | txFlag fxNodeCodeThis(void* it, void* param, txFlag flag) |
2034 | 1.09M | { |
2035 | 1.09M | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
2036 | 1.09M | fxNodeDispatchCode(it, param); |
2037 | 1.09M | return 1; |
2038 | 1.09M | } |
2039 | | |
2040 | | void fxAccessNodeCode(void* it, void* param) |
2041 | 568k | { |
2042 | 568k | txAccessNode* self = it; |
2043 | 568k | txDeclareNode* declaration = self->declaration; |
2044 | 568k | if (!declaration) { |
2045 | 531k | fxAccessNodeCodeReference(it, param, 0); |
2046 | 531k | fxCoderAddSymbol(param, 0, XS_CODE_GET_VARIABLE, self->symbol); |
2047 | 531k | } |
2048 | 36.9k | else |
2049 | 36.9k | fxCoderAddIndex(param, 1, (declaration->flags & mxDeclareNodeClosureFlag) ? XS_CODE_GET_CLOSURE_1 : XS_CODE_GET_LOCAL_1, declaration->index); |
2050 | 568k | } |
2051 | | |
2052 | | void fxAccessNodeCodeAssign(void* it, void* param, txFlag flag) |
2053 | 59.7k | { |
2054 | 59.7k | txAccessNode* self = it; |
2055 | 59.7k | txDeclareNode* declaration = self->declaration; |
2056 | 59.7k | if (!declaration) |
2057 | 50.9k | fxCoderAddSymbol(param, -1, XS_CODE_SET_VARIABLE, self->symbol); |
2058 | 8.87k | else |
2059 | 8.87k | fxCoderAddIndex(param, 0, (declaration->flags & mxDeclareNodeClosureFlag) ? XS_CODE_SET_CLOSURE_1 : XS_CODE_SET_LOCAL_1, declaration->index); |
2060 | 59.7k | } |
2061 | | |
2062 | | void fxAccessNodeCodeDelete(void* it, void* param) |
2063 | 5.06k | { |
2064 | 5.06k | txAccessNode* self = it; |
2065 | 5.06k | txCoder* coder = param; |
2066 | 5.06k | txDeclareNode* declaration = self->declaration; |
2067 | 5.06k | if (self->flags & mxStrictFlag) |
2068 | 1 | fxReportParserError(coder->parser, self->line, "delete identifier (strict code)"); |
2069 | 5.06k | if (!declaration) { |
2070 | 4.97k | fxAccessNodeCodeReference(it, param, 0); |
2071 | 4.97k | fxCoderAddSymbol(param, 0, XS_CODE_DELETE_PROPERTY, self->symbol); |
2072 | 4.97k | } |
2073 | 89 | else |
2074 | 89 | fxCoderAddByte(param, 1, XS_CODE_FALSE); |
2075 | 5.06k | } |
2076 | | |
2077 | | void fxAccessNodeCodeReference(void* it, void* param, txFlag flag) |
2078 | 615k | { |
2079 | 615k | txAccessNode* self = it; |
2080 | 615k | txCoder* coder = param; |
2081 | 615k | txDeclareNode* declaration = self->declaration; |
2082 | 615k | if (!declaration) { |
2083 | 608k | if (coder->evalFlag) |
2084 | 246k | fxCoderAddSymbol(param, 1, XS_CODE_EVAL_REFERENCE, self->symbol); |
2085 | 361k | else |
2086 | 361k | fxCoderAddSymbol(param, 1, XS_CODE_PROGRAM_REFERENCE, self->symbol); |
2087 | 608k | } |
2088 | 615k | } |
2089 | | |
2090 | | txFlag fxAccessNodeCodeThis(void* it, void* param, txFlag flag) |
2091 | 50.0k | { |
2092 | 50.0k | txAccessNode* self = it; |
2093 | 50.0k | txDeclareNode* declaration = self->declaration; |
2094 | 50.0k | if (!flag) |
2095 | 26.5k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
2096 | 50.0k | if (!declaration) { |
2097 | 41.8k | fxAccessNodeCodeReference(it, param, 0); |
2098 | 41.8k | if (flag) |
2099 | 21.4k | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2100 | 41.8k | fxCoderAddSymbol(param, 0, XS_CODE_GET_THIS_VARIABLE, self->symbol); |
2101 | 41.8k | } |
2102 | 8.19k | else { |
2103 | 8.19k | fxCoderAddIndex(param, 1, (declaration->flags & mxDeclareNodeClosureFlag) ? XS_CODE_GET_CLOSURE_1 : XS_CODE_GET_LOCAL_1, declaration->index); |
2104 | 8.19k | flag = 0; |
2105 | 8.19k | } |
2106 | 50.0k | return flag; |
2107 | 50.0k | } |
2108 | | |
2109 | | void fxAndExpressionNodeCode(void* it, void* param) |
2110 | 1.70k | { |
2111 | 1.70k | txBinaryExpressionNode* self = it; |
2112 | 1.70k | txTargetCode* endTarget = fxCoderCreateTarget(param); |
2113 | 1.70k | self->right->flags |= (self->flags & mxTailRecursionFlag); |
2114 | 1.70k | fxNodeDispatchCode(self->left, param); |
2115 | 1.70k | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2116 | 1.70k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, endTarget); |
2117 | 1.70k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2118 | 1.70k | fxNodeDispatchCode(self->right, param); |
2119 | 1.70k | fxCoderAdd(param, 0, endTarget); |
2120 | 1.70k | } |
2121 | | |
2122 | | void fxArgumentsNodeCode(void* it, void* param) |
2123 | 0 | { |
2124 | 0 | fxCoderAddIndex(param, 1, XS_CODE_ARGUMENTS, 0); |
2125 | 0 | } |
2126 | | |
2127 | | void fxArrayNodeCode(void* it, void* param) |
2128 | 38.9k | { |
2129 | 38.9k | txArrayNode* self = it; |
2130 | 38.9k | txCoder* coder = param; |
2131 | 38.9k | txInteger array = fxCoderUseTemporaryVariable(param); |
2132 | 38.9k | fxCoderAddByte(param, 1, XS_CODE_ARRAY); |
2133 | 38.9k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, array); |
2134 | 38.9k | if (self->items) { |
2135 | 38.9k | txNode* item = self->items->first; |
2136 | 38.9k | if (self->flags & mxSpreadFlag) { |
2137 | 514 | txInteger counter = fxCoderUseTemporaryVariable(param); |
2138 | 514 | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, 0); |
2139 | 514 | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, counter); |
2140 | 1.75k | while (item) { |
2141 | 1.23k | if (item->description->token == XS_TOKEN_SPREAD) { |
2142 | 530 | txInteger iterator = fxCoderUseTemporaryVariable(param); |
2143 | 530 | txInteger result = fxCoderUseTemporaryVariable(param); |
2144 | 530 | txTargetCode* nextTarget = fxCoderCreateTarget(param); |
2145 | 530 | txTargetCode* doneTarget = fxCoderCreateTarget(param); |
2146 | 530 | fxNodeDispatchCode(((txSpreadNode*)item)->expression, param); |
2147 | 530 | fxCoderAddByte(param, 0, XS_CODE_FOR_OF); |
2148 | 530 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, iterator); |
2149 | 530 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2150 | 530 | fxCoderAdd(param, 0, nextTarget); |
2151 | 530 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2152 | 530 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2153 | 530 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->nextSymbol); |
2154 | 530 | fxCoderAddByte(param, 1, XS_CODE_CALL); |
2155 | 530 | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
2156 | 530 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, result); |
2157 | 530 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->doneSymbol); |
2158 | 530 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, doneTarget); |
2159 | 530 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, array); |
2160 | 530 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, counter); |
2161 | 530 | fxCoderAddByte(param, 0, XS_CODE_AT); |
2162 | 530 | fxCoderAddIndex(param, 0, XS_CODE_GET_LOCAL_1, result); |
2163 | 530 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->valueSymbol); |
2164 | 530 | fxCoderAddByte(param, -2, XS_CODE_SET_PROPERTY_AT); |
2165 | 530 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2166 | 530 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, counter); |
2167 | 530 | fxCoderAddByte(param, 0, XS_CODE_INCREMENT); |
2168 | 530 | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, counter); |
2169 | 530 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, nextTarget); |
2170 | 530 | fxCoderAdd(param, 1, doneTarget); |
2171 | 530 | fxCoderUnuseTemporaryVariables(param, 2); |
2172 | 530 | } |
2173 | 708 | else { |
2174 | 708 | if (item->description->token != XS_TOKEN_ELISION) { |
2175 | 530 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, array); |
2176 | 530 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, counter); |
2177 | 530 | fxCoderAddByte(param, 0, XS_CODE_AT); |
2178 | 530 | fxNodeDispatchCode(item, param); |
2179 | 530 | fxCoderAddByte(param, -2, XS_CODE_SET_PROPERTY_AT); |
2180 | 530 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2181 | 530 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, counter); |
2182 | 530 | fxCoderAddByte(param, 0, XS_CODE_INCREMENT); |
2183 | 530 | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, counter); |
2184 | 530 | } |
2185 | 178 | else { |
2186 | 178 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, array); |
2187 | 178 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, counter); |
2188 | 178 | fxCoderAddByte(param, 0, XS_CODE_INCREMENT); |
2189 | 178 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, counter); |
2190 | 178 | fxCoderAddSymbol(param, -1, XS_CODE_SET_PROPERTY, coder->parser->lengthSymbol); |
2191 | 178 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2192 | 178 | } |
2193 | 708 | } |
2194 | 1.23k | item = item->next; |
2195 | 1.23k | } |
2196 | 514 | fxCoderUnuseTemporaryVariables(param, 1); |
2197 | 514 | } |
2198 | 38.3k | else { |
2199 | 38.3k | txInteger index = 0; |
2200 | 38.3k | txInteger count = self->items->length; |
2201 | 38.3k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, array); |
2202 | 38.3k | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, count); |
2203 | 38.3k | fxCoderAddSymbol(param, -1, XS_CODE_SET_PROPERTY, coder->parser->lengthSymbol); |
2204 | 38.3k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2205 | 193k | while (item) { |
2206 | 155k | if (item->description->token == XS_TOKEN_ELISION) |
2207 | 792 | break; |
2208 | 154k | item = item->next; |
2209 | 154k | } |
2210 | | // if (!item) { |
2211 | | // fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, array); |
2212 | | // fxCoderAddByte(param, 1, XS_CODE_DUB); |
2213 | | // fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->fillSymbol); |
2214 | | // fxCoderAddByte(param, 1, XS_CODE_CALL); |
2215 | | // fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
2216 | | // fxCoderAddByte(param, -1, XS_CODE_POP); |
2217 | | // } |
2218 | 38.3k | item = self->items->first; |
2219 | 199k | while (item) { |
2220 | 161k | if (item->description->token != XS_TOKEN_ELISION) { |
2221 | 156k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, array); |
2222 | 156k | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, index); |
2223 | 156k | fxCoderAddByte(param, 0, XS_CODE_AT); |
2224 | 156k | fxNodeDispatchCode(item, param); |
2225 | 156k | fxCoderAddByte(param, -3, XS_CODE_NEW_PROPERTY_AT); |
2226 | 156k | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, 0); |
2227 | 156k | } |
2228 | 161k | item = item->next; |
2229 | 161k | index++; |
2230 | 161k | } |
2231 | 38.3k | } |
2232 | 38.9k | } |
2233 | 38.9k | fxCoderUnuseTemporaryVariables(param, 1); |
2234 | 38.9k | } |
2235 | | |
2236 | | void fxArrayBindingNodeCode(void* it, void* param) |
2237 | 27.7k | { |
2238 | 27.7k | txArrayBindingNode* self = it; |
2239 | 27.7k | txCoder* coder = param; |
2240 | 27.7k | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
2241 | 27.7k | fxArrayBindingNodeCodeAssign(self, param, 0); |
2242 | 27.7k | } |
2243 | | |
2244 | | void fxArrayBindingNodeCodeAssign(void* it, void* param, txFlag flag) |
2245 | 28.2k | { |
2246 | 28.2k | txArrayBindingNode* self = it; |
2247 | 28.2k | txCoder* coder = param; |
2248 | 28.2k | txNode* item = self->items->first; |
2249 | 28.2k | txInteger iterator; |
2250 | 28.2k | txInteger next; |
2251 | 28.2k | txInteger done; |
2252 | 28.2k | txInteger rest; |
2253 | 28.2k | txInteger result; |
2254 | 28.2k | txInteger selector; |
2255 | 28.2k | txInteger selection; |
2256 | 28.2k | txTargetCode* catchTarget; |
2257 | 28.2k | txTargetCode* normalTarget; |
2258 | 28.2k | txTargetCode* finallyTarget; |
2259 | | |
2260 | 28.2k | txTargetCode* returnTarget; |
2261 | 28.2k | txTargetCode* stepTarget; |
2262 | 28.2k | txTargetCode* doneTarget; |
2263 | 28.2k | txTargetCode* nextTarget; |
2264 | | |
2265 | 28.2k | iterator = fxCoderUseTemporaryVariable(param); |
2266 | 28.2k | next = fxCoderUseTemporaryVariable(param); |
2267 | 28.2k | done = fxCoderUseTemporaryVariable(param); |
2268 | 28.2k | selector = fxCoderUseTemporaryVariable(param); |
2269 | 28.2k | rest = fxCoderUseTemporaryVariable(param); |
2270 | 28.2k | result = fxCoderUseTemporaryVariable(param); |
2271 | | |
2272 | 28.2k | coder->returnTarget = fxCoderAliasTargets(param, coder->returnTarget); |
2273 | 28.2k | catchTarget = fxCoderCreateTarget(param); |
2274 | 28.2k | normalTarget = fxCoderCreateTarget(param); |
2275 | 28.2k | finallyTarget = fxCoderCreateTarget(param); |
2276 | | |
2277 | 28.2k | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2278 | 28.2k | fxCoderAddByte(param, 0, XS_CODE_FOR_OF); |
2279 | 28.2k | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, iterator); |
2280 | 28.2k | fxCoderAddByte(param, 1, XS_CODE_FALSE); |
2281 | 28.2k | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, done); |
2282 | 28.2k | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, 0); |
2283 | 28.2k | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, selector); |
2284 | 28.2k | fxCoderAddBranch(param, 0, XS_CODE_CATCH_1, catchTarget); |
2285 | | |
2286 | 28.2k | if (item) { |
2287 | 470 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2288 | 470 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->nextSymbol); |
2289 | 470 | fxCoderAddIndex(param, 0, XS_CODE_PULL_LOCAL_1, next); |
2290 | | |
2291 | 68.2k | while (item && (item->description->token != XS_TOKEN_REST_BINDING)) { |
2292 | 67.8k | stepTarget = fxCoderCreateTarget(param); |
2293 | | |
2294 | 67.8k | if (item->description->token == XS_TOKEN_SKIP_BINDING) { |
2295 | 49.3k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, done); |
2296 | 49.3k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, stepTarget); |
2297 | 49.3k | fxCoderAddByte(param, 1, XS_CODE_TRUE); |
2298 | 49.3k | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, done); |
2299 | 49.3k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2300 | 49.3k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, next); |
2301 | 49.3k | fxCoderAddByte(param, 1, XS_CODE_CALL); |
2302 | 49.3k | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
2303 | 49.3k | fxCoderAddByte(param, 0, XS_CODE_CHECK_INSTANCE); |
2304 | 49.3k | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->doneSymbol); |
2305 | 49.3k | fxCoderAddIndex(param, 0, XS_CODE_PULL_LOCAL_1, done); |
2306 | 49.3k | fxCoderAdd(param, 1, stepTarget); |
2307 | 49.3k | } |
2308 | 18.4k | else { |
2309 | 18.4k | doneTarget = fxCoderCreateTarget(param); |
2310 | 18.4k | nextTarget = fxCoderCreateTarget(param); |
2311 | 18.4k | fxNodeDispatchCodeReference(item, param, 1); |
2312 | | |
2313 | 18.4k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, done); |
2314 | 18.4k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, stepTarget); |
2315 | 18.4k | fxCoderAddByte(param, 1, XS_CODE_TRUE); |
2316 | 18.4k | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, done); |
2317 | 18.4k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2318 | 18.4k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, next); |
2319 | 18.4k | fxCoderAddByte(param, 1, XS_CODE_CALL); |
2320 | 18.4k | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
2321 | 18.4k | fxCoderAddByte(param, 0, XS_CODE_CHECK_INSTANCE); |
2322 | 18.4k | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2323 | 18.4k | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->doneSymbol); |
2324 | 18.4k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, done); |
2325 | 18.4k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, doneTarget); |
2326 | 18.4k | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->valueSymbol); |
2327 | 18.4k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, nextTarget); |
2328 | 18.4k | fxCoderAdd(param, 1, doneTarget); |
2329 | 18.4k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2330 | 18.4k | fxCoderAdd(param, 1, stepTarget); |
2331 | 18.4k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
2332 | 18.4k | fxCoderAdd(param, 1, nextTarget); |
2333 | 18.4k | fxNodeDispatchCodeAssign(item, param, 1); |
2334 | 18.4k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2335 | 18.4k | } |
2336 | 67.8k | item = item->next; |
2337 | 67.8k | } |
2338 | 470 | if (item) { |
2339 | 16 | nextTarget = fxCoderCreateTarget(param); |
2340 | 16 | doneTarget = fxCoderCreateTarget(param); |
2341 | | |
2342 | 16 | fxNodeDispatchCodeReference(((txRestBindingNode*)item)->binding, param, 1); |
2343 | 16 | fxCoderAddByte(param, 1, XS_CODE_ARRAY); |
2344 | 16 | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, rest); |
2345 | | |
2346 | 16 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, done); |
2347 | 16 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, doneTarget); |
2348 | | |
2349 | 16 | fxCoderAdd(param, 0, nextTarget); |
2350 | 16 | fxCoderAddByte(param, 1, XS_CODE_TRUE); |
2351 | 16 | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, done); |
2352 | 16 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2353 | 16 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, next); |
2354 | 16 | fxCoderAddByte(param, 1, XS_CODE_CALL); |
2355 | 16 | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
2356 | 16 | fxCoderAddByte(param, 0, XS_CODE_CHECK_INSTANCE); |
2357 | 16 | fxCoderAddIndex(param, 1, XS_CODE_SET_LOCAL_1, result); |
2358 | 16 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->doneSymbol); |
2359 | 16 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, done); |
2360 | | |
2361 | 16 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, doneTarget); |
2362 | | |
2363 | 16 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, rest); |
2364 | 16 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2365 | 16 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->lengthSymbol); |
2366 | 16 | fxCoderAddByte(param, 0, XS_CODE_AT); |
2367 | 16 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, result); |
2368 | 16 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->valueSymbol); |
2369 | 16 | fxCoderAddByte(param, -2, XS_CODE_SET_PROPERTY_AT); |
2370 | 16 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2371 | | |
2372 | 16 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, nextTarget); |
2373 | 16 | fxCoderAdd(param, 1, doneTarget); |
2374 | | |
2375 | 16 | fxCoderAddIndex(param, 0, XS_CODE_GET_LOCAL_1, rest); |
2376 | 16 | fxNodeDispatchCodeAssign(((txRestBindingNode*)item)->binding, param, 1); |
2377 | 16 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2378 | 16 | } |
2379 | | |
2380 | 470 | } |
2381 | 28.2k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, normalTarget); |
2382 | | |
2383 | 28.2k | selection = 1; |
2384 | 28.2k | coder->returnTarget = fxCoderFinalizeTargets(param, coder->returnTarget, selector, &selection, finallyTarget); |
2385 | 28.2k | fxCoderAdd(param, 0, normalTarget); |
2386 | 28.2k | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, selection); |
2387 | 28.2k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, selector); |
2388 | 28.2k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2389 | 28.2k | fxCoderAdd(param, 0, finallyTarget); |
2390 | 28.2k | fxCoderAddByte(param, 0, XS_CODE_UNCATCH); |
2391 | 28.2k | fxCoderAdd(param, 0, catchTarget); |
2392 | | |
2393 | 28.2k | nextTarget = fxCoderCreateTarget(param); |
2394 | 28.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, selector); |
2395 | 28.2k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, nextTarget); |
2396 | 28.2k | fxCoderAddByte(param, 1, XS_CODE_EXCEPTION); |
2397 | 28.2k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, result); |
2398 | 28.2k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2399 | 28.2k | catchTarget = fxCoderCreateTarget(param); |
2400 | 28.2k | fxCoderAddBranch(param, 0, XS_CODE_CATCH_1, catchTarget); |
2401 | 28.2k | fxCoderAdd(param, 0, nextTarget); |
2402 | | |
2403 | 28.2k | doneTarget = fxCoderCreateTarget(param); |
2404 | 28.2k | returnTarget = fxCoderCreateTarget(param); |
2405 | 28.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, done); |
2406 | 28.2k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, doneTarget); |
2407 | 28.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2408 | 28.2k | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->returnSymbol); |
2409 | 28.2k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_CHAIN_1, returnTarget); |
2410 | 28.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2411 | 28.2k | fxCoderAddByte(param, 0, XS_CODE_SWAP); |
2412 | 28.2k | fxCoderAddByte(param, 1, XS_CODE_CALL); |
2413 | 28.2k | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
2414 | 28.2k | fxCoderAddByte(param, 0, XS_CODE_CHECK_INSTANCE); |
2415 | 28.2k | fxCoderAdd(param, 0, returnTarget); |
2416 | 28.2k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2417 | 28.2k | fxCoderAdd(param, 0, doneTarget); |
2418 | | |
2419 | 28.2k | nextTarget = fxCoderCreateTarget(param); |
2420 | 28.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, selector); |
2421 | 28.2k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, nextTarget); |
2422 | 28.2k | fxCoderAddByte(param, 0, XS_CODE_UNCATCH); |
2423 | 28.2k | fxCoderAdd(param, 0, catchTarget); |
2424 | 28.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, result); |
2425 | 28.2k | fxCoderAddByte(param, -1, XS_CODE_THROW); |
2426 | 28.2k | fxCoderAdd(param, 0, nextTarget); |
2427 | | |
2428 | 28.2k | selection = 1; |
2429 | 28.2k | fxCoderJumpTargets(param, coder->returnTarget, selector, &selection); |
2430 | | |
2431 | 28.2k | fxCoderUnuseTemporaryVariables(param, 6); |
2432 | 28.2k | } |
2433 | | |
2434 | | void fxAssignNodeCode(void* it, void* param) |
2435 | 47.7k | { |
2436 | 47.7k | txAssignNode* self = it; |
2437 | 47.7k | fxNodeDispatchCodeReference(self->reference, param, 1); |
2438 | 47.7k | fxNodeDispatchCode(self->value, param); |
2439 | 47.7k | fxNodeDispatchCodeAssign(self->reference, param, 1); |
2440 | 47.7k | } |
2441 | | |
2442 | | void fxAwaitNodeCode(void* it, void* param) |
2443 | 580 | { |
2444 | 580 | txStatementNode* self = it; |
2445 | 580 | txCoder* coder = param; |
2446 | 580 | txTargetCode* target = fxCoderCreateTarget(coder); |
2447 | 580 | fxNodeDispatchCode(self->expression, param); |
2448 | 580 | fxCoderAddByte(param, 0, XS_CODE_AWAIT); |
2449 | 580 | fxCoderAddBranch(coder, 1, XS_CODE_BRANCH_STATUS_1, target); |
2450 | 580 | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
2451 | 580 | fxCoderAdjustEnvironment(coder, coder->returnTarget); |
2452 | 580 | fxCoderAdjustScope(coder, coder->returnTarget); |
2453 | 580 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, coder->returnTarget); |
2454 | 580 | fxCoderAdd(coder, 0, target); |
2455 | 580 | } |
2456 | | |
2457 | | void fxBigIntNodeCode(void* it, void* param) |
2458 | 32.1k | { |
2459 | 32.1k | txBigIntNode* self = it; |
2460 | 32.1k | fxCoderAddBigInt(param, 1, XS_CODE_BIGINT_1, &self->value); |
2461 | 32.1k | } |
2462 | | |
2463 | | void fxBinaryExpressionNodeCode(void* it, void* param) |
2464 | 87.0k | { |
2465 | 87.0k | txBinaryExpressionNode* self = it; |
2466 | 87.0k | fxNodeDispatchCode(self->left, param); |
2467 | 87.0k | fxNodeDispatchCode(self->right, param); |
2468 | 87.0k | fxCoderAddByte(param, -1, self->description->code); |
2469 | 87.0k | } |
2470 | | |
2471 | | void fxBindingNodeCode(void* it, void* param) |
2472 | 46.1k | { |
2473 | 46.1k | txBindingNode* self = it; |
2474 | 46.1k | txCoder* coder = param; |
2475 | | |
2476 | 46.1k | if (self->target->description->token == XS_TOKEN_ACCESS) { |
2477 | 3 | fxReportParserError(coder->parser, self->line, "invalid initializer"); |
2478 | 3 | fxNodeDispatchCode(self->initializer, param); |
2479 | 3 | return; |
2480 | 3 | } |
2481 | | |
2482 | 46.1k | fxNodeDispatchCodeReference(self->target, param, 0); |
2483 | 46.1k | fxNodeDispatchCode(self->initializer, param); |
2484 | 46.1k | fxNodeDispatchCodeAssign(self->target, param, 0); |
2485 | 46.1k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
2486 | 46.1k | } |
2487 | | |
2488 | | void fxBindingNodeCodeAssign(void* it, void* param, txFlag flag) |
2489 | 333 | { |
2490 | 333 | txBindingNode* self = it; |
2491 | 333 | txTargetCode* target = fxCoderCreateTarget(param); |
2492 | 333 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2493 | 333 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
2494 | 333 | fxCoderAddByte(param, -1, XS_CODE_STRICT_NOT_EQUAL); |
2495 | 333 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, target); |
2496 | 333 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2497 | 333 | fxNodeDispatchCode(self->initializer, param); |
2498 | 333 | fxCoderAdd(param, 0, target); |
2499 | 333 | fxNodeDispatchCodeAssign(self->target, param, flag); |
2500 | 333 | } |
2501 | | |
2502 | | void fxBindingNodeCodeReference(void* it, void* param, txFlag flag) |
2503 | 333 | { |
2504 | 333 | txBindingNode* self = it; |
2505 | 333 | fxNodeDispatchCodeReference(self->target, param, flag); |
2506 | 333 | } |
2507 | | |
2508 | | void fxBlockNodeCode(void* it, void* param) |
2509 | 9.09k | { |
2510 | 9.09k | txBlockNode* self = it; |
2511 | 9.09k | fxScopeCodingBlock(self->scope, param); |
2512 | 9.09k | fxScopeCodeDefineNodes(self->scope, param); |
2513 | 9.09k | fxScopeCodeUsingStatement(self->scope, param, self->statement); |
2514 | 9.09k | fxScopeCoded(self->scope, param); |
2515 | 9.09k | } |
2516 | | |
2517 | | void fxBodyNodeCode(void* it, void* param) |
2518 | 151k | { |
2519 | 151k | txBlockNode* self = it; |
2520 | 151k | txCoder* coder = param; |
2521 | 151k | txBoolean evalFlag = coder->evalFlag; |
2522 | 151k | if ((self->flags & mxEvalFlag) && !(self->flags & mxStrictFlag)) |
2523 | 1.88k | coder->evalFlag = 1; |
2524 | 151k | fxScopeCodingBody(self->scope, param); |
2525 | 151k | fxScopeCodeDefineNodes(self->scope, param); |
2526 | 151k | fxScopeCodeUsingStatement(self->scope, param, self->statement); |
2527 | 151k | fxScopeCodedBody(self->scope, param); |
2528 | 151k | if ((self->flags & mxEvalFlag) && !(self->flags & mxStrictFlag)) |
2529 | 1.88k | coder->evalFlag = evalFlag; |
2530 | 151k | } |
2531 | | |
2532 | | void fxBreakContinueNodeCode(void* it, void* param) |
2533 | 4.48k | { |
2534 | 4.48k | txBreakContinueNode* self = it; |
2535 | 4.48k | txCoder* coder = param; |
2536 | 4.48k | txTargetCode* target = (self->description->token == XS_TOKEN_BREAK) ? coder->firstBreakTarget : coder->firstContinueTarget; |
2537 | 6.47k | while (target) { |
2538 | 2.35k | txLabelNode* label = target->label; |
2539 | 8.34k | while (label) { |
2540 | 6.35k | if (label->symbol == self->symbol) { |
2541 | 359 | fxCoderAdjustEnvironment(coder, target); |
2542 | 359 | fxCoderAdjustScope(coder, target); |
2543 | 359 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, target); |
2544 | 359 | return; |
2545 | 359 | } |
2546 | 5.99k | label = label->nextLabel; |
2547 | 5.99k | } |
2548 | 1.99k | target = target->nextTarget; |
2549 | 1.99k | } |
2550 | 4.12k | if (self->description->token == XS_TOKEN_BREAK) |
2551 | 1.99k | fxReportParserError(coder->parser, self->line, "invalid break"); |
2552 | 2.12k | else |
2553 | 2.12k | fxReportParserError(coder->parser, self->line, "invalid continue"); |
2554 | 4.12k | } |
2555 | | |
2556 | | void fxCallNodeCode(void* it, void* param) |
2557 | 132k | { |
2558 | 132k | txCallNewNode* self = it; |
2559 | 132k | fxNodeDispatchCodeThis(self->reference, param, 0); |
2560 | 132k | fxCoderAddByte(param, 1, XS_CODE_CALL); |
2561 | 132k | self->params->flags |= self->flags & mxTailRecursionFlag; |
2562 | 132k | fxNodeDispatchCode(self->params, param); |
2563 | 132k | } |
2564 | | |
2565 | | void fxCatchNodeCode(void* it, void* param) |
2566 | 2.19k | { |
2567 | 2.19k | txCatchNode* self = it; |
2568 | 2.19k | if (self->parameter) { |
2569 | 2.07k | fxScopeCodingBlock(self->scope, param); |
2570 | 2.07k | fxNodeDispatchCodeReference(self->parameter, param, 0); |
2571 | 2.07k | fxCoderAddByte(param, 1, XS_CODE_EXCEPTION); |
2572 | 2.07k | fxNodeDispatchCodeAssign(self->parameter, param, 0); |
2573 | 2.07k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2574 | 2.07k | fxScopeCodingBlock(self->statementScope, param); |
2575 | 2.07k | fxScopeCodeDefineNodes(self->statementScope, param); |
2576 | 2.07k | fxScopeCodeUsingStatement(self->statementScope, param, self->statement); |
2577 | 2.07k | fxScopeCoded(self->statementScope, param); |
2578 | 2.07k | fxScopeCoded(self->scope, param); |
2579 | 2.07k | } |
2580 | 112 | else { |
2581 | 112 | fxScopeCodingBlock(self->statementScope, param); |
2582 | 112 | fxScopeCodeDefineNodes(self->statementScope, param); |
2583 | 112 | fxScopeCodeUsingStatement(self->statementScope, param, self->statement); |
2584 | 112 | fxScopeCoded(self->statementScope, param); |
2585 | 112 | } |
2586 | 2.19k | } |
2587 | | |
2588 | | void fxChainNodeCode(void* it, void* param) |
2589 | 1.09k | { |
2590 | 1.09k | txUnaryExpressionNode* self = it; |
2591 | 1.09k | txCoder* coder = param; |
2592 | 1.09k | txTargetCode* chainTarget = coder->chainTarget; |
2593 | 1.09k | coder->chainTarget = fxCoderCreateTarget(param); |
2594 | 1.09k | fxNodeDispatchCode(self->right, param); |
2595 | 1.09k | fxCoderAdd(param, 0, coder->chainTarget); |
2596 | 1.09k | coder->chainTarget = chainTarget; |
2597 | 1.09k | } |
2598 | | |
2599 | | txFlag fxChainNodeCodeThis(void* it, void* param, txFlag flag) |
2600 | 18 | { |
2601 | 18 | txUnaryExpressionNode* self = it; |
2602 | 18 | txCoder* coder = param; |
2603 | 18 | txTargetCode* chainTarget = coder->chainTarget; |
2604 | 18 | coder->chainTarget = fxCoderCreateTarget(param); |
2605 | 18 | flag = fxNodeDispatchCodeThis(self->right, param, flag); |
2606 | 18 | fxCoderAdd(param, 0, coder->chainTarget); |
2607 | 18 | coder->chainTarget = chainTarget; |
2608 | 18 | return flag; |
2609 | 18 | } |
2610 | | |
2611 | | void fxClassNodeCode(void* it, void* param) |
2612 | 4.06k | { |
2613 | 4.06k | txClassNode* self = it; |
2614 | 4.06k | txCoder* coder = param; |
2615 | 4.06k | txClassNode* former = coder->classNode; |
2616 | 4.06k | txFlag flag; |
2617 | 4.06k | txInteger prototype = fxCoderUseTemporaryVariable(coder); |
2618 | 4.06k | txInteger constructor = fxCoderUseTemporaryVariable(coder); |
2619 | 4.06k | txDeclareNode* declaration = self->scope->firstDeclareNode; |
2620 | 4.06k | txNode* item = self->items->first; |
2621 | 4.06k | if (self->symbol) |
2622 | 3.76k | fxScopeCodingBlock(self->symbolScope, param); |
2623 | 4.06k | if (self->heritage) { |
2624 | 247 | if (self->heritage->description->token == XS_TOKEN_HOST) { |
2625 | 0 | fxCoderAddByte(param, 1, XS_CODE_NULL); |
2626 | 0 | fxNodeDispatchCode(self->heritage, param); |
2627 | 0 | } |
2628 | 247 | else { |
2629 | 247 | fxNodeDispatchCode(self->heritage, param); |
2630 | 247 | fxCoderAddByte(param, 1, XS_CODE_EXTEND); |
2631 | 247 | } |
2632 | 247 | } |
2633 | 3.81k | else { |
2634 | 3.81k | fxCoderAddByte(param, 1, XS_CODE_NULL); |
2635 | 3.81k | fxCoderAddByte(param, 1, XS_CODE_OBJECT); |
2636 | 3.81k | } |
2637 | 4.06k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, prototype); |
2638 | 4.06k | fxScopeCodingBlock(self->scope, param); |
2639 | | |
2640 | 4.06k | coder->classNode = self; |
2641 | 4.06k | fxNodeDispatchCode(self->constructor, param); |
2642 | | |
2643 | 4.06k | fxCoderAddByte(param, 0, XS_CODE_TO_INSTANCE); |
2644 | 4.06k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, constructor); |
2645 | 4.06k | fxCoderAddByte(param, -3, XS_CODE_CLASS); |
2646 | 4.06k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, constructor); |
2647 | 4.06k | if (self->symbol) |
2648 | 3.76k | fxCoderAddSymbol(param, 0, XS_CODE_NAME, self->symbol); |
2649 | | |
2650 | 17.6k | while (item) { |
2651 | 13.5k | if (item->description->token == XS_TOKEN_PROPERTY) { |
2652 | 4.35k | txPropertyNode* property = (txPropertyNode*)item; |
2653 | 4.35k | if (item->flags & (mxMethodFlag | mxGetterFlag | mxSetterFlag)) { |
2654 | 544 | if (item->flags & mxStaticFlag) |
2655 | 41 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2656 | 503 | else |
2657 | 503 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, prototype); |
2658 | 544 | fxNodeDispatchCode(property->value, param); |
2659 | 544 | fxCoderAddSymbol(param, -2, XS_CODE_NEW_PROPERTY, property->symbol); |
2660 | 544 | flag = XS_DONT_ENUM_FLAG; |
2661 | 544 | if (item->flags & mxMethodFlag) |
2662 | 189 | flag |= XS_NAME_FLAG | XS_METHOD_FLAG; |
2663 | 355 | else if (item->flags & mxGetterFlag) |
2664 | 93 | flag |= XS_NAME_FLAG | XS_METHOD_FLAG | XS_GETTER_FLAG; |
2665 | 262 | else if (item->flags & mxSetterFlag) |
2666 | 47 | flag |= XS_NAME_FLAG | XS_METHOD_FLAG | XS_SETTER_FLAG; |
2667 | 544 | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, flag); |
2668 | 544 | } |
2669 | 4.35k | } |
2670 | 9.18k | else if (item->description->token == XS_TOKEN_PROPERTY_AT) { |
2671 | 3.90k | txPropertyAtNode* property = (txPropertyAtNode*)item; |
2672 | 3.90k | if (item->flags & (mxMethodFlag | mxGetterFlag | mxSetterFlag)) { |
2673 | 105 | if (item->flags & mxStaticFlag) |
2674 | 89 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2675 | 16 | else |
2676 | 16 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, prototype); |
2677 | 105 | fxNodeDispatchCode(property->at, param); |
2678 | 105 | fxCoderAddByte(param, 0, XS_CODE_AT); |
2679 | 105 | fxNodeDispatchCode(property->value, param); |
2680 | 105 | fxCoderAddByte(param, -3, XS_CODE_NEW_PROPERTY_AT); |
2681 | 105 | flag = XS_DONT_ENUM_FLAG; |
2682 | 105 | if (item->flags & mxMethodFlag) |
2683 | 84 | flag |= XS_NAME_FLAG | XS_METHOD_FLAG; |
2684 | 21 | else if (item->flags & mxGetterFlag) |
2685 | 17 | flag |= XS_NAME_FLAG | XS_METHOD_FLAG | XS_GETTER_FLAG; |
2686 | 4 | else if (item->flags & mxSetterFlag) |
2687 | 4 | flag |= XS_NAME_FLAG | XS_METHOD_FLAG | XS_SETTER_FLAG; |
2688 | 105 | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, flag); |
2689 | 105 | } |
2690 | 3.80k | else { |
2691 | 3.80k | fxNodeDispatchCode(property->at, param); |
2692 | 3.80k | fxCoderAddByte(param, 0, XS_CODE_AT); |
2693 | 3.80k | fxCoderAddIndex(param, 0, XS_CODE_CONST_CLOSURE_1, declaration->index); |
2694 | 3.80k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2695 | 3.80k | declaration = declaration->nextDeclareNode; |
2696 | 3.80k | } |
2697 | 3.90k | } |
2698 | 5.27k | else { |
2699 | 5.27k | txPrivatePropertyNode* property = (txPrivatePropertyNode*)item; |
2700 | 5.27k | fxCoderAddIndex(param, 0, XS_CODE_CONST_CLOSURE_1, declaration->index); |
2701 | 5.27k | declaration = declaration->nextDeclareNode; |
2702 | 5.27k | if (item->flags & (mxMethodFlag | mxGetterFlag | mxSetterFlag)) { |
2703 | 2.48k | fxNodeDispatchCode(property->value, param); |
2704 | 2.48k | fxCoderAddIndex(param, 0, XS_CODE_CONST_CLOSURE_1, declaration->index); |
2705 | 2.48k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2706 | 2.48k | declaration = declaration->nextDeclareNode; |
2707 | 2.48k | } |
2708 | 5.27k | } |
2709 | 13.5k | item = item->next; |
2710 | 13.5k | } |
2711 | 4.06k | if (self->symbol) |
2712 | 2.83k | fxCoderAddIndex(param, 0, XS_CODE_CONST_CLOSURE_1, self->symbolScope->firstDeclareNode->index); |
2713 | 4.06k | if (self->instanceInit) { |
2714 | 2.16k | fxNodeDispatchCode(self->instanceInit, param); |
2715 | 2.16k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, prototype); |
2716 | 2.16k | fxCoderAddByte(param, -1, XS_CODE_SET_HOME); |
2717 | 2.16k | fxCoderAddIndex(param, 0, XS_CODE_CONST_CLOSURE_1, declaration->index); |
2718 | 2.16k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2719 | 2.16k | } |
2720 | 4.06k | if (self->constructorInit) { |
2721 | 174 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, constructor); |
2722 | 174 | fxNodeDispatchCode(self->constructorInit, param); |
2723 | 174 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, constructor); |
2724 | 174 | fxCoderAddByte(param, -1, XS_CODE_SET_HOME); |
2725 | 174 | fxCoderAddByte(param, 1, XS_CODE_CALL); |
2726 | 174 | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
2727 | 174 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2728 | 174 | } |
2729 | 4.06k | coder->classNode = former; |
2730 | 4.06k | fxScopeCoded(self->scope, param); |
2731 | 4.06k | if (self->symbol) |
2732 | 2.83k | fxScopeCoded(self->symbolScope, param); |
2733 | 4.06k | fxCoderUnuseTemporaryVariables(coder, 2); |
2734 | 4.06k | } |
2735 | | |
2736 | | void fxCoalesceExpressionNodeCode(void* it, void* param) |
2737 | 338 | { |
2738 | 338 | txBinaryExpressionNode* self = it; |
2739 | 338 | txTargetCode* endTarget = fxCoderCreateTarget(param); |
2740 | 338 | self->right->flags |= (self->flags & mxTailRecursionFlag); |
2741 | 338 | fxNodeDispatchCode(self->left, param); |
2742 | 338 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_COALESCE_1, endTarget); |
2743 | 338 | fxNodeDispatchCode(self->right, param); |
2744 | 338 | fxCoderAdd(param, 0, endTarget); |
2745 | 338 | } |
2746 | | |
2747 | | void fxCompoundExpressionNodeCode(void* it, void* param) |
2748 | 4.70k | { |
2749 | 4.70k | txAssignNode* self = it; |
2750 | 4.70k | txCoder* coder = param; |
2751 | 4.70k | txToken token = self->description->token; |
2752 | 4.70k | txFlag shortcut = ((token == XS_TOKEN_AND_ASSIGN) || (token == XS_TOKEN_COALESCE_ASSIGN) || (token == XS_TOKEN_OR_ASSIGN)) ? 1 : 0; |
2753 | 4.70k | txTargetCode* elseTarget = (shortcut) ? fxCoderCreateTarget(param) : C_NULL; |
2754 | 4.70k | txTargetCode* endTarget = (shortcut) ? fxCoderCreateTarget(param) : C_NULL; |
2755 | 4.70k | txInteger stackLevel; |
2756 | 4.70k | txFlag swap = fxNodeDispatchCodeThis(self->reference, param, 1); |
2757 | 4.70k | switch (self->description->token) { |
2758 | 588 | case XS_TOKEN_AND_ASSIGN: |
2759 | 588 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2760 | 588 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, elseTarget); |
2761 | 588 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2762 | 588 | fxNodeDispatchCode(self->value, param); |
2763 | 588 | fxCompoundExpressionNodeCodeName(it, param); |
2764 | 588 | stackLevel = coder->stackLevel; |
2765 | 588 | break; |
2766 | 340 | case XS_TOKEN_COALESCE_ASSIGN: |
2767 | 340 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_COALESCE_1, elseTarget); |
2768 | 340 | fxNodeDispatchCode(self->value, param); |
2769 | 340 | fxCompoundExpressionNodeCodeName(it, param); |
2770 | 340 | stackLevel = coder->stackLevel; |
2771 | 340 | break; |
2772 | 666 | case XS_TOKEN_OR_ASSIGN: |
2773 | 666 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2774 | 666 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, elseTarget); |
2775 | 666 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2776 | 666 | fxNodeDispatchCode(self->value, param); |
2777 | 666 | fxCompoundExpressionNodeCodeName(it, param); |
2778 | 666 | stackLevel = coder->stackLevel; |
2779 | 666 | break; |
2780 | 3.11k | default: |
2781 | 3.11k | fxNodeDispatchCode(self->value, param); |
2782 | 3.11k | fxCoderAddByte(param, -1, self->description->code); |
2783 | 3.11k | break; |
2784 | 4.70k | } |
2785 | 4.70k | fxNodeDispatchCodeAssign(self->reference, param, 0); |
2786 | 4.70k | if (shortcut) { |
2787 | 1.59k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, endTarget); |
2788 | 1.59k | coder->stackLevel = stackLevel; |
2789 | 1.59k | fxCoderAdd(param, 0, elseTarget); |
2790 | 2.69k | while (swap > 0) { |
2791 | 1.09k | if (!(self->flags & mxExpressionNoValue)) |
2792 | 1.07k | fxCoderAddByte(param, 0, XS_CODE_SWAP); |
2793 | 1.09k | fxCoderAddByte(param, -1, XS_CODE_POP); |
2794 | 1.09k | swap--; |
2795 | 1.09k | } |
2796 | 1.59k | fxCoderAdd(param, 0, endTarget); |
2797 | 1.59k | } |
2798 | 4.70k | } |
2799 | | |
2800 | | void fxCompoundExpressionNodeCodeName(void* it, void* param) |
2801 | 1.59k | { |
2802 | 1.59k | txAssignNode* self = it; |
2803 | 1.59k | txAccessNode* reference = (txAccessNode*)(self->reference); |
2804 | 1.59k | txToken token = reference->description->token; |
2805 | 1.59k | txNode* value = self->value; |
2806 | 1.59k | if (token != XS_TOKEN_ACCESS) |
2807 | 80 | return; |
2808 | 1.51k | if (fxNodeCodeName(value)) |
2809 | 197 | fxCoderAddSymbol(param, 0, XS_CODE_NAME, reference->symbol); |
2810 | 1.51k | } |
2811 | | |
2812 | | void fxDebuggerNodeCode(void* it, void* param) |
2813 | 383 | { |
2814 | 383 | fxCoderAddByte(param, 0, XS_CODE_DEBUGGER); |
2815 | 383 | } |
2816 | | |
2817 | | void fxDeclareNodeCode(void* it, void* param) |
2818 | 19.3k | { |
2819 | 19.3k | txDeclareNode* self = it; |
2820 | 19.3k | txCoder* coder = param; |
2821 | 19.3k | if (self->description->token == XS_TOKEN_CONST) |
2822 | 4.58k | fxReportParserError(coder->parser, self->line, "invalid const"); |
2823 | 14.7k | else if (self->description->token == XS_TOKEN_LET) { |
2824 | 892 | fxNodeDispatchCodeReference(self, param, 0); |
2825 | 892 | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
2826 | 892 | fxNodeDispatchCodeAssign(self, param, 0); |
2827 | 892 | fxCoderAddByte(coder, -1, XS_CODE_POP); |
2828 | 892 | } |
2829 | 13.8k | else if (self->description->token == XS_TOKEN_USING) |
2830 | 928 | fxReportParserError(coder->parser, self->line, "invalid using"); |
2831 | 19.3k | } |
2832 | | |
2833 | | void fxDeclareNodeCodeAssign(void* it, void* param, txFlag flag) |
2834 | 210k | { |
2835 | 210k | txDeclareNode* self = it; |
2836 | 210k | txDeclareNode* declaration = self->declaration; |
2837 | 210k | if (!declaration) |
2838 | 56.5k | fxCoderAddSymbol(param, -1, XS_CODE_SET_VARIABLE, self->symbol); |
2839 | 153k | else { |
2840 | 153k | if (self->description->token == XS_TOKEN_CONST) |
2841 | 106k | fxCoderAddIndex(param, 0, (declaration->flags & mxDeclareNodeClosureFlag) ? XS_CODE_CONST_CLOSURE_1: XS_CODE_CONST_LOCAL_1, declaration->index); |
2842 | 47.4k | else if (self->description->token == XS_TOKEN_LET) |
2843 | 12.5k | fxCoderAddIndex(param, 0, (declaration->flags & mxDeclareNodeClosureFlag) ? XS_CODE_LET_CLOSURE_1: XS_CODE_LET_LOCAL_1, declaration->index); |
2844 | 34.8k | else if (self->description->token == XS_TOKEN_USING) { |
2845 | 0 | fxCoderAddIndex(param, 0, (declaration->flags & mxDeclareNodeClosureFlag) ? XS_CODE_CONST_CLOSURE_1: XS_CODE_CONST_LOCAL_1, declaration->index); |
2846 | 0 | if (self->flags & mxAwaitingFlag) |
2847 | 0 | fxCoderAddByte(param, 0, XS_CODE_USING_ASYNC); |
2848 | 0 | else |
2849 | 0 | fxCoderAddByte(param, 0, XS_CODE_USING); |
2850 | 0 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, declaration->index + 1); |
2851 | 0 | } |
2852 | 34.8k | else |
2853 | 34.8k | fxCoderAddIndex(param, 0, (declaration->flags & mxDeclareNodeClosureFlag) ? XS_CODE_VAR_CLOSURE_1 : XS_CODE_VAR_LOCAL_1, declaration->index); |
2854 | 153k | } |
2855 | 210k | } |
2856 | | |
2857 | | void fxDeclareNodeCodeReference(void* it, void* param, txFlag flag) |
2858 | 211k | { |
2859 | 211k | txAccessNode* self = it; |
2860 | 211k | txCoder* coder = param; |
2861 | 211k | txDeclareNode* declaration = self->declaration; |
2862 | 211k | if (!declaration) { |
2863 | 56.5k | if (coder->evalFlag) |
2864 | 4.92k | fxCoderAddSymbol(param, 1, XS_CODE_EVAL_REFERENCE, self->symbol); |
2865 | 51.6k | else |
2866 | 51.6k | fxCoderAddSymbol(param, 1, XS_CODE_PROGRAM_REFERENCE, self->symbol); |
2867 | 56.5k | } |
2868 | 211k | } |
2869 | | |
2870 | | void fxDefineNodeCode(void* it, void* param) |
2871 | 105k | { |
2872 | 105k | txDefineNode* self = it; |
2873 | 105k | txCoder* coder = param; |
2874 | 105k | if (self->flags & mxDefineNodeCodedFlag) |
2875 | 3.61k | return; |
2876 | 101k | self->flags |= mxDefineNodeCodedFlag; |
2877 | 101k | fxDeclareNodeCodeReference(it, param, 0); |
2878 | 101k | fxNodeDispatchCode(self->initializer, coder); |
2879 | 101k | self->initializer = C_NULL; |
2880 | 101k | fxDeclareNodeCodeAssign(it, param, 0); |
2881 | 101k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
2882 | 101k | } |
2883 | | |
2884 | | void fxDelegateNodeCode(void* it, void* param) |
2885 | 51 | { |
2886 | 51 | txStatementNode* self = it; |
2887 | 51 | txBoolean async = (self->flags & mxAsyncFlag) ? 1 : 0; |
2888 | 51 | txCoder* coder = param; |
2889 | 51 | txInteger iterator; |
2890 | 51 | txInteger method; |
2891 | 51 | txInteger next; |
2892 | 51 | txInteger result; |
2893 | | |
2894 | 51 | txTargetCode* nextTarget = fxCoderCreateTarget(param); |
2895 | 51 | txTargetCode* catchTarget = fxCoderCreateTarget(param); |
2896 | 51 | txTargetCode* rethrowTarget = fxCoderCreateTarget(param); |
2897 | 51 | txTargetCode* returnTarget = fxCoderCreateTarget(param); |
2898 | 51 | txTargetCode* normalTarget = fxCoderCreateTarget(param); |
2899 | 51 | txTargetCode* doneTarget = fxCoderCreateTarget(param); |
2900 | | |
2901 | 51 | iterator = fxCoderUseTemporaryVariable(param); |
2902 | 51 | method = fxCoderUseTemporaryVariable(param); |
2903 | 51 | next = fxCoderUseTemporaryVariable(param); |
2904 | 51 | result = fxCoderUseTemporaryVariable(param); |
2905 | | |
2906 | 51 | fxNodeDispatchCode(self->expression, param); |
2907 | 51 | if (async) |
2908 | 9 | fxCoderAddByte(param, 0, XS_CODE_FOR_AWAIT_OF); |
2909 | 42 | else |
2910 | 42 | fxCoderAddByte(param, 0, XS_CODE_FOR_OF); |
2911 | 51 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, iterator); |
2912 | 51 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->nextSymbol); |
2913 | 51 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, next); |
2914 | 51 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2915 | | |
2916 | 51 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
2917 | 51 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, result); |
2918 | 51 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2919 | 51 | fxCoderAddBranch(param, 0, XS_CODE_CATCH_1, catchTarget); |
2920 | 51 | fxCoderAddBranch(coder, 0, XS_CODE_BRANCH_1, normalTarget); |
2921 | | |
2922 | | // LOOP |
2923 | 51 | fxCoderAdd(param, 0, nextTarget); |
2924 | 51 | if (async) |
2925 | 9 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->valueSymbol); |
2926 | 51 | fxCoderAddByte(coder, 0, XS_CODE_YIELD_STAR); |
2927 | 51 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, result); |
2928 | 51 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2929 | 51 | fxCoderAddBranch(param, 0, XS_CODE_CATCH_1, catchTarget); |
2930 | 51 | fxCoderAddBranch(coder, 1, XS_CODE_BRANCH_STATUS_1, normalTarget); |
2931 | | |
2932 | | // RETURN |
2933 | 51 | fxCoderAddByte(param, 0, XS_CODE_UNCATCH); |
2934 | 51 | if (async) { |
2935 | 9 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, result); |
2936 | 9 | fxCoderAddByte(param, 0, XS_CODE_AWAIT); |
2937 | 9 | fxCoderAddByte(param, 0, XS_CODE_THROW_STATUS); |
2938 | 9 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, result); |
2939 | 9 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2940 | 9 | } |
2941 | | |
2942 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2943 | 51 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->returnSymbol); |
2944 | 51 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_CHAIN_1, returnTarget); |
2945 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2946 | 51 | fxCoderAddByte(param, 0, XS_CODE_SWAP); |
2947 | 51 | fxCoderAddByte(param, 1, XS_CODE_CALL); |
2948 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, result); |
2949 | 51 | fxCoderAddInteger(param, -3, XS_CODE_RUN_1, 1); |
2950 | 51 | if (async) { |
2951 | 9 | fxCoderAddByte(param, 0, XS_CODE_AWAIT); |
2952 | 9 | fxCoderAddByte(param, 0, XS_CODE_THROW_STATUS); |
2953 | 9 | } |
2954 | 51 | fxCoderAddByte(param, 0, XS_CODE_CHECK_INSTANCE); |
2955 | 51 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
2956 | 51 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->doneSymbol); |
2957 | 51 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, nextTarget); |
2958 | 51 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->valueSymbol); |
2959 | 51 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, result); |
2960 | 51 | fxCoderAdd(coder, 0, returnTarget); |
2961 | 51 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2962 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, result); |
2963 | 51 | if (async) { |
2964 | 9 | fxCoderAddByte(param, 0, XS_CODE_AWAIT); |
2965 | 9 | fxCoderAddByte(param, 0, XS_CODE_THROW_STATUS); |
2966 | 9 | } |
2967 | 51 | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
2968 | 51 | fxCoderAdjustEnvironment(coder, coder->returnTarget); |
2969 | 51 | fxCoderAdjustScope(coder, coder->returnTarget); |
2970 | 51 | fxCoderAddBranch(coder, 0, XS_CODE_BRANCH_1, coder->returnTarget); |
2971 | | |
2972 | | // THROW |
2973 | 51 | fxCoderAdd(coder, 0, catchTarget); |
2974 | | |
2975 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2976 | 51 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->throwSymbol); |
2977 | 51 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, method); |
2978 | 51 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_COALESCE_1, doneTarget); |
2979 | | |
2980 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2981 | 51 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->returnSymbol); |
2982 | 51 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_CHAIN_1, rethrowTarget); |
2983 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
2984 | 51 | fxCoderAddByte(param, 0, XS_CODE_SWAP); |
2985 | 51 | fxCoderAddByte(param, 1, XS_CODE_CALL); |
2986 | 51 | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
2987 | 51 | if (async) { |
2988 | 9 | fxCoderAddByte(param, 0, XS_CODE_AWAIT); |
2989 | 9 | fxCoderAddByte(param, 0, XS_CODE_THROW_STATUS); |
2990 | 9 | } |
2991 | 51 | fxCoderAddByte(param, 0, XS_CODE_CHECK_INSTANCE); |
2992 | 51 | fxCoderAdd(coder, 0, rethrowTarget); |
2993 | 51 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2994 | | |
2995 | 51 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
2996 | 51 | fxCoderAddByte(param, 0, XS_CODE_CHECK_INSTANCE); |
2997 | 51 | fxCoderAddByte(param, -1, XS_CODE_POP); |
2998 | | |
2999 | | // NORMAL |
3000 | 51 | fxCoderAdd(coder, 0, normalTarget); |
3001 | 51 | fxCoderAddByte(param, 0, XS_CODE_UNCATCH); |
3002 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, next); |
3003 | 51 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, method); |
3004 | 51 | fxCoderAdd(param, 1, doneTarget); |
3005 | 51 | fxCoderAddByte(param, -1, XS_CODE_POP); |
3006 | | |
3007 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
3008 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, method); |
3009 | 51 | fxCoderAddByte(param, 1, XS_CODE_CALL); |
3010 | 51 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, result); |
3011 | 51 | fxCoderAddInteger(param, -3, XS_CODE_RUN_1, 1); |
3012 | 51 | if (async) { |
3013 | 9 | fxCoderAddByte(param, 0, XS_CODE_AWAIT); |
3014 | 9 | fxCoderAddByte(param, 0, XS_CODE_THROW_STATUS); |
3015 | 9 | } |
3016 | 51 | fxCoderAddByte(param, 0, XS_CODE_CHECK_INSTANCE); |
3017 | 51 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
3018 | 51 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->doneSymbol); |
3019 | 51 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, nextTarget); |
3020 | 51 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->valueSymbol); |
3021 | | |
3022 | 51 | fxCoderUnuseTemporaryVariables(param, 4); |
3023 | 51 | } |
3024 | | |
3025 | | void fxDeleteNodeCode(void* it, void* param) |
3026 | 7.12k | { |
3027 | 7.12k | txDeleteNode* self = it; |
3028 | 7.12k | fxNodeDispatchCodeDelete(self->reference, param); |
3029 | 7.12k | } |
3030 | | |
3031 | | void fxDoNodeCode(void* it, void* param) |
3032 | 328 | { |
3033 | 328 | txDoNode* self = it; |
3034 | 328 | txCoder* coder = param; |
3035 | 328 | txTargetCode* loopTarget = fxCoderCreateTarget(param); |
3036 | 328 | if (coder->programFlag) { |
3037 | 299 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
3038 | 299 | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
3039 | 299 | } |
3040 | 328 | fxCoderAdd(param, 0, loopTarget); |
3041 | 328 | fxNodeDispatchCode(self->statement, param); |
3042 | 328 | fxCoderAdd(param, 0, coder->firstContinueTarget); |
3043 | 328 | fxNodeDispatchCode(self->expression, param); |
3044 | 328 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, loopTarget); |
3045 | 328 | } |
3046 | | |
3047 | | void fxExportNodeCode(void* it, void* param) |
3048 | 473 | { |
3049 | 473 | } |
3050 | | |
3051 | | void fxExpressionsNodeCode(void* it, void* param) |
3052 | 127k | { |
3053 | 127k | txExpressionsNode* self = it; |
3054 | 127k | if (self->items) { |
3055 | 127k | txNode* item = self->items->first; |
3056 | 127k | txNode* previous = NULL; |
3057 | 127k | txNode* next; |
3058 | 278k | while (item) { |
3059 | 151k | next = item->next; |
3060 | 151k | if (previous) |
3061 | 23.4k | fxCoderAddByte(param, -1, XS_CODE_POP); |
3062 | 151k | if (!next) |
3063 | 127k | item->flags |= (self->flags & mxTailRecursionFlag); |
3064 | 151k | fxNodeDispatchCode(item, param); |
3065 | 151k | previous = item; |
3066 | 151k | item = next; |
3067 | 151k | } |
3068 | 127k | } |
3069 | 127k | } |
3070 | | |
3071 | | txFlag fxExpressionsNodeCodeThis(void* it, void* param, txFlag flag) |
3072 | 996 | { |
3073 | 996 | txExpressionsNode* self = it; |
3074 | 996 | if (self->items) { |
3075 | 996 | txNode* item = self->items->first; |
3076 | 996 | if (item->next == C_NULL) { |
3077 | 987 | return fxNodeDispatchCodeThis(item, param, flag); |
3078 | 987 | } |
3079 | 996 | } |
3080 | 9 | return fxNodeCodeThis(it, param, flag); |
3081 | 996 | } |
3082 | | |
3083 | | void fxExpressionsNodeCodeDelete(void* it, void* param) |
3084 | 151 | { |
3085 | 151 | txExpressionsNode* self = it; |
3086 | 151 | if (self->items) { |
3087 | 151 | txNode* item = self->items->first; |
3088 | 151 | if (item->next == C_NULL) { |
3089 | 150 | fxNodeDispatchCodeDelete(item, param); |
3090 | 150 | return; |
3091 | 150 | } |
3092 | 151 | } |
3093 | 1 | fxNodeCodeDelete(it, param); |
3094 | 1 | } |
3095 | | |
3096 | | void fxFieldNodeCode(void* it, void* param) |
3097 | 9.40k | { |
3098 | 9.40k | txFieldNode* self = it; |
3099 | 9.40k | txNode* item = self->item; |
3100 | 9.40k | fxCoderAddByte(param, 1, XS_CODE_THIS); |
3101 | 9.40k | if (item->description->token == XS_TOKEN_PROPERTY) { |
3102 | 2.87k | fxNodeDispatchCode(self->value, param); |
3103 | 2.87k | fxCoderAddSymbol(param, -2, XS_CODE_NEW_PROPERTY, ((txPropertyNode*)item)->symbol); |
3104 | 2.87k | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, fxNodeCodeName(self->value) ? XS_NAME_FLAG : 0); |
3105 | 2.87k | } |
3106 | 6.52k | else if (item->description->token == XS_TOKEN_PROPERTY_AT) { |
3107 | 2.88k | fxCoderAddIndex(param, 1, XS_CODE_GET_CLOSURE_1, ((txPropertyAtNode*)item)->atAccess->declaration->index); |
3108 | 2.88k | fxNodeDispatchCode(self->value, param); |
3109 | 2.88k | fxCoderAddByte(param, -3, XS_CODE_NEW_PROPERTY_AT); |
3110 | 2.88k | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, fxNodeCodeName(self->value) ? XS_NAME_FLAG : 0); |
3111 | 2.88k | } |
3112 | 3.63k | else { |
3113 | 3.63k | if (item->flags & (mxMethodFlag | mxGetterFlag | mxSetterFlag)) |
3114 | 1.77k | fxCoderAddIndex(param, 1, XS_CODE_GET_CLOSURE_1, ((txPrivatePropertyNode*)item)->valueAccess->declaration->index); |
3115 | 1.86k | else |
3116 | 1.86k | fxNodeDispatchCode(self->value, param); |
3117 | 3.63k | fxCoderAddIndex(param, -2, XS_CODE_NEW_PRIVATE_1, ((txPrivatePropertyNode*)item)->symbolAccess->declaration->index); |
3118 | 3.63k | if (item->flags & mxMethodFlag) |
3119 | 1.77k | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, XS_NAME_FLAG | XS_METHOD_FLAG); |
3120 | 1.86k | else if (item->flags & mxGetterFlag) |
3121 | 0 | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, XS_NAME_FLAG | XS_METHOD_FLAG | XS_GETTER_FLAG); |
3122 | 1.86k | else if (item->flags & mxSetterFlag) |
3123 | 0 | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, XS_NAME_FLAG | XS_METHOD_FLAG | XS_SETTER_FLAG); |
3124 | 1.86k | else |
3125 | 1.86k | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, fxNodeCodeName(self->value) ? XS_NAME_FLAG : 0); |
3126 | 3.63k | } |
3127 | 9.40k | } |
3128 | | |
3129 | | void fxForNodeCode(void* it, void* param) |
3130 | 9.60k | { |
3131 | 9.60k | txForNode* self = it; |
3132 | 9.60k | txCoder* coder = param; |
3133 | 9.60k | txTargetCode* continueTarget; |
3134 | 9.60k | txTargetCode* nextTarget; |
3135 | 9.60k | txTargetCode* doneTarget; |
3136 | 9.60k | txUsingContext context; |
3137 | | |
3138 | 9.60k | continueTarget = coder->firstContinueTarget; |
3139 | 9.60k | coder->firstContinueTarget = continueTarget->nextTarget; |
3140 | 9.60k | continueTarget->nextTarget = C_NULL; |
3141 | | |
3142 | 9.60k | fxScopeCodingBlock(self->scope, param); |
3143 | 9.60k | fxScopeCodeDefineNodes(self->scope, param); |
3144 | 9.60k | if (self->scope->disposableNodeCount) |
3145 | 0 | fxScopeCodeUsing(self->scope, coder, &context); |
3146 | 9.60k | nextTarget = fxCoderCreateTarget(param); |
3147 | 9.60k | doneTarget = fxCoderCreateTarget(param); |
3148 | 9.60k | if (self->initialization) |
3149 | 9.49k | fxNodeDispatchCode(self->initialization, param); |
3150 | 9.60k | if (coder->programFlag) { |
3151 | 4.87k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
3152 | 4.87k | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
3153 | 4.87k | } |
3154 | 9.60k | fxScopeCodeRefresh(self->scope, param); |
3155 | 9.60k | fxCoderAdd(param, 0, nextTarget); |
3156 | 9.60k | if (self->expression) { |
3157 | 9.45k | fxNodeDispatchCode(self->expression, param); |
3158 | 9.45k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, doneTarget); |
3159 | 9.45k | } |
3160 | | |
3161 | 9.60k | continueTarget->environmentLevel = coder->environmentLevel; |
3162 | 9.60k | continueTarget->scopeLevel = coder->scopeLevel; |
3163 | 9.60k | continueTarget->stackLevel = coder->stackLevel; |
3164 | 9.60k | continueTarget->nextTarget = coder->firstContinueTarget; |
3165 | 9.60k | coder->firstContinueTarget = continueTarget; |
3166 | 9.60k | fxNodeDispatchCode(self->statement, param); |
3167 | 9.60k | fxCoderAdd(param, 0, continueTarget); |
3168 | 9.60k | coder->firstContinueTarget = continueTarget->nextTarget; |
3169 | 9.60k | continueTarget->nextTarget = C_NULL; |
3170 | | |
3171 | 9.60k | if (self->iteration) { |
3172 | 7.46k | fxScopeCodeRefresh(self->scope, param); |
3173 | 7.46k | self->iteration->flags |= mxExpressionNoValue; |
3174 | 7.46k | fxNodeDispatchCode(self->iteration, param); |
3175 | 7.46k | fxCoderAddByte(param, -1, XS_CODE_POP); |
3176 | 7.46k | } |
3177 | 9.60k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, nextTarget); |
3178 | 9.60k | fxCoderAdd(param, 0, doneTarget); |
3179 | 9.60k | if (self->scope->disposableNodeCount) |
3180 | 0 | fxScopeCodeUsed(self->scope, coder, &context); |
3181 | 9.60k | fxScopeCoded(self->scope, param); |
3182 | | |
3183 | 9.60k | continueTarget->nextTarget = coder->firstContinueTarget; |
3184 | 9.60k | coder->firstContinueTarget = continueTarget; |
3185 | 9.60k | } |
3186 | | |
3187 | | void fxForInForOfNodeCode(void* it, void* param) |
3188 | 11.2k | { |
3189 | 11.2k | txForInForOfNode* self = it; |
3190 | 11.2k | txCoder* coder = param; |
3191 | 11.2k | txBoolean async = (self->description->code == XS_CODE_FOR_AWAIT_OF) ? 1 : 0; |
3192 | 11.2k | txTargetCode* continueTarget; |
3193 | 11.2k | txInteger iterator; |
3194 | 11.2k | txInteger next; |
3195 | 11.2k | txInteger done; |
3196 | 11.2k | txInteger result; |
3197 | 11.2k | txInteger exception; |
3198 | 11.2k | txInteger selector; |
3199 | 11.2k | txInteger selection; |
3200 | 11.2k | txTargetCode* nextTarget; |
3201 | 11.2k | txTargetCode* returnTarget; |
3202 | 11.2k | txTargetCode* doneTarget; |
3203 | 11.2k | txTargetCode* catchTarget; |
3204 | 11.2k | txTargetCode* normalTarget; |
3205 | 11.2k | txTargetCode* uncatchTarget; |
3206 | 11.2k | txTargetCode* finallyTarget; |
3207 | 11.2k | txTargetCode* elseTarget; |
3208 | | |
3209 | 11.2k | iterator = fxCoderUseTemporaryVariable(param); |
3210 | 11.2k | next = fxCoderUseTemporaryVariable(param); |
3211 | 11.2k | done = fxCoderUseTemporaryVariable(param); |
3212 | 11.2k | result = fxCoderUseTemporaryVariable(param); |
3213 | 11.2k | exception = fxCoderUseTemporaryVariable(coder); |
3214 | 11.2k | selector = fxCoderUseTemporaryVariable(coder); |
3215 | | |
3216 | 11.2k | continueTarget = coder->firstContinueTarget; |
3217 | 11.2k | coder->firstContinueTarget = continueTarget->nextTarget; |
3218 | 11.2k | continueTarget->nextTarget = C_NULL; |
3219 | | |
3220 | 11.2k | fxScopeCodingBlock(self->scope, param); |
3221 | 11.2k | fxScopeCodeDefineNodes(self->scope, param); |
3222 | | |
3223 | 11.2k | if (coder->programFlag) { |
3224 | 10.7k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
3225 | 10.7k | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
3226 | 10.7k | } |
3227 | 11.2k | fxNodeDispatchCode(self->expression, param); |
3228 | 11.2k | fxCoderAddByte(param, 0, self->description->code); |
3229 | 11.2k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, iterator); |
3230 | 11.2k | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->nextSymbol); |
3231 | 11.2k | fxCoderAddIndex(param, 0, XS_CODE_PULL_LOCAL_1, next); |
3232 | | |
3233 | 11.2k | coder->firstBreakTarget = fxCoderAliasTargets(param, coder->firstBreakTarget); |
3234 | 11.2k | coder->firstContinueTarget = fxCoderAliasTargets(param, coder->firstContinueTarget); |
3235 | 11.2k | coder->returnTarget = fxCoderAliasTargets(param, coder->returnTarget); |
3236 | 11.2k | catchTarget = fxCoderCreateTarget(param); |
3237 | 11.2k | normalTarget = fxCoderCreateTarget(param); |
3238 | 11.2k | fxCoderAddBranch(param, 0, XS_CODE_CATCH_1, catchTarget); |
3239 | | |
3240 | | // LOOP |
3241 | 11.2k | nextTarget = fxCoderCreateTarget(param); |
3242 | 11.2k | fxCoderAdd(param, 0, nextTarget); |
3243 | 11.2k | fxCoderAddByte(param, 1, XS_CODE_TRUE); |
3244 | 11.2k | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, done); |
3245 | 11.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
3246 | 11.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, next); |
3247 | 11.2k | fxCoderAddByte(param, 1, XS_CODE_CALL); |
3248 | 11.2k | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
3249 | 11.2k | if (async) { |
3250 | 6 | fxCoderAddByte(param, 0, XS_CODE_AWAIT); |
3251 | 6 | fxCoderAddByte(param, 0, XS_CODE_THROW_STATUS); |
3252 | 6 | } |
3253 | 11.2k | fxCoderAddByte(param, 0, XS_CODE_CHECK_INSTANCE); |
3254 | 11.2k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, result); |
3255 | 11.2k | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->doneSymbol); |
3256 | 11.2k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, done); |
3257 | 11.2k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, normalTarget); |
3258 | | |
3259 | 11.2k | fxScopeCodeReset(self->scope, param); |
3260 | 11.2k | fxNodeDispatchCodeReference(self->reference, param, 0); |
3261 | 11.2k | fxCoderAddByte(param, 1, XS_CODE_TRUE); |
3262 | 11.2k | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, done); |
3263 | 11.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, result); |
3264 | 11.2k | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->valueSymbol); |
3265 | 11.2k | fxCoderAddByte(param, 1, XS_CODE_FALSE); |
3266 | 11.2k | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, done); |
3267 | 11.2k | fxNodeDispatchCodeAssign(self->reference, param, 0); |
3268 | 11.2k | fxCoderAddByte(param, -1, XS_CODE_POP); |
3269 | | |
3270 | 11.2k | continueTarget->environmentLevel = coder->environmentLevel; |
3271 | 11.2k | continueTarget->scopeLevel = coder->scopeLevel; |
3272 | 11.2k | continueTarget->stackLevel = coder->stackLevel; |
3273 | 11.2k | continueTarget->nextTarget = coder->firstContinueTarget; |
3274 | 11.2k | coder->firstContinueTarget = continueTarget; |
3275 | 11.2k | fxNodeDispatchCode(self->statement, param); |
3276 | 11.2k | fxCoderAdd(param, 0, coder->firstContinueTarget); |
3277 | 11.2k | coder->firstContinueTarget = continueTarget->nextTarget; |
3278 | 11.2k | continueTarget->nextTarget = C_NULL; |
3279 | | |
3280 | 11.2k | fxScopeCodeUsedReverse(self->scope, coder, self->scope->firstDeclareNode, exception, selector); |
3281 | | |
3282 | 11.2k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, nextTarget); |
3283 | | |
3284 | | // PRE FINALLY |
3285 | 11.2k | uncatchTarget = fxCoderCreateTarget(param); |
3286 | 11.2k | finallyTarget = fxCoderCreateTarget(param); |
3287 | | |
3288 | 11.2k | fxCoderAdd(coder, 0, catchTarget); |
3289 | 11.2k | fxCoderAddByte(coder, 1, XS_CODE_EXCEPTION); |
3290 | 11.2k | fxCoderAddIndex(coder, -1, XS_CODE_PULL_LOCAL_1, exception); |
3291 | 11.2k | fxCoderAddInteger(coder, 1, XS_CODE_INTEGER_1, 0); |
3292 | 11.2k | fxCoderAddIndex(coder, -1, XS_CODE_PULL_LOCAL_1, selector); |
3293 | 11.2k | fxCoderAddBranch(coder, 0, XS_CODE_BRANCH_1, finallyTarget); |
3294 | 11.2k | selection = 1; |
3295 | 11.2k | coder->firstBreakTarget = fxCoderFinalizeTargets(param, coder->firstBreakTarget, selector, &selection, uncatchTarget); |
3296 | 11.2k | coder->firstContinueTarget = fxCoderFinalizeTargets(param, coder->firstContinueTarget, selector, &selection, uncatchTarget); |
3297 | 11.2k | coder->returnTarget = fxCoderFinalizeTargets(param, coder->returnTarget, selector, &selection, uncatchTarget); |
3298 | 11.2k | fxCoderAdd(param, 0, normalTarget); |
3299 | 11.2k | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, selection); |
3300 | 11.2k | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, selector); |
3301 | 11.2k | fxCoderAdd(coder, 0, uncatchTarget); |
3302 | 11.2k | fxCoderAddByte(param, 0, XS_CODE_UNCATCH); |
3303 | 11.2k | fxCoderAdd(param, 0, finallyTarget); |
3304 | | |
3305 | | // FINALLY |
3306 | 11.2k | catchTarget = fxCoderCreateTarget(param); |
3307 | 11.2k | normalTarget = fxCoderCreateTarget(param); |
3308 | | |
3309 | 11.2k | fxCoderAddBranch(param, 0, XS_CODE_CATCH_1, catchTarget); |
3310 | | |
3311 | 11.2k | doneTarget = fxCoderCreateTarget(param); |
3312 | 11.2k | returnTarget = fxCoderCreateTarget(param); |
3313 | 11.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, done); |
3314 | 11.2k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, doneTarget); |
3315 | 11.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
3316 | 11.2k | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->returnSymbol); |
3317 | 11.2k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_CHAIN_1, returnTarget); |
3318 | 11.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
3319 | 11.2k | fxCoderAddByte(param, 0, XS_CODE_SWAP); |
3320 | 11.2k | fxCoderAddByte(param, 1, XS_CODE_CALL); |
3321 | 11.2k | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
3322 | 11.2k | if (async) { |
3323 | 6 | fxCoderAddByte(param, 0, XS_CODE_AWAIT); |
3324 | 6 | fxCoderAddByte(param, 0, XS_CODE_THROW_STATUS); |
3325 | 6 | } |
3326 | 11.2k | fxCoderAddByte(param, 0, XS_CODE_CHECK_INSTANCE); |
3327 | 11.2k | fxCoderAdd(param, 0, returnTarget); |
3328 | 11.2k | fxCoderAddByte(param, -1, XS_CODE_POP); |
3329 | 11.2k | fxCoderAdd(param, 0, doneTarget); |
3330 | | |
3331 | 11.2k | fxCoderAddByte(coder, 0, XS_CODE_UNCATCH); |
3332 | 11.2k | fxCoderAddBranch(coder, 0, XS_CODE_BRANCH_1, normalTarget); |
3333 | | |
3334 | 11.2k | fxCoderAdd(coder, 0, catchTarget); |
3335 | 11.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, selector); |
3336 | 11.2k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, normalTarget); |
3337 | 11.2k | fxCoderAddByte(coder, 1, XS_CODE_EXCEPTION); |
3338 | 11.2k | fxCoderAddIndex(coder, -1, XS_CODE_PULL_LOCAL_1, exception); |
3339 | 11.2k | fxCoderAddInteger(coder, 1, XS_CODE_INTEGER_1, 0); |
3340 | 11.2k | fxCoderAddIndex(coder, -1, XS_CODE_PULL_LOCAL_1, selector); |
3341 | 11.2k | fxCoderAdd(param, 0, normalTarget); |
3342 | | |
3343 | 11.2k | fxScopeCodeUsedReverse(self->scope, coder, self->scope->firstDeclareNode, exception, selector); |
3344 | | |
3345 | | // POST FINALLY |
3346 | 11.2k | elseTarget = fxCoderCreateTarget(param); |
3347 | 11.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, selector); |
3348 | 11.2k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, elseTarget); |
3349 | 11.2k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, exception); |
3350 | 11.2k | fxCoderAddByte(param, -1, XS_CODE_THROW); |
3351 | 11.2k | fxCoderAdd(param, 0, elseTarget); |
3352 | 11.2k | selection = 1; |
3353 | 11.2k | fxCoderJumpTargets(param, coder->firstBreakTarget, selector, &selection); |
3354 | 11.2k | fxCoderJumpTargets(param, coder->firstContinueTarget, selector, &selection); |
3355 | 11.2k | fxCoderJumpTargets(param, coder->returnTarget, selector, &selection); |
3356 | | |
3357 | 11.2k | fxScopeCoded(self->scope, param); |
3358 | 11.2k | continueTarget->nextTarget = coder->firstContinueTarget; |
3359 | 11.2k | coder->firstContinueTarget = continueTarget; |
3360 | | |
3361 | 11.2k | fxCoderUnuseTemporaryVariables(param, 6); |
3362 | 11.2k | } |
3363 | | |
3364 | | void fxFunctionNodeCode(void* it, void* param) |
3365 | 151k | { |
3366 | 151k | txFunctionNode* self = it; |
3367 | 151k | txCoder* coder = param; |
3368 | 151k | txInteger environmentLevel = coder->environmentLevel; |
3369 | 151k | txBoolean evalFlag = coder->evalFlag; |
3370 | 151k | txInteger line = coder->line; |
3371 | 151k | txBoolean programFlag = coder->programFlag; |
3372 | 151k | txInteger scopeLevel = coder->scopeLevel; |
3373 | 151k | txTargetCode* firstBreakTarget = coder->firstBreakTarget; |
3374 | 151k | txTargetCode* firstContinueTarget = coder->firstContinueTarget; |
3375 | 151k | txTargetCode* returnTarget = coder->returnTarget; |
3376 | 151k | txSymbol* name = self->symbol; |
3377 | 151k | txTargetCode* target = fxCoderCreateTarget(param); |
3378 | | |
3379 | 151k | if ((self->flags & mxEvalFlag) && !(self->flags & mxStrictFlag)) |
3380 | 1.88k | coder->evalFlag = 1; |
3381 | 151k | coder->line = -1; |
3382 | 151k | coder->programFlag = 0; |
3383 | 151k | coder->scopeLevel = 0; |
3384 | 151k | coder->firstBreakTarget = NULL; |
3385 | 151k | coder->firstContinueTarget = NULL; |
3386 | | |
3387 | 151k | if (name) { |
3388 | 112k | if (self->flags & mxGetterFlag) { |
3389 | 0 | txString buffer = coder->parser->buffer; |
3390 | 0 | c_strcpy(buffer, "get "); |
3391 | 0 | c_strcat(buffer, name->string); |
3392 | 0 | name = fxNewParserSymbol(coder->parser, buffer); |
3393 | 0 | } |
3394 | 112k | else if (self->flags & mxSetterFlag) { |
3395 | 0 | txString buffer = coder->parser->buffer; |
3396 | 0 | c_strcpy(buffer, "set "); |
3397 | 0 | c_strcat(buffer, name->string); |
3398 | 0 | name = fxNewParserSymbol(coder->parser, buffer); |
3399 | 0 | } |
3400 | 112k | } |
3401 | | |
3402 | 151k | if (self->flags & mxAsyncFlag) { |
3403 | 2.13k | if (self->flags & mxGeneratorFlag) |
3404 | 186 | fxCoderAddSymbol(param, 1, XS_CODE_ASYNC_GENERATOR_FUNCTION, name); |
3405 | 1.94k | else |
3406 | 1.94k | fxCoderAddSymbol(param, 1, XS_CODE_ASYNC_FUNCTION, name); |
3407 | 2.13k | } |
3408 | 149k | else if (self->flags & mxGeneratorFlag) |
3409 | 449 | fxCoderAddSymbol(param, 1, XS_CODE_GENERATOR_FUNCTION, name); |
3410 | 149k | else if (self->flags & (mxArrowFlag | mxMethodFlag | mxGetterFlag | mxSetterFlag)) |
3411 | 28.3k | fxCoderAddSymbol(param, 1, XS_CODE_FUNCTION, name); |
3412 | 120k | else |
3413 | 120k | fxCoderAddSymbol(param, 1, XS_CODE_CONSTRUCTOR_FUNCTION, name); |
3414 | 151k | if (coder->parser->flags & mxDebugFlag) |
3415 | 151k | fxCoderAddByte(param, 0, XS_CODE_PROFILE); |
3416 | 151k | fxCoderAddBranch(param, 0, XS_CODE_CODE_1, target); |
3417 | 151k | if (self->flags & mxFieldFlag) |
3418 | 2.33k | fxCoderAddIndex(param, 0, XS_CODE_BEGIN_STRICT_FIELD, fxCoderCountParameters(coder, self->params)); |
3419 | 149k | else if (self->flags & mxDerivedFlag) |
3420 | 247 | fxCoderAddIndex(param, 0, XS_CODE_BEGIN_STRICT_DERIVED, fxCoderCountParameters(coder, self->params)); |
3421 | 149k | else if (self->flags & mxBaseFlag) |
3422 | 3.81k | fxCoderAddIndex(param, 0, XS_CODE_BEGIN_STRICT_BASE, fxCoderCountParameters(coder, self->params)); |
3423 | 145k | else if (self->flags & mxStrictFlag) |
3424 | 4.05k | fxCoderAddIndex(param, 0, XS_CODE_BEGIN_STRICT, fxCoderCountParameters(coder, self->params)); |
3425 | 141k | else |
3426 | 141k | fxCoderAddIndex(param, 0, XS_CODE_BEGIN_SLOPPY, fxCoderCountParameters(coder, self->params)); |
3427 | 151k | coder->path = C_NULL; |
3428 | 151k | if (self->line >= 0) |
3429 | 146k | fxCoderAddLine(coder, 0, XS_CODE_LINE, it); |
3430 | 151k | if (self->scopeCount) |
3431 | 134k | fxCoderAddIndex(param, 0, XS_CODE_RESERVE_1, self->scopeCount); |
3432 | 151k | fxScopeCodeRetrieve(self->scope, param); |
3433 | 151k | fxScopeCodingParams(self->scope, param); |
3434 | 151k | if ((self->flags & mxAsyncFlag) && !(self->flags & mxGeneratorFlag)) |
3435 | 1.94k | fxCoderAddByte(param, 0, XS_CODE_START_ASYNC); |
3436 | 151k | if (self->flags & mxBaseFlag) { |
3437 | 3.81k | if (coder->classNode->instanceInitAccess) { |
3438 | 3.07k | fxCoderAddByte(param, 1, XS_CODE_THIS); |
3439 | 3.07k | fxCoderAddIndex(param, 1, XS_CODE_GET_CLOSURE_1, coder->classNode->instanceInitAccess->declaration->index); |
3440 | 3.07k | fxCoderAddByte(param, 1, XS_CODE_CALL); |
3441 | 3.07k | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
3442 | 3.07k | fxCoderAddByte(param, -1, XS_CODE_POP); |
3443 | 3.07k | } |
3444 | 3.81k | } |
3445 | 151k | fxNodeDispatchCode(self->params, param); |
3446 | 151k | if ((coder->parser->flags & mxDebugFlag) && coder->path) |
3447 | 146k | fxCoderAddIndex(coder, 0, XS_CODE_LINE, 0); |
3448 | 151k | fxScopeCodeDefineNodes(self->scope, param); |
3449 | 151k | coder->returnTarget = fxCoderCreateTarget(param); |
3450 | 151k | if (self->flags & mxGeneratorFlag) { |
3451 | 635 | if (self->flags & mxAsyncFlag) |
3452 | 186 | fxCoderAddByte(param, 0, XS_CODE_START_ASYNC_GENERATOR); |
3453 | 449 | else |
3454 | 449 | fxCoderAddByte(param, 0, XS_CODE_START_GENERATOR); |
3455 | 635 | } |
3456 | 151k | fxNodeDispatchCode(self->body, param); |
3457 | 151k | fxCoderAdd(param, 0, coder->returnTarget); |
3458 | 151k | if (self->flags & mxArrowFlag) |
3459 | 21.8k | fxCoderAddByte(param, 0, XS_CODE_END_ARROW); |
3460 | 129k | else if (self->flags & mxBaseFlag) |
3461 | 3.81k | fxCoderAddByte(param, 0, XS_CODE_END_BASE); |
3462 | 126k | else if (self->flags & mxDerivedFlag) |
3463 | 247 | fxCoderAddByte(param, 0, XS_CODE_END_DERIVED); |
3464 | 125k | else |
3465 | 125k | fxCoderAddByte(param, 0, XS_CODE_END); |
3466 | 151k | fxCoderAdd(param, 0, target); |
3467 | | |
3468 | 151k | if ((self->scope->flags & mxEvalFlag) || coder->evalFlag) { |
3469 | 17.3k | fxCoderAddByte(coder, 1, XS_CODE_FUNCTION_ENVIRONMENT); |
3470 | 17.3k | fxScopeCodeStore(self->scope, param); |
3471 | 17.3k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
3472 | 17.3k | } |
3473 | 134k | else if (self->scope->closureNodeCount || ((self->flags & mxArrowFlag) && (self->flags & mxDefaultFlag))) { |
3474 | 9.52k | fxCoderAddByte(coder, 1, XS_CODE_ENVIRONMENT); |
3475 | 9.52k | fxScopeCodeStore(self->scope, param); |
3476 | 9.52k | fxCoderAddByte(coder, -1, XS_CODE_POP); |
3477 | 9.52k | } |
3478 | 151k | if ((self->flags & (mxArrowFlag | mxBaseFlag | mxDerivedFlag | mxGeneratorFlag | mxStrictFlag | mxMethodFlag)) == 0) { |
3479 | 113k | fxCoderAddByte(param, 1, XS_CODE_DUB); |
3480 | 113k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
3481 | 113k | fxCoderAddSymbol(param, -2, XS_CODE_NEW_PROPERTY, coder->parser->callerSymbol); |
3482 | 113k | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, XS_DONT_ENUM_FLAG); |
3483 | 113k | } |
3484 | | |
3485 | 151k | coder->returnTarget = returnTarget; |
3486 | 151k | coder->firstContinueTarget = firstContinueTarget; |
3487 | 151k | coder->firstBreakTarget = firstBreakTarget; |
3488 | 151k | coder->scopeLevel = scopeLevel; |
3489 | 151k | coder->programFlag = programFlag; |
3490 | 151k | coder->line = line; |
3491 | 151k | coder->evalFlag = evalFlag; |
3492 | 151k | coder->environmentLevel = environmentLevel; |
3493 | 151k | } |
3494 | | |
3495 | | void fxHostNodeCode(void* it, void* param) |
3496 | 0 | { |
3497 | 0 | txHostNode* self = it; |
3498 | 0 | txCoder* coder = param; |
3499 | 0 | txParser* parser = coder->parser; |
3500 | 0 | if (self->symbol) { |
3501 | 0 | if (self->flags & mxGetterFlag) { |
3502 | 0 | txString buffer = coder->parser->buffer; |
3503 | 0 | c_strcpy(buffer, "get "); |
3504 | 0 | c_strcat(buffer, self->symbol->string); |
3505 | 0 | self->symbol = fxNewParserSymbol(coder->parser, buffer); |
3506 | 0 | } |
3507 | 0 | else if (self->flags & mxSetterFlag) { |
3508 | 0 | txString buffer = coder->parser->buffer; |
3509 | 0 | c_strcpy(buffer, "set "); |
3510 | 0 | c_strcat(buffer, self->symbol->string); |
3511 | 0 | self->symbol = fxNewParserSymbol(coder->parser, buffer); |
3512 | 0 | } |
3513 | 0 | } |
3514 | 0 | if (self->params) |
3515 | 0 | self->paramsCount = fxCoderCountParameters(coder, self->params); |
3516 | 0 | else |
3517 | 0 | self->paramsCount = -1; |
3518 | 0 | if (parser->firstHostNode) |
3519 | 0 | parser->lastHostNode->nextHostNode = self; |
3520 | 0 | else |
3521 | 0 | parser->firstHostNode = self; |
3522 | 0 | parser->lastHostNode = self; |
3523 | 0 | fxCoderAddIndex(param, 1, XS_CODE_HOST, parser->hostNodeIndex); |
3524 | 0 | parser->hostNodeIndex++; |
3525 | 0 | } |
3526 | | |
3527 | | void fxIfNodeCode(void* it, void* param) |
3528 | 3.82k | { |
3529 | 3.82k | txIfNode* self = it; |
3530 | 3.82k | txCoder* coder = param; |
3531 | 3.82k | fxNodeDispatchCode(self->expression, param); |
3532 | 3.82k | if (coder->programFlag) { |
3533 | 2.73k | txTargetCode* elseTarget = fxCoderCreateTarget(param); |
3534 | 2.73k | txTargetCode* endTarget = fxCoderCreateTarget(param); |
3535 | 2.73k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, elseTarget); |
3536 | 2.73k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
3537 | 2.73k | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
3538 | 2.73k | fxNodeDispatchCode(self->thenStatement, param); |
3539 | 2.73k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, endTarget); |
3540 | 2.73k | fxCoderAdd(param, 0, elseTarget); |
3541 | 2.73k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
3542 | 2.73k | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
3543 | 2.73k | if (self->elseStatement) |
3544 | 407 | fxNodeDispatchCode(self->elseStatement, param); |
3545 | 2.73k | fxCoderAdd(param, 0, endTarget); |
3546 | 2.73k | } |
3547 | 1.09k | else { |
3548 | 1.09k | if (self->elseStatement) { |
3549 | 636 | txTargetCode* elseTarget = fxCoderCreateTarget(param); |
3550 | 636 | txTargetCode* endTarget = fxCoderCreateTarget(param); |
3551 | 636 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, elseTarget); |
3552 | 636 | fxNodeDispatchCode(self->thenStatement, param); |
3553 | 636 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, endTarget); |
3554 | 636 | fxCoderAdd(param, 0, elseTarget); |
3555 | 636 | fxNodeDispatchCode(self->elseStatement, param); |
3556 | 636 | fxCoderAdd(param, 0, endTarget); |
3557 | 636 | } |
3558 | 458 | else { |
3559 | 458 | txTargetCode* endTarget = fxCoderCreateTarget(param); |
3560 | 458 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, endTarget); |
3561 | 458 | fxNodeDispatchCode(self->thenStatement, param); |
3562 | 458 | fxCoderAdd(param, 0, endTarget); |
3563 | 458 | } |
3564 | 1.09k | } |
3565 | 3.82k | } |
3566 | | |
3567 | | void fxImportNodeCode(void* it, void* param) |
3568 | 118 | { |
3569 | 118 | } |
3570 | | |
3571 | | void fxImportCallNodeCode(void* it, void* param) |
3572 | 1.16k | { |
3573 | 1.16k | txCoder* coder = param; |
3574 | 1.16k | txImportCallNode* self = it; |
3575 | 1.16k | fxNodeDispatchCode(self->expression, param); |
3576 | 1.16k | if (self->withExpression) |
3577 | 9 | fxNodeDispatchCode(self->withExpression, param); |
3578 | 1.15k | else |
3579 | 1.15k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
3580 | 1.16k | coder->importFlag = 1; |
3581 | 1.16k | fxCoderAddByte(param, -1, XS_CODE_IMPORT); |
3582 | 1.16k | } |
3583 | | |
3584 | | void fxImportMetaNodeCode(void* it, void* param) |
3585 | 101 | { |
3586 | 101 | txCoder* coder = param; |
3587 | 101 | coder->importMetaFlag = 1; |
3588 | 101 | fxCoderAddByte(param, 1, XS_CODE_IMPORT_META); |
3589 | 101 | } |
3590 | | |
3591 | | void fxIncludeNodeCode(void* it, void* param) |
3592 | 0 | { |
3593 | 0 | txIncludeNode* self = it; |
3594 | 0 | fxNodeDispatchCode(self->body, param); |
3595 | 0 | } |
3596 | | |
3597 | | void fxIntegerNodeCode(void* it, void* param) |
3598 | 296k | { |
3599 | 296k | txIntegerNode* self = it; |
3600 | 296k | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, self->value); |
3601 | 296k | } |
3602 | | |
3603 | | void fxLabelNodeCode(void* it, void* param) |
3604 | 28.0k | { |
3605 | 28.0k | txLabelNode* self = it; |
3606 | 28.0k | txCoder* coder = param; |
3607 | 28.0k | txNode* statement = self->statement; |
3608 | 28.0k | txTargetCode* breakTarget; |
3609 | 34.0k | while (statement->description->token == XS_TOKEN_LABEL) { |
3610 | 6.00k | txLabelNode* former = (txLabelNode*)statement; |
3611 | 6.00k | txLabelNode* current = self; |
3612 | 14.1k | while (current) { |
3613 | 8.15k | if (former->symbol && current->symbol && (former->symbol == current->symbol)) { |
3614 | 1.60k | fxReportParserError(coder->parser, current->line, "duplicate label %s", current->symbol->string); |
3615 | 1.60k | } |
3616 | 8.15k | current = current->nextLabel; |
3617 | 8.15k | } |
3618 | 6.00k | former->nextLabel = self; |
3619 | 6.00k | self = former; |
3620 | 6.00k | statement = self->statement; |
3621 | 6.00k | } |
3622 | 28.0k | breakTarget = coder->firstBreakTarget; |
3623 | 132k | while (breakTarget) { |
3624 | 104k | txLabelNode* former = breakTarget->label; |
3625 | 104k | if (former) { |
3626 | 104k | txLabelNode* current = self; |
3627 | 209k | while (current) { |
3628 | 104k | if (former->symbol && current->symbol && (former->symbol == current->symbol)) { |
3629 | 3 | fxReportParserError(coder->parser, current->line, "duplicate label %s", current->symbol->string); |
3630 | 3 | } |
3631 | 104k | current = current->nextLabel; |
3632 | 104k | } |
3633 | 104k | } |
3634 | 104k | breakTarget = breakTarget->nextTarget; |
3635 | 104k | } |
3636 | 28.0k | breakTarget = fxCoderCreateTarget(coder); |
3637 | 28.0k | breakTarget->nextTarget = coder->firstBreakTarget; |
3638 | 28.0k | coder->firstBreakTarget = breakTarget; |
3639 | 28.0k | breakTarget->label = self; |
3640 | 28.0k | if (self->symbol) |
3641 | 2.25k | fxNodeDispatchCode(statement, param); |
3642 | 25.7k | else { |
3643 | 25.7k | txTargetCode* continueTarget = fxCoderCreateTarget(coder); |
3644 | 25.7k | continueTarget->nextTarget = coder->firstContinueTarget; |
3645 | 25.7k | coder->firstContinueTarget = continueTarget; |
3646 | 25.7k | continueTarget->label = self; |
3647 | 25.7k | fxNodeDispatchCode(statement, param); |
3648 | 25.7k | coder->firstContinueTarget = continueTarget->nextTarget; |
3649 | 25.7k | } |
3650 | 28.0k | fxCoderAdd(param, 0, coder->firstBreakTarget); |
3651 | 28.0k | coder->firstBreakTarget = breakTarget->nextTarget; |
3652 | 28.0k | } |
3653 | | |
3654 | | void fxMemberNodeCode(void* it, void* param) |
3655 | 44.1k | { |
3656 | 44.1k | txMemberNode* self = it; |
3657 | 44.1k | fxNodeDispatchCode(self->reference, param); |
3658 | 44.1k | fxCoderAddSymbol(param, 0, (self->reference->flags & mxSuperFlag) ? XS_CODE_GET_SUPER : XS_CODE_GET_PROPERTY, self->symbol); |
3659 | 44.1k | } |
3660 | | |
3661 | | void fxMemberNodeCodeAssign(void* it, void* param, txFlag flag) |
3662 | 9.36k | { |
3663 | 9.36k | txMemberNode* self = it; |
3664 | 9.36k | fxCoderAddSymbol(param, -1, (self->reference->flags & mxSuperFlag) ? XS_CODE_SET_SUPER : XS_CODE_SET_PROPERTY, self->symbol); |
3665 | 9.36k | } |
3666 | | |
3667 | | void fxMemberNodeCodeDelete(void* it, void* param) |
3668 | 1.41k | { |
3669 | 1.41k | txMemberNode* self = it; |
3670 | 1.41k | fxNodeDispatchCode(self->reference, param); |
3671 | 1.41k | fxCoderAddSymbol(param, 0, (self->reference->flags & mxSuperFlag) ? XS_CODE_DELETE_SUPER : XS_CODE_DELETE_PROPERTY, self->symbol); |
3672 | 1.41k | } |
3673 | | |
3674 | | void fxMemberNodeCodeReference(void* it, void* param, txFlag flag) |
3675 | 8.90k | { |
3676 | 8.90k | txMemberNode* self = it; |
3677 | 8.90k | fxNodeDispatchCode(self->reference, param); |
3678 | 8.90k | } |
3679 | | |
3680 | | txFlag fxMemberNodeCodeThis(void* it, void* param, txFlag flag) |
3681 | 108k | { |
3682 | 108k | txMemberNode* self = it; |
3683 | 108k | fxNodeDispatchCode(self->reference, param); |
3684 | 108k | fxCoderAddByte(param, 1, XS_CODE_DUB); |
3685 | 108k | fxCoderAddSymbol(param, 0, (self->reference->flags & mxSuperFlag) ? XS_CODE_GET_SUPER : XS_CODE_GET_PROPERTY, self->symbol); |
3686 | 108k | return 1; |
3687 | 108k | } |
3688 | | |
3689 | | void fxMemberAtNodeCode(void* it, void* param) |
3690 | 7.45k | { |
3691 | 7.45k | txMemberAtNode* self = it; |
3692 | 7.45k | fxNodeDispatchCode(self->reference, param); |
3693 | 7.45k | fxNodeDispatchCode(self->at, param); |
3694 | 7.45k | fxCoderAddByte(param, 0, (self->reference->flags & mxSuperFlag) ? XS_CODE_SUPER_AT : XS_CODE_AT); |
3695 | 7.45k | fxCoderAddByte(param, -1, (self->reference->flags & mxSuperFlag) ? XS_CODE_GET_SUPER_AT : XS_CODE_GET_PROPERTY_AT); |
3696 | 7.45k | } |
3697 | | |
3698 | | void fxMemberAtNodeCodeAssign(void* it, void* param, txFlag flag) |
3699 | 2.85k | { |
3700 | 2.85k | txMemberAtNode* self = it; |
3701 | 2.85k | if (flag) |
3702 | 2.28k | fxCoderAddByte(param, 0, (self->reference->flags & mxSuperFlag) ? XS_CODE_SUPER_AT_2 : XS_CODE_AT_2); |
3703 | 2.85k | fxCoderAddByte(param, -2, (self->reference->flags & mxSuperFlag) ? XS_CODE_SET_SUPER_AT : XS_CODE_SET_PROPERTY_AT); |
3704 | 2.85k | } |
3705 | | |
3706 | | void fxMemberAtNodeCodeDelete(void* it, void* param) |
3707 | 155 | { |
3708 | 155 | txMemberAtNode* self = it; |
3709 | 155 | fxMemberAtNodeCodeReference(it, param, (self->reference->flags & mxSuperFlag) ? 1 : 0); |
3710 | 155 | fxCoderAddByte(param, -1, (self->reference->flags & mxSuperFlag) ? XS_CODE_DELETE_SUPER_AT : XS_CODE_DELETE_PROPERTY_AT); |
3711 | 155 | } |
3712 | | |
3713 | | void fxMemberAtNodeCodeReference(void* it, void* param, txFlag flag) |
3714 | 3.01k | { |
3715 | 3.01k | txMemberAtNode* self = it; |
3716 | 3.01k | fxNodeDispatchCode(self->reference, param); |
3717 | 3.01k | fxNodeDispatchCode(self->at, param); |
3718 | 3.01k | if (!flag) |
3719 | 729 | fxCoderAddByte(param, 0, (self->reference->flags & mxSuperFlag) ? XS_CODE_SUPER_AT : XS_CODE_AT); |
3720 | 3.01k | } |
3721 | | |
3722 | | txFlag fxMemberAtNodeCodeThis(void* it, void* param, txFlag flag) |
3723 | 1.65k | { |
3724 | 1.65k | txMemberAtNode* self = it; |
3725 | 1.65k | if (flag) { |
3726 | 573 | fxMemberAtNodeCodeReference(it, param, 0); |
3727 | 573 | fxCoderAddByte(param, 2, XS_CODE_DUB_AT); |
3728 | 573 | flag = 2; |
3729 | 573 | } |
3730 | 1.08k | else { |
3731 | 1.08k | fxNodeDispatchCode(self->reference, param); |
3732 | 1.08k | fxCoderAddByte(param, 1, XS_CODE_DUB); |
3733 | 1.08k | fxNodeDispatchCode(self->at, param); |
3734 | 1.08k | fxCoderAddByte(param, 0, (self->reference->flags & mxSuperFlag) ? XS_CODE_SUPER_AT : XS_CODE_AT); |
3735 | 1.08k | } |
3736 | 1.65k | fxCoderAddByte(param, -1, (self->reference->flags & mxSuperFlag) ? XS_CODE_GET_SUPER_AT : XS_CODE_GET_PROPERTY_AT); |
3737 | 1.65k | return flag; |
3738 | 1.65k | } |
3739 | | |
3740 | | void fxModuleNodeCode(void* it, void* param) |
3741 | 257 | { |
3742 | 257 | txModuleNode* self = it; |
3743 | 257 | txCoder* coder = param; |
3744 | 257 | txTargetCode* target = fxCoderCreateTarget(param); |
3745 | 257 | txDeclareNode* declaration; |
3746 | 257 | txInteger count; |
3747 | 257 | txSymbol* name = /*(coder->parser->flags & mxDebugFlag) ? self->path :*/ C_NULL; |
3748 | 257 | txFlag flag = 0; |
3749 | | |
3750 | 257 | coder->line = -1; |
3751 | 257 | coder->programFlag = 0; |
3752 | 257 | coder->scopeLevel = 0; |
3753 | 257 | coder->firstBreakTarget = NULL; |
3754 | 257 | coder->firstContinueTarget = NULL; |
3755 | | |
3756 | 257 | count = 0; |
3757 | 257 | declaration = self->scope->firstDeclareNode; |
3758 | 884 | while (declaration) { |
3759 | 627 | if ((declaration->description->token == XS_TOKEN_DEFINE) || (declaration->description->token == XS_TOKEN_VAR)) |
3760 | 24 | count++; |
3761 | 627 | declaration = declaration->nextDeclareNode; |
3762 | 627 | } |
3763 | 257 | if (count) { |
3764 | 22 | fxCoderAddSymbol(param, 1, XS_CODE_FUNCTION, name); |
3765 | 22 | if (coder->parser->flags & mxDebugFlag) |
3766 | 22 | fxCoderAddByte(param, 0, XS_CODE_PROFILE); |
3767 | 22 | fxCoderAddBranch(param, 0, XS_CODE_CODE_1, target); |
3768 | 22 | fxCoderAddIndex(param, 0, XS_CODE_BEGIN_STRICT, 0); |
3769 | 22 | coder->path = C_NULL; |
3770 | 22 | if (self->line >= 0) |
3771 | 22 | fxCoderAddLine(coder, 0, XS_CODE_LINE, it); |
3772 | 22 | if (self->scopeCount) |
3773 | 22 | fxCoderAddIndex(param, 0, XS_CODE_RESERVE_1, self->scopeCount); |
3774 | 22 | fxScopeCodeRetrieve(self->scope, param); |
3775 | 22 | declaration = self->scope->firstDeclareNode; |
3776 | 117 | while (declaration) { |
3777 | 95 | if (declaration->description->token == XS_TOKEN_VAR) { |
3778 | 21 | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
3779 | 21 | fxCoderAddIndex(coder, 0, XS_CODE_VAR_CLOSURE_1, declaration->index); |
3780 | 21 | fxCoderAddByte(coder, -1, XS_CODE_POP); |
3781 | 21 | } |
3782 | 95 | declaration = declaration->nextDeclareNode; |
3783 | 95 | } |
3784 | 22 | fxScopeCodeDefineNodes(self->scope, param); |
3785 | 22 | fxCoderAddByte(param, 0, XS_CODE_END); |
3786 | 22 | fxCoderAdd(param, 0, target); |
3787 | 22 | fxCoderAddByte(param, 1, XS_CODE_ENVIRONMENT); |
3788 | 22 | fxCoderAddByte(param, -1, XS_CODE_POP); |
3789 | | |
3790 | 22 | target = fxCoderCreateTarget(param); |
3791 | 22 | coder->line = -1; |
3792 | 22 | coder->programFlag = 0; |
3793 | 22 | coder->scopeLevel = 0; |
3794 | 22 | coder->firstBreakTarget = NULL; |
3795 | 22 | coder->firstContinueTarget = NULL; |
3796 | 22 | } |
3797 | 235 | else { |
3798 | 235 | fxCoderAddByte(coder, 1, XS_CODE_NULL); |
3799 | 235 | } |
3800 | | |
3801 | 257 | if (self->flags & mxAwaitingFlag) |
3802 | 3 | fxCoderAddSymbol(param, 1, XS_CODE_ASYNC_FUNCTION, name); |
3803 | 254 | else |
3804 | 254 | fxCoderAddSymbol(param, 1, XS_CODE_FUNCTION, name); |
3805 | 257 | if (coder->parser->flags & mxDebugFlag) |
3806 | 257 | fxCoderAddByte(param, 0, XS_CODE_PROFILE); |
3807 | 257 | fxCoderAddBranch(param, 0, XS_CODE_CODE_1, target); |
3808 | 257 | fxCoderAddIndex(param, 0, XS_CODE_BEGIN_STRICT, 0); |
3809 | 257 | coder->path = C_NULL; |
3810 | 257 | if (self->line >= 0) |
3811 | 257 | fxCoderAddLine(coder, 0, XS_CODE_LINE, it); |
3812 | 257 | if (self->scopeCount) |
3813 | 251 | fxCoderAddIndex(param, 0, XS_CODE_RESERVE_1, self->scopeCount); |
3814 | 257 | fxScopeCodeRetrieve(self->scope, param); |
3815 | | |
3816 | 257 | if (self->flags & mxAwaitingFlag) |
3817 | 3 | fxCoderAddByte(param, 0, XS_CODE_START_ASYNC); |
3818 | | |
3819 | 257 | coder->returnTarget = fxCoderCreateTarget(param); |
3820 | | |
3821 | 257 | fxNodeDispatchCode(self->body, param); |
3822 | | |
3823 | 257 | fxCoderAdd(param, 0, coder->returnTarget); |
3824 | 257 | fxCoderAddByte(param, 0, XS_CODE_END); |
3825 | 257 | fxCoderAdd(param, 0, target); |
3826 | | |
3827 | 257 | fxCoderAddByte(param, 1, XS_CODE_ENVIRONMENT); |
3828 | 257 | fxCoderAddByte(param, -1, XS_CODE_POP); |
3829 | | |
3830 | 257 | count = 2 + fxScopeCodeSpecifierNodes(self->scope, coder); |
3831 | 257 | fxCoderAddInteger(coder, 1, XS_CODE_INTEGER_1, count); |
3832 | 257 | if (!(self->flags & mxStrictFlag)) |
3833 | 0 | flag |= XS_JSON_MODULE_FLAG; |
3834 | 257 | if (coder->importFlag) |
3835 | 4 | flag |= XS_IMPORT_FLAG; |
3836 | 257 | if (coder->importMetaFlag) |
3837 | 100 | flag |= XS_IMPORT_META_FLAG; |
3838 | 257 | fxCoderAddIndex(coder, 0 - count, XS_CODE_MODULE, flag); |
3839 | 257 | fxCoderAddByte(coder, -1, XS_CODE_SET_RESULT); |
3840 | 257 | fxCoderAddByte(coder, 0, XS_CODE_END); |
3841 | 257 | } |
3842 | | |
3843 | | void fxNewNodeCode(void* it, void* param) |
3844 | 21.0k | { |
3845 | 21.0k | txCallNewNode* self = it; |
3846 | 21.0k | fxNodeDispatchCode(self->reference, param); |
3847 | 21.0k | fxCoderAddByte(param, 2, XS_CODE_NEW); |
3848 | 21.0k | fxNodeDispatchCode(self->params, param); |
3849 | 21.0k | } |
3850 | | |
3851 | | void fxNumberNodeCode(void* it, void* param) |
3852 | 14.2k | { |
3853 | 14.2k | txNumberNode* self = it; |
3854 | 14.2k | fxCoderAddNumber(param, 1, XS_CODE_NUMBER, self->value); |
3855 | 14.2k | } |
3856 | | |
3857 | | void fxObjectNodeCode(void* it, void* param) |
3858 | 31.9k | { |
3859 | 31.9k | txObjectNode* self = it; |
3860 | 31.9k | txCoder* coder = param; |
3861 | 31.9k | txInteger object = fxCoderUseTemporaryVariable(param); |
3862 | 31.9k | txNode* item; |
3863 | 31.9k | txFlag flag = 0; |
3864 | 31.9k | if (self->items) { |
3865 | 31.9k | item = self->items->first; |
3866 | 91.0k | while (item) { |
3867 | 59.0k | if (item->description->token == XS_TOKEN_PROPERTY) { |
3868 | 57.7k | if (!(item->flags & mxShorthandFlag) && (((txPropertyNode*)item)->symbol == coder->parser->__proto__Symbol)) { |
3869 | 25 | if (flag) |
3870 | 0 | fxReportParserError(coder->parser, item->line, "invalid __proto__"); |
3871 | 25 | flag = 1; |
3872 | 25 | fxNodeDispatchCode(((txPropertyNode*)item)->value, param); |
3873 | 25 | fxCoderAddByte(param, 0, XS_CODE_INSTANTIATE); |
3874 | 25 | } |
3875 | 57.7k | } |
3876 | 59.0k | item = item->next; |
3877 | 59.0k | } |
3878 | 31.9k | } |
3879 | 31.9k | if (!flag) |
3880 | 31.9k | fxCoderAddByte(param, 1, XS_CODE_OBJECT); |
3881 | 31.9k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, object); |
3882 | 31.9k | if (self->items) { |
3883 | 31.9k | item = self->items->first; |
3884 | 91.0k | while (item) { |
3885 | 59.0k | if (item->description->token == XS_TOKEN_SPREAD) { |
3886 | 372 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
3887 | 372 | fxCoderAddByte(param, 1, XS_CODE_COPY_OBJECT); |
3888 | 372 | fxCoderAddByte(param, 1, XS_CODE_CALL); |
3889 | 372 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, object); |
3890 | 372 | fxNodeDispatchCode(((txSpreadNode*)item)->expression, param); |
3891 | 372 | fxCoderAddInteger(param, -4, XS_CODE_RUN_1, 2); |
3892 | 372 | fxCoderAddByte(param, -1, XS_CODE_POP); |
3893 | 372 | } |
3894 | 58.6k | else { |
3895 | 58.6k | txNode* value; |
3896 | 58.6k | if (item->description->token == XS_TOKEN_PROPERTY) { |
3897 | 57.7k | if (!(item->flags & mxShorthandFlag) && (((txPropertyNode*)item)->symbol == coder->parser->__proto__Symbol)) { |
3898 | 25 | item = item->next; |
3899 | 25 | continue; |
3900 | 25 | } |
3901 | 57.7k | value = ((txPropertyNode*)item)->value; |
3902 | 57.7k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, object); |
3903 | 57.7k | fxNodeDispatchCode(value, param); |
3904 | 57.7k | fxCoderAddSymbol(param, -2, XS_CODE_NEW_PROPERTY, ((txPropertyNode*)item)->symbol); |
3905 | 57.7k | } |
3906 | 877 | else { |
3907 | 877 | value = ((txPropertyAtNode*)item)->value; |
3908 | 877 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, object); |
3909 | 877 | fxNodeDispatchCode(((txPropertyAtNode*)item)->at, param); |
3910 | 877 | fxCoderAddByte(param, 0, XS_CODE_AT); |
3911 | 877 | fxNodeDispatchCode(value, param); |
3912 | 877 | fxCoderAddByte(param, -3, XS_CODE_NEW_PROPERTY_AT); |
3913 | 877 | } |
3914 | 58.6k | flag = 0; |
3915 | 58.6k | if (item->flags & mxMethodFlag) |
3916 | 856 | flag |= XS_NAME_FLAG | XS_METHOD_FLAG; |
3917 | 57.7k | else if (item->flags & mxGetterFlag) |
3918 | 304 | flag |= XS_NAME_FLAG | XS_METHOD_FLAG | XS_GETTER_FLAG; |
3919 | 57.4k | else if (item->flags & mxSetterFlag) |
3920 | 62 | flag |= XS_NAME_FLAG | XS_METHOD_FLAG | XS_SETTER_FLAG; |
3921 | 57.3k | else if (fxNodeCodeName(value)) |
3922 | 1.62k | flag |= XS_NAME_FLAG; |
3923 | 58.6k | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, flag); |
3924 | 58.6k | } |
3925 | 58.9k | item = item->next; |
3926 | 58.9k | } |
3927 | 31.9k | } |
3928 | 31.9k | fxCoderUnuseTemporaryVariables(param, 1); |
3929 | 31.9k | } |
3930 | | |
3931 | | void fxObjectBindingNodeCode(void* it, void* param) |
3932 | 5 | { |
3933 | 5 | txObjectBindingNode* self = it; |
3934 | 5 | txCoder* coder = param; |
3935 | 5 | fxCoderAddByte(coder, 1, XS_CODE_UNDEFINED); |
3936 | 5 | fxObjectBindingNodeCodeAssign(self, param, 0); |
3937 | 5 | } |
3938 | | |
3939 | | void fxObjectBindingNodeCodeAssign(void* it, void* param, txFlag flag) |
3940 | 921 | { |
3941 | 921 | txObjectBindingNode* self = it; |
3942 | 921 | txNode* item = self->items->first; |
3943 | 921 | txInteger object; |
3944 | 921 | txInteger at; |
3945 | 921 | txInteger c = 0; |
3946 | 921 | object = fxCoderUseTemporaryVariable(param); |
3947 | 921 | at = fxCoderUseTemporaryVariable(param); |
3948 | 921 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
3949 | 921 | fxCoderAddByte(param, 0, XS_CODE_TO_INSTANCE); |
3950 | 921 | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, object); |
3951 | 921 | if (self->flags & mxSpreadFlag) { |
3952 | 128 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
3953 | 128 | fxCoderAddByte(param, 1, XS_CODE_COPY_OBJECT); |
3954 | 128 | fxCoderAddByte(param, 1, XS_CODE_CALL); |
3955 | 128 | fxCoderAddByte(param, 1, XS_CODE_OBJECT); |
3956 | 128 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, object); |
3957 | 128 | c = 2; |
3958 | 128 | } |
3959 | 2.13k | while (item && (item->description->token != XS_TOKEN_REST_BINDING)) { |
3960 | 1.20k | if (item->description->token == XS_TOKEN_PROPERTY_BINDING) { |
3961 | 847 | if (self->flags & mxSpreadFlag) { |
3962 | 18 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, object); |
3963 | 18 | fxCoderAddSymbol(param, 1, XS_CODE_SYMBOL, ((txPropertyBindingNode*)item)->symbol); |
3964 | 18 | fxCoderAddByte(param, 0, XS_CODE_AT); |
3965 | 18 | fxCoderAddByte(param, 0, XS_CODE_SWAP); |
3966 | 18 | fxCoderAddByte(param, -1, XS_CODE_POP); |
3967 | 18 | c++; |
3968 | 18 | } |
3969 | 847 | fxNodeDispatchCodeReference(((txPropertyBindingNode*)item)->binding, param, 1); |
3970 | 847 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, object); |
3971 | 847 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, ((txPropertyBindingNode*)item)->symbol); |
3972 | 847 | fxNodeDispatchCodeAssign(((txPropertyBindingNode*)item)->binding, param, 1); |
3973 | 847 | } |
3974 | 362 | else { |
3975 | 362 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, object); |
3976 | 362 | fxNodeDispatchCode(((txPropertyBindingAtNode*)item)->at, param); |
3977 | 362 | fxCoderAddByte(param, 0, XS_CODE_AT); |
3978 | 362 | if (self->flags & mxSpreadFlag) { |
3979 | 9 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, at); |
3980 | 9 | fxCoderAddByte(param, 0, XS_CODE_SWAP); |
3981 | 9 | fxCoderAddByte(param, -1, XS_CODE_POP); |
3982 | 9 | c++; |
3983 | 9 | } |
3984 | 353 | else { |
3985 | 353 | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, at); |
3986 | 353 | fxCoderAddByte(param, -1, XS_CODE_POP); |
3987 | 353 | } |
3988 | 362 | fxNodeDispatchCodeReference(((txPropertyBindingAtNode*)item)->binding, param, 1); |
3989 | 362 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, object); |
3990 | 362 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, at); |
3991 | 362 | fxCoderAddByte(param, -1, XS_CODE_GET_PROPERTY_AT); |
3992 | 362 | fxNodeDispatchCodeAssign(((txPropertyBindingAtNode*)item)->binding, param, 1); |
3993 | 362 | } |
3994 | 1.20k | fxCoderAddByte(param, -1, XS_CODE_POP); |
3995 | 1.20k | item = item->next; |
3996 | 1.20k | } |
3997 | 921 | if (self->flags & mxSpreadFlag) { |
3998 | 128 | fxCoderAddInteger(param, -2 - c, XS_CODE_RUN_1, c); |
3999 | 128 | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, object); |
4000 | 128 | fxNodeDispatchCodeReference(((txRestBindingNode*)item)->binding, param, 1); |
4001 | 128 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, object); |
4002 | 128 | fxNodeDispatchCodeAssign(((txRestBindingNode*)item)->binding, param, 1); |
4003 | 128 | fxCoderAddByte(param, -1, XS_CODE_POP); |
4004 | 128 | } |
4005 | 921 | fxCoderUnuseTemporaryVariables(param, 2); |
4006 | 921 | } |
4007 | | |
4008 | | void fxOptionNodeCode(void* it, void* param) |
4009 | 1.06k | { |
4010 | 1.06k | txUnaryExpressionNode* self = it; |
4011 | 1.06k | txCoder* coder = param; |
4012 | 1.06k | self->right->flags |= (self->flags & mxTailRecursionFlag); |
4013 | 1.06k | fxNodeDispatchCode(self->right, param); |
4014 | 1.06k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_CHAIN_1, coder->chainTarget); |
4015 | 1.06k | } |
4016 | | |
4017 | | txFlag fxOptionNodeCodeThis(void* it, void* param, txFlag flag) |
4018 | 74 | { |
4019 | 74 | txUnaryExpressionNode* self = it; |
4020 | 74 | txCoder* coder = param; |
4021 | 74 | txTargetCode* swapTarget = fxCoderCreateTarget(param); |
4022 | 74 | txTargetCode* skipTarget = fxCoderCreateTarget(param); |
4023 | 74 | self->right->flags |= (self->flags & mxTailRecursionFlag); |
4024 | 74 | flag = fxNodeDispatchCodeThis(self->right, param, flag); |
4025 | 74 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_CHAIN_1, swapTarget); |
4026 | 74 | fxCoderAddBranch(param, 1, XS_CODE_BRANCH_1, skipTarget); |
4027 | 74 | fxCoderAdd(param, 0, swapTarget); |
4028 | 74 | fxCoderAddByte(param, 0, XS_CODE_SWAP); |
4029 | 74 | fxCoderAddByte(param, -1, XS_CODE_POP); |
4030 | 74 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, coder->chainTarget); |
4031 | 74 | fxCoderAdd(param, 0, skipTarget); |
4032 | 74 | return flag; |
4033 | 74 | } |
4034 | | |
4035 | | void fxOrExpressionNodeCode(void* it, void* param) |
4036 | 866 | { |
4037 | 866 | txBinaryExpressionNode* self = it; |
4038 | 866 | txTargetCode* endTarget = fxCoderCreateTarget(param); |
4039 | 866 | self->right->flags |= (self->flags & mxTailRecursionFlag); |
4040 | 866 | fxNodeDispatchCode(self->left, param); |
4041 | 866 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
4042 | 866 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, endTarget); |
4043 | 866 | fxCoderAddByte(param, -1, XS_CODE_POP); |
4044 | 866 | fxNodeDispatchCode(self->right, param); |
4045 | 866 | fxCoderAdd(param, 0, endTarget); |
4046 | 866 | } |
4047 | | |
4048 | | void fxParamsNodeCode(void* it, void* param) |
4049 | 153k | { |
4050 | 153k | txParamsNode* self = it; |
4051 | 153k | txInteger c = 0; |
4052 | 153k | if (self->flags & mxSpreadFlag) { |
4053 | 337 | txInteger counter = fxCoderUseTemporaryVariable(param); |
4054 | 337 | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, 0); |
4055 | 337 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, counter); |
4056 | 337 | fxCoderAddByte(param, -1, XS_CODE_POP); |
4057 | 337 | if (self->items) { |
4058 | 337 | txNode* item = self->items->first; |
4059 | 1.53k | while (item) { |
4060 | 1.20k | if (item->description->token == XS_TOKEN_SPREAD) { |
4061 | 945 | fxSpreadNodeCode(item, param, counter); |
4062 | 945 | } |
4063 | 255 | else { |
4064 | 255 | c++; |
4065 | 255 | fxNodeDispatchCode(item, param); |
4066 | 255 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, counter); |
4067 | 255 | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, 1); |
4068 | 255 | fxCoderAddByte(param, -1, XS_CODE_ADD); |
4069 | 255 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, counter); |
4070 | 255 | fxCoderAddByte(param, -1, XS_CODE_POP); |
4071 | 255 | } |
4072 | 1.20k | item = item->next; |
4073 | 1.20k | } |
4074 | 337 | } |
4075 | 337 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, counter); |
4076 | 337 | if (self->flags & mxEvalParametersFlag) |
4077 | 1 | fxCoderAddByte(param, -3 - c, (self->flags & mxTailRecursionFlag) ? XS_CODE_EVAL_TAIL : XS_CODE_EVAL); |
4078 | 336 | else |
4079 | 336 | fxCoderAddByte(param, -3 - c, (self->flags & mxTailRecursionFlag) ? XS_CODE_RUN_TAIL : XS_CODE_RUN); |
4080 | 337 | fxCoderUnuseTemporaryVariables(param, 1); |
4081 | 337 | } |
4082 | 153k | else { |
4083 | 153k | if (self->items) { |
4084 | 153k | txNode* item = self->items->first; |
4085 | 392k | while (item) { |
4086 | 239k | fxNodeDispatchCode(item, param); |
4087 | 239k | c++; |
4088 | 239k | item = item->next; |
4089 | 239k | } |
4090 | 153k | if (self->flags & mxEvalParametersFlag) { |
4091 | 2.31k | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, c); |
4092 | 2.31k | fxCoderAddByte(param, -3 - c, (self->flags & mxTailRecursionFlag) ? XS_CODE_EVAL_TAIL : XS_CODE_EVAL); |
4093 | 2.31k | } |
4094 | 151k | else |
4095 | 151k | fxCoderAddInteger(param, -2 - c, (self->flags & mxTailRecursionFlag) ? XS_CODE_RUN_TAIL_1 : XS_CODE_RUN_1, c); |
4096 | 153k | } |
4097 | 153k | } |
4098 | 153k | } |
4099 | | |
4100 | | void fxParamsBindingNodeCode(void* it, void* param) |
4101 | 151k | { |
4102 | 151k | txParamsBindingNode* self = it; |
4103 | 151k | txNode* item = self->items->first; |
4104 | 151k | txInteger index = 0; |
4105 | 151k | if (self->declaration) { |
4106 | 1.38k | if (self->mapped) |
4107 | 1.05k | fxCoderAddIndex(param, 1, XS_CODE_ARGUMENTS_SLOPPY, self->items->length); |
4108 | 338 | else |
4109 | 338 | fxCoderAddIndex(param, 1, XS_CODE_ARGUMENTS_STRICT, self->items->length); |
4110 | 1.38k | if (self->declaration->flags & mxDeclareNodeClosureFlag) |
4111 | 59 | fxCoderAddIndex(param, 0, XS_CODE_VAR_CLOSURE_1, self->declaration->index); |
4112 | 1.33k | else |
4113 | 1.33k | fxCoderAddIndex(param, 0, XS_CODE_VAR_LOCAL_1, self->declaration->index); |
4114 | 1.38k | fxCoderAddByte(param, -1, XS_CODE_POP); |
4115 | 1.38k | } |
4116 | 183k | while (item) { |
4117 | 31.7k | if (item->description->token == XS_TOKEN_REST_BINDING) { |
4118 | 538 | fxNodeDispatchCodeReference(((txRestBindingNode*)item)->binding, param, 0); |
4119 | 538 | fxCoderAddIndex(param, 1, XS_CODE_ARGUMENTS, index); |
4120 | 538 | fxNodeDispatchCodeAssign(((txRestBindingNode*)item)->binding, param, 0); |
4121 | 538 | } |
4122 | 31.2k | else { |
4123 | 31.2k | fxNodeDispatchCodeReference(item, param, 0); |
4124 | 31.2k | fxCoderAddIndex(param, 1, XS_CODE_ARGUMENT, index); |
4125 | 31.2k | fxNodeDispatchCodeAssign(item, param, 0); |
4126 | 31.2k | } |
4127 | 31.7k | fxCoderAddByte(param, -1, XS_CODE_POP); |
4128 | 31.7k | item = item->next; |
4129 | 31.7k | index++; |
4130 | 31.7k | } |
4131 | 151k | } |
4132 | | |
4133 | | void fxPostfixExpressionNodeCode(void* it, void* param) |
4134 | 19.9k | { |
4135 | 19.9k | txPostfixExpressionNode* self = it; |
4136 | 19.9k | txInteger value; |
4137 | 19.9k | fxNodeDispatchCodeThis(self->left, param, 1); |
4138 | 19.9k | if (!(self->flags & mxExpressionNoValue)) { |
4139 | 10.4k | value = fxCoderUseTemporaryVariable(param); |
4140 | 10.4k | fxCoderAddByte(param, 0, XS_CODE_TO_NUMERIC); |
4141 | 10.4k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, value); |
4142 | 10.4k | } |
4143 | 19.9k | fxCoderAddByte(param, 0, self->description->code); |
4144 | 19.9k | fxNodeDispatchCodeAssign(self->left, param, 0); |
4145 | 19.9k | if (!(self->flags & mxExpressionNoValue)) { |
4146 | 10.4k | fxCoderAddByte(param, -1, XS_CODE_POP); |
4147 | 10.4k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, value); |
4148 | 10.4k | fxCoderUnuseTemporaryVariables(param, 1); |
4149 | 10.4k | } |
4150 | 19.9k | } |
4151 | | |
4152 | | void fxPrivateIdentifierNodeCode(void* it, void* param) |
4153 | 0 | { |
4154 | 0 | txPrivateMemberNode* self = it; |
4155 | 0 | fxNodeDispatchCode(self->reference, param); |
4156 | 0 | fxCoderAddIndex(param, 0, XS_CODE_HAS_PRIVATE_1, self->declaration->index); |
4157 | 0 | } |
4158 | | |
4159 | | void fxPrivateMemberNodeCode(void* it, void* param) |
4160 | 3.57k | { |
4161 | 3.57k | txPrivateMemberNode* self = it; |
4162 | 3.57k | fxNodeDispatchCode(self->reference, param); |
4163 | 3.57k | fxCoderAddIndex(param, 0, XS_CODE_GET_PRIVATE_1, self->declaration->index); |
4164 | 3.57k | } |
4165 | | |
4166 | | void fxPrivateMemberNodeCodeAssign(void* it, void* param, txFlag flag) |
4167 | 48 | { |
4168 | 48 | txPrivateMemberNode* self = it; |
4169 | 48 | fxCoderAddIndex(param, -1, XS_CODE_SET_PRIVATE_1, self->declaration->index); |
4170 | 48 | } |
4171 | | |
4172 | | void fxPrivateMemberNodeCodeDelete(void* it, void* param) |
4173 | 0 | { |
4174 | 0 | txPrivateMemberNode* self = it; |
4175 | 0 | txCoder* coder = param; |
4176 | 0 | fxNodeDispatchCode(self->reference, param); |
4177 | 0 | fxReportParserError(coder->parser, self->line, "delete private property"); |
4178 | 0 | } |
4179 | | |
4180 | | void fxPrivateMemberNodeCodeReference(void* it, void* param, txFlag flag) |
4181 | 39 | { |
4182 | 39 | txPrivateMemberNode* self = it; |
4183 | 39 | fxNodeDispatchCode(self->reference, param); |
4184 | 39 | } |
4185 | | |
4186 | | txFlag fxPrivateMemberNodeCodeThis(void* it, void* param, txFlag flag) |
4187 | 9 | { |
4188 | 9 | txPrivateMemberNode* self = it; |
4189 | 9 | fxNodeDispatchCode(self->reference, param); |
4190 | 9 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
4191 | 9 | fxCoderAddIndex(param, 0, XS_CODE_GET_PRIVATE_1, self->declaration->index); |
4192 | 9 | return 1; |
4193 | 9 | } |
4194 | | |
4195 | | void fxProgramNodeCode(void* it, void* param) |
4196 | 306k | { |
4197 | 306k | txProgramNode* self = it; |
4198 | 306k | txCoder* coder = param; |
4199 | | |
4200 | 306k | coder->line = -1; |
4201 | 306k | coder->programFlag = 1; |
4202 | 306k | coder->scopeLevel = 0; |
4203 | 306k | coder->firstBreakTarget = NULL; |
4204 | 306k | coder->firstContinueTarget = NULL; |
4205 | | |
4206 | 306k | if (self->flags & mxStrictFlag) |
4207 | 1.62k | fxCoderAddIndex(param, 0, XS_CODE_BEGIN_STRICT, 0); |
4208 | 304k | else |
4209 | 304k | fxCoderAddIndex(param, 0, XS_CODE_BEGIN_SLOPPY, 0); |
4210 | 306k | coder->path = C_NULL; |
4211 | 306k | if (self->line >= 0) |
4212 | 306k | fxCoderAddLine(coder, 0, XS_CODE_LINE, it); |
4213 | 306k | if (coder->parser->flags & mxEvalFlag) { |
4214 | 185k | coder->evalFlag = 1; |
4215 | 185k | fxScopeCodingEval(self->scope, param); |
4216 | 185k | } |
4217 | 120k | else |
4218 | 120k | fxScopeCodingProgram(self->scope, param); |
4219 | 306k | coder->returnTarget = fxCoderCreateTarget(param); |
4220 | 306k | fxScopeCodeDefineNodes(self->scope, param); |
4221 | 306k | fxNodeDispatchCode(self->body, param); |
4222 | 306k | fxCoderAdd(param, 0, coder->returnTarget); |
4223 | 306k | fxCoderAddByte(param, 0, XS_CODE_RETURN); |
4224 | 306k | } |
4225 | | |
4226 | | void fxQuestionMarkNodeCode(void* it, void* param) |
4227 | 543 | { |
4228 | 543 | txQuestionMarkNode* self = it; |
4229 | 543 | txTargetCode* elseTarget = fxCoderCreateTarget(param); |
4230 | 543 | txTargetCode* endTarget = fxCoderCreateTarget(param); |
4231 | 543 | self->thenExpression->flags |= (self->flags & mxTailRecursionFlag); |
4232 | 543 | self->elseExpression->flags |= (self->flags & mxTailRecursionFlag); |
4233 | 543 | fxNodeDispatchCode(self->expression, param); |
4234 | 543 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, elseTarget); |
4235 | 543 | fxNodeDispatchCode(self->thenExpression, param); |
4236 | 543 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, endTarget); |
4237 | 543 | fxCoderAdd(param, -1, elseTarget); |
4238 | 543 | fxNodeDispatchCode(self->elseExpression, param); |
4239 | 543 | fxCoderAdd(param, 0, endTarget); |
4240 | 543 | } |
4241 | | |
4242 | | void fxRegexpNodeCode(void* it, void* param) |
4243 | 7.21k | { |
4244 | 7.21k | txRegexpNode* self = it; |
4245 | 7.21k | fxCoderAddByte(param, 1, XS_CODE_REGEXP); |
4246 | 7.21k | fxCoderAddByte(param, 2, XS_CODE_NEW); |
4247 | 7.21k | fxNodeDispatchCode(self->modifier, param); |
4248 | 7.21k | fxNodeDispatchCode(self->value, param); |
4249 | 7.21k | fxCoderAddInteger(param, -4, XS_CODE_RUN_1, 2); |
4250 | 7.21k | } |
4251 | | |
4252 | | void fxReturnNodeCode(void* it, void* param) |
4253 | 27.3k | { |
4254 | 27.3k | txStatementNode* self = it; |
4255 | 27.3k | txCoder* coder = param; |
4256 | 27.3k | if (coder->programFlag) |
4257 | 0 | fxReportParserError(coder->parser, self->line, "invalid return"); |
4258 | 27.3k | if (self->expression) { |
4259 | 25.3k | if (((self->flags & (mxStrictFlag | mxGeneratorFlag)) == mxStrictFlag) && (coder->returnTarget->original == NULL)) |
4260 | 710 | self->expression->flags |= mxTailRecursionFlag; |
4261 | 25.3k | fxNodeDispatchCode(self->expression, param); |
4262 | 25.3k | if ((self->flags & (mxAsyncFlag | mxGeneratorFlag)) == (mxAsyncFlag | mxGeneratorFlag)) { |
4263 | 5 | fxCoderAddByte(param, 0, XS_CODE_AWAIT); |
4264 | 5 | fxCoderAddByte(coder, 0, XS_CODE_THROW_STATUS); |
4265 | 5 | } |
4266 | 25.3k | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4267 | 25.3k | } |
4268 | 2.02k | else if ((self->flags & (mxAsyncFlag | mxGeneratorFlag)) != (mxAsyncFlag | mxGeneratorFlag)) { |
4269 | 2.02k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
4270 | 2.02k | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4271 | 2.02k | } |
4272 | 27.3k | fxCoderAdjustEnvironment(coder, coder->returnTarget); |
4273 | 27.3k | fxCoderAdjustScope(coder, coder->returnTarget); |
4274 | 27.3k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, coder->returnTarget); |
4275 | 27.3k | } |
4276 | | |
4277 | | void fxSpreadNodeCode(void* it, void* param, txInteger counter) |
4278 | 945 | { |
4279 | 945 | txSpreadNode* self = it; |
4280 | 945 | txCoder* coder = param; |
4281 | 945 | txTargetCode* nextTarget = fxCoderCreateTarget(param); |
4282 | 945 | txTargetCode* doneTarget = fxCoderCreateTarget(param); |
4283 | 945 | txInteger iterator; |
4284 | 945 | fxNodeDispatchCode(self->expression, param); |
4285 | 945 | fxCoderAddByte(param, 0, XS_CODE_FOR_OF); |
4286 | 945 | iterator = fxCoderUseTemporaryVariable(param); |
4287 | 945 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, iterator); |
4288 | 945 | fxCoderAddByte(param, -1, XS_CODE_POP); |
4289 | 945 | fxCoderAdd(param, 0, nextTarget); |
4290 | 945 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, iterator); |
4291 | 945 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
4292 | 945 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->nextSymbol); |
4293 | 945 | fxCoderAddByte(param, 1, XS_CODE_CALL); |
4294 | 945 | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
4295 | 945 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
4296 | 945 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->doneSymbol); |
4297 | 945 | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, doneTarget); |
4298 | 945 | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, coder->parser->valueSymbol); |
4299 | 945 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, counter); |
4300 | 945 | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, 1); |
4301 | 945 | fxCoderAddByte(param, -1, XS_CODE_ADD); |
4302 | 945 | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, counter); |
4303 | 945 | fxCoderAddByte(param, -1, XS_CODE_POP); |
4304 | 945 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, nextTarget); |
4305 | 945 | fxCoderAdd(param, 1, doneTarget); |
4306 | 945 | fxCoderAddByte(param, -1, XS_CODE_POP); |
4307 | 945 | fxCoderUnuseTemporaryVariables(param, 1); |
4308 | 945 | } |
4309 | | |
4310 | | void fxStatementNodeCode(void* it, void* param) |
4311 | 696k | { |
4312 | 696k | txStatementNode* self = it; |
4313 | 696k | txCoder* coder = param; |
4314 | 696k | if (coder->programFlag) { |
4315 | 498k | fxNodeDispatchCode(self->expression, param); |
4316 | 498k | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4317 | 498k | } |
4318 | 198k | else { |
4319 | 198k | self->expression->flags |= mxExpressionNoValue; |
4320 | 198k | fxNodeDispatchCode(self->expression, param); |
4321 | 198k | if (coder->lastCode->id == XS_CODE_SET_CLOSURE_1) { |
4322 | 564 | coder->lastCode->id = XS_CODE_PULL_CLOSURE_1; |
4323 | 564 | coder->stackLevel--; |
4324 | 564 | coder->lastCode->stackLevel = coder->stackLevel; |
4325 | 564 | } |
4326 | 197k | else if (coder->lastCode->id == XS_CODE_SET_LOCAL_1) { |
4327 | 1.06k | coder->lastCode->id = XS_CODE_PULL_LOCAL_1; |
4328 | 1.06k | coder->stackLevel--; |
4329 | 1.06k | coder->lastCode->stackLevel = coder->stackLevel; |
4330 | 1.06k | } |
4331 | 196k | else |
4332 | 196k | fxCoderAddByte(param, -1, XS_CODE_POP); |
4333 | 198k | } |
4334 | 696k | } |
4335 | | |
4336 | | void fxStatementsNodeCode(void* it, void* param) |
4337 | 98.6k | { |
4338 | 98.6k | txStatementsNode* self = it; |
4339 | 98.6k | txNode* item = self->items->first; |
4340 | 568k | while (item) { |
4341 | 469k | fxNodeDispatchCode(item, param); |
4342 | 469k | item = item->next; |
4343 | 469k | } |
4344 | 98.6k | } |
4345 | | |
4346 | | void fxStringNodeCode(void* it, void* param) |
4347 | 2.42M | { |
4348 | 2.42M | txStringNode* self = it; |
4349 | 2.42M | txCoder* coder = param; |
4350 | 2.42M | txParser* parser = coder->parser; |
4351 | 2.42M | if (self->flags & mxStringErrorFlag) |
4352 | 1.12k | fxReportParserError(parser, self->line, "invalid escape sequence"); |
4353 | 2.42M | fxCoderAddString(param, 1, XS_CODE_STRING_1, self->length, self->value); |
4354 | 2.42M | } |
4355 | | |
4356 | | void fxSuperNodeCode(void* it, void* param) |
4357 | 239 | { |
4358 | 239 | txSuperNode* self = it; |
4359 | 239 | fxCoderAddByte(param, 3, XS_CODE_SUPER); |
4360 | 239 | fxNodeDispatchCode(self->params, param); |
4361 | 239 | fxCoderAddByte(param, 0, XS_CODE_SET_THIS); |
4362 | 239 | if (self->instanceInitAccess) { |
4363 | 12 | fxCoderAddByte(param, 1, XS_CODE_GET_THIS); |
4364 | 12 | fxCoderAddIndex(param, 1, XS_CODE_GET_CLOSURE_1, self->instanceInitAccess->declaration->index); |
4365 | 12 | fxCoderAddByte(param, 1, XS_CODE_CALL); |
4366 | 12 | fxCoderAddInteger(param, -2, XS_CODE_RUN_1, 0); |
4367 | 12 | fxCoderAddByte(param, -1, XS_CODE_POP); |
4368 | 12 | } |
4369 | 239 | } |
4370 | | |
4371 | | void fxSwitchNodeCode(void* it, void* param) |
4372 | 971 | { |
4373 | 971 | txSwitchNode* self = it; |
4374 | 971 | txCoder* coder = param; |
4375 | 971 | txTargetCode* breakTarget; |
4376 | 971 | txCaseNode* caseNode; |
4377 | 971 | txCaseNode* defaultNode = NULL; |
4378 | 971 | txUsingContext context; |
4379 | 971 | fxNodeDispatchCode(self->expression, param); |
4380 | 971 | fxScopeCodingBlock(self->scope, param); |
4381 | 971 | if (self->scope->disposableNodeCount) |
4382 | 0 | fxScopeCodeUsing(self->scope, coder, &context); |
4383 | 971 | breakTarget = fxCoderCreateTarget(coder); |
4384 | 971 | breakTarget->label = fxNewParserChunkClear(coder->parser, sizeof(txLabelNode)); |
4385 | 971 | breakTarget->nextTarget = coder->firstBreakTarget; |
4386 | 971 | coder->firstBreakTarget = breakTarget; |
4387 | 971 | if (coder->programFlag) { |
4388 | 942 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
4389 | 942 | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4390 | 942 | } |
4391 | 971 | caseNode = (txCaseNode*)self->items->first; |
4392 | 2.02k | while (caseNode) { |
4393 | 1.05k | caseNode->target = fxCoderCreateTarget(param); |
4394 | 1.05k | if (caseNode->expression) { |
4395 | 1.03k | fxCoderAddByte(param, 1, XS_CODE_DUB); |
4396 | 1.03k | fxNodeDispatchCode(caseNode->expression, param); |
4397 | 1.03k | fxCoderAddByte(param, -1, XS_CODE_STRICT_EQUAL); |
4398 | 1.03k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, caseNode->target); |
4399 | 1.03k | } |
4400 | 17 | else |
4401 | 17 | defaultNode = caseNode; |
4402 | 1.05k | caseNode = (txCaseNode*)caseNode->next; |
4403 | 1.05k | } |
4404 | 971 | if (defaultNode) |
4405 | 17 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, defaultNode->target); |
4406 | 954 | else |
4407 | 954 | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, coder->firstBreakTarget); |
4408 | 971 | caseNode = (txCaseNode*)self->items->first; |
4409 | 2.02k | while (caseNode) { |
4410 | 1.05k | fxCoderAdd(param, 0, caseNode->target); |
4411 | 1.05k | if (caseNode->statement) |
4412 | 77 | fxNodeDispatchCode(caseNode->statement, param); |
4413 | 1.05k | caseNode = (txCaseNode*)caseNode->next; |
4414 | 1.05k | } |
4415 | 971 | fxCoderAdd(param, 0, coder->firstBreakTarget); |
4416 | 971 | coder->firstBreakTarget = breakTarget->nextTarget; |
4417 | 971 | if (self->scope->disposableNodeCount) |
4418 | 0 | fxScopeCodeUsed(self->scope, coder, &context); |
4419 | 971 | fxScopeCoded(self->scope, param); |
4420 | 971 | fxCoderAddByte(param, -1, XS_CODE_POP); |
4421 | 971 | } |
4422 | | |
4423 | | void fxTemplateNodeCode(void* it, void* param) |
4424 | 1.13M | { |
4425 | 1.13M | txTemplateNode* self = it; |
4426 | 1.13M | txCoder* coder = param; |
4427 | 1.13M | txParser* parser = coder->parser; |
4428 | 1.13M | txNode* item = self->items->first; |
4429 | | |
4430 | 1.13M | if (self->reference) { |
4431 | 1.09M | txSymbol* symbol; |
4432 | 1.09M | txTargetCode* cacheTarget = fxCoderCreateTarget(param); |
4433 | 1.09M | txInteger i = (self->items->length / 2) + 1; |
4434 | 1.09M | txInteger raws = fxCoderUseTemporaryVariable(param); |
4435 | 1.09M | txInteger strings = fxCoderUseTemporaryVariable(param); |
4436 | 1.09M | txFlag flag = XS_DONT_DELETE_FLAG | XS_DONT_SET_FLAG; |
4437 | | |
4438 | 1.09M | fxNodeDispatchCodeThis(self->reference, param, 0); |
4439 | 1.09M | fxCoderAddByte(param, 1, XS_CODE_CALL); |
4440 | | |
4441 | 1.09M | fxGenerateTag(parser->console, parser->buffer, parser->bufferSize, (parser->path) ? parser->path->string : C_NULL); |
4442 | 1.09M | symbol = fxNewParserSymbol(parser, parser->buffer); |
4443 | 1.09M | fxCoderAddByte(param, 1, XS_CODE_TEMPLATE_CACHE); |
4444 | 1.09M | fxCoderAddSymbol(param, 0, XS_CODE_GET_PROPERTY, symbol); |
4445 | 1.09M | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_COALESCE_1, cacheTarget); |
4446 | 1.09M | fxCoderAddByte(param, 1, XS_CODE_TEMPLATE_CACHE); |
4447 | | |
4448 | 1.09M | fxCoderAddByte(param, 1, XS_CODE_ARRAY); |
4449 | 1.09M | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, strings); |
4450 | 1.09M | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, i); |
4451 | 1.09M | fxCoderAddSymbol(param, -1, XS_CODE_SET_PROPERTY, coder->parser->lengthSymbol); |
4452 | 1.09M | fxCoderAddByte(param, -1, XS_CODE_POP); |
4453 | 1.09M | fxCoderAddByte(param, 1, XS_CODE_ARRAY); |
4454 | 1.09M | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, raws); |
4455 | 1.09M | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, i); |
4456 | 1.09M | fxCoderAddSymbol(param, -1, XS_CODE_SET_PROPERTY, coder->parser->lengthSymbol); |
4457 | 1.09M | fxCoderAddByte(param, -1, XS_CODE_POP); |
4458 | 1.09M | i = 0; |
4459 | 2.22M | while (item) { |
4460 | 1.12M | if (item->description->token == XS_TOKEN_TEMPLATE_MIDDLE) { |
4461 | | |
4462 | 1.11M | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, strings); |
4463 | 1.11M | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, i); |
4464 | 1.11M | fxCoderAddByte(param, 0, XS_CODE_AT); |
4465 | 1.11M | if (((txTemplateItemNode*)item)->string->flags & mxStringErrorFlag) |
4466 | 5.74k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
4467 | 1.10M | else |
4468 | 1.10M | fxNodeDispatchCode(((txTemplateItemNode*)item)->string, param); |
4469 | 1.11M | fxCoderAddByte(param, -3, XS_CODE_NEW_PROPERTY_AT); |
4470 | 1.11M | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, flag); |
4471 | | |
4472 | 1.11M | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, raws); |
4473 | 1.11M | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, i); |
4474 | 1.11M | fxCoderAddByte(param, 0, XS_CODE_AT); |
4475 | 1.11M | fxNodeDispatchCode(((txTemplateItemNode*)item)->raw, param); |
4476 | 1.11M | fxCoderAddByte(param, -3, XS_CODE_NEW_PROPERTY_AT); |
4477 | 1.11M | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, flag); |
4478 | | |
4479 | 1.11M | i++; |
4480 | 1.11M | } |
4481 | 1.12M | item = item->next; |
4482 | 1.12M | } |
4483 | 1.09M | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, strings); |
4484 | 1.09M | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, raws); |
4485 | 1.09M | fxCoderAddSymbol(param, -1, XS_CODE_SET_PROPERTY, parser->rawSymbol); |
4486 | 1.09M | fxCoderAddByte(param, -1, XS_CODE_POP); |
4487 | 1.09M | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, strings); |
4488 | 1.09M | fxCoderAddByte(param, 0, XS_CODE_TEMPLATE); |
4489 | | |
4490 | 1.09M | fxCoderAddSymbol(param, -1, XS_CODE_SET_PROPERTY, symbol); |
4491 | | |
4492 | 1.09M | fxCoderAdd(param, 0, cacheTarget); |
4493 | | |
4494 | 1.09M | i = 1; |
4495 | 1.09M | item = self->items->first; |
4496 | 2.22M | while (item) { |
4497 | 1.12M | if (item->description->token != XS_TOKEN_TEMPLATE_MIDDLE) { |
4498 | 10.0k | fxNodeDispatchCode(item, param); |
4499 | 10.0k | i++; |
4500 | 10.0k | } |
4501 | 1.12M | item = item->next; |
4502 | 1.12M | } |
4503 | 1.09M | fxCoderAddInteger(param, -2 - i, (self->flags & mxTailRecursionFlag) ? XS_CODE_RUN_TAIL_1 : XS_CODE_RUN_1, i); |
4504 | 1.09M | fxCoderUnuseTemporaryVariables(coder, 2); |
4505 | 1.09M | } |
4506 | 36.4k | else { |
4507 | 36.4k | fxNodeDispatchCode(((txTemplateItemNode*)item)->string, param); |
4508 | 36.4k | item = item->next; |
4509 | 41.3k | while (item) { |
4510 | 4.87k | if (item->description->token == XS_TOKEN_TEMPLATE_MIDDLE) { |
4511 | 2.52k | fxNodeDispatchCode(((txTemplateItemNode*)item)->string, param); |
4512 | 2.52k | } |
4513 | 2.34k | else { |
4514 | 2.34k | fxNodeDispatchCode(item, param); |
4515 | 2.34k | fxCoderAddByte(param, 1, XS_CODE_TO_STRING); |
4516 | 2.34k | } |
4517 | 4.87k | fxCoderAddByte(param, -1, XS_CODE_ADD); |
4518 | 4.87k | item = item->next; |
4519 | 4.87k | } |
4520 | 36.4k | } |
4521 | 1.13M | } |
4522 | | |
4523 | | void fxThisNodeCode(void* it, void* param) |
4524 | 6.98k | { |
4525 | 6.98k | txNode* self = it; |
4526 | 6.98k | if (self->flags & mxDerivedFlag) |
4527 | 5 | fxCoderAddByte(param, 1, XS_CODE_GET_THIS); |
4528 | 6.98k | else |
4529 | 6.98k | fxCoderAddByte(param, 1, self->description->code); |
4530 | 6.98k | } |
4531 | | |
4532 | | void fxThrowNodeCode(void* it, void* param) |
4533 | 3.89k | { |
4534 | 3.89k | txStatementNode* self = it; |
4535 | 3.89k | fxNodeDispatchCode(self->expression, param); |
4536 | 3.89k | fxCoderAddByte(param, -1, XS_CODE_THROW); |
4537 | 3.89k | } |
4538 | | |
4539 | | void fxTryNodeCode(void* it, void* param) |
4540 | 2.21k | { |
4541 | 2.21k | txTryNode* self = it; |
4542 | 2.21k | txCoder* coder = param; |
4543 | 2.21k | txInteger exception; |
4544 | 2.21k | txInteger selector; |
4545 | 2.21k | txInteger result; |
4546 | 2.21k | txInteger selection; |
4547 | 2.21k | txTargetCode* catchTarget; |
4548 | 2.21k | txTargetCode* normalTarget; |
4549 | 2.21k | txTargetCode* finallyTarget; |
4550 | | |
4551 | 2.21k | exception = fxCoderUseTemporaryVariable(coder); |
4552 | 2.21k | selector = fxCoderUseTemporaryVariable(coder); |
4553 | 2.21k | result = fxCoderUseTemporaryVariable(coder); |
4554 | | |
4555 | 2.21k | coder->firstBreakTarget = fxCoderAliasTargets(param, coder->firstBreakTarget); |
4556 | 2.21k | coder->firstContinueTarget = fxCoderAliasTargets(param, coder->firstContinueTarget); |
4557 | 2.21k | coder->returnTarget = fxCoderAliasTargets(param, coder->returnTarget); |
4558 | 2.21k | catchTarget = fxCoderCreateTarget(param); |
4559 | 2.21k | normalTarget = fxCoderCreateTarget(param); |
4560 | 2.21k | finallyTarget = fxCoderCreateTarget(param); |
4561 | | |
4562 | 2.21k | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, 0); |
4563 | 2.21k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, selector); |
4564 | 2.21k | fxCoderAddByte(param, -1, XS_CODE_POP); |
4565 | | |
4566 | 2.21k | fxCoderAddBranch(param, 0, XS_CODE_CATCH_1, catchTarget); |
4567 | 2.21k | if (coder->programFlag) { |
4568 | 2.05k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
4569 | 2.05k | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4570 | 2.05k | } |
4571 | 2.21k | fxNodeDispatchCode(self->tryBlock, param); |
4572 | 2.21k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, normalTarget); |
4573 | 2.21k | if (self->catchBlock) { |
4574 | 2.19k | fxCoderAddByte(param, 0, XS_CODE_UNCATCH); |
4575 | 2.19k | fxCoderAdd(param, 0, catchTarget); |
4576 | 2.19k | catchTarget = fxCoderCreateTarget(param); |
4577 | 2.19k | fxCoderAddBranch(param, 0, XS_CODE_CATCH_1, catchTarget); |
4578 | 2.19k | if (coder->programFlag) { |
4579 | 2.05k | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
4580 | 2.05k | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4581 | 2.05k | } |
4582 | 2.19k | fxNodeDispatchCode(self->catchBlock, param); |
4583 | 2.19k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, normalTarget); |
4584 | 2.19k | } |
4585 | | |
4586 | 2.21k | selection = 1; |
4587 | 2.21k | coder->firstBreakTarget = fxCoderFinalizeTargets(param, coder->firstBreakTarget, selector, &selection, finallyTarget); |
4588 | 2.21k | coder->firstContinueTarget = fxCoderFinalizeTargets(param, coder->firstContinueTarget, selector, &selection, finallyTarget); |
4589 | 2.21k | coder->returnTarget = fxCoderFinalizeTargets(param, coder->returnTarget, selector, &selection, finallyTarget); |
4590 | 2.21k | fxCoderAdd(param, 0, normalTarget); |
4591 | 2.21k | fxCoderAddInteger(param, 1, XS_CODE_INTEGER_1, selection); |
4592 | 2.21k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, selector); |
4593 | 2.21k | fxCoderAddByte(param, -1, XS_CODE_POP); |
4594 | 2.21k | fxCoderAdd(param, 0, finallyTarget); |
4595 | 2.21k | fxCoderAddByte(param, 0, XS_CODE_UNCATCH); |
4596 | 2.21k | fxCoderAdd(param, 0, catchTarget); |
4597 | 2.21k | fxCoderAddByte(param, 1, XS_CODE_EXCEPTION); |
4598 | 2.21k | fxCoderAddIndex(param, 0, XS_CODE_SET_LOCAL_1, exception); |
4599 | 2.21k | fxCoderAddByte(param, -1, XS_CODE_POP); |
4600 | 2.21k | if (self->finallyBlock) { |
4601 | 28 | if (coder->programFlag) { |
4602 | 9 | fxCoderAddByte(param, 1, XS_CODE_GET_RESULT); |
4603 | 9 | fxCoderAddIndex(param, -1, XS_CODE_PULL_LOCAL_1, result); |
4604 | 9 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
4605 | 9 | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4606 | 9 | } |
4607 | 28 | fxNodeDispatchCode(self->finallyBlock, param); |
4608 | 28 | if (coder->programFlag) { |
4609 | 9 | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, result); |
4610 | 9 | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4611 | 9 | } |
4612 | 28 | } |
4613 | 2.21k | catchTarget = fxCoderCreateTarget(param); |
4614 | 2.21k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, selector); |
4615 | 2.21k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_IF_1, catchTarget); |
4616 | 2.21k | fxCoderAddIndex(param, 1, XS_CODE_GET_LOCAL_1, exception); |
4617 | 2.21k | fxCoderAddByte(param, -1, XS_CODE_THROW); |
4618 | 2.21k | fxCoderAdd(param, 0, catchTarget); |
4619 | 2.21k | selection = 1; |
4620 | 2.21k | fxCoderJumpTargets(param, coder->firstBreakTarget, selector, &selection); |
4621 | 2.21k | fxCoderJumpTargets(param, coder->firstContinueTarget, selector, &selection); |
4622 | 2.21k | fxCoderJumpTargets(param, coder->returnTarget, selector, &selection); |
4623 | 2.21k | fxCoderUnuseTemporaryVariables(coder, 3); |
4624 | 2.21k | } |
4625 | | |
4626 | | void fxUnaryExpressionNodeCode(void* it, void* param) |
4627 | 46.3k | { |
4628 | 46.3k | txUnaryExpressionNode* self = it; |
4629 | 46.3k | fxNodeDispatchCode(self->right, param); |
4630 | 46.3k | fxCoderAddByte(param, 0, self->description->code); |
4631 | 46.3k | } |
4632 | | |
4633 | | void fxUndefinedNodeCodeAssign(void* it, void* param, txFlag flag) |
4634 | 0 | { |
4635 | 0 | txCoder* coder = param; |
4636 | 0 | fxCoderAddSymbol(param, -1, XS_CODE_SET_VARIABLE, coder->parser->undefinedSymbol); |
4637 | 0 | } |
4638 | | |
4639 | | void fxUndefinedNodeCodeDelete(void* it, void* param) |
4640 | 0 | { |
4641 | 0 | txNode* self = it; |
4642 | 0 | txCoder* coder = param; |
4643 | 0 | if (self->flags & mxStrictFlag) |
4644 | 0 | fxReportParserError(coder->parser, self->line, "delete identifier (strict code)"); |
4645 | 0 | fxCoderAddByte(param, 1, XS_CODE_FALSE); |
4646 | 0 | } |
4647 | | |
4648 | | void fxUndefinedNodeCodeReference(void* it, void* param, txFlag flag) |
4649 | 0 | { |
4650 | 0 | txCoder* coder = param; |
4651 | 0 | if (coder->evalFlag) |
4652 | 0 | fxCoderAddSymbol(param, 1, XS_CODE_EVAL_REFERENCE, coder->parser->undefinedSymbol); |
4653 | 0 | else |
4654 | 0 | fxCoderAddSymbol(param, 1, XS_CODE_PROGRAM_REFERENCE, coder->parser->undefinedSymbol); |
4655 | 0 | } |
4656 | | |
4657 | | void fxValueNodeCode(void* it, void* param) |
4658 | 154k | { |
4659 | 154k | txNode* self = it; |
4660 | 154k | fxCoderAddByte(param, 1, self->description->code); |
4661 | 154k | } |
4662 | | |
4663 | | void fxWhileNodeCode(void* it, void* param) |
4664 | 2.91k | { |
4665 | 2.91k | txWhileNode* self = it; |
4666 | 2.91k | txCoder* coder = param; |
4667 | 2.91k | if (coder->programFlag) { |
4668 | 540 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
4669 | 540 | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4670 | 540 | } |
4671 | 2.91k | fxCoderAdd(param, 0, coder->firstContinueTarget); |
4672 | 2.91k | fxNodeDispatchCode(self->expression, param); |
4673 | 2.91k | fxCoderAddBranch(param, -1, XS_CODE_BRANCH_ELSE_1, coder->firstBreakTarget); |
4674 | 2.91k | fxNodeDispatchCode(self->statement, param); |
4675 | 2.91k | fxCoderAddBranch(param, 0, XS_CODE_BRANCH_1, coder->firstContinueTarget); |
4676 | 2.91k | } |
4677 | | |
4678 | | void fxWithNodeCode(void* it, void* param) |
4679 | 1.66k | { |
4680 | 1.66k | txWithNode* self = it; |
4681 | 1.66k | txCoder* coder = param; |
4682 | 1.66k | txBoolean evalFlag; |
4683 | 1.66k | fxNodeDispatchCode(self->expression, param); |
4684 | 1.66k | fxCoderAddByte(param, 0, XS_CODE_TO_INSTANCE); |
4685 | 1.66k | fxCoderAddByte(param, 0, XS_CODE_WITH); |
4686 | 1.66k | fxCoderAddByte(param, -1, XS_CODE_POP); |
4687 | 1.66k | evalFlag = coder->evalFlag; |
4688 | 1.66k | coder->environmentLevel++; |
4689 | 1.66k | coder->evalFlag = 1; |
4690 | 1.66k | if (coder->programFlag) { |
4691 | 214 | fxCoderAddByte(param, 1, XS_CODE_UNDEFINED); |
4692 | 214 | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4693 | 214 | } |
4694 | 1.66k | fxNodeDispatchCode(self->statement, param); |
4695 | 1.66k | coder->evalFlag = evalFlag; |
4696 | 1.66k | coder->environmentLevel--; |
4697 | 1.66k | fxCoderAddByte(param, 0, XS_CODE_WITHOUT); |
4698 | 1.66k | } |
4699 | | |
4700 | | void fxYieldNodeCode(void* it, void* param) |
4701 | 506 | { |
4702 | 506 | txStatementNode* self = it; |
4703 | 506 | txBoolean async = (self->flags & mxAsyncFlag) ? 1 : 0; |
4704 | 506 | txCoder* coder = param; |
4705 | 506 | txTargetCode* target = fxCoderCreateTarget(coder); |
4706 | 506 | if (async) { |
4707 | 21 | fxNodeDispatchCode(self->expression, param); |
4708 | 21 | } |
4709 | 485 | else { |
4710 | 485 | fxCoderAddByte(param, 1, XS_CODE_OBJECT); |
4711 | 485 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
4712 | 485 | fxNodeDispatchCode(self->expression, param); |
4713 | 485 | fxCoderAddSymbol(param, -2, XS_CODE_NEW_PROPERTY, coder->parser->valueSymbol); |
4714 | 485 | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, 0); |
4715 | 485 | fxCoderAddByte(param, 1, XS_CODE_DUB); |
4716 | 485 | fxCoderAddByte(param, 1, XS_CODE_FALSE); |
4717 | 485 | fxCoderAddSymbol(param, -2, XS_CODE_NEW_PROPERTY, coder->parser->doneSymbol); |
4718 | 485 | fxCoderAddInteger(param, 0, XS_CODE_INTEGER_1, 0); |
4719 | 485 | } |
4720 | 506 | fxCoderAddByte(coder, 0, XS_CODE_YIELD); |
4721 | 506 | fxCoderAddBranch(coder, 1, XS_CODE_BRANCH_STATUS_1, target); |
4722 | 506 | if (async) { |
4723 | 21 | fxCoderAddByte(param, 0, XS_CODE_AWAIT); |
4724 | 21 | fxCoderAddByte(coder, 0, XS_CODE_THROW_STATUS); |
4725 | 21 | } |
4726 | 506 | fxCoderAddByte(param, -1, XS_CODE_SET_RESULT); |
4727 | 506 | fxCoderAdjustEnvironment(coder, coder->returnTarget); |
4728 | 506 | fxCoderAdjustScope(coder, coder->returnTarget); |
4729 | 506 | fxCoderAddBranch(coder, 0, XS_CODE_BRANCH_1, coder->returnTarget); |
4730 | 506 | fxCoderAdd(coder, 0, target); |
4731 | 506 | } |
4732 | | |