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