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