Coverage Report

Created: 2026-03-07 07:04

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