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