@agoric/xsnap 0.14.3-u14.0 → 0.14.3-u16.0

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