@agoric/xsnap 0.14.3-dev-b047af2.0 → 0.14.3-dev-3eb4230.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 (126) hide show
  1. package/api.js +1 -1
  2. package/package.json +16 -23
  3. package/src/build.js +4 -61
  4. package/moddable/modules/data/base64/base64.js +0 -28
  5. package/moddable/modules/data/base64/manifest.json +0 -11
  6. package/moddable/modules/data/base64/modBase64.c +0 -188
  7. package/moddable/modules/data/binaryMessage/BinaryMessage.js +0 -106
  8. package/moddable/modules/data/crc/crc.c +0 -205
  9. package/moddable/modules/data/crc/crc.js +0 -36
  10. package/moddable/modules/data/crc/manifest.json +0 -8
  11. package/moddable/modules/data/hex/hex.js +0 -28
  12. package/moddable/modules/data/hex/manifest.json +0 -11
  13. package/moddable/modules/data/hex/modHex.c +0 -139
  14. package/moddable/modules/data/logical/logical.js +0 -32
  15. package/moddable/modules/data/logical/modLogical.c +0 -98
  16. package/moddable/modules/data/qrcode/manifest.json +0 -9
  17. package/moddable/modules/data/qrcode/qrcode.c +0 -93
  18. package/moddable/modules/data/qrcode/qrcode.js +0 -23
  19. package/moddable/modules/data/qrcode/qrcodegen.c +0 -1025
  20. package/moddable/modules/data/qrcode/qrcodegen.h +0 -267
  21. package/moddable/modules/data/text/decoder/manifest.json +0 -8
  22. package/moddable/modules/data/text/decoder/textdecoder.c +0 -480
  23. package/moddable/modules/data/text/decoder/textdecoder.js +0 -27
  24. package/moddable/modules/data/text/encoder/manifest.json +0 -8
  25. package/moddable/modules/data/text/encoder/textencoder.c +0 -232
  26. package/moddable/modules/data/text/encoder/textencoder.js +0 -24
  27. package/moddable/modules/data/tinyint/tinyint.c +0 -150
  28. package/moddable/modules/data/tinyint/tinyint.js +0 -53
  29. package/moddable/modules/data/url/manifest.json +0 -17
  30. package/moddable/modules/data/url/url.c +0 -1959
  31. package/moddable/modules/data/url/url.js +0 -210
  32. package/moddable/modules/data/wavreader/manifest.json +0 -8
  33. package/moddable/modules/data/wavreader/wavreader.js +0 -128
  34. package/moddable/modules/data/zlib/deflate.c +0 -161
  35. package/moddable/modules/data/zlib/deflate.js +0 -63
  36. package/moddable/modules/data/zlib/inflate.c +0 -145
  37. package/moddable/modules/data/zlib/inflate.js +0 -66
  38. package/moddable/modules/data/zlib/manifest_deflate.json +0 -9
  39. package/moddable/modules/data/zlib/manifest_inflate.json +0 -9
  40. package/moddable/modules/data/zlib/miniz.c +0 -4924
  41. package/moddable/xs/includes/xs.d.ts +0 -73
  42. package/moddable/xs/includes/xs.h +0 -1533
  43. package/moddable/xs/includes/xsmc.h +0 -206
  44. package/moddable/xs/makefiles/lin/makefile +0 -33
  45. package/moddable/xs/makefiles/lin/xsc.mk +0 -118
  46. package/moddable/xs/makefiles/lin/xsid.mk +0 -90
  47. package/moddable/xs/makefiles/lin/xsl.mk +0 -168
  48. package/moddable/xs/makefiles/lin/xst.mk +0 -201
  49. package/moddable/xs/makefiles/mac/makefile +0 -33
  50. package/moddable/xs/makefiles/mac/xsc.mk +0 -130
  51. package/moddable/xs/makefiles/mac/xsid.mk +0 -102
  52. package/moddable/xs/makefiles/mac/xsl.mk +0 -177
  53. package/moddable/xs/makefiles/mac/xst.mk +0 -203
  54. package/moddable/xs/makefiles/mac/xst_no_asan.txt +0 -52
  55. package/moddable/xs/makefiles/win/build.bat +0 -26
  56. package/moddable/xs/makefiles/win/xsc.mak +0 -142
  57. package/moddable/xs/makefiles/win/xsid.mak +0 -113
  58. package/moddable/xs/makefiles/win/xsl.mak +0 -186
  59. package/moddable/xs/makefiles/win/xst.mak +0 -195
  60. package/moddable/xs/platforms/lin_xs.h +0 -99
  61. package/moddable/xs/platforms/mac_xs.h +0 -97
  62. package/moddable/xs/platforms/wasm_xs.h +0 -79
  63. package/moddable/xs/platforms/win_xs.h +0 -104
  64. package/moddable/xs/platforms/xsHost.h +0 -63
  65. package/moddable/xs/platforms/xsPlatform.h +0 -618
  66. package/moddable/xs/sources/xsAPI.c +0 -2555
  67. package/moddable/xs/sources/xsAll.c +0 -294
  68. package/moddable/xs/sources/xsAll.h +0 -2741
  69. package/moddable/xs/sources/xsArguments.c +0 -222
  70. package/moddable/xs/sources/xsArray.c +0 -2657
  71. package/moddable/xs/sources/xsAtomics.c +0 -844
  72. package/moddable/xs/sources/xsBigInt.c +0 -1859
  73. package/moddable/xs/sources/xsBoolean.c +0 -109
  74. package/moddable/xs/sources/xsCode.c +0 -4493
  75. package/moddable/xs/sources/xsCommon.c +0 -1710
  76. package/moddable/xs/sources/xsCommon.h +0 -1142
  77. package/moddable/xs/sources/xsDataView.c +0 -2890
  78. package/moddable/xs/sources/xsDate.c +0 -1541
  79. package/moddable/xs/sources/xsDebug.c +0 -2710
  80. package/moddable/xs/sources/xsDefaults.c +0 -134
  81. package/moddable/xs/sources/xsError.c +0 -353
  82. package/moddable/xs/sources/xsFunction.c +0 -776
  83. package/moddable/xs/sources/xsGenerator.c +0 -865
  84. package/moddable/xs/sources/xsGlobal.c +0 -839
  85. package/moddable/xs/sources/xsJSON.c +0 -1091
  86. package/moddable/xs/sources/xsLexical.c +0 -1969
  87. package/moddable/xs/sources/xsLockdown.c +0 -933
  88. package/moddable/xs/sources/xsMapSet.c +0 -1649
  89. package/moddable/xs/sources/xsMarshall.c +0 -1020
  90. package/moddable/xs/sources/xsMath.c +0 -624
  91. package/moddable/xs/sources/xsMemory.c +0 -1941
  92. package/moddable/xs/sources/xsModule.c +0 -3101
  93. package/moddable/xs/sources/xsNumber.c +0 -560
  94. package/moddable/xs/sources/xsObject.c +0 -1102
  95. package/moddable/xs/sources/xsPlatforms.c +0 -480
  96. package/moddable/xs/sources/xsProfile.c +0 -577
  97. package/moddable/xs/sources/xsPromise.c +0 -1199
  98. package/moddable/xs/sources/xsProperty.c +0 -636
  99. package/moddable/xs/sources/xsProxy.c +0 -1014
  100. package/moddable/xs/sources/xsRegExp.c +0 -1168
  101. package/moddable/xs/sources/xsRun.c +0 -4889
  102. package/moddable/xs/sources/xsScope.c +0 -1293
  103. package/moddable/xs/sources/xsScript.c +0 -288
  104. package/moddable/xs/sources/xsScript.h +0 -1186
  105. package/moddable/xs/sources/xsSnapshot.c +0 -2161
  106. package/moddable/xs/sources/xsSnapshot.h +0 -51
  107. package/moddable/xs/sources/xsSourceMap.c +0 -218
  108. package/moddable/xs/sources/xsString.c +0 -3332
  109. package/moddable/xs/sources/xsSymbol.c +0 -503
  110. package/moddable/xs/sources/xsSyntaxical.c +0 -4193
  111. package/moddable/xs/sources/xsTree.c +0 -1893
  112. package/moddable/xs/sources/xsType.c +0 -1488
  113. package/moddable/xs/sources/xsdtoa.c +0 -6672
  114. package/moddable/xs/sources/xsmc.c +0 -340
  115. package/moddable/xs/sources/xsre.c +0 -7578
  116. package/xsnap-native/xsnap/makefiles/lin/makefile +0 -10
  117. package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +0 -153
  118. package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +0 -144
  119. package/xsnap-native/xsnap/makefiles/mac/makefile +0 -10
  120. package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +0 -162
  121. package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +0 -153
  122. package/xsnap-native/xsnap/sources/xsnap-worker.c +0 -996
  123. package/xsnap-native/xsnap/sources/xsnap.c +0 -716
  124. package/xsnap-native/xsnap/sources/xsnap.h +0 -142
  125. package/xsnap-native/xsnap/sources/xsnapPlatform.c +0 -1496
  126. package/xsnap-native/xsnap/sources/xsnapPlatform.h +0 -105
@@ -1,4889 +0,0 @@
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 "xsAll.h"
39
-
40
- //#define mxTrace 1
41
- //#define mxTraceCall 1
42
-
43
- #define c_iszero(NUMBER) (FP_ZERO == c_fpclassify(NUMBER))
44
-
45
- extern void fxRemapIDs(txMachine* the, txByte* codeBuffer, txSize codeSize, txID* theIDs);
46
- static void fxRunArguments(txMachine* the, txIndex offset);
47
- static void fxRunBase(txMachine* the);
48
- static void fxRunConstructor(txMachine* the);
49
- static txBoolean fxRunDefine(txMachine* the, txSlot* instance, txSlot* check, txID id, txIndex index, txSlot* slot, txFlag mask);
50
- static txBoolean fxRunDelete(txMachine* the, txSlot* instance, txID id, txIndex index);
51
- static void fxRunDerived(txMachine* the);
52
- static void fxRunExtends(txMachine* the);
53
- static void fxRunForOf(txMachine* the);
54
- static txBoolean fxRunHas(txMachine* the, txSlot* instance, txID id, txIndex index);
55
- static void fxRunIn(txMachine* the);
56
- static void fxRunInstantiate(txMachine* the);
57
- static void fxRunProxy(txMachine* the, txSlot* instance);
58
- static void fxRunInstanceOf(txMachine* the);
59
- static txBoolean fxIsScopableSlot(txMachine* the, txSlot* instance, txID id);
60
- static txBoolean fxToNumericInteger(txMachine* the, txSlot* theSlot);
61
- static txBoolean fxToNumericIntegerUnary(txMachine* the, txSlot* theSlot, txBigIntUnary op);
62
- static txBoolean fxToNumericIntegerBinary(txMachine* the, txSlot* a, txSlot* b, txBigIntBinary op);
63
- static txBoolean fxToNumericNumber(txMachine* the, txSlot* theSlot);
64
- static txBoolean fxToNumericNumberUnary(txMachine* the, txSlot* theSlot, txBigIntUnary op);
65
- static txBoolean fxToNumericNumberBinary(txMachine* the, txSlot* a, txSlot* b, txBigIntBinary op);
66
-
67
- #if defined(__GNUC__) && defined(__OPTIMIZE__)
68
- #if defined(mxFrequency)
69
- #define mxBreak \
70
- the->frequencies[byte]++; \
71
- goto *bytes[byte]
72
- #elif defined(mxTrace)
73
- #define mxBreak \
74
- if (gxDoTrace) fxTraceCode(the, stack, byte); \
75
- goto *bytes[byte]
76
- #elif defined(mxMetering)
77
- #define mxBreak \
78
- the->meterIndex++; \
79
- goto *bytes[byte]
80
- #else
81
- #define mxBreak \
82
- goto *bytes[byte]
83
- #endif
84
- #define mxCase(OPCODE) OPCODE:
85
- #define mxSwitch(OPCODE) mxBreak;
86
- #else
87
- #define mxBreak \
88
- break
89
- #define mxCase(OPCODE) \
90
- case OPCODE:
91
- #if defined(mxFrequency)
92
- #define mxSwitch(OPCODE) \
93
- the->frequencies[OPCODE]++; \
94
- switch(OPCODE)
95
- #else
96
- #define mxSwitch(OPCODE) \
97
- switch(OPCODE)
98
- #endif
99
- #endif
100
-
101
- #define mxCode code
102
- #define mxFrame frame
103
- #define mxEnvironment environment
104
- #define mxScope scope
105
- #define mxStack stack
106
-
107
- #define mxFrameEnd (mxFrame + 5)
108
- #define mxFrameThis (mxFrame + 4)
109
- #define mxFrameFunction (mxFrame + 3)
110
- #define mxFrameTarget (mxFrame + 2)
111
- #define mxFrameResult (mxFrame + 1)
112
- #define mxFrameArgc ((mxFrame - 1)->value.integer)
113
- #define mxFrameArgv(THE_INDEX) (mxFrame - 2 - (THE_INDEX))
114
-
115
- #define mxRestoreState { \
116
- mxStack = the->stack; \
117
- mxScope = the->scope; \
118
- mxFrame = the->frame; \
119
- mxEnvironment = mxFrameToEnvironment(mxFrame); \
120
- mxCode = the->code; \
121
- }
122
- #if defined(mxFrequency)
123
- #define mxSaveState { \
124
- the->exits[byte]++; \
125
- the->stack = mxStack; \
126
- the->scope = mxScope; \
127
- the->frame = mxFrame; \
128
- the->code = mxCode; \
129
- }
130
- #else
131
- #define mxSaveState { \
132
- the->stack = mxStack; \
133
- the->scope = mxScope; \
134
- the->frame = mxFrame; \
135
- the->code = mxCode; \
136
- }
137
- #endif
138
-
139
- #if mxBoundsCheck
140
- #define mxAllocStack(_COUNT) \
141
- if ((mxStack - _COUNT) < the->stackBottom) { \
142
- mxSaveState; \
143
- fxAbort(the, XS_STACK_OVERFLOW_EXIT); \
144
- } \
145
- mxStack -= _COUNT
146
- #else
147
- #define mxAllocStack(_COUNT) \
148
- mxStack -= _COUNT
149
- #endif
150
-
151
- #define mxPushKind(_KIND) { \
152
- mxAllocStack(1); \
153
- mxStack->next = C_NULL; \
154
- mxInitSlotKind(mxStack, _KIND); \
155
- }
156
-
157
- #define mxRunDebug(_ERROR, ...) { \
158
- mxSaveState; \
159
- fxThrowMessage(the, NULL, 0, _ERROR, __VA_ARGS__); \
160
- }
161
-
162
- #define mxRunDebugID(_ERROR, _MESSAGE, _ID) { \
163
- mxSaveState; \
164
- fxIDToString(the, _ID, the->nameBuffer, sizeof(the->nameBuffer)); \
165
- fxThrowMessage(the, NULL, 0, _ERROR, _MESSAGE, the->nameBuffer); \
166
- }
167
-
168
- #define mxToBoolean(SLOT) \
169
- if (XS_BOOLEAN_KIND != (SLOT)->kind) { \
170
- if (XS_SYMBOL_KIND <= (SLOT)->kind) { \
171
- mxSaveState; \
172
- fxToBoolean(the, SLOT); \
173
- mxRestoreState; \
174
- } \
175
- else \
176
- fxToBoolean(the, SLOT); \
177
- }
178
-
179
- #define mxToInteger(SLOT) \
180
- if (XS_INTEGER_KIND != (SLOT)->kind) { \
181
- if (XS_STRING_KIND <= (SLOT)->kind) { \
182
- mxSaveState; \
183
- fxToInteger(the, SLOT); \
184
- mxRestoreState; \
185
- } \
186
- else \
187
- fxToInteger(the, SLOT); \
188
- }
189
-
190
- #define mxToNumber(SLOT) \
191
- if (XS_NUMBER_KIND != (SLOT)->kind) { \
192
- if (XS_STRING_KIND <= (SLOT)->kind) { \
193
- mxSaveState; \
194
- fxToNumber(the, SLOT); \
195
- mxRestoreState; \
196
- } \
197
- else \
198
- fxToNumber(the, SLOT); \
199
- }
200
-
201
- #define mxToString(SLOT) \
202
- if ((XS_STRING_KIND != (SLOT)->kind) && (XS_STRING_X_KIND != (SLOT)->kind)) { \
203
- mxSaveState; \
204
- fxToString(the, SLOT); \
205
- mxRestoreState; \
206
- }
207
-
208
- #define mxToInstance(SLOT) \
209
- if (XS_REFERENCE_KIND != (SLOT)->kind) { \
210
- mxSaveState; \
211
- variable = fxToInstance(the, SLOT); \
212
- mxRestoreState; \
213
- primitive = 1; \
214
- } \
215
- else { \
216
- variable = (SLOT)->value.reference; \
217
- primitive = 0; \
218
- }
219
-
220
- #ifndef mxUnalignedAccess
221
- #define mxUnalignedAccess 1
222
- #endif
223
-
224
- #define mxRunS1(OFFSET) ((txS1*)mxCode)[OFFSET]
225
- #define mxRunU1(OFFSET) ((txU1*)mxCode)[OFFSET]
226
- #if mxBigEndian
227
- #define mxRunS2(OFFSET) (((txS1*)mxCode)[OFFSET+0] << 8) | ((txU1*)mxCode)[OFFSET+1]
228
- #define mxRunS4(OFFSET) (((txS1*)mxCode)[OFFSET+0] << 24) | (((txU1*)mxCode)[OFFSET+1] << 16) | (((txU1*)mxCode)[OFFSET+2] << 8) | ((txU1*)mxCode)[OFFSET+3]
229
- #define mxRunU2(OFFSET) (((txU1*)mxCode)[OFFSET+0] << 8) | ((txU1*)mxCode)[OFFSET+1]
230
- #else
231
- #if mxUnalignedAccess
232
- #define mxRunS2(OFFSET) *((txS2*)(mxCode + OFFSET))
233
- #define mxRunS4(OFFSET) *((txS4*)(mxCode + OFFSET))
234
- #define mxRunU2(OFFSET) *((txU2*)(mxCode + OFFSET))
235
- #else
236
- #define mxRunS2(OFFSET) (((txS1*)mxCode)[OFFSET+1] << 8) | ((txU1*)mxCode)[OFFSET+0]
237
- #define mxRunS4(OFFSET) (((txS1*)mxCode)[OFFSET+3] << 24) | (((txU1*)mxCode)[OFFSET+2] << 16) | (((txU1*)mxCode)[OFFSET+1] << 8) | ((txU1*)mxCode)[OFFSET+0]
238
- #define mxRunU2(OFFSET) (((txU1*)mxCode)[OFFSET+1] << 8) | ((txU1*)mxCode)[OFFSET+0]
239
- #endif
240
- #endif
241
- #ifdef mx32bitID
242
- #define mxRunID(OFFSET) mxRunS4(OFFSET)
243
- #else
244
- #define mxRunID(OFFSET) mxRunS2(OFFSET)
245
- #endif
246
-
247
- #define mxNextCode(OFFSET) { \
248
- mxCode += OFFSET; \
249
- byte = *((txU1*)mxCode); \
250
- }
251
- #define mxSkipCode(OFFSET) { \
252
- mxCode += OFFSET; \
253
- }
254
-
255
- #ifdef mxMetering
256
- #define mxCheckMeter() \
257
- if (the->meterInterval && (the->meterIndex > the->meterCount)) { \
258
- mxSaveState; \
259
- fxCheckMetering(the); \
260
- mxRestoreState; \
261
- }
262
- #define mxBranch(INDEX, OFFSET) \
263
- if ((OFFSET) < 0) { \
264
- mxCheckMeter(); \
265
- } \
266
- mxNextCode((txS4)INDEX + OFFSET)
267
- #define mxBranchElse(TEST, INDEX, OFFSET) \
268
- if (TEST) { \
269
- mxNextCode((txS4)INDEX); \
270
- } \
271
- else { \
272
- mxBranch(INDEX, OFFSET); \
273
- }
274
- #define mxBranchIf(TEST, INDEX, OFFSET) \
275
- if (TEST) { \
276
- mxBranch(INDEX, OFFSET); \
277
- } \
278
- else { \
279
- mxNextCode((txS4)index); \
280
- }
281
- #define mxFirstCode() \
282
- mxCheckMeter(); \
283
- byte = *((txU1*)mxCode)
284
- #else
285
- #define mxBranch(INDEX, OFFSET) \
286
- mxNextCode((txS4)INDEX + OFFSET)
287
- #define mxBranchElse(TEST, INDEX, OFFSET) \
288
- mxNextCode((TEST) ? (txS4)INDEX : (txS4)INDEX + OFFSET)
289
- #define mxBranchIf(TEST, INDEX, OFFSET) \
290
- mxNextCode((TEST) ? (txS4)INDEX + OFFSET : (txS4)INDEX)
291
- #define mxFirstCode() \
292
- byte = *((txU1*)mxCode)
293
- #endif
294
-
295
- #ifdef mxTrace
296
- short gxDoTrace = 1;
297
-
298
- #ifdef mxMetering
299
- static void fxTraceCode(txMachine* the, txSlot* stack, txU1 theCode)
300
- {
301
- if (((XS_NO_CODE < theCode) && (theCode < XS_CODE_COUNT)))
302
- fprintf(stderr, "\n%u %ld: %s", the->meterIndex, the->stackTop - stack, gxCodeNames[theCode]);
303
- else
304
- fprintf(stderr, "\n%u %ld: ?", the->meterIndex, the->stackTop - stack);
305
- }
306
- #else
307
- static void fxTraceCode(txMachine* the, txSlot* stack, txU1 theCode)
308
- {
309
- if (((XS_NO_CODE < theCode) && (theCode < XS_CODE_COUNT)))
310
- fprintf(stderr, "\n%ld: %s", the->stackTop - stack, gxCodeNames[theCode]);
311
- else
312
- fprintf(stderr, "\n%ld: ?", the->stackTop - stack);
313
- }
314
- #endif
315
-
316
- static void fxTraceID(txMachine* the, txID id, txIndex index)
317
- {
318
- if (id) {
319
- char* key = fxGetKeyName(the, id);
320
- if (key)
321
- fprintf(stderr, " [%s]", key);
322
- else
323
- fprintf(stderr, " [?]");
324
- }
325
- else
326
- fprintf(stderr, " [%d]", index);
327
- }
328
-
329
- static void fxTraceIndex(txMachine* the, txU2 theIndex)
330
- {
331
- fprintf(stderr, " %d", theIndex);
332
- }
333
-
334
- static void fxTraceInteger(txMachine* the, txInteger theInteger)
335
- {
336
- fprintf(stderr, " %ld", (long)theInteger);
337
- }
338
-
339
- static void fxTraceNumber(txMachine* the, txNumber theNumber)
340
- {
341
- fprintf(stderr, " %lf", theNumber);
342
- }
343
-
344
- static void fxTraceReturn(txMachine* the)
345
- {
346
- fprintf(stderr, "\n");
347
- }
348
-
349
- static void fxTraceString(txMachine* the, txString theString)
350
- {
351
- fprintf(stderr, " \"%s\"", theString);
352
- }
353
- #endif
354
-
355
- #ifdef mxTraceCall
356
- int gxTraceCall = 0;
357
- static int depth = 0;
358
- static void fxTraceCallBegin(txMachine* the, txSlot* function)
359
- {
360
- if (gxTraceCall) {
361
- txSlot* slot = mxBehaviorGetProperty(the, function->value.reference, mxID(_name), 0, XS_ANY);
362
- int i;
363
- for (i = 0; i < depth; i++)
364
- fprintf(stderr, "\t");
365
- if (slot && ((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)))
366
- fprintf(stderr, " [%s]\n", slot->value.string);
367
- else
368
- fprintf(stderr, " [?]\n");
369
- depth++;
370
- }
371
- }
372
- static void fxTraceCallEnd(txMachine* the, txSlot* function)
373
- {
374
- if (gxTraceCall) {
375
- depth--;
376
- if (depth < 0)
377
- depth = 0;
378
- }
379
- }
380
- #endif
381
-
382
- void fxRunID(txMachine* the, txSlot* generator, txInteger count)
383
- {
384
- register txSlot* stack = the->stack;
385
- register txSlot* scope = the->scope;
386
- register txSlot* frame = the->frame;
387
- register txSlot* environment;
388
- register txByte* code = the->code;
389
- register txSlot* variable;
390
- register txSlot* slot;
391
- register txU1 byte = 0;
392
- register txU4 index;
393
- register txS4 offset;
394
- txU1 primitive = 0;
395
- #if defined(__GNUC__) && defined(__OPTIMIZE__)
396
- static void *const
397
- #if !defined(__ets__) || ESP32
398
- ICACHE_RAM_ATTR
399
- #endif
400
- gxBytes[] = {
401
- &&XS_NO_CODE,
402
- &&XS_CODE_ADD,
403
- &&XS_CODE_ARGUMENT,
404
- &&XS_CODE_ARGUMENTS,
405
- &&XS_CODE_ARGUMENTS_SLOPPY,
406
- &&XS_CODE_ARGUMENTS_STRICT,
407
- &&XS_CODE_ARRAY,
408
- &&XS_CODE_ASYNC_FUNCTION,
409
- &&XS_CODE_ASYNC_GENERATOR_FUNCTION,
410
- &&XS_CODE_AT,
411
- &&XS_CODE_AWAIT,
412
- &&XS_CODE_BEGIN_SLOPPY,
413
- &&XS_CODE_BEGIN_STRICT,
414
- &&XS_CODE_BEGIN_STRICT_BASE,
415
- &&XS_CODE_BEGIN_STRICT_DERIVED,
416
- &&XS_CODE_BEGIN_STRICT_FIELD,
417
- &&XS_CODE_BIGINT_1,
418
- &&XS_CODE_BIGINT_2,
419
- &&XS_CODE_BIT_AND,
420
- &&XS_CODE_BIT_NOT,
421
- &&XS_CODE_BIT_OR,
422
- &&XS_CODE_BIT_XOR,
423
- &&XS_CODE_BRANCH_1,
424
- &&XS_CODE_BRANCH_2,
425
- &&XS_CODE_BRANCH_4,
426
- &&XS_CODE_BRANCH_CHAIN_1,
427
- &&XS_CODE_BRANCH_CHAIN_2,
428
- &&XS_CODE_BRANCH_CHAIN_4,
429
- &&XS_CODE_BRANCH_COALESCE_1,
430
- &&XS_CODE_BRANCH_COALESCE_2,
431
- &&XS_CODE_BRANCH_COALESCE_4,
432
- &&XS_CODE_BRANCH_ELSE_1,
433
- &&XS_CODE_BRANCH_ELSE_2,
434
- &&XS_CODE_BRANCH_ELSE_4,
435
- &&XS_CODE_BRANCH_IF_1,
436
- &&XS_CODE_BRANCH_IF_2,
437
- &&XS_CODE_BRANCH_IF_4,
438
- &&XS_CODE_BRANCH_STATUS_1,
439
- &&XS_CODE_BRANCH_STATUS_2,
440
- &&XS_CODE_BRANCH_STATUS_4,
441
- &&XS_CODE_CALL,
442
- &&XS_CODE_CATCH_1,
443
- &&XS_CODE_CATCH_2,
444
- &&XS_CODE_CATCH_4,
445
- &&XS_CODE_CHECK_INSTANCE,
446
- &&XS_CODE_CLASS,
447
- &&XS_CODE_CODE_1,
448
- &&XS_CODE_CODE_2,
449
- &&XS_CODE_CODE_4,
450
- &&XS_CODE_CODE_ARCHIVE_1,
451
- &&XS_CODE_CODE_ARCHIVE_2,
452
- &&XS_CODE_CODE_ARCHIVE_4,
453
- &&XS_CODE_CONST_CLOSURE_1,
454
- &&XS_CODE_CONST_CLOSURE_2,
455
- &&XS_CODE_CONST_LOCAL_1,
456
- &&XS_CODE_CONST_LOCAL_2,
457
- &&XS_CODE_CONSTRUCTOR_FUNCTION,
458
- &&XS_CODE_COPY_OBJECT,
459
- &&XS_CODE_CURRENT,
460
- &&XS_CODE_DEBUGGER,
461
- &&XS_CODE_DECREMENT,
462
- &&XS_CODE_DELETE_PROPERTY,
463
- &&XS_CODE_DELETE_PROPERTY_AT,
464
- &&XS_CODE_DELETE_SUPER,
465
- &&XS_CODE_DELETE_SUPER_AT,
466
- &&XS_CODE_DIVIDE,
467
- &&XS_CODE_DUB,
468
- &&XS_CODE_DUB_AT,
469
- &&XS_CODE_END,
470
- &&XS_CODE_END_ARROW,
471
- &&XS_CODE_END_BASE,
472
- &&XS_CODE_END_DERIVED,
473
- &&XS_CODE_ENVIRONMENT,
474
- &&XS_CODE_EQUAL,
475
- &&XS_CODE_EVAL,
476
- &&XS_CODE_EVAL_ENVIRONMENT,
477
- &&XS_CODE_EVAL_PRIVATE,
478
- &&XS_CODE_EVAL_REFERENCE,
479
- &&XS_CODE_EVAL_TAIL,
480
- &&XS_CODE_EXCEPTION,
481
- &&XS_CODE_EXPONENTIATION,
482
- &&XS_CODE_EXTEND,
483
- &&XS_CODE_FALSE,
484
- &&XS_CODE_FILE,
485
- &&XS_CODE_FOR_AWAIT_OF,
486
- &&XS_CODE_FOR_IN,
487
- &&XS_CODE_FOR_OF,
488
- &&XS_CODE_FUNCTION,
489
- &&XS_CODE_FUNCTION_ENVIRONMENT,
490
- &&XS_CODE_GENERATOR_FUNCTION,
491
- &&XS_CODE_GET_CLOSURE_1,
492
- &&XS_CODE_GET_CLOSURE_2,
493
- &&XS_CODE_GET_LOCAL_1,
494
- &&XS_CODE_GET_LOCAL_2,
495
- &&XS_CODE_GET_PRIVATE_1,
496
- &&XS_CODE_GET_PRIVATE_2,
497
- &&XS_CODE_GET_PROPERTY,
498
- &&XS_CODE_GET_PROPERTY_AT,
499
- &&XS_CODE_GET_RESULT,
500
- &&XS_CODE_GET_SUPER,
501
- &&XS_CODE_GET_SUPER_AT,
502
- &&XS_CODE_GET_THIS,
503
- &&XS_CODE_GET_VARIABLE,
504
- &&XS_CODE_GET_THIS_VARIABLE,
505
- &&XS_CODE_GLOBAL,
506
- &&XS_CODE_HAS_PRIVATE_1,
507
- &&XS_CODE_HAS_PRIVATE_2,
508
- &&XS_CODE_HOST,
509
- &&XS_CODE_IMPORT,
510
- &&XS_CODE_IMPORT_META,
511
- &&XS_CODE_IN,
512
- &&XS_CODE_INCREMENT,
513
- &&XS_CODE_INSTANCEOF,
514
- &&XS_CODE_INSTANTIATE,
515
- &&XS_CODE_INTEGER_1,
516
- &&XS_CODE_INTEGER_2,
517
- &&XS_CODE_INTEGER_4,
518
- &&XS_CODE_LEFT_SHIFT,
519
- &&XS_CODE_LESS,
520
- &&XS_CODE_LESS_EQUAL,
521
- &&XS_CODE_LET_CLOSURE_1,
522
- &&XS_CODE_LET_CLOSURE_2,
523
- &&XS_CODE_LET_LOCAL_1,
524
- &&XS_CODE_LET_LOCAL_2,
525
- &&XS_CODE_LINE,
526
- &&XS_CODE_MINUS,
527
- &&XS_CODE_MODULE,
528
- &&XS_CODE_MODULO,
529
- &&XS_CODE_MORE,
530
- &&XS_CODE_MORE_EQUAL,
531
- &&XS_CODE_MULTIPLY,
532
- &&XS_CODE_NAME,
533
- &&XS_CODE_NEW,
534
- &&XS_CODE_NEW_CLOSURE,
535
- &&XS_CODE_NEW_LOCAL,
536
- &&XS_CODE_NEW_PRIVATE_1,
537
- &&XS_CODE_NEW_PRIVATE_2,
538
- &&XS_CODE_NEW_PROPERTY,
539
- &&XS_CODE_NEW_PROPERTY_AT,
540
- &&XS_CODE_NEW_TEMPORARY,
541
- &&XS_CODE_NOT,
542
- &&XS_CODE_NOT_EQUAL,
543
- &&XS_CODE_NULL,
544
- &&XS_CODE_NUMBER,
545
- &&XS_CODE_OBJECT,
546
- &&XS_CODE_PLUS,
547
- &&XS_CODE_POP,
548
- &&XS_CODE_PROGRAM_ENVIRONMENT,
549
- &&XS_CODE_PROGRAM_REFERENCE,
550
- &&XS_CODE_PULL_CLOSURE_1,
551
- &&XS_CODE_PULL_CLOSURE_2,
552
- &&XS_CODE_PULL_LOCAL_1,
553
- &&XS_CODE_PULL_LOCAL_2,
554
- &&XS_CODE_REFRESH_CLOSURE_1,
555
- &&XS_CODE_REFRESH_CLOSURE_2,
556
- &&XS_CODE_REFRESH_LOCAL_1,
557
- &&XS_CODE_REFRESH_LOCAL_2,
558
- &&XS_CODE_REGEXP,
559
- &&XS_CODE_RESERVE_1,
560
- &&XS_CODE_RESERVE_2,
561
- &&XS_CODE_RESET_CLOSURE_1,
562
- &&XS_CODE_RESET_CLOSURE_2,
563
- &&XS_CODE_RESET_LOCAL_1,
564
- &&XS_CODE_RESET_LOCAL_2,
565
- &&XS_CODE_RETHROW,
566
- &&XS_CODE_RETRIEVE_1,
567
- &&XS_CODE_RETRIEVE_2,
568
- &&XS_CODE_RETRIEVE_TARGET,
569
- &&XS_CODE_RETRIEVE_THIS,
570
- &&XS_CODE_RETURN,
571
- &&XS_CODE_RUN,
572
- &&XS_CODE_RUN_1,
573
- &&XS_CODE_RUN_2,
574
- &&XS_CODE_RUN_4,
575
- &&XS_CODE_RUN_TAIL,
576
- &&XS_CODE_RUN_TAIL_1,
577
- &&XS_CODE_RUN_TAIL_2,
578
- &&XS_CODE_RUN_TAIL_4,
579
- &&XS_CODE_SET_CLOSURE_1,
580
- &&XS_CODE_SET_CLOSURE_2,
581
- &&XS_CODE_SET_HOME,
582
- &&XS_CODE_SET_LOCAL_1,
583
- &&XS_CODE_SET_LOCAL_2,
584
- &&XS_CODE_SET_PRIVATE_1,
585
- &&XS_CODE_SET_PRIVATE_2,
586
- &&XS_CODE_SET_PROPERTY,
587
- &&XS_CODE_SET_PROPERTY_AT,
588
- &&XS_CODE_SET_RESULT,
589
- &&XS_CODE_SET_SUPER,
590
- &&XS_CODE_SET_SUPER_AT,
591
- &&XS_CODE_SET_THIS,
592
- &&XS_CODE_SET_VARIABLE,
593
- &&XS_CODE_SIGNED_RIGHT_SHIFT,
594
- &&XS_CODE_START_ASYNC,
595
- &&XS_CODE_START_ASYNC_GENERATOR,
596
- &&XS_CODE_START_GENERATOR,
597
- &&XS_CODE_STORE_1,
598
- &&XS_CODE_STORE_2,
599
- &&XS_CODE_STORE_ARROW,
600
- &&XS_CODE_STRICT_EQUAL,
601
- &&XS_CODE_STRICT_NOT_EQUAL,
602
- &&XS_CODE_STRING_1,
603
- &&XS_CODE_STRING_2,
604
- &&XS_CODE_STRING_4,
605
- &&XS_CODE_STRING_ARCHIVE_1,
606
- &&XS_CODE_STRING_ARCHIVE_2,
607
- &&XS_CODE_STRING_ARCHIVE_4,
608
- &&XS_CODE_SUBTRACT,
609
- &&XS_CODE_SUPER,
610
- &&XS_CODE_SWAP,
611
- &&XS_CODE_SYMBOL,
612
- &&XS_CODE_TARGET,
613
- &&XS_CODE_TEMPLATE,
614
- &&XS_CODE_TEMPLATE_CACHE,
615
- &&XS_CODE_THIS,
616
- &&XS_CODE_THROW,
617
- &&XS_CODE_THROW_STATUS,
618
- &&XS_CODE_TO_INSTANCE,
619
- &&XS_CODE_TO_NUMERIC,
620
- &&XS_CODE_TO_STRING,
621
- &&XS_CODE_TRANSFER,
622
- &&XS_CODE_TRUE,
623
- &&XS_CODE_TYPEOF,
624
- &&XS_CODE_UNCATCH,
625
- &&XS_CODE_UNDEFINED,
626
- &&XS_CODE_UNSIGNED_RIGHT_SHIFT,
627
- &&XS_CODE_UNWIND_1,
628
- &&XS_CODE_UNWIND_2,
629
- &&XS_CODE_VAR_CLOSURE_1,
630
- &&XS_CODE_VAR_CLOSURE_2,
631
- &&XS_CODE_VAR_LOCAL_1,
632
- &&XS_CODE_VAR_LOCAL_2,
633
- &&XS_CODE_VOID,
634
- &&XS_CODE_WITH,
635
- &&XS_CODE_WITHOUT,
636
- &&XS_CODE_YIELD,
637
- &&XS_CODE_PROFILE,
638
- };
639
- register void * const *bytes = gxBytes;
640
- #endif
641
- txJump* jump = C_NULL;
642
- txSlot scratch;
643
- txSlot** address;
644
- txJump* yieldJump = the->firstJump;
645
-
646
- mxCheckCStack();
647
- if (generator) {
648
- slot = mxStack;
649
- variable = generator->next;
650
- offset = variable->value.stack.length;
651
- mxAllocStack(offset);
652
- c_memcpy(mxStack, variable->value.stack.address, offset * sizeof(txSlot));
653
- mxCode = (mxStack++)->value.reference->next->value.code.address;
654
- offset = (mxStack++)->value.integer;
655
- while (offset) {
656
- jump = c_malloc(sizeof(txJump));
657
- if (jump) {
658
- jump->nextJump = the->firstJump;
659
- jump->stack = slot - (mxStack++)->value.integer;
660
- jump->frame = slot - (mxStack++)->value.integer;
661
- jump->scope = slot - (mxStack++)->value.integer;
662
- jump->code = mxCode + (mxStack++)->value.integer;
663
- jump->flag = 1;
664
- the->firstJump = jump;
665
- if (c_setjmp(jump->buffer) == 1) {
666
- jump = the->firstJump;
667
- the->firstJump = jump->nextJump;
668
- mxStack = jump->stack;
669
- mxScope = jump->scope;
670
- mxFrame = jump->frame;
671
- mxEnvironment = mxFrameToEnvironment(mxFrame);
672
- mxCode = jump->code;
673
- c_free(jump);
674
- goto XS_CODE_JUMP;
675
- }
676
- }
677
- else {
678
- mxSaveState;
679
- fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
680
- }
681
- offset--;
682
- }
683
- variable = slot - (mxStack++)->value.integer;
684
- variable->next = mxFrame;
685
- variable->flag &= XS_STRICT_FLAG;
686
- #ifdef mxDebug
687
- if (mxFrame && (mxFrame->flag & XS_STEP_INTO_FLAG))
688
- variable->flag |= XS_STEP_INTO_FLAG | XS_STEP_OVER_FLAG;
689
- #endif
690
- variable->value.frame.code = the->code;
691
- variable->value.frame.scope = mxScope;
692
- mxFrame = variable;
693
- mxEnvironment = mxFrameToEnvironment(mxFrame);
694
- mxScope = slot - (mxStack++)->value.integer;
695
- mxCode = mxCode + (mxStack++)->value.integer;
696
- mxStack->kind = the->scratch.kind;
697
- mxStack->value = the->scratch.value;
698
- #ifdef mxTraceCall
699
- fxTraceCallBegin(the, mxFrameFunction);
700
- #endif
701
- XS_CODE_JUMP:
702
- mxFirstCode();
703
- }
704
- else {
705
- offset = count;
706
- goto XS_CODE_RUN_ALL;
707
- }
708
- for (;;) {
709
-
710
- #ifdef mxTrace
711
- if (gxDoTrace) fxTraceCode(the, stack, byte);
712
- #endif
713
- #ifdef mxMetering
714
- the->meterIndex++;
715
- #endif
716
-
717
- mxSwitch(byte) {
718
- mxCase(XS_NO_CODE)
719
- mxBreak;
720
-
721
- mxCase(XS_CODE_RUN_TAIL)
722
- mxSkipCode(1);
723
- offset = mxStack->value.integer;
724
- mxStack++;
725
- goto XS_CODE_RUN_TAIL_ALL;
726
- mxCase(XS_CODE_RUN_TAIL_4)
727
- offset = mxRunS4(1);
728
- mxSkipCode(5);
729
- goto XS_CODE_RUN_TAIL_ALL;
730
- mxCase(XS_CODE_RUN_TAIL_2)
731
- offset = mxRunS2(1);
732
- mxSkipCode(3);
733
- goto XS_CODE_RUN_TAIL_ALL;
734
- mxCase(XS_CODE_RUN_TAIL_1)
735
- offset = mxRunS1(1);
736
- mxSkipCode(2);
737
- XS_CODE_RUN_TAIL_ALL:
738
- if (mxFrameTarget->kind)
739
- goto XS_CODE_RUN_ALL;
740
- #ifdef mxDebug
741
- slot = mxStack + offset + 4;
742
- if (!fxIsCallable(the, slot))
743
- goto XS_CODE_RUN_ALL;
744
- #endif
745
- variable = mxFrameEnd - 6 - offset;
746
- mxScope = mxFrame->value.frame.scope;
747
- mxCode = mxFrame->value.frame.code;
748
- mxFrame = mxFrame->next;
749
- c_memmove(variable, mxStack, (6 + offset) * sizeof(txSlot));
750
- mxStack = variable;
751
- goto XS_CODE_RUN_ALL;
752
-
753
- mxCase(XS_CODE_RUN)
754
- mxSkipCode(1);
755
- offset = mxStack->value.integer;
756
- mxStack++;
757
- goto XS_CODE_RUN_ALL;
758
- mxCase(XS_CODE_RUN_4)
759
- offset = mxRunS4(1);
760
- mxSkipCode(5);
761
- goto XS_CODE_RUN_ALL;
762
- mxCase(XS_CODE_RUN_2)
763
- offset = mxRunS2(1);
764
- mxSkipCode(3);
765
- goto XS_CODE_RUN_ALL;
766
- mxCase(XS_CODE_RUN_1)
767
- offset = mxRunS1(1);
768
- mxSkipCode(2);
769
- XS_CODE_RUN_ALL:
770
- #ifdef mxTrace
771
- if (gxDoTrace) fxTraceInteger(the, offset);
772
- #endif
773
- // COUNT
774
- slot = mxStack + offset;
775
- slot->kind = XS_INTEGER_KIND;
776
- slot->value.integer = offset;
777
- slot++;
778
- // FRAME
779
- slot->kind = XS_FRAME_KIND;
780
- slot->next = mxFrame;
781
- slot->flag = XS_NO_FLAG;
782
- #ifdef mxDebug
783
- if (mxFrame && (mxFrame->flag & XS_STEP_INTO_FLAG))
784
- slot->flag |= XS_STEP_INTO_FLAG | XS_STEP_OVER_FLAG;
785
- #endif
786
- slot->value.frame.code = mxCode;
787
- slot->value.frame.scope = mxScope;
788
- slot++;
789
- // RESULT
790
- slot++;
791
- // TARGET
792
- slot++;
793
- // FUNCTION
794
- byte = ((slot + 1)->kind == XS_UNINITIALIZED_KIND) ? 1 : 0;
795
- if (slot->kind == XS_REFERENCE_KIND) {
796
- variable = slot->value.reference;
797
- slot = variable->next;
798
- if (slot && (slot->flag & XS_INTERNAL_FLAG)) {
799
- if ((slot->kind == XS_CODE_KIND) || (slot->kind == XS_CODE_X_KIND)) {
800
- if (byte && !mxIsConstructor(variable))
801
- mxRunDebug(XS_TYPE_ERROR, "no constructor");
802
- variable = slot->value.code.closures;
803
- if (variable) {
804
- mxPushKind(XS_REFERENCE_KIND);
805
- mxStack->value.environment.variable.reference = variable;
806
- }
807
- else {
808
- mxPushKind(XS_NULL_KIND);
809
- mxStack->value.environment.variable.reference = C_NULL;
810
- }
811
- #ifdef mxDebug
812
- mxStack->ID = XS_NO_ID;
813
- mxStack->value.environment.line = 0;
814
- #endif
815
- mxFrame = mxStack + 1 + offset + 1;
816
- mxEnvironment = mxStack;
817
- mxScope = mxStack;
818
- mxCode = slot->value.code.address;
819
- #ifdef mxTraceCall
820
- fxTraceCallBegin(the, mxFrameFunction);
821
- #endif
822
- mxFirstCode();
823
- mxBreak;
824
- }
825
- if ((slot->kind == XS_CALLBACK_KIND) || (slot->kind == XS_CALLBACK_X_KIND)) {
826
- if (byte && !mxIsConstructor(variable))
827
- mxRunDebug(XS_TYPE_ERROR, "no constructor");
828
- mxPushKind(XS_VAR_KIND);
829
- mxStack->value.environment.variable.count = 0;
830
- #ifdef mxDebug
831
- mxStack->ID = XS_NO_ID;
832
- mxStack->value.environment.line = 0;
833
- #endif
834
- mxFrame = mxStack + 1 + offset + 1;
835
- mxFrame->flag |= XS_C_FLAG;
836
- mxScope = mxStack;
837
- mxCode = C_NULL;
838
- byte = XS_CODE_CALL;
839
- #ifdef mxTraceCall
840
- fxTraceCallBegin(the, mxFrameFunction);
841
- #endif
842
- mxSaveState;
843
- #ifdef mxLink
844
- if ((txU1*)slot->value.callback.address - (txU1*)the->fakeCallback < 0)
845
- mxRunDebug(XS_TYPE_ERROR, "not available");
846
- #endif
847
- if (slot->flag & XS_BASE_FLAG)
848
- fxRunBase(the);
849
- else if (slot->flag & XS_DERIVED_FLAG)
850
- fxRunDerived(the);
851
- (*(slot->value.callback.address))(the);
852
- mxRestoreState;
853
- #if defined(mxInstrument) || defined(mxProfile)
854
- fxCheckProfiler(the, mxFrame);
855
- #endif
856
- if (slot->flag & XS_BASE_FLAG)
857
- goto XS_CODE_END_BASE_ALL;
858
- if (slot->flag & XS_DERIVED_FLAG)
859
- goto XS_CODE_END_DERIVED_ALL;
860
- slot = mxFrameResult;
861
- goto XS_CODE_END_ALL;
862
- }
863
- if (slot->kind == XS_PROXY_KIND) {
864
- mxPushKind(XS_VAR_KIND);
865
- mxStack->value.environment.variable.count = 0;
866
- #ifdef mxDebug
867
- mxStack->ID = XS_NO_ID;
868
- mxStack->value.environment.line = 0;
869
- #endif
870
- mxFrame = mxStack + 1 + offset + 1;
871
- mxFrame->flag |= XS_C_FLAG;
872
- mxScope = mxStack;
873
- mxCode = C_NULL;
874
- byte = XS_CODE_CALL;
875
- #ifdef mxTraceCall
876
- fxTraceCallBegin(the, mxFrameFunction);
877
- #endif
878
- mxSaveState;
879
- fxRunProxy(the, variable);
880
- mxRestoreState;
881
- slot = mxFrameResult;
882
- goto XS_CODE_END_ALL;
883
- }
884
- }
885
- }
886
- #ifdef mxHostFunctionPrimitive
887
- else if (slot->kind == XS_HOST_FUNCTION_KIND) {
888
- if (byte)
889
- mxRunDebug(XS_TYPE_ERROR, "no constructor");
890
- mxPushKind(XS_VAR_KIND);
891
- mxStack->value.environment.variable.count = 0;
892
- #ifdef mxDebug
893
- mxStack->ID = XS_NO_ID;
894
- mxStack->value.environment.line = 0;
895
- #endif
896
- mxFrame = mxStack + 1 + offset + 1;
897
- mxFrame->flag |= XS_C_FLAG;
898
- mxScope = mxStack;
899
- mxCode = C_NULL;
900
- byte = XS_CODE_CALL;
901
- #ifdef mxTraceCall
902
- fxTraceCallBegin(the, mxFrameFunction);
903
- #endif
904
- mxSaveState;
905
- #ifdef mxLink
906
- if ((txU1*)slot->value.hostFunction.builder->callback - (txU1*)the->fakeCallback < 0)
907
- mxRunDebug(XS_TYPE_ERROR, "not available");
908
- #endif
909
- (*(slot->value.hostFunction.builder->callback))(the);
910
- mxRestoreState;
911
- slot = mxFrameResult;
912
- goto XS_CODE_END_ALL;
913
- }
914
- #endif
915
- mxRunDebug(XS_TYPE_ERROR, "no function");
916
- mxBreak;
917
-
918
- mxCase(XS_CODE_BEGIN_SLOPPY)
919
- if (mxFrameTarget->kind != XS_UNDEFINED_KIND) {
920
- mxSaveState;
921
- fxRunConstructor(the);
922
- mxRestoreState;
923
- }
924
- else {
925
- index = mxFrameThis->kind;
926
- if (index < XS_REFERENCE_KIND) {
927
- if ((index == XS_UNDEFINED_KIND) || (index == XS_NULL_KIND)) {
928
- mxFrameThis->kind = XS_REFERENCE_KIND;
929
- variable = mxFunctionInstanceHome(mxFrameFunction->value.reference)->value.home.module;
930
- variable = mxModuleInstanceInternal(variable)->value.module.realm;
931
- if (!variable) variable = mxModuleInstanceInternal(mxProgram.value.reference)->value.module.realm;
932
- mxFrameThis->value.reference = mxRealmGlobal(variable)->value.reference;
933
- }
934
- else {
935
- mxSaveState;
936
- fxToInstance(the, mxFrameThis);
937
- mxRestoreState;
938
- }
939
- }
940
- }
941
- mxNextCode(2);
942
- mxBreak;
943
- mxCase(XS_CODE_BEGIN_STRICT)
944
- mxFrame->flag |= XS_STRICT_FLAG;
945
- if (mxFrameTarget->kind != XS_UNDEFINED_KIND) {
946
- mxSaveState;
947
- fxRunConstructor(the);
948
- mxRestoreState;
949
- }
950
- mxNextCode(2);
951
- mxBreak;
952
- mxCase(XS_CODE_BEGIN_STRICT_BASE)
953
- mxFrame->flag |= XS_STRICT_FLAG;
954
- mxSaveState;
955
- fxRunBase(the);
956
- mxRestoreState;
957
- mxNextCode(2);
958
- mxBreak;
959
- mxCase(XS_CODE_BEGIN_STRICT_DERIVED)
960
- mxFrame->flag |= XS_STRICT_FLAG;
961
- mxSaveState;
962
- fxRunDerived(the);
963
- mxRestoreState;
964
- mxNextCode(2);
965
- mxBreak;
966
- mxCase(XS_CODE_BEGIN_STRICT_FIELD)
967
- mxFrame->flag |= XS_STRICT_FLAG | XS_FIELD_FLAG;
968
- if (mxFrameTarget->kind != XS_UNDEFINED_KIND) {
969
- mxSaveState;
970
- fxRunConstructor(the);
971
- mxRestoreState;
972
- }
973
- mxNextCode(2);
974
- mxBreak;
975
-
976
- mxCase(XS_CODE_END_ARROW)
977
- slot = mxFrameResult;
978
- goto XS_CODE_END_ALL;
979
- mxCase(XS_CODE_END_BASE)
980
- XS_CODE_END_BASE_ALL:
981
- slot = mxFrameResult;
982
- if (slot->kind != XS_REFERENCE_KIND)
983
- slot = mxFrameThis;
984
- goto XS_CODE_END_ALL;
985
- mxCase(XS_CODE_END_DERIVED)
986
- XS_CODE_END_DERIVED_ALL:
987
- slot = mxFrameResult;
988
- if (slot->kind != XS_REFERENCE_KIND) {
989
- if ((slot->kind != XS_UNDEFINED_KIND) && (slot->kind != XS_CLOSURE_KIND))
990
- mxRunDebug(XS_TYPE_ERROR, "invalid result");
991
- slot = mxFrameThis->value.closure;
992
- if (slot->kind < 0)
993
- mxRunDebug(XS_REFERENCE_ERROR, "this is not initialized");
994
- }
995
- goto XS_CODE_END_ALL;
996
- mxCase(XS_CODE_END)
997
- slot = mxFrameResult;
998
- if (mxFrameTarget->kind) {
999
- if (slot->kind != XS_REFERENCE_KIND)
1000
- slot = mxFrameThis;
1001
- }
1002
- XS_CODE_END_ALL:
1003
- #ifdef mxTraceCall
1004
- fxTraceCallEnd(the, mxFrameFunction);
1005
- #endif
1006
- #ifdef mxInstrument
1007
- if (the->stackPeak > mxStack)
1008
- the->stackPeak = mxStack;
1009
- #endif
1010
- mxStack = mxFrameEnd;
1011
- mxScope = mxFrame->value.frame.scope;
1012
- mxCode = mxFrame->value.frame.code;
1013
- mxAllocStack(1);
1014
- *mxStack = *slot;
1015
- mxFrame = mxFrame->next;
1016
- if (!mxFrame || (mxFrame->flag & XS_C_FLAG)) {
1017
- #ifdef mxTrace
1018
- if (gxDoTrace) fxTraceReturn(the);
1019
- #endif
1020
- byte = XS_CODE_END;
1021
- mxSaveState;
1022
- return;
1023
- }
1024
- mxEnvironment = mxFrameToEnvironment(mxFrame);
1025
- mxFirstCode();
1026
- mxBreak;
1027
- mxCase(XS_CODE_RETURN)
1028
- mxStack = mxFrameEnd;
1029
- mxScope = mxFrame->value.frame.scope;
1030
- mxCode = mxFrame->value.frame.code;
1031
- mxAllocStack(1);
1032
- *mxStack = *mxFrameResult;
1033
- mxFrame = mxFrame->next;
1034
- #ifdef mxTrace
1035
- if (gxDoTrace)
1036
- if (gxDoTrace) fxTraceReturn(the);
1037
- #endif
1038
- mxSaveState;
1039
- return;
1040
-
1041
- mxCase(XS_CODE_START_ASYNC)
1042
- mxSkipCode(1);
1043
- mxSaveState;
1044
- variable = gxDefaults.newAsyncInstance(the);
1045
- mxRestoreState;
1046
- slot = mxFrameEnd;
1047
- mxPushKind(XS_INTEGER_KIND);
1048
- mxStack->value.integer = mxPtrDiff(mxCode - mxFrameFunction->value.reference->next->value.code.address);
1049
- mxPushKind(XS_INTEGER_KIND);
1050
- mxStack->value.integer = mxPtrDiff(slot - mxScope);
1051
- mxPushKind(XS_INTEGER_KIND);
1052
- mxStack->value.integer = mxPtrDiff(slot - mxFrame);
1053
- mxPushKind(XS_INTEGER_KIND);
1054
- mxStack->value.integer = 0;
1055
- mxPushKind(mxFrameFunction->kind);
1056
- mxStack->value = mxFrameFunction->value;
1057
- index = mxPtrDiff(slot - mxStack);
1058
- slot = variable->next;
1059
- variable = slot->value.stack.address;
1060
- if (slot->value.stack.length < index) {
1061
- mxSaveState;
1062
- if (variable)
1063
- variable = (txSlot *)fxRenewChunk(the, variable, index * sizeof(txSlot));
1064
- if (!variable)
1065
- variable = (txSlot *)fxNewChunk(the, index * sizeof(txSlot));
1066
- mxRestoreState;
1067
- slot->value.stack.address = variable;
1068
- }
1069
- slot->value.stack.length = index;
1070
- c_memcpy(variable, mxStack, index * sizeof(txSlot));
1071
- mxStack += 5;
1072
- mxSaveState;
1073
- gxDefaults.runAsync(the, mxStack->value.reference);
1074
- mxRestoreState;
1075
- slot = mxFrameResult;
1076
- goto XS_CODE_END_ALL;
1077
-
1078
- mxCase(XS_CODE_START_ASYNC_GENERATOR)
1079
- mxSkipCode(1);
1080
- if (mxFrameTarget->kind != XS_UNDEFINED_KIND)
1081
- mxRunDebug(XS_TYPE_ERROR, "new async generator");
1082
- slot = mxBehaviorGetProperty(the, mxFrameFunction->value.reference, mxID(_prototype), 0, XS_ANY);
1083
- mxPushKind(slot->kind);
1084
- mxStack->value = slot->value;
1085
- mxSaveState;
1086
- variable = gxDefaults.newAsyncGeneratorInstance(the);
1087
- mxRestoreState;
1088
- mxFrameResult->kind = XS_UNINITIALIZED_KIND;
1089
- slot = mxFrameEnd;
1090
- mxPushKind(XS_INTEGER_KIND);
1091
- mxStack->value.integer = mxPtrDiff(mxCode - mxFrameFunction->value.reference->next->value.code.address);
1092
- mxPushKind(XS_INTEGER_KIND);
1093
- mxStack->value.integer = mxPtrDiff(slot - mxScope);
1094
- mxPushKind(XS_INTEGER_KIND);
1095
- mxStack->value.integer = mxPtrDiff(slot - mxFrame);
1096
- mxPushKind(XS_INTEGER_KIND);
1097
- mxStack->value.integer = 0;
1098
- mxPushKind(mxFrameFunction->kind);
1099
- mxStack->value = mxFrameFunction->value;
1100
- index = mxPtrDiff(slot - mxStack);
1101
- slot = variable->next;
1102
- variable = slot->value.stack.address;
1103
- if (slot->value.stack.length < index) {
1104
- mxSaveState;
1105
- if (variable)
1106
- variable = (txSlot *)fxRenewChunk(the, variable, index * sizeof(txSlot));
1107
- if (!variable)
1108
- variable = (txSlot *)fxNewChunk(the, index * sizeof(txSlot));
1109
- mxRestoreState;
1110
- slot->value.stack.address = variable;
1111
- }
1112
- slot->value.stack.length = index;
1113
- c_memcpy(variable, mxStack, index * sizeof(txSlot));
1114
- mxStack += 5;
1115
- *mxFrameResult = *(mxStack++);
1116
- slot = mxFrameResult;
1117
- goto XS_CODE_END_ALL;
1118
-
1119
- mxCase(XS_CODE_START_GENERATOR)
1120
- mxSkipCode(1);
1121
- if (mxFrameTarget->kind != XS_UNDEFINED_KIND)
1122
- mxRunDebug(XS_TYPE_ERROR, "new generator");
1123
- slot = mxBehaviorGetProperty(the, mxFrameFunction->value.reference, mxID(_prototype), 0, XS_ANY);
1124
- mxPushKind(slot->kind);
1125
- mxStack->value = slot->value;
1126
- mxSaveState;
1127
- variable = gxDefaults.newGeneratorInstance(the);
1128
- mxRestoreState;
1129
- slot = mxFrameEnd;
1130
- mxPushKind(XS_INTEGER_KIND);
1131
- mxStack->value.integer = mxPtrDiff(mxCode - mxFrameFunction->value.reference->next->value.code.address);
1132
- mxPushKind(XS_INTEGER_KIND);
1133
- mxStack->value.integer = mxPtrDiff(slot - mxScope);
1134
- mxPushKind(XS_INTEGER_KIND);
1135
- mxStack->value.integer = mxPtrDiff(slot - mxFrame);
1136
- mxPushKind(XS_INTEGER_KIND);
1137
- mxStack->value.integer = 0;
1138
- mxPushKind(mxFrameFunction->kind);
1139
- mxStack->value = mxFrameFunction->value;
1140
- index = mxPtrDiff(slot - mxStack);
1141
- slot = variable->next;
1142
- variable = slot->value.stack.address;
1143
- if (slot->value.stack.length < index) {
1144
- mxSaveState;
1145
- if (variable)
1146
- variable = (txSlot *)fxRenewChunk(the, variable, index * sizeof(txSlot));
1147
- if (!variable)
1148
- variable = (txSlot *)fxNewChunk(the, index * sizeof(txSlot));
1149
- mxRestoreState;
1150
- slot->value.stack.address = variable;
1151
- }
1152
- slot->value.stack.length = index;
1153
- c_memcpy(variable, mxStack, index * sizeof(txSlot));
1154
- mxStack += 5;
1155
- *mxFrameResult = *(mxStack++);
1156
- slot = mxFrameResult;
1157
- goto XS_CODE_END_ALL;
1158
-
1159
- mxCase(XS_CODE_AWAIT)
1160
- mxCase(XS_CODE_YIELD)
1161
- generator->next->next->value.integer = byte;
1162
- mxSkipCode(1);
1163
- slot = mxFrameEnd;
1164
- mxPushKind(XS_INTEGER_KIND);
1165
- mxStack->value.integer = mxPtrDiff(mxCode - mxFrameFunction->value.reference->next->value.code.address);
1166
- mxPushKind(XS_INTEGER_KIND);
1167
- mxStack->value.integer = mxPtrDiff(slot - mxScope);
1168
- mxPushKind(XS_INTEGER_KIND);
1169
- mxStack->value.integer = mxPtrDiff(slot - mxFrame);
1170
- jump = the->firstJump;
1171
- offset = 0;
1172
- while (jump != yieldJump) {
1173
- txJump* nextJump = jump->nextJump;
1174
- mxPushKind(XS_INTEGER_KIND);
1175
- mxStack->value.integer = mxPtrDiff(jump->code - mxFrameFunction->value.reference->next->value.code.address);
1176
- mxPushKind(XS_INTEGER_KIND);
1177
- mxStack->value.integer = mxPtrDiff(slot - jump->scope);
1178
- mxPushKind(XS_INTEGER_KIND);
1179
- mxStack->value.integer = mxPtrDiff(slot - jump->frame);
1180
- mxPushKind(XS_INTEGER_KIND);
1181
- mxStack->value.integer = mxPtrDiff(slot - jump->stack);
1182
- c_free(jump);
1183
- jump = nextJump;
1184
- offset++;
1185
- }
1186
- the->firstJump = yieldJump;
1187
- mxPushKind(XS_INTEGER_KIND);
1188
- mxStack->value.integer = offset;
1189
- mxPushKind(mxFrameFunction->kind);
1190
- mxStack->value = mxFrameFunction->value;
1191
- index = mxPtrDiff(slot - mxStack);
1192
- slot = generator->next;
1193
- variable = slot->value.stack.address;
1194
- if (slot->value.stack.length < index) {
1195
- mxSaveState;
1196
- if (variable)
1197
- variable = (txSlot *)fxRenewChunk(the, variable, index * sizeof(txSlot));
1198
- if (!variable)
1199
- variable = (txSlot *)fxNewChunk(the, index * sizeof(txSlot));
1200
- mxRestoreState;
1201
- slot->value.stack.address = variable;
1202
- }
1203
- slot->value.stack.length = index;
1204
- c_memcpy(variable, mxStack, index * sizeof(txSlot));
1205
- mxStack += 5 + (offset * 4);
1206
- *mxFrameResult = *(mxStack++);
1207
- slot = mxFrameResult;
1208
- goto XS_CODE_END_ALL;
1209
-
1210
- /* FRAMES */
1211
- mxCase(XS_CODE_ARGUMENT)
1212
- offset = mxRunU1(1);
1213
- #ifdef mxTrace
1214
- if (gxDoTrace) fxTraceInteger(the, offset);
1215
- #endif
1216
- if (offset < mxFrameArgc) {
1217
- slot = mxFrameArgv(offset);
1218
- mxPushKind(slot->kind);
1219
- mxStack->value = slot->value;
1220
- }
1221
- else {
1222
- mxPushKind(XS_UNDEFINED_KIND);
1223
- }
1224
- mxNextCode(2);
1225
- mxBreak;
1226
- mxCase(XS_CODE_ARGUMENTS)
1227
- offset = mxRunU1(1);
1228
- #ifdef mxTrace
1229
- if (gxDoTrace) fxTraceInteger(the, offset);
1230
- #endif
1231
- mxSaveState;
1232
- fxRunArguments(the, offset);
1233
- mxRestoreState;
1234
- mxNextCode(2);
1235
- mxBreak;
1236
- mxCase(XS_CODE_ARGUMENTS_SLOPPY)
1237
- offset = mxRunU1(1);
1238
- mxAllocStack(1);
1239
- *mxStack = mxArgumentsSloppyPrototype;
1240
- mxSaveState;
1241
- gxDefaults.newArgumentsSloppyInstance(the, offset);
1242
- mxRestoreState;
1243
- mxNextCode(2);
1244
- mxBreak;
1245
- mxCase(XS_CODE_ARGUMENTS_STRICT)
1246
- offset = mxRunU1(1);
1247
- mxAllocStack(1);
1248
- *mxStack = mxArgumentsStrictPrototype;
1249
- mxSaveState;
1250
- gxDefaults.newArgumentsStrictInstance(the, offset);
1251
- mxRestoreState;
1252
- mxNextCode(2);
1253
- mxBreak;
1254
- mxCase(XS_CODE_CURRENT)
1255
- mxAllocStack(1);
1256
- *mxStack = *mxFrameFunction;
1257
- mxNextCode(1);
1258
- mxBreak;
1259
- mxCase(XS_CODE_GET_RESULT)
1260
- mxAllocStack(1);
1261
- *mxStack = *mxFrameResult;
1262
- mxNextCode(1);
1263
- mxBreak;
1264
- mxCase(XS_CODE_SET_RESULT)
1265
- *mxFrameResult = *(mxStack++);
1266
- mxNextCode(1);
1267
- mxBreak;
1268
- mxCase(XS_CODE_TARGET)
1269
- mxAllocStack(1);
1270
- *mxStack = *mxFrameTarget;
1271
- mxNextCode(1);
1272
- mxBreak;
1273
- mxCase(XS_CODE_THIS)
1274
- mxAllocStack(1);
1275
- *mxStack = *mxFrameThis;
1276
- mxNextCode(1);
1277
- mxBreak;
1278
- mxCase(XS_CODE_GET_THIS)
1279
- slot = mxFrameThis;
1280
- variable = slot->value.closure;
1281
- if (variable->kind < 0)
1282
- mxRunDebug(XS_REFERENCE_ERROR, "this is not initialized yet");
1283
- mxPushKind(variable->kind);
1284
- mxStack->value = variable->value;
1285
- mxNextCode(1);
1286
- mxBreak;
1287
- mxCase(XS_CODE_SET_THIS)
1288
- slot = mxFrameThis;
1289
- variable = slot->value.closure;
1290
- if (variable->kind >= 0)
1291
- mxRunDebug(XS_REFERENCE_ERROR, "this is already initialized");
1292
- variable->kind = mxStack->kind;
1293
- variable->value = mxStack->value;
1294
- mxNextCode(1);
1295
- mxBreak;
1296
-
1297
- /* EXCEPTIONS */
1298
- mxCase(XS_CODE_EXCEPTION)
1299
- mxAllocStack(1);
1300
- *mxStack = mxException;
1301
- mxException = mxUndefined;
1302
- mxNextCode(1);
1303
- mxBreak;
1304
- mxCase(XS_CODE_CATCH_4)
1305
- offset = mxRunS4(1);
1306
- mxNextCode(5);
1307
- goto XS_CODE_CATCH;
1308
- mxCase(XS_CODE_CATCH_2)
1309
- offset = mxRunS2(1);
1310
- mxNextCode(3);
1311
- goto XS_CODE_CATCH;
1312
- mxCase(XS_CODE_CATCH_1)
1313
- offset = mxRunS1(1);
1314
- mxNextCode(2);
1315
- XS_CODE_CATCH:
1316
- jump = c_malloc(sizeof(txJump));
1317
- if (jump) {
1318
- jump->nextJump = the->firstJump;
1319
- jump->stack = mxStack;
1320
- jump->scope = mxScope;
1321
- jump->frame = mxFrame;
1322
- jump->environment = mxEnvironment->value.reference;
1323
- jump->code = mxCode + offset;
1324
- jump->flag = 1;
1325
- the->firstJump = jump;
1326
- if (c_setjmp(jump->buffer) != 0) {
1327
- jump = the->firstJump;
1328
- the->firstJump = jump->nextJump;
1329
- mxStack = jump->stack;
1330
- mxScope = jump->scope;
1331
- mxFrame = jump->frame;
1332
- mxEnvironment = mxFrameToEnvironment(mxFrame);
1333
- mxEnvironment->value.reference = jump->environment;
1334
- mxCode = jump->code;
1335
- c_free(jump);
1336
- mxFirstCode();
1337
- }
1338
- }
1339
- else {
1340
- mxSaveState;
1341
- fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
1342
- }
1343
- mxBreak;
1344
- mxCase(XS_CODE_RETHROW)
1345
- mxSaveState;
1346
- fxJump(the);
1347
- mxBreak;
1348
- mxCase(XS_CODE_THROW)
1349
- mxException = *mxStack;
1350
- #ifdef mxDebug
1351
- mxSaveState;
1352
- fxDebugThrow(the, C_NULL, 0, "throw");
1353
- mxRestoreState;
1354
- #endif
1355
- mxSaveState;
1356
- fxJump(the);
1357
- mxBreak;
1358
- mxCase(XS_CODE_THROW_STATUS)
1359
- if (the->status & XS_THROW_STATUS) {
1360
- mxException = *mxStack;
1361
- #ifdef mxDebug
1362
- mxSaveState;
1363
- fxDebugThrow(the, C_NULL, 0, "throw");
1364
- mxRestoreState;
1365
- #endif
1366
- mxSaveState;
1367
- fxJump(the);
1368
- }
1369
- mxNextCode(1);
1370
- mxBreak;
1371
- mxCase(XS_CODE_UNCATCH)
1372
- jump = the->firstJump;
1373
- the->firstJump = jump->nextJump;
1374
- c_free(jump);
1375
- mxNextCode(1);
1376
- mxBreak;
1377
-
1378
- /* BRANCHES */
1379
- mxCase(XS_CODE_BRANCH_1)
1380
- offset = mxRunS1(1);
1381
- mxBranch(2, offset);
1382
- mxBreak;
1383
- mxCase(XS_CODE_BRANCH_2)
1384
- offset = mxRunS2(1);
1385
- mxBranch(3, offset);
1386
- mxBreak;
1387
- mxCase(XS_CODE_BRANCH_4)
1388
- offset = mxRunS4(1);
1389
- mxBranch(5, offset);
1390
- mxBreak;
1391
- mxCase(XS_CODE_BRANCH_CHAIN_4)
1392
- offset = mxRunS4(1);
1393
- index = 5;
1394
- goto XS_CODE_BRANCH_CHAIN;
1395
- mxCase(XS_CODE_BRANCH_CHAIN_2)
1396
- offset = mxRunS2(1);
1397
- index = 3;
1398
- goto XS_CODE_BRANCH_CHAIN;
1399
- mxCase(XS_CODE_BRANCH_CHAIN_1)
1400
- offset = mxRunS1(1);
1401
- index = 2;
1402
- XS_CODE_BRANCH_CHAIN:
1403
- byte = mxStack->kind;
1404
- if ((XS_UNDEFINED_KIND == byte) || (XS_NULL_KIND == byte)) {
1405
- mxStack->kind = XS_UNDEFINED_KIND;
1406
- mxBranch(index, offset);
1407
- }
1408
- else
1409
- mxNextCode((txS4)index);
1410
- mxBreak;
1411
- mxCase(XS_CODE_BRANCH_COALESCE_4)
1412
- offset = mxRunS4(1);
1413
- index = 5;
1414
- goto XS_CODE_BRANCH_COALESCE;
1415
- mxCase(XS_CODE_BRANCH_COALESCE_2)
1416
- offset = mxRunS2(1);
1417
- index = 3;
1418
- goto XS_CODE_BRANCH_COALESCE;
1419
- mxCase(XS_CODE_BRANCH_COALESCE_1)
1420
- offset = mxRunS1(1);
1421
- index = 2;
1422
- XS_CODE_BRANCH_COALESCE:
1423
- byte = mxStack->kind;
1424
- if ((XS_UNDEFINED_KIND == byte) || (XS_NULL_KIND == byte)) {
1425
- mxStack++;
1426
- mxNextCode((txS4)index);
1427
- }
1428
- else {
1429
- mxBranch(index, offset);
1430
- }
1431
- mxBreak;
1432
- mxCase(XS_CODE_BRANCH_ELSE_4)
1433
- offset = mxRunS4(1);
1434
- index = 5;
1435
- goto XS_CODE_BRANCH_ELSE;
1436
- mxCase(XS_CODE_BRANCH_ELSE_2)
1437
- offset = mxRunS2(1);
1438
- index = 3;
1439
- goto XS_CODE_BRANCH_ELSE;
1440
- mxCase(XS_CODE_BRANCH_ELSE_1)
1441
- offset = mxRunS1(1);
1442
- index = 2;
1443
- XS_CODE_BRANCH_ELSE:
1444
- byte = mxStack->kind;
1445
- if (XS_BOOLEAN_KIND == byte) {
1446
- mxBranchElse(mxStack->value.boolean, index, offset);
1447
- }
1448
- else if (XS_INTEGER_KIND == byte) {
1449
- mxBranchElse(mxStack->value.integer, index, offset);
1450
- }
1451
- else if (XS_NUMBER_KIND == byte) {
1452
- mxBranchIf((c_isnan(mxStack->value.number) || c_iszero(mxStack->value.number)), index, offset);
1453
- mxFloatingPointOp("else");
1454
- }
1455
- else if ((XS_BIGINT_KIND == byte) || (XS_BIGINT_X_KIND == byte)) {
1456
- mxBranchIf(((mxStack->value.bigint.size == 1) && (mxStack->value.bigint.data[0] == 0)), index, offset);
1457
- }
1458
- else if ((XS_STRING_KIND == byte) || (XS_STRING_X_KIND == byte)) {
1459
- mxBranchIf(c_isEmpty(mxStack->value.string), index, offset);
1460
- }
1461
- else {
1462
- mxBranchIf((XS_UNDEFINED_KIND == byte) || (XS_NULL_KIND == byte), index, offset);
1463
- }
1464
- mxStack++;
1465
- mxBreak;
1466
- mxCase(XS_CODE_BRANCH_IF_4)
1467
- offset = mxRunS4(1);
1468
- index = 5;
1469
- goto XS_CODE_BRANCH_IF;
1470
- mxCase(XS_CODE_BRANCH_IF_2)
1471
- offset = mxRunS2(1);
1472
- index = 3;
1473
- goto XS_CODE_BRANCH_IF;
1474
- mxCase(XS_CODE_BRANCH_IF_1)
1475
- offset = mxRunS1(1);
1476
- index = 2;
1477
- XS_CODE_BRANCH_IF:
1478
- byte = mxStack->kind;
1479
- if (XS_BOOLEAN_KIND == byte) {
1480
- mxBranchIf(mxStack->value.boolean, index, offset);
1481
- }
1482
- else if (XS_INTEGER_KIND == byte) {
1483
- mxBranchIf(mxStack->value.integer, index, offset);
1484
- }
1485
- else if (XS_NUMBER_KIND == byte) {
1486
- mxBranchElse(c_isnan(mxStack->value.number) || c_iszero(mxStack->value.number), index, offset);
1487
- mxFloatingPointOp("if");
1488
- }
1489
- else if ((XS_BIGINT_KIND == byte) || (XS_BIGINT_X_KIND == byte)) {
1490
- mxBranchElse((mxStack->value.bigint.size == 1) && (mxStack->value.bigint.data[0] == 0), index, offset);
1491
- }
1492
- else if ((XS_STRING_KIND == byte) || (XS_STRING_X_KIND == byte)) {
1493
- mxBranchElse(c_isEmpty(mxStack->value.string), index, offset);
1494
- }
1495
- else {
1496
- mxBranchElse((XS_UNDEFINED_KIND == byte) || (XS_NULL_KIND == byte), index, offset);
1497
- }
1498
- mxStack++;
1499
- mxBreak;
1500
- mxCase(XS_CODE_BRANCH_STATUS_4)
1501
- offset = mxRunS4(1);
1502
- index = 5;
1503
- goto XS_CODE_BRANCH_STATUS;
1504
- mxCase(XS_CODE_BRANCH_STATUS_2)
1505
- offset = mxRunS2(1);
1506
- index = 3;
1507
- goto XS_CODE_BRANCH_STATUS;
1508
- mxCase(XS_CODE_BRANCH_STATUS_1)
1509
- offset = mxRunS1(1);
1510
- index = 2;
1511
- XS_CODE_BRANCH_STATUS:
1512
- if (the->status & XS_THROW_STATUS) {
1513
- mxException = *mxStack;
1514
- #ifdef mxDebug
1515
- mxSaveState;
1516
- fxDebugThrow(the, C_NULL, 0, "throw");
1517
- mxRestoreState;
1518
- #endif
1519
- mxSaveState;
1520
- fxJump(the);
1521
- }
1522
- mxNextCode((the->status & XS_RETURN_STATUS) ? index : index + offset);
1523
- mxBreak;
1524
-
1525
- /* STACK */
1526
- mxCase(XS_CODE_DUB)
1527
- mxAllocStack(1);
1528
- *mxStack = *(mxStack + 1);
1529
- mxNextCode(1);
1530
- mxBreak;
1531
- mxCase(XS_CODE_DUB_AT)
1532
- mxAllocStack(2);
1533
- *(mxStack + 1) = *(mxStack + 3);
1534
- *mxStack = *(mxStack + 2);
1535
- mxNextCode(1);
1536
- mxBreak;
1537
- mxCase(XS_CODE_POP)
1538
- mxStack++;
1539
- mxNextCode(1);
1540
- mxBreak;
1541
- mxCase(XS_CODE_SWAP)
1542
- scratch = *(mxStack);
1543
- *(mxStack) = *(mxStack + 1);
1544
- *(mxStack + 1) = scratch;
1545
- mxNextCode(1);
1546
- mxBreak;
1547
-
1548
- /* SCOPE */
1549
- mxCase(XS_CODE_CONST_CLOSURE_2)
1550
- index = mxRunU2(1);
1551
- mxNextCode(3);
1552
- goto XS_CODE_CONST_CLOSURE;
1553
- mxCase(XS_CODE_CONST_CLOSURE_1)
1554
- index = mxRunU1(1);
1555
- mxNextCode(2);
1556
- XS_CODE_CONST_CLOSURE:
1557
- #ifdef mxTrace
1558
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1559
- #endif
1560
- slot = mxEnvironment - index;
1561
- variable = slot->value.closure;
1562
- if (variable->kind >= 0)
1563
- mxRunDebugID(XS_REFERENCE_ERROR, "set %s: already initialized", slot->ID);
1564
- slot->flag |= XS_DONT_SET_FLAG; //@@
1565
- variable->flag |= XS_DONT_SET_FLAG;
1566
- variable->kind = mxStack->kind;
1567
- variable->value = mxStack->value;
1568
- mxBreak;
1569
- mxCase(XS_CODE_CONST_LOCAL_2)
1570
- index = mxRunU2(1);
1571
- mxNextCode(3);
1572
- goto XS_CODE_CONST_LOCAL;
1573
- mxCase(XS_CODE_CONST_LOCAL_1)
1574
- index = mxRunU1(1);
1575
- mxNextCode(2);
1576
- XS_CODE_CONST_LOCAL:
1577
- #ifdef mxTrace
1578
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1579
- #endif
1580
- variable = mxEnvironment - index;
1581
- if (variable->kind >= 0)
1582
- mxRunDebugID(XS_REFERENCE_ERROR, "set %s: already initialized", variable->ID);
1583
- variable->flag |= XS_DONT_SET_FLAG;
1584
- variable->kind = mxStack->kind;
1585
- variable->value = mxStack->value;
1586
- mxBreak;
1587
-
1588
- mxCase(XS_CODE_GET_CLOSURE_2)
1589
- index = mxRunU2(1);
1590
- mxNextCode(3);
1591
- goto XS_CODE_GET_CLOSURE;
1592
- mxCase(XS_CODE_GET_CLOSURE_1)
1593
- index = mxRunU1(1);
1594
- mxNextCode(2);
1595
- XS_CODE_GET_CLOSURE:
1596
- #ifdef mxTrace
1597
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1598
- #endif
1599
- slot = mxEnvironment - index;
1600
- #ifdef mxDebug
1601
- offset = slot->ID;
1602
- #endif
1603
- variable = slot->value.closure;
1604
- if (variable->kind < 0)
1605
- mxRunDebugID(XS_REFERENCE_ERROR, "get %s: not initialized yet", slot->ID);
1606
- offset = variable->ID;
1607
- if (offset) {
1608
- slot = the->aliasArray[offset];
1609
- if (slot)
1610
- variable = slot;
1611
- }
1612
- mxPushKind(variable->kind);
1613
- mxStack->value = variable->value;
1614
- mxBreak;
1615
- mxCase(XS_CODE_GET_LOCAL_2)
1616
- index = mxRunU2(1);
1617
- mxNextCode(3);
1618
- goto XS_CODE_GET_LOCAL;
1619
- mxCase(XS_CODE_GET_LOCAL_1)
1620
- index = mxRunU1(1);
1621
- mxNextCode(2);
1622
- XS_CODE_GET_LOCAL:
1623
- #ifdef mxTrace
1624
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1625
- #endif
1626
- variable = mxEnvironment - index;
1627
- #ifdef mxDebug
1628
- offset = variable->ID;
1629
- #endif
1630
- if (variable->kind < 0)
1631
- mxRunDebugID(XS_REFERENCE_ERROR, "get %s: not initialized yet", variable->ID);
1632
- mxPushKind(variable->kind);
1633
- mxStack->value = variable->value;
1634
- mxBreak;
1635
-
1636
- mxCase(XS_CODE_LET_CLOSURE_2)
1637
- index = mxRunU2(1);
1638
- mxNextCode(3);
1639
- goto XS_CODE_LET_CLOSURE;
1640
- mxCase(XS_CODE_LET_CLOSURE_1)
1641
- index = mxRunU1(1);
1642
- mxNextCode(2);
1643
- XS_CODE_LET_CLOSURE:
1644
- #ifdef mxTrace
1645
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1646
- #endif
1647
- slot = mxEnvironment - index;
1648
- variable = slot->value.closure;
1649
- variable->kind = mxStack->kind;
1650
- variable->value = mxStack->value;
1651
- mxBreak;
1652
- mxCase(XS_CODE_LET_LOCAL_2)
1653
- index = mxRunU2(1);
1654
- mxNextCode(3);
1655
- goto XS_CODE_LET_LOCAL;
1656
- mxCase(XS_CODE_LET_LOCAL_1)
1657
- index = mxRunU1(1);
1658
- mxNextCode(2);
1659
- XS_CODE_LET_LOCAL:
1660
- #ifdef mxTrace
1661
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1662
- #endif
1663
- variable = mxEnvironment - index;
1664
- variable->kind = mxStack->kind;
1665
- variable->value = mxStack->value;
1666
- mxBreak;
1667
-
1668
- mxCase(XS_CODE_NEW_CLOSURE)
1669
- offset = mxRunID(1);
1670
- #ifdef mxTrace
1671
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
1672
- #endif
1673
- mxNextCode(1 + sizeof(txID));
1674
- slot = --mxScope;
1675
- #ifdef mxTrace
1676
- if (gxDoTrace) fxTraceIndex(the, mxEnvironment - mxScope - 1);
1677
- #endif
1678
- mxSaveState;
1679
- variable = fxNewSlot(the);
1680
- mxRestoreState;
1681
- slot->flag = XS_DONT_DELETE_FLAG;
1682
- slot->ID = (txID)offset;
1683
- slot->kind = XS_CLOSURE_KIND;
1684
- slot->value.closure = variable;
1685
- variable->kind = XS_UNINITIALIZED_KIND;
1686
- mxBreak;
1687
- mxCase(XS_CODE_NEW_LOCAL)
1688
- offset = mxRunID(1);
1689
- #ifdef mxTrace
1690
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
1691
- #endif
1692
- mxNextCode(1 + sizeof(txID));
1693
- variable = --mxScope;
1694
- #ifdef mxTrace
1695
- if (gxDoTrace) fxTraceIndex(the, mxEnvironment - mxScope - 1);
1696
- #endif
1697
- variable->flag = XS_DONT_DELETE_FLAG;
1698
- variable->ID = (txID)offset;
1699
- variable->kind = XS_UNINITIALIZED_KIND;
1700
- mxBreak;
1701
- mxCase(XS_CODE_NEW_TEMPORARY)
1702
- variable = --mxScope;
1703
- #ifdef mxTrace
1704
- if (gxDoTrace) fxTraceIndex(the, mxEnvironment - mxScope - 1);
1705
- #endif
1706
- mxInitSlotKind(variable, XS_UNDEFINED_KIND);
1707
- mxNextCode(1);
1708
- mxBreak;
1709
-
1710
- mxCase(XS_CODE_PULL_CLOSURE_2)
1711
- index = mxRunU2(1);
1712
- mxNextCode(3);
1713
- goto XS_CODE_PULL_CLOSURE;
1714
- mxCase(XS_CODE_PULL_CLOSURE_1)
1715
- index = mxRunU1(1);
1716
- mxNextCode(2);
1717
- XS_CODE_PULL_CLOSURE:
1718
- #ifdef mxTrace
1719
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1720
- #endif
1721
- slot = mxEnvironment - index;
1722
- if (slot->flag & XS_DONT_SET_FLAG) // import
1723
- mxRunDebugID(XS_TYPE_ERROR, "set %s: const", slot->ID);
1724
- variable = slot->value.closure;
1725
- if (variable->kind < 0)
1726
- mxRunDebugID(XS_REFERENCE_ERROR, "set %s: not initialized yet", slot->ID);
1727
- if (variable->flag & XS_DONT_SET_FLAG)
1728
- mxRunDebugID(XS_TYPE_ERROR, "set %s: const", slot->ID);
1729
- offset = variable->ID;
1730
- if (offset) {
1731
- variable = the->aliasArray[offset];
1732
- if (!variable) {
1733
- mxSaveState;
1734
- variable = fxNewSlot(the);
1735
- mxRestoreState;
1736
- the->aliasArray[offset] = variable;
1737
- }
1738
- }
1739
- variable->kind = mxStack->kind;
1740
- variable->value = mxStack->value;
1741
- mxStack++;
1742
- mxBreak;
1743
- mxCase(XS_CODE_PULL_LOCAL_2)
1744
- index = mxRunU2(1);
1745
- mxNextCode(3);
1746
- goto XS_CODE_PULL_LOCAL;
1747
- mxCase(XS_CODE_PULL_LOCAL_1)
1748
- index = mxRunU1(1);
1749
- mxNextCode(2);
1750
- XS_CODE_PULL_LOCAL:
1751
- #ifdef mxTrace
1752
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1753
- #endif
1754
- variable = mxEnvironment - index;
1755
- if (variable->kind < 0)
1756
- mxRunDebugID(XS_REFERENCE_ERROR, "set %s: not initialized yet", variable->ID);
1757
- if (variable->flag & XS_DONT_SET_FLAG)
1758
- mxRunDebugID(XS_TYPE_ERROR, "set %s: const", variable->ID);
1759
- variable->kind = mxStack->kind;
1760
- variable->value = mxStack->value;
1761
- mxStack++;
1762
- mxBreak;
1763
-
1764
- mxCase(XS_CODE_REFRESH_CLOSURE_2)
1765
- index = mxRunU2(1);
1766
- mxNextCode(3);
1767
- goto XS_CODE_REFRESH_CLOSURE;
1768
- mxCase(XS_CODE_REFRESH_CLOSURE_1)
1769
- index = mxRunU1(1);
1770
- mxNextCode(2);
1771
- XS_CODE_REFRESH_CLOSURE:
1772
- #ifdef mxTrace
1773
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1774
- #endif
1775
- variable = mxEnvironment - index;
1776
- mxSaveState;
1777
- slot = fxNewSlot(the);
1778
- mxRestoreState;
1779
- slot->flag = variable->value.closure->flag;
1780
- slot->kind = variable->value.closure->kind;
1781
- slot->value = variable->value.closure->value;
1782
- variable->value.closure = slot;
1783
- mxBreak;
1784
- mxCase(XS_CODE_REFRESH_LOCAL_2)
1785
- index = mxRunU2(1);
1786
- mxNextCode(3);
1787
- goto XS_CODE_REFRESH_LOCAL;
1788
- mxCase(XS_CODE_REFRESH_LOCAL_1)
1789
- index = mxRunU1(1);
1790
- mxNextCode(2);
1791
- XS_CODE_REFRESH_LOCAL:
1792
- #ifdef mxTrace
1793
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1794
- #endif
1795
- variable = mxEnvironment - index;
1796
- mxBreak;
1797
-
1798
- mxCase(XS_CODE_RESERVE_2)
1799
- index = mxRunU2(1);
1800
- mxNextCode(3);
1801
- goto XS_CODE_RESERVE;
1802
- mxCase(XS_CODE_RESERVE_1)
1803
- index = mxRunU1(1);
1804
- mxNextCode(2);
1805
- XS_CODE_RESERVE:
1806
- #ifdef mxTrace
1807
- if (gxDoTrace) fxTraceIndex(the, index);
1808
- #endif
1809
- mxAllocStack(index);
1810
- c_memset(mxStack, 0, index * sizeof(txSlot));
1811
- mxBreak;
1812
-
1813
- mxCase(XS_CODE_RESET_CLOSURE_2)
1814
- index = mxRunU2(1);
1815
- mxNextCode(3);
1816
- goto XS_CODE_RESET_CLOSURE;
1817
- mxCase(XS_CODE_RESET_CLOSURE_1)
1818
- index = mxRunU1(1);
1819
- mxNextCode(2);
1820
- XS_CODE_RESET_CLOSURE:
1821
- #ifdef mxTrace
1822
- if (gxDoTrace) fxTraceIndex(the, index);
1823
- #endif
1824
- slot = mxEnvironment - index;
1825
- mxSaveState;
1826
- variable = fxNewSlot(the);
1827
- mxRestoreState;
1828
- variable->kind = XS_UNINITIALIZED_KIND;
1829
- slot->value.closure = variable;
1830
- mxBreak;
1831
- mxCase(XS_CODE_RESET_LOCAL_2)
1832
- index = mxRunU2(1);
1833
- mxNextCode(3);
1834
- goto XS_CODE_RESET_LOCAL;
1835
- mxCase(XS_CODE_RESET_LOCAL_1)
1836
- index = mxRunU1(1);
1837
- mxNextCode(2);
1838
- XS_CODE_RESET_LOCAL:
1839
- #ifdef mxTrace
1840
- if (gxDoTrace) fxTraceIndex(the, index);
1841
- #endif
1842
- variable = mxEnvironment - index;
1843
- variable->flag = XS_NO_FLAG;
1844
- variable->kind = XS_UNINITIALIZED_KIND;
1845
- mxBreak;
1846
-
1847
- mxCase(XS_CODE_SET_CLOSURE_2)
1848
- index = mxRunU2(1);
1849
- mxNextCode(3);
1850
- goto XS_CODE_SET_CLOSURE;
1851
- mxCase(XS_CODE_SET_CLOSURE_1)
1852
- index = mxRunU1(1);
1853
- mxNextCode(2);
1854
- XS_CODE_SET_CLOSURE:
1855
- #ifdef mxTrace
1856
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1857
- #endif
1858
- slot = mxEnvironment - index;
1859
- if (slot->flag & XS_DONT_SET_FLAG) // import
1860
- mxRunDebugID(XS_TYPE_ERROR, "set %s: const", slot->ID);
1861
- variable = slot->value.closure;
1862
- if (variable->kind < 0)
1863
- mxRunDebugID(XS_REFERENCE_ERROR, "set %s: not initialized yet", slot->ID);
1864
- if (variable->flag & XS_DONT_SET_FLAG)
1865
- mxRunDebugID(XS_TYPE_ERROR, "set %s: const", slot->ID);
1866
- offset = variable->ID;
1867
- if (offset > 0) {
1868
- variable = the->aliasArray[offset];
1869
- if (!variable) {
1870
- mxSaveState;
1871
- variable = fxNewSlot(the);
1872
- mxRestoreState;
1873
- the->aliasArray[offset] = variable;
1874
- }
1875
- }
1876
- variable->kind = mxStack->kind;
1877
- variable->value = mxStack->value;
1878
- mxBreak;
1879
- mxCase(XS_CODE_SET_LOCAL_2)
1880
- index = mxRunU2(1);
1881
- mxNextCode(3);
1882
- goto XS_CODE_SET_LOCAL;
1883
- mxCase(XS_CODE_SET_LOCAL_1)
1884
- index = mxRunU1(1);
1885
- mxNextCode(2);
1886
- XS_CODE_SET_LOCAL:
1887
- #ifdef mxTrace
1888
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1889
- #endif
1890
- variable = mxEnvironment - index;
1891
- if (variable->kind < 0)
1892
- mxRunDebugID(XS_REFERENCE_ERROR, "set %s: not initialized yet", variable->ID);
1893
- if (variable->flag & XS_DONT_SET_FLAG)
1894
- mxRunDebugID(XS_TYPE_ERROR, "set %s: const", variable->ID);
1895
- variable->kind = mxStack->kind;
1896
- variable->value = mxStack->value;
1897
- mxBreak;
1898
-
1899
- mxCase(XS_CODE_VAR_CLOSURE_2)
1900
- index = mxRunU2(1);
1901
- mxNextCode(3);
1902
- goto XS_CODE_VAR_CLOSURE;
1903
- mxCase(XS_CODE_VAR_CLOSURE_1)
1904
- index = mxRunU1(1);
1905
- mxNextCode(2);
1906
- XS_CODE_VAR_CLOSURE:
1907
- #ifdef mxTrace
1908
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1909
- #endif
1910
- variable = (mxEnvironment - index)->value.closure;
1911
- variable->kind = mxStack->kind;
1912
- variable->value = mxStack->value;
1913
- mxBreak;
1914
- mxCase(XS_CODE_VAR_LOCAL_2)
1915
- index = mxRunU2(1);
1916
- mxNextCode(3);
1917
- goto XS_CODE_VAR_LOCAL;
1918
- mxCase(XS_CODE_VAR_LOCAL_1)
1919
- index = mxRunU1(1);
1920
- mxNextCode(2);
1921
- XS_CODE_VAR_LOCAL:
1922
- #ifdef mxTrace
1923
- if (gxDoTrace) fxTraceIndex(the, index - 1);
1924
- #endif
1925
- variable = mxEnvironment - index;
1926
- variable->kind = mxStack->kind;
1927
- variable->value = mxStack->value;
1928
- mxBreak;
1929
-
1930
- mxCase(XS_CODE_UNWIND_2)
1931
- index = mxRunU2(1);
1932
- mxNextCode(3);
1933
- goto XS_CODE_UNWIND;
1934
- mxCase(XS_CODE_UNWIND_1)
1935
- index = mxRunU1(1);
1936
- mxNextCode(2);
1937
- XS_CODE_UNWIND:
1938
- #ifdef mxTrace
1939
- if (gxDoTrace) fxTraceIndex(the, index);
1940
- #endif
1941
- slot = mxScope;
1942
- mxScope += index;
1943
- while (slot < mxScope)
1944
- (slot++)->kind = XS_UNDEFINED_KIND;
1945
- mxBreak;
1946
-
1947
- mxCase(XS_CODE_RETRIEVE_2)
1948
- index = mxRunU2(1);
1949
- mxNextCode(3);
1950
- goto XS_CODE_RETRIEVE;
1951
- mxCase(XS_CODE_RETRIEVE_1)
1952
- index = mxRunU1(1);
1953
- mxNextCode(2);
1954
- XS_CODE_RETRIEVE:
1955
- #ifdef mxTrace
1956
- if (gxDoTrace) fxTraceIndex(the, index);
1957
- #endif
1958
- slot = mxEnvironment->value.reference->next->next;
1959
- variable = mxScope;
1960
- while (index) {
1961
- --variable;
1962
- offset = variable->ID = slot->ID;
1963
- variable->flag = slot->flag;
1964
- variable->kind = slot->kind;
1965
- variable->value = slot->value;
1966
- #ifdef mxTrace
1967
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
1968
- #endif
1969
- index--;
1970
- slot = slot->next;
1971
- }
1972
- mxScope = variable;
1973
- mxBreak;
1974
- mxCase(XS_CODE_RETRIEVE_TARGET)
1975
- variable = mxFrameTarget;
1976
- variable->kind = slot->kind;
1977
- variable->value = slot->value;
1978
- slot = slot->next;
1979
- mxNextCode(1);
1980
- mxBreak;
1981
- mxCase(XS_CODE_RETRIEVE_THIS)
1982
- variable = mxFrameThis;
1983
- variable->kind = slot->kind;
1984
- variable->value = slot->value;
1985
- slot = slot->next;
1986
- mxNextCode(1);
1987
- mxBreak;
1988
-
1989
- mxCase(XS_CODE_ENVIRONMENT)
1990
- mxPushKind(XS_UNDEFINED_KIND);
1991
- mxSaveState;
1992
- slot = fxNewEnvironmentInstance(the, C_NULL);
1993
- mxRestoreState;
1994
- variable = mxFunctionInstanceCode((mxStack + 1)->value.reference);
1995
- variable->value.code.closures = slot;
1996
- mxNextCode(1);
1997
- mxBreak;
1998
-
1999
- mxCase(XS_CODE_STORE_2)
2000
- index = mxRunU2(1);
2001
- mxNextCode(3);
2002
- goto XS_CODE_STORE;
2003
- mxCase(XS_CODE_STORE_1)
2004
- index = mxRunU1(1);
2005
- mxNextCode(2);
2006
- XS_CODE_STORE:
2007
- #ifdef mxTrace
2008
- if (gxDoTrace) fxTraceIndex(the, index - 1);
2009
- #endif
2010
- address = &(mxStack->value.reference->next);
2011
- while ((slot = *address)) {
2012
- address = &slot->next;
2013
- }
2014
- mxSaveState;
2015
- *address = slot = fxNewSlot(the);
2016
- mxRestoreState;
2017
- variable = mxEnvironment - index;
2018
- offset = slot->ID = variable->ID;
2019
- slot->flag = variable->flag;
2020
- slot->kind = variable->kind;
2021
- slot->value = variable->value;
2022
- #ifdef mxTrace
2023
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
2024
- #endif
2025
- mxBreak;
2026
- mxCase(XS_CODE_STORE_ARROW)
2027
- // super
2028
- variable = mxFunctionInstanceHome(mxFrameFunction->value.reference);
2029
- slot = mxFunctionInstanceHome((mxStack + 1)->value.reference);
2030
- slot->value.home.object = variable->value.home.object;
2031
- // target
2032
- address = &(mxStack->value.reference->next);
2033
- while ((slot = *address)) {
2034
- address = &slot->next;
2035
- }
2036
- mxSaveState;
2037
- *address = slot = fxNewSlot(the);
2038
- mxRestoreState;
2039
- variable = mxFrameTarget;
2040
- slot->ID = mxID(_new_target);
2041
- slot->kind = variable->kind;
2042
- slot->value = variable->value;
2043
- // this
2044
- address = &slot->next;
2045
- mxSaveState;
2046
- *address = slot = fxNewSlot(the);
2047
- mxRestoreState;
2048
- variable = mxFrameThis;
2049
- slot->ID = mxID(_this);
2050
- slot->kind = variable->kind;
2051
- slot->value = variable->value;
2052
- mxNextCode(1);
2053
- mxBreak;
2054
-
2055
- /* PROPERTIES */
2056
- mxCase(XS_CODE_CHECK_INSTANCE)
2057
- if (mxStack->kind != XS_REFERENCE_KIND)
2058
- mxRunDebug(XS_TYPE_ERROR, "result: no instance");
2059
- mxNextCode(1);
2060
- mxBreak;
2061
- mxCase(XS_CODE_TO_INSTANCE)
2062
- mxToInstance(mxStack);
2063
- mxNextCode(1);
2064
- mxBreak;
2065
- mxCase(XS_CODE_AT)
2066
- mxToInstance(mxStack + 1);
2067
- if (mxStack->kind == XS_REFERENCE_KIND) {
2068
- mxSaveState;
2069
- fxToPrimitive(the, mxStack, XS_STRING_HINT);
2070
- mxRestoreState;
2071
- }
2072
- if ((mxStack->kind == XS_INTEGER_KIND) && fxIntegerToIndex(the->dtoa, mxStack->value.integer, &(scratch.value.at.index))) {
2073
- mxStack->kind = XS_AT_KIND;
2074
- mxStack->value.at.id = XS_NO_ID;
2075
- mxStack->value.at.index = scratch.value.at.index;
2076
- }
2077
- else if ((mxStack->kind == XS_NUMBER_KIND) && fxNumberToIndex(the->dtoa, mxStack->value.number, &(scratch.value.at.index))) {
2078
- mxStack->kind = XS_AT_KIND;
2079
- mxStack->value.at.id = XS_NO_ID;
2080
- mxStack->value.at.index = scratch.value.at.index;
2081
- }
2082
- else if (mxStack->kind == XS_SYMBOL_KIND) {
2083
- mxStack->kind = XS_AT_KIND;
2084
- mxStack->value.at.id = mxStack->value.symbol;
2085
- mxStack->value.at.index = 0;
2086
- }
2087
- else {
2088
- txFlag flag;
2089
-
2090
- mxToString(mxStack);
2091
- mxSaveState;
2092
- flag = fxStringToIndex(the->dtoa, mxStack->value.string, &(scratch.value.at.index));
2093
- mxRestoreState;
2094
- if (flag) {
2095
- #ifdef mxMetering
2096
- the->meterIndex += 2;
2097
- #endif
2098
- mxStack->kind = XS_AT_KIND;
2099
- mxStack->value.at.id = XS_NO_ID;
2100
- mxStack->value.at.index = scratch.value.at.index;
2101
- }
2102
- else {
2103
- txID id;
2104
- mxSaveState;
2105
- if (mxStack->kind == XS_STRING_X_KIND)
2106
- id = fxNewNameX(the, mxStack->value.string);
2107
- else
2108
- id = fxNewName(the, mxStack);
2109
- mxRestoreState;
2110
- mxStack->kind = XS_AT_KIND;
2111
- mxStack->value.at.id = id;
2112
- mxStack->value.at.index = 0;
2113
- }
2114
- }
2115
- mxNextCode(1);
2116
- mxBreak;
2117
-
2118
- mxCase(XS_CODE_DELETE_SUPER_AT)
2119
- variable = (mxStack + 1)->value.reference;
2120
- offset = mxStack->value.at.id;
2121
- index = mxStack->value.at.index;
2122
- mxStack++;
2123
- mxNextCode(1);
2124
- goto XS_CODE_DELETE_SUPER_ALL;
2125
- mxCase(XS_CODE_DELETE_SUPER)
2126
- mxToInstance(mxStack);
2127
- offset = mxRunID(1);
2128
- index = 0;
2129
- mxNextCode(1 + sizeof(txID));
2130
- /* continue */
2131
- XS_CODE_DELETE_SUPER_ALL:
2132
- mxRunDebugID(XS_REFERENCE_ERROR, "delete super.%s", (txID)offset);
2133
- mxBreak;
2134
-
2135
- mxCase(XS_CODE_DELETE_PROPERTY_AT)
2136
- variable = (mxStack + 1)->value.reference;
2137
- offset = mxStack->value.at.id;
2138
- index = mxStack->value.at.index;
2139
- mxStack++;
2140
- mxNextCode(1);
2141
- goto XS_CODE_DELETE_PROPERTY_ALL;
2142
- mxCase(XS_CODE_DELETE_PROPERTY)
2143
- mxToInstance(mxStack);
2144
- offset = mxRunID(1);
2145
- index = 0;
2146
- mxNextCode(1 + sizeof(txID));
2147
- /* continue */
2148
- XS_CODE_DELETE_PROPERTY_ALL:
2149
- #ifdef mxTrace
2150
- if (gxDoTrace) fxTraceID(the, (txID)offset, index);
2151
- #endif
2152
- mxSaveState;
2153
- index = (txU4)fxRunDelete(the, variable, (txID)offset, index);
2154
- mxRestoreState;
2155
- if (!index && (mxFrame->flag & XS_STRICT_FLAG))
2156
- mxRunDebugID(XS_TYPE_ERROR, "delete %s: no permission (strict mode)", (txID)offset);
2157
- mxStack->kind = XS_BOOLEAN_KIND;
2158
- mxStack->value.boolean = index;
2159
- mxBreak;
2160
-
2161
- mxCase(XS_CODE_GET_THIS_VARIABLE)
2162
- mxCase(XS_CODE_GET_VARIABLE)
2163
- mxToInstance(mxStack);
2164
- offset = mxRunID(1);
2165
- index = 0;
2166
- mxNextCode(1 + sizeof(txID));
2167
- slot = mxBehaviorGetProperty(the, variable, (txID)offset, index, XS_ANY);
2168
- if (slot) {
2169
- if (slot->kind < 0)
2170
- mxRunDebugID(XS_REFERENCE_ERROR, "get %s: not initialized yet", (txID)offset);
2171
- }
2172
- else {
2173
- if (byte != XS_CODE_TYPEOF)
2174
- mxRunDebugID(XS_REFERENCE_ERROR, "get %s: undefined variable", (txID)offset);
2175
- }
2176
- goto XS_CODE_GET_ALL;
2177
- mxCase(XS_CODE_GET_SUPER_AT)
2178
- variable = (mxStack + 1)->value.reference;
2179
- offset = mxStack->value.at.id;
2180
- index = mxStack->value.at.index;
2181
- mxStack++;
2182
- mxNextCode(1);
2183
- goto XS_CODE_GET_SUPER_ALL;
2184
- mxCase(XS_CODE_GET_SUPER)
2185
- mxToInstance(mxStack);
2186
- offset = mxRunID(1);
2187
- index = 0;
2188
- mxNextCode(1 + sizeof(txID));
2189
- /* continue */
2190
- XS_CODE_GET_SUPER_ALL:
2191
- slot = mxFunctionInstanceHome(mxFrameFunction->value.reference);
2192
- if (!slot->value.home.object)
2193
- mxRunDebugID(XS_TYPE_ERROR, "get super %s: no home", (txID)offset);
2194
- slot = fxGetPrototype(the, slot->value.home.object);
2195
- if (!slot)
2196
- mxRunDebugID(XS_TYPE_ERROR, "get super %s: no prototype", (txID)offset);
2197
- slot = mxBehaviorGetProperty(the, slot, (txID)offset, index, XS_ANY);
2198
- goto XS_CODE_GET_ALL;
2199
- mxCase(XS_CODE_GET_PRIVATE_2)
2200
- index = mxRunU2(1);
2201
- mxNextCode(3);
2202
- goto XS_CODE_GET_PRIVATE;
2203
- mxCase(XS_CODE_GET_PRIVATE_1)
2204
- index = mxRunU1(1);
2205
- mxNextCode(2);
2206
- XS_CODE_GET_PRIVATE:
2207
- #ifdef mxTrace
2208
- if (gxDoTrace) fxTraceIndex(the, index - 1);
2209
- #endif
2210
- slot = (mxEnvironment - index);
2211
- mxToInstance(mxStack);
2212
- offset = slot->ID;
2213
- index = 0;
2214
- if (slot->value.closure->kind < 0)
2215
- mxRunDebugID(XS_TYPE_ERROR, "get %s: undefined private property", (txID)offset);
2216
- slot = gxDefaults.getPrivateProperty(the, variable, slot->value.closure->value.reference, (txID)offset);
2217
- if (!slot)
2218
- mxRunDebugID(XS_TYPE_ERROR, "get %s: undefined private property", (txID)offset);
2219
- goto XS_CODE_GET_ALL;
2220
- mxCase(XS_CODE_GET_PROPERTY_AT)
2221
- variable = (mxStack + 1)->value.reference;
2222
- offset = mxStack->value.at.id;
2223
- index = mxStack->value.at.index;
2224
- mxStack++;
2225
- mxNextCode(1);
2226
- goto XS_CODE_GET_PROPERTY_ALL;
2227
- mxCase(XS_CODE_GET_PROPERTY)
2228
- mxToInstance(mxStack);
2229
- offset = mxRunID(1);
2230
- index = 0;
2231
- mxNextCode(1 + sizeof(txID));
2232
- /* continue */
2233
- XS_CODE_GET_PROPERTY_ALL:
2234
- slot = mxBehaviorGetProperty(the, variable, (txID)offset, index, XS_ANY);
2235
- XS_CODE_GET_ALL:
2236
- #ifdef mxTrace
2237
- if (gxDoTrace) fxTraceID(the, (txID)offset, index);
2238
- #endif
2239
- if (!slot) {
2240
- mxStack->kind = XS_UNDEFINED_KIND;
2241
- mxBreak;
2242
- }
2243
- if (slot->kind == XS_ACCESSOR_KIND) {
2244
- variable = slot->value.accessor.getter;
2245
- if (!mxIsFunction(variable)) {
2246
- mxStack->kind = XS_UNDEFINED_KIND;
2247
- mxBreak;
2248
- }
2249
- mxAllocStack(5);
2250
- slot = mxStack;
2251
- mxInitSlotKind(slot++, XS_UNINITIALIZED_KIND);
2252
- mxInitSlotKind(slot++, XS_UNINITIALIZED_KIND);
2253
- mxInitSlotKind(slot++, XS_UNDEFINED_KIND);
2254
- mxInitSlotKind(slot++, XS_UNDEFINED_KIND);
2255
- slot->value.reference = variable;
2256
- mxInitSlotKind(slot++, XS_REFERENCE_KIND);
2257
- if (primitive) {
2258
- variable = slot->value.reference->next;
2259
- slot->value = variable->value;
2260
- mxInitSlotKind(slot, variable->kind);
2261
- }
2262
- offset = 0;
2263
- goto XS_CODE_RUN_ALL;
2264
- }
2265
- mxStack->kind = slot->kind;
2266
- mxStack->value = slot->value;
2267
- mxBreak;
2268
-
2269
- mxCase(XS_CODE_NEW_PRIVATE_2)
2270
- index = mxRunU2(1);
2271
- mxNextCode(3);
2272
- goto XS_CODE_NEW_PRIVATE;
2273
- mxCase(XS_CODE_NEW_PRIVATE_1)
2274
- index = mxRunU1(1);
2275
- mxNextCode(2);
2276
- XS_CODE_NEW_PRIVATE:
2277
- #ifdef mxTrace
2278
- if (gxDoTrace) fxTraceIndex(the, index - 1);
2279
- #endif
2280
- slot = (mxEnvironment - index);
2281
- mxToInstance(mxStack + 1);
2282
- offset = slot->ID;
2283
- index = 0;
2284
- slot = slot->value.closure->value.reference;
2285
- goto XS_CODE_NEW_PROPERTY_ALL;
2286
- mxCase(XS_CODE_NEW_PROPERTY_AT)
2287
- mxToInstance(mxStack + 2);
2288
- offset = (mxStack + 1)->value.at.id;
2289
- index = (mxStack + 1)->value.at.index;
2290
- slot = C_NULL;
2291
- *(mxStack + 1) = *mxStack;
2292
- mxStack++;
2293
- mxNextCode(1);
2294
- goto XS_CODE_NEW_PROPERTY_ALL;
2295
- mxCase(XS_CODE_NEW_PROPERTY)
2296
- mxToInstance(mxStack + 1);
2297
- offset = mxRunID(1);
2298
- index = 0;
2299
- slot = C_NULL;
2300
- mxNextCode(1 + sizeof(txID));
2301
- XS_CODE_NEW_PROPERTY_ALL:
2302
- byte = mxRunU1(1);
2303
- mxSaveState;
2304
- if (byte & XS_GETTER_FLAG) {
2305
- mxStack->value.accessor.getter = fxToInstance(the, mxStack);
2306
- mxStack->value.accessor.setter = C_NULL;
2307
- mxStack->kind = XS_ACCESSOR_KIND;
2308
- }
2309
- else if (byte & XS_SETTER_FLAG) {
2310
- mxStack->value.accessor.setter = fxToInstance(the, mxStack);
2311
- mxStack->value.accessor.getter = C_NULL;
2312
- mxStack->kind = XS_ACCESSOR_KIND;
2313
- }
2314
- mxStack->flag = byte & XS_GET_ONLY;
2315
- index = fxRunDefine(the, variable, slot, (txID)offset, index, mxStack, byte | XS_GET_ONLY);
2316
- mxRestoreState;
2317
- mxStack += 2;
2318
- if (!index)
2319
- mxRunDebugID(XS_TYPE_ERROR, "set %s: const", (txID)offset);
2320
- mxNextCode(2);
2321
- mxBreak;
2322
-
2323
- mxCase(XS_CODE_SET_VARIABLE)
2324
- mxToInstance(mxStack + 1);
2325
- offset = mxRunID(1);
2326
- index = 0;
2327
- mxNextCode(1 + sizeof(txID));
2328
- if (mxFrame->flag & XS_STRICT_FLAG) {
2329
- mxSaveState;
2330
- if (!fxRunHas(the, variable, (txID)offset, index))
2331
- mxRunDebugID(XS_REFERENCE_ERROR, "set %s: undefined variable", (txID)offset);
2332
- mxRestoreState;
2333
- }
2334
- mxSaveState;
2335
- slot = mxBehaviorSetProperty(the, variable, (txID)offset, index, XS_ANY);
2336
- mxRestoreState;
2337
- if (slot && (slot->kind < 0))
2338
- mxRunDebugID(XS_REFERENCE_ERROR, "set %s: not initialized yet", (txID)offset);
2339
- goto XS_CODE_SET_ALL;
2340
- mxCase(XS_CODE_SET_SUPER_AT)
2341
- variable = (mxStack + 2)->value.reference;
2342
- offset = (mxStack + 1)->value.at.id;
2343
- index = (mxStack + 1)->value.at.index;
2344
- *(mxStack + 1) = *mxStack;
2345
- mxStack++;
2346
- mxNextCode(1);
2347
- goto XS_CODE_SET_SUPER_ALL;
2348
- mxCase(XS_CODE_SET_SUPER)
2349
- mxToInstance(mxStack + 1);
2350
- offset = mxRunID(1);
2351
- index = 0;
2352
- mxNextCode(1 + sizeof(txID));
2353
- /* continue */
2354
- XS_CODE_SET_SUPER_ALL:
2355
- slot = mxFunctionInstanceHome(mxFrameFunction->value.reference);
2356
- if (!slot->value.home.object)
2357
- mxRunDebugID(XS_TYPE_ERROR, "set super %s: no home", (txID)offset);
2358
- slot = fxGetPrototype(the, slot->value.home.object);
2359
- if (!slot)
2360
- mxRunDebugID(XS_TYPE_ERROR, "set super %s: no prototype", (txID)offset);
2361
- slot = mxBehaviorGetProperty(the, slot, (txID)offset, index, XS_ANY);
2362
- if (!slot || (slot->kind != XS_ACCESSOR_KIND)) {
2363
- mxSaveState;
2364
- slot = mxBehaviorSetProperty(the, variable, (txID)offset, index, XS_OWN);
2365
- mxRestoreState;
2366
- }
2367
- goto XS_CODE_SET_ALL;
2368
- mxCase(XS_CODE_SET_PRIVATE_2)
2369
- index = mxRunU2(1);
2370
- mxNextCode(3);
2371
- goto XS_CODE_SET_PRIVATE;
2372
- mxCase(XS_CODE_SET_PRIVATE_1)
2373
- index = mxRunU1(1);
2374
- mxNextCode(2);
2375
- XS_CODE_SET_PRIVATE:
2376
- #ifdef mxTrace
2377
- if (gxDoTrace) fxTraceIndex(the, index - 1);
2378
- #endif
2379
- slot = (mxEnvironment - index);
2380
- mxToInstance(mxStack + 1);
2381
- offset = slot->ID;
2382
- index = 0;
2383
- if (slot->value.closure->kind < 0)
2384
- mxRunDebugID(XS_REFERENCE_ERROR, "set %s: undefined private property", (txID)offset);
2385
- slot = gxDefaults.setPrivateProperty(the, variable, slot->value.closure->value.reference, (txID)offset);
2386
- if (!slot)
2387
- mxRunDebugID(XS_TYPE_ERROR, "set %s: undefined private property", (txID)offset);
2388
- goto XS_CODE_SET_ALL;
2389
- mxCase(XS_CODE_SET_PROPERTY_AT)
2390
- variable = (mxStack + 2)->value.reference;
2391
- offset = (mxStack + 1)->value.at.id;
2392
- index = (mxStack + 1)->value.at.index;
2393
- *(mxStack + 1) = *mxStack;
2394
- mxStack++;
2395
- mxNextCode(1);
2396
- goto XS_CODE_SET_PROPERTY_ALL;
2397
- mxCase(XS_CODE_SET_PROPERTY)
2398
- mxToInstance(mxStack + 1);
2399
- offset = mxRunID(1);
2400
- index = 0;
2401
- mxNextCode(1 + sizeof(txID));
2402
- /* continue */
2403
- XS_CODE_SET_PROPERTY_ALL:
2404
- mxSaveState;
2405
- slot = mxBehaviorSetProperty(the, variable, (txID)offset, index, XS_ANY);
2406
- mxRestoreState;
2407
- XS_CODE_SET_ALL:
2408
- #ifdef mxTrace
2409
- if (gxDoTrace) fxTraceID(the, (txID)offset, index);
2410
- #endif
2411
- if (!slot) {
2412
- if (mxFrame->flag & XS_STRICT_FLAG) {
2413
- mxRunDebugID(XS_TYPE_ERROR, "set %s: not extensible", (txID)offset);
2414
- }
2415
- goto XS_CODE_SET_SKIP;
2416
- }
2417
- if (slot->kind == XS_ACCESSOR_KIND) {
2418
- variable = slot->value.accessor.setter;
2419
- if (!mxIsFunction(variable)) {
2420
- if (mxFrame->flag & XS_STRICT_FLAG) {
2421
- mxRunDebugID(XS_TYPE_ERROR, "set %s: no setter", (txID)offset);
2422
- }
2423
- goto XS_CODE_SET_SKIP;
2424
- }
2425
- slot = mxStack;
2426
- mxAllocStack(5);
2427
- mxStack->value = slot->value;
2428
- mxInitSlotKind(mxStack, slot->kind);
2429
- slot = mxStack + 1;
2430
- mxInitSlotKind(slot++, XS_UNINITIALIZED_KIND);
2431
- mxInitSlotKind(slot++, XS_UNINITIALIZED_KIND);
2432
- slot->value = mxStack->value;
2433
- mxInitSlotKind(slot++, mxStack->kind);
2434
- mxInitSlotKind(slot++, XS_UNDEFINED_KIND);
2435
- slot->value.reference = variable;
2436
- mxInitSlotKind(slot++, XS_REFERENCE_KIND);
2437
- offset = 1;
2438
- goto XS_CODE_RUN_ALL;
2439
- }
2440
- if (slot->flag & (XS_DONT_SET_FLAG | XS_MARK_FLAG)) {
2441
- if (mxFrame->flag & XS_STRICT_FLAG) {
2442
- mxRunDebugID(XS_TYPE_ERROR, "set %s: not writable", (txID)offset);
2443
- }
2444
- goto XS_CODE_SET_SKIP;
2445
- }
2446
- slot->kind = mxStack->kind;
2447
- slot->value = mxStack->value;
2448
- XS_CODE_SET_SKIP:
2449
- *(mxStack + 1) = *mxStack;
2450
- mxStack++;
2451
- mxBreak;
2452
-
2453
- mxCase(XS_CODE_HAS_PRIVATE_2)
2454
- index = mxRunU2(1);
2455
- mxNextCode(3);
2456
- goto XS_CODE_HAS_PRIVATE;
2457
- mxCase(XS_CODE_HAS_PRIVATE_1)
2458
- index = mxRunU1(1);
2459
- mxNextCode(2);
2460
- XS_CODE_HAS_PRIVATE:
2461
- #ifdef mxTrace
2462
- if (gxDoTrace) fxTraceIndex(the, index - 1);
2463
- #endif
2464
- slot = (mxEnvironment - index);
2465
- if (mxStack->kind == XS_REFERENCE_KIND)
2466
- variable = mxStack->value.reference;
2467
- else
2468
- mxRunDebug(XS_TYPE_ERROR, "in: no instance");
2469
- offset = slot->ID;
2470
- index = 0;
2471
- if (slot->value.closure->kind < 0)
2472
- mxRunDebugID(XS_TYPE_ERROR, "get %s: undefined private property", (txID)offset);
2473
- slot = gxDefaults.getPrivateProperty(the, variable, slot->value.closure->value.reference, (txID)offset);
2474
- mxStack->kind = XS_BOOLEAN_KIND;
2475
- mxStack->value.boolean = (slot) ? 1 : 0;
2476
- mxBreak;
2477
-
2478
- /* INSTANCES */
2479
- mxCase(XS_CODE_ARRAY)
2480
- // mxAllocStack(1);
2481
- mxSaveState;
2482
- fxNewArray(the, 0);
2483
- mxRestoreState;
2484
- mxNextCode(1);
2485
- mxBreak;
2486
- mxCase(XS_CODE_CLASS)
2487
- variable = fxToInstance(the, mxStack);
2488
- slot = mxStack + 2;
2489
- variable->flag |= XS_CAN_CONSTRUCT_FLAG;
2490
- if (slot->kind == XS_NULL_KIND)
2491
- variable->next->flag |= XS_BASE_FLAG;
2492
- else {
2493
- variable->next->flag |= XS_DERIVED_FLAG;
2494
- variable->value.instance.prototype = slot->value.reference;
2495
- }
2496
- slot = mxStack + 1;
2497
- mxFunctionInstanceHome(variable)->value.home.object = slot->value.reference;
2498
- mxSaveState;
2499
- slot->flag = XS_GET_ONLY;
2500
- fxRunDefine(the, variable, C_NULL, mxID(_prototype), 0, slot, XS_GET_ONLY);
2501
- slot = mxBehaviorSetProperty(the, slot->value.reference, mxID(_constructor), 0, XS_OWN);
2502
- mxRestoreState;
2503
- slot->flag |= XS_DONT_ENUM_FLAG;
2504
- slot->kind = mxStack->kind;
2505
- slot->value = mxStack->value;
2506
- mxStack += 3;
2507
- mxNextCode(1);
2508
- mxBreak;
2509
- mxCase(XS_CODE_COPY_OBJECT)
2510
- mxNextCode(1);
2511
- mxAllocStack(1);
2512
- *mxStack = mxCopyObjectFunction;
2513
- mxBreak;
2514
- mxCase(XS_CODE_EXTEND)
2515
- if (mxStack->kind == XS_NULL_KIND) {
2516
- mxSaveState;
2517
- fxNewInstance(the);
2518
- mxRestoreState;
2519
- }
2520
- else {
2521
- mxSaveState;
2522
- fxRunExtends(the);
2523
- mxRestoreState;
2524
- }
2525
- mxNextCode(1);
2526
- mxBreak;
2527
- mxCase(XS_CODE_GLOBAL)
2528
- mxPushKind(XS_REFERENCE_KIND);
2529
- variable = mxFunctionInstanceHome(mxFrameFunction->value.reference)->value.home.module;
2530
- variable = mxModuleInstanceInternal(variable)->value.module.realm;
2531
- if (!variable) variable = mxModuleInstanceInternal(mxProgram.value.reference)->value.module.realm;
2532
- mxStack->value.reference = mxRealmGlobal(variable)->value.reference;
2533
- mxNextCode(1);
2534
- mxBreak;
2535
- mxCase(XS_CODE_HOST)
2536
- index = mxRunU2(1);
2537
- #ifdef mxTrace
2538
- if (gxDoTrace) fxTraceIndex(the, index);
2539
- #endif
2540
- mxAllocStack(1);
2541
- *mxStack = mxHosts;
2542
- slot = mxBehaviorGetProperty(the, mxStack->value.reference, 0, index, XS_OWN);
2543
- mxStack->kind = slot->kind;
2544
- mxStack->value = slot->value;
2545
- mxNextCode(3);
2546
- mxBreak;
2547
- mxCase(XS_CODE_INSTANTIATE)
2548
- mxSaveState;
2549
- fxRunInstantiate(the);
2550
- mxRestoreState;
2551
- mxNextCode(1);
2552
- mxBreak;
2553
- mxCase(XS_CODE_CALL)
2554
- mxNextCode(1);
2555
- mxAllocStack(4);
2556
- slot = mxStack;
2557
- mxInitSlotKind(slot++, XS_UNINITIALIZED_KIND);
2558
- mxInitSlotKind(slot++, XS_UNINITIALIZED_KIND);
2559
- mxInitSlotKind(slot++, XS_UNDEFINED_KIND);
2560
- mxInitSlotKind(slot, XS_UNDEFINED_KIND);
2561
- mxBreak;
2562
- mxCase(XS_CODE_NEW)
2563
- mxNextCode(1);
2564
- variable = mxStack;
2565
- mxAllocStack(5);
2566
- slot = mxStack;
2567
- mxInitSlotKind(slot++, XS_UNINITIALIZED_KIND);
2568
- mxInitSlotKind(slot++, XS_UNINITIALIZED_KIND);
2569
- mxInitSlotKind(slot++, XS_UNDEFINED_KIND);
2570
- slot->value = variable->value;
2571
- mxInitSlotKind(slot++, variable->kind);
2572
- slot->value = variable->value;
2573
- mxInitSlotKind(slot++, variable->kind);
2574
- mxInitSlotKind(slot, XS_UNINITIALIZED_KIND);
2575
- mxBreak;
2576
- mxCase(XS_CODE_OBJECT)
2577
- // mxAllocStack(1);
2578
- mxSaveState;
2579
- fxNewObject(the);
2580
- mxRestoreState;
2581
- mxNextCode(1);
2582
- mxBreak;
2583
- mxCase(XS_CODE_REGEXP)
2584
- mxNextCode(1);
2585
- mxAllocStack(1);
2586
- *mxStack = mxRegExpConstructor;
2587
- mxBreak;
2588
- mxCase(XS_CODE_SUPER)
2589
- mxNextCode(1);
2590
- variable = mxFrameFunction->value.reference;
2591
- if (mxIsConstructor(variable))
2592
- variable = fxGetPrototype(the, variable);
2593
- else {
2594
- variable = mxFunctionInstanceHome(variable);
2595
- variable = mxBehaviorGetProperty(the, variable->value.home.object, mxID(_constructor), 0, XS_ANY);
2596
- variable = fxGetPrototype(the, variable->value.reference);
2597
- }
2598
- if (!mxIsConstructor(variable))
2599
- mxRunDebug(XS_TYPE_ERROR, "super: no constructor");
2600
- mxAllocStack(6);
2601
- slot = mxStack;
2602
- mxInitSlotKind(slot++, XS_UNINITIALIZED_KIND);
2603
- mxInitSlotKind(slot++, XS_UNINITIALIZED_KIND);
2604
- mxInitSlotKind(slot++, XS_UNDEFINED_KIND);
2605
- slot->value = mxFrameTarget->value;
2606
- mxInitSlotKind(slot++, mxFrameTarget->kind);
2607
- slot->value.reference = variable;
2608
- mxInitSlotKind(slot++, XS_REFERENCE_KIND);
2609
- mxInitSlotKind(slot, XS_UNINITIALIZED_KIND);
2610
- mxBreak;
2611
- mxCase(XS_CODE_TEMPLATE)
2612
- mxNextCode(1);
2613
- variable = mxStack->value.reference;
2614
- slot = mxBehaviorGetProperty(the, variable, mxID(_raw), 0, XS_OWN);
2615
- if (!slot)
2616
- mxRunDebug(XS_TYPE_ERROR, "template: no raw");
2617
- variable->flag |= XS_DONT_PATCH_FLAG;
2618
- variable->next->flag |= XS_DONT_SET_FLAG;
2619
- slot->flag |= XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
2620
- variable = slot->value.reference;
2621
- variable->flag |= XS_DONT_PATCH_FLAG;
2622
- variable->next->flag |= XS_DONT_SET_FLAG;
2623
- mxBreak;
2624
- mxCase(XS_CODE_TEMPLATE_CACHE)
2625
- mxNextCode(1);
2626
- variable = mxFunctionInstanceHome(mxFrameFunction->value.reference)->value.home.module;
2627
- variable = mxModuleInstanceInternal(variable)->value.module.realm;
2628
- if (!variable) variable = mxModuleInstanceInternal(mxProgram.value.reference)->value.module.realm;
2629
- slot = mxRealmTemplateCache(variable);
2630
- mxPushKind(XS_REFERENCE_KIND);
2631
- mxStack->value.reference = slot->value.reference;
2632
- mxBreak;
2633
-
2634
- /* FUNCTIONS */
2635
- mxCase(XS_CODE_ASYNC_FUNCTION)
2636
- offset = mxRunID(1);
2637
- #ifdef mxTrace
2638
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
2639
- #endif
2640
- mxAllocStack(1);
2641
- *mxStack = mxAsyncFunctionPrototype;
2642
- mxSaveState;
2643
- fxNewFunctionInstance(the, (txID)offset);
2644
- mxRestoreState;
2645
- mxNextCode(1 + sizeof(txID));
2646
- mxBreak;
2647
- mxCase(XS_CODE_ASYNC_GENERATOR_FUNCTION)
2648
- offset = mxRunID(1);
2649
- #ifdef mxTrace
2650
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
2651
- #endif
2652
- mxAllocStack(1);
2653
- *mxStack = mxAsyncGeneratorFunctionPrototype;
2654
- mxSaveState;
2655
- gxDefaults.newAsyncGeneratorFunctionInstance(the,(txID) offset);
2656
- mxRestoreState;
2657
- mxNextCode(1 + sizeof(txID));
2658
- mxBreak;
2659
- mxCase(XS_CODE_CONSTRUCTOR_FUNCTION)
2660
- offset = mxRunID(1);
2661
- #ifdef mxTrace
2662
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
2663
- #endif
2664
- mxAllocStack(1);
2665
- *mxStack = mxFunctionPrototype;
2666
- mxSaveState;
2667
- fxNewFunctionInstance(the, (txID)offset);
2668
- fxDefaultFunctionPrototype(the);
2669
- mxRestoreState;
2670
- mxNextCode(1 + sizeof(txID));
2671
- mxBreak;
2672
- mxCase(XS_CODE_FUNCTION)
2673
- offset = mxRunID(1);
2674
- #ifdef mxTrace
2675
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
2676
- #endif
2677
- mxAllocStack(1);
2678
- *mxStack = mxFunctionPrototype;
2679
- mxSaveState;
2680
- fxNewFunctionInstance(the, (txID)offset);
2681
- mxRestoreState;
2682
- mxNextCode(1 + sizeof(txID));
2683
- mxBreak;
2684
- mxCase(XS_CODE_GENERATOR_FUNCTION)
2685
- offset = mxRunID(1);
2686
- #ifdef mxTrace
2687
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
2688
- #endif
2689
- mxAllocStack(1);
2690
- *mxStack = mxGeneratorFunctionPrototype;
2691
- mxSaveState;
2692
- gxDefaults.newGeneratorFunctionInstance(the,(txID) offset);
2693
- mxRestoreState;
2694
- mxNextCode(1 + sizeof(txID));
2695
- mxBreak;
2696
- mxCase(XS_CODE_PROFILE)
2697
- offset = mxRunID(1);
2698
- variable = mxFunctionInstanceHome(mxStack->value.reference);
2699
- variable->ID = offset;
2700
- mxNextCode(1 + sizeof(txID));
2701
- mxBreak;
2702
- mxCase(XS_CODE_NAME)
2703
- offset = mxRunID(1);
2704
- #ifdef mxTrace
2705
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
2706
- #endif
2707
- mxSaveState;
2708
- fxRenameFunction(the, mxStack->value.reference, (txID)offset, 0, XS_NO_ID, C_NULL);
2709
- mxRestoreState;
2710
- mxNextCode(1 + sizeof(txID));
2711
- mxBreak;
2712
- mxCase(XS_CODE_SET_HOME)
2713
- slot = mxFunctionInstanceHome((mxStack + 1)->value.reference);
2714
- slot->value.home.object = mxStack->value.reference;
2715
- mxStack++;
2716
- mxNextCode(1);
2717
- mxBreak;
2718
- mxCase(XS_CODE_CODE_4)
2719
- offset = mxRunS4(1);
2720
- mxSkipCode(5);
2721
- goto XS_CODE_CODE;
2722
- mxCase(XS_CODE_CODE_2)
2723
- offset = mxRunS2(1);
2724
- mxSkipCode(3);
2725
- goto XS_CODE_CODE;
2726
- mxCase(XS_CODE_CODE_1)
2727
- offset = mxRunS1(1);
2728
- mxSkipCode(2);
2729
- XS_CODE_CODE:
2730
- mxSaveState;
2731
- scratch.value.code.address = (txByte*)fxNewChunk(the, (txSize)offset);
2732
- mxRestoreState;
2733
- c_memcpy(scratch.value.code.address, mxCode, offset);
2734
- variable = mxStack->value.reference;
2735
- slot = mxFunctionInstanceCode(variable);
2736
- slot->kind = XS_CODE_KIND;
2737
- slot->value.code.address = scratch.value.code.address;
2738
- if (gxDefaults.newFunctionLength) {
2739
- gxDefaults.newFunctionLength(the, variable, *(((txU1*)scratch.value.code.address + 1)));
2740
- }
2741
- mxNextCode(offset);
2742
- mxBreak;
2743
- mxCase(XS_CODE_CODE_ARCHIVE_4)
2744
- offset = mxRunS4(1);
2745
- mxSkipCode(5);
2746
- goto XS_CODE_CODE_ARCHIVE;
2747
- mxCase(XS_CODE_CODE_ARCHIVE_2)
2748
- offset = mxRunS2(1);
2749
- mxSkipCode(3);
2750
- goto XS_CODE_CODE_ARCHIVE;
2751
- mxCase(XS_CODE_CODE_ARCHIVE_1)
2752
- offset = mxRunS1(1);
2753
- mxSkipCode(2);
2754
- XS_CODE_CODE_ARCHIVE:
2755
- variable = mxStack->value.reference;
2756
- slot = mxFunctionInstanceCode(variable);
2757
- slot->kind = XS_CODE_X_KIND;
2758
- slot->value.code.address = mxCode;
2759
- if (gxDefaults.newFunctionLength) {
2760
- gxDefaults.newFunctionLength(the, variable, mxRunU1(1));
2761
- }
2762
- mxNextCode(offset);
2763
- mxBreak;
2764
-
2765
- /* VALUES */
2766
- mxCase(XS_CODE_UNDEFINED)
2767
- mxPushKind(XS_UNDEFINED_KIND);
2768
- mxNextCode(1);
2769
- mxBreak;
2770
- mxCase(XS_CODE_NULL)
2771
- mxPushKind(XS_NULL_KIND);
2772
- mxNextCode(1);
2773
- mxBreak;
2774
- mxCase(XS_CODE_FALSE)
2775
- mxPushKind(XS_BOOLEAN_KIND);
2776
- mxStack->value.boolean = 0;
2777
- mxNextCode(1);
2778
- mxBreak;
2779
- mxCase(XS_CODE_TRUE)
2780
- mxPushKind(XS_BOOLEAN_KIND);
2781
- mxStack->value.boolean = 1;
2782
- mxNextCode(1);
2783
- mxBreak;
2784
- mxCase(XS_CODE_INTEGER_1)
2785
- mxPushKind(XS_INTEGER_KIND);
2786
- mxStack->value.integer = mxRunS1(1);
2787
- mxNextCode(2);
2788
- #ifdef mxTrace
2789
- if (gxDoTrace) fxTraceInteger(the, mxStack->value.integer);
2790
- #endif
2791
- mxBreak;
2792
- mxCase(XS_CODE_INTEGER_2)
2793
- mxPushKind(XS_INTEGER_KIND);
2794
- mxStack->value.integer = mxRunS2(1);
2795
- mxNextCode(3);
2796
- #ifdef mxTrace
2797
- if (gxDoTrace) fxTraceInteger(the, mxStack->value.integer);
2798
- #endif
2799
- mxBreak;
2800
- mxCase(XS_CODE_INTEGER_4)
2801
- mxPushKind(XS_INTEGER_KIND);
2802
- mxStack->value.integer = mxRunS4(1);
2803
- mxNextCode(5);
2804
- #ifdef mxTrace
2805
- if (gxDoTrace) fxTraceInteger(the, mxStack->value.integer);
2806
- #endif
2807
- mxBreak;
2808
- mxCase(XS_CODE_NUMBER)
2809
- mxPushKind(XS_NUMBER_KIND);
2810
- {
2811
- txByte* number = (txByte*)&(mxStack->value.number);
2812
- #if mxBigEndian
2813
- number[7] = mxCode[1];
2814
- number[6] = mxCode[2];
2815
- number[5] = mxCode[3];
2816
- number[4] = mxCode[4];
2817
- number[3] = mxCode[5];
2818
- number[2] = mxCode[6];
2819
- number[1] = mxCode[7];
2820
- number[0] = mxCode[8];
2821
- #else
2822
- number[0] = mxCode[1];
2823
- number[1] = mxCode[2];
2824
- number[2] = mxCode[3];
2825
- number[3] = mxCode[4];
2826
- number[4] = mxCode[5];
2827
- number[5] = mxCode[6];
2828
- number[6] = mxCode[7];
2829
- number[7] = mxCode[8];
2830
- #endif
2831
- }
2832
- mxNextCode(9);
2833
- #ifdef mxTrace
2834
- if (gxDoTrace) fxTraceNumber(the, mxStack->value.number);
2835
- #endif
2836
- mxBreak;
2837
-
2838
- mxCase(XS_CODE_STRING_4)
2839
- index = mxRunS4(1);
2840
- mxSkipCode(5);
2841
- goto XS_CODE_STRING;
2842
- mxCase(XS_CODE_STRING_2)
2843
- index = mxRunU2(1);
2844
- mxSkipCode(3);
2845
- goto XS_CODE_STRING;
2846
- mxCase(XS_CODE_STRING_1)
2847
- index = mxRunU1(1);
2848
- mxSkipCode(2);
2849
- XS_CODE_STRING:
2850
- mxSaveState;
2851
- scratch.value.string = (txString)fxNewChunk(the, index);
2852
- mxRestoreState;
2853
- c_memcpy(scratch.value.string, mxCode, index);
2854
- mxPushKind(XS_STRING_KIND);
2855
- mxStack->value.string = scratch.value.string;
2856
- mxNextCode(index);
2857
- #ifdef mxTrace
2858
- if (gxDoTrace) fxTraceString(the, mxStack->value.string);
2859
- #endif
2860
- mxBreak;
2861
- mxCase(XS_CODE_STRING_ARCHIVE_4)
2862
- index = mxRunS4(1);
2863
- mxSkipCode(5);
2864
- goto XS_CODE_STRING_ARCHIVE;
2865
- mxCase(XS_CODE_STRING_ARCHIVE_2)
2866
- index = mxRunU2(1);
2867
- mxSkipCode(3);
2868
- goto XS_CODE_STRING_ARCHIVE;
2869
- mxCase(XS_CODE_STRING_ARCHIVE_1)
2870
- index = mxRunU1(1);
2871
- mxSkipCode(2);
2872
- XS_CODE_STRING_ARCHIVE:
2873
- mxPushKind(XS_STRING_X_KIND);
2874
- mxStack->value.string = (txString)mxCode;
2875
- mxNextCode(index);
2876
- #ifdef mxTrace
2877
- if (gxDoTrace) fxTraceString(the, mxStack->value.string);
2878
- #endif
2879
- mxBreak;
2880
- mxCase(XS_CODE_TO_STRING)
2881
- mxToString(mxStack);
2882
- mxNextCode(1);
2883
- mxBreak;
2884
-
2885
- mxCase(XS_CODE_SYMBOL)
2886
- mxPushKind(XS_SYMBOL_KIND);
2887
- mxStack->value.symbol = mxRunID(1);
2888
- #ifdef mxTrace
2889
- if (gxDoTrace) fxTraceID(the, mxStack->value.symbol, 0);
2890
- #endif
2891
- mxNextCode(1 + sizeof(txID));
2892
- mxBreak;
2893
-
2894
- mxCase(XS_CODE_BIGINT_2)
2895
- index = mxRunU2(1);
2896
- mxSkipCode(3);
2897
- goto XS_CODE_BIGINT;
2898
- mxCase(XS_CODE_BIGINT_1)
2899
- index = mxRunU1(1);
2900
- mxSkipCode(2);
2901
- XS_CODE_BIGINT:
2902
- mxSaveState;
2903
- gxTypeBigInt.decode(the, index);
2904
- mxRestoreState;
2905
- mxNextCode(index);
2906
- mxBreak;
2907
-
2908
- /* EXPRESSIONS */
2909
- mxCase(XS_CODE_BIT_NOT)
2910
- if (mxStack->kind == XS_INTEGER_KIND)
2911
- mxStack->value.integer = ~mxStack->value.integer;
2912
- else if (mxStack->kind == XS_NUMBER_KIND) {
2913
- mxStack->kind = XS_INTEGER_KIND;
2914
- mxStack->value.integer = ~fxNumberToInteger(mxStack->value.number);
2915
- mxFloatingPointOp("not");
2916
- }
2917
- else {
2918
- mxSaveState;
2919
- if (fxToNumericIntegerUnary(the, mxStack, gxTypeBigInt._not))
2920
- mxStack->value.integer = ~mxStack->value.integer;
2921
- mxRestoreState;
2922
- }
2923
- mxNextCode(1);
2924
- mxBreak;
2925
- mxCase(XS_CODE_BIT_AND)
2926
- slot = mxStack + 1;
2927
- if (slot->kind == XS_INTEGER_KIND) {
2928
- if (mxStack->kind == XS_INTEGER_KIND)
2929
- slot->value.integer &= mxStack->value.integer;
2930
- else if (mxStack->kind == XS_NUMBER_KIND) {
2931
- slot->value.integer &= fxNumberToInteger(mxStack->value.number);
2932
- mxFloatingPointOp("and");
2933
- }
2934
- else
2935
- goto XS_CODE_BIT_AND_GENERAL;
2936
- }
2937
- else if (slot->kind == XS_NUMBER_KIND) {
2938
- if (mxStack->kind == XS_INTEGER_KIND) {
2939
- slot->kind = XS_INTEGER_KIND;
2940
- slot->value.integer = fxNumberToInteger(slot->value.number) & mxStack->value.integer;
2941
- mxFloatingPointOp("and");
2942
- }
2943
- else if (mxStack->kind == XS_NUMBER_KIND) {
2944
- slot->kind = XS_INTEGER_KIND;
2945
- slot->value.integer = fxNumberToInteger(slot->value.number) & fxNumberToInteger(mxStack->value.number);
2946
- mxFloatingPointOp("and");
2947
- }
2948
- else
2949
- goto XS_CODE_BIT_AND_GENERAL;
2950
- }
2951
- else {
2952
- XS_CODE_BIT_AND_GENERAL:
2953
- mxSaveState;
2954
- if (fxToNumericIntegerBinary(the, slot, mxStack, gxTypeBigInt._and))
2955
- slot->value.integer &= mxStack->value.integer;
2956
- mxRestoreState;
2957
- }
2958
- mxStack++;
2959
- mxNextCode(1);
2960
- mxBreak;
2961
- mxCase(XS_CODE_BIT_OR)
2962
- slot = mxStack + 1;
2963
- if (slot->kind == XS_INTEGER_KIND) {
2964
- if (mxStack->kind == XS_INTEGER_KIND)
2965
- slot->value.integer |= mxStack->value.integer;
2966
- else if (mxStack->kind == XS_NUMBER_KIND) {
2967
- slot->value.integer |= fxNumberToInteger(mxStack->value.number);
2968
- mxFloatingPointOp("or");
2969
- }
2970
- else
2971
- goto XS_CODE_BIT_OR_GENERAL;
2972
- }
2973
- else if (slot->kind == XS_NUMBER_KIND) {
2974
- if (mxStack->kind == XS_INTEGER_KIND) {
2975
- slot->kind = XS_INTEGER_KIND;
2976
- slot->value.integer = fxNumberToInteger(slot->value.number) | mxStack->value.integer;
2977
- mxFloatingPointOp("or");
2978
- }
2979
- else if (mxStack->kind == XS_NUMBER_KIND) {
2980
- slot->kind = XS_INTEGER_KIND;
2981
- slot->value.integer = fxNumberToInteger(slot->value.number) | fxNumberToInteger(mxStack->value.number);
2982
- mxFloatingPointOp("or");
2983
- }
2984
- else
2985
- goto XS_CODE_BIT_OR_GENERAL;
2986
- }
2987
- else {
2988
- XS_CODE_BIT_OR_GENERAL:
2989
- mxSaveState;
2990
- if (fxToNumericIntegerBinary(the, slot, mxStack, gxTypeBigInt._or))
2991
- slot->value.integer |= mxStack->value.integer;
2992
- mxRestoreState;
2993
- }
2994
- mxStack++;
2995
- mxNextCode(1);
2996
- mxBreak;
2997
- mxCase(XS_CODE_BIT_XOR)
2998
- slot = mxStack + 1;
2999
- if (slot->kind == XS_INTEGER_KIND) {
3000
- if (mxStack->kind == XS_INTEGER_KIND)
3001
- slot->value.integer ^= mxStack->value.integer;
3002
- else if (mxStack->kind == XS_NUMBER_KIND) {
3003
- slot->value.integer ^= fxNumberToInteger(mxStack->value.number);
3004
- mxFloatingPointOp("xor");
3005
- }
3006
- else
3007
- goto XS_CODE_BIT_XOR_GENERAL;
3008
- }
3009
- else if (slot->kind == XS_NUMBER_KIND) {
3010
- if (mxStack->kind == XS_INTEGER_KIND) {
3011
- slot->kind = XS_INTEGER_KIND;
3012
- slot->value.integer = fxNumberToInteger(slot->value.number) ^ mxStack->value.integer;
3013
- mxFloatingPointOp("xor");
3014
- }
3015
- else if (mxStack->kind == XS_NUMBER_KIND) {
3016
- slot->kind = XS_INTEGER_KIND;
3017
- slot->value.integer = fxNumberToInteger(slot->value.number) ^ fxNumberToInteger(mxStack->value.number);
3018
- mxFloatingPointOp("xor");
3019
- }
3020
- else
3021
- goto XS_CODE_BIT_XOR_GENERAL;
3022
- }
3023
- else {
3024
- XS_CODE_BIT_XOR_GENERAL:
3025
- mxSaveState;
3026
- if (fxToNumericIntegerBinary(the, slot, mxStack, gxTypeBigInt._xor))
3027
- slot->value.integer ^= mxStack->value.integer;
3028
- mxRestoreState;
3029
- }
3030
- mxStack++;
3031
- mxNextCode(1);
3032
- mxBreak;
3033
-
3034
- mxCase(XS_CODE_LEFT_SHIFT)
3035
- slot = mxStack + 1;
3036
- if (slot->kind == XS_INTEGER_KIND) {
3037
- if (mxStack->kind == XS_INTEGER_KIND)
3038
- slot->value.integer <<= mxStack->value.integer & 0x1f;
3039
- else if (mxStack->kind == XS_NUMBER_KIND) {
3040
- slot->value.integer <<= fxNumberToInteger(mxStack->value.number) & 0x1f;
3041
- mxFloatingPointOp("left shift");
3042
- }
3043
- else
3044
- goto XS_CODE_LEFT_SHIFT_GENERAL;
3045
- }
3046
- else if (slot->kind == XS_NUMBER_KIND) {
3047
- if (mxStack->kind == XS_INTEGER_KIND) {
3048
- slot->kind = XS_INTEGER_KIND;
3049
- slot->value.integer = fxNumberToInteger(slot->value.number) << (mxStack->value.integer & 0x1f);
3050
- mxFloatingPointOp("left shift");
3051
- }
3052
- else if (mxStack->kind == XS_NUMBER_KIND) {
3053
- slot->kind = XS_INTEGER_KIND;
3054
- slot->value.integer = fxNumberToInteger(slot->value.number) << (fxNumberToInteger(mxStack->value.number) & 0x1f);
3055
- mxFloatingPointOp("left shift");
3056
- }
3057
- else
3058
- goto XS_CODE_LEFT_SHIFT_GENERAL;
3059
- }
3060
- else {
3061
- XS_CODE_LEFT_SHIFT_GENERAL:
3062
- mxSaveState;
3063
- if (fxToNumericIntegerBinary(the, slot, mxStack, gxTypeBigInt._lsl))
3064
- slot->value.integer <<= mxStack->value.integer & 0x1f;
3065
- mxRestoreState;
3066
- }
3067
- mxStack++;
3068
- mxNextCode(1);
3069
- mxBreak;
3070
- mxCase(XS_CODE_SIGNED_RIGHT_SHIFT)
3071
- slot = mxStack + 1;
3072
- if (slot->kind == XS_INTEGER_KIND) {
3073
- if (mxStack->kind == XS_INTEGER_KIND)
3074
- slot->value.integer >>= mxStack->value.integer & 0x1f;
3075
- else if (mxStack->kind == XS_NUMBER_KIND) {
3076
- slot->value.integer >>= fxNumberToInteger(mxStack->value.number) & 0x1f;
3077
- mxFloatingPointOp("signed right shift");
3078
- }
3079
- else
3080
- goto XS_CODE_SIGNED_RIGHT_SHIFT_GENERAL;
3081
- }
3082
- else if (slot->kind == XS_NUMBER_KIND) {
3083
- if (mxStack->kind == XS_INTEGER_KIND) {
3084
- slot->kind = XS_INTEGER_KIND;
3085
- slot->value.integer = fxNumberToInteger(slot->value.number) >> (mxStack->value.integer & 0x1f);
3086
- mxFloatingPointOp("signed right shift");
3087
- }
3088
- else if (mxStack->kind == XS_NUMBER_KIND) {
3089
- slot->kind = XS_INTEGER_KIND;
3090
- slot->value.integer = fxNumberToInteger(slot->value.number) >> (fxNumberToInteger(mxStack->value.number) & 0x1f);
3091
- mxFloatingPointOp("signed right shift");
3092
- }
3093
- else
3094
- goto XS_CODE_SIGNED_RIGHT_SHIFT_GENERAL;
3095
- }
3096
- else {
3097
- XS_CODE_SIGNED_RIGHT_SHIFT_GENERAL:
3098
- mxSaveState;
3099
- if (fxToNumericIntegerBinary(the, slot, mxStack, gxTypeBigInt._lsr))
3100
- slot->value.integer >>= mxStack->value.integer & 0x1f;
3101
- mxRestoreState;
3102
- }
3103
- mxStack++;
3104
- mxNextCode(1);
3105
- mxBreak;
3106
- mxCase(XS_CODE_UNSIGNED_RIGHT_SHIFT)
3107
- slot = mxStack + 1;
3108
- if (((slot->kind == XS_INTEGER_KIND) || (slot->kind == XS_NUMBER_KIND)) && ((mxStack->kind == XS_INTEGER_KIND) || (mxStack->kind == XS_NUMBER_KIND))) {
3109
- fxUnsigned(the, slot, fxToUnsigned(the, slot) >> (fxToUnsigned(the, mxStack) & 0x1F));
3110
- }
3111
- else {
3112
- mxSaveState;
3113
- if (fxToNumericNumberBinary(the, slot, mxStack, gxTypeBigInt._nop))
3114
- fxUnsigned(the, slot, fxToUnsigned(the, slot) >> (fxToUnsigned(the, mxStack) & 0x1F));
3115
- mxRestoreState;
3116
- }
3117
- mxStack++;
3118
- mxNextCode(1);
3119
- mxBreak;
3120
-
3121
- mxCase(XS_CODE_MINUS)
3122
- if (mxStack->kind == XS_INTEGER_KIND) {
3123
- if (mxStack->value.integer & 0x7FFFFFFF)
3124
- mxStack->value.integer = -mxStack->value.integer;
3125
- else {
3126
- mxStack->kind = XS_NUMBER_KIND;
3127
- mxStack->value.number = -((txNumber)(mxStack->value.integer));
3128
- mxFloatingPointOp("minus");
3129
- }
3130
- }
3131
- else if (mxStack->kind == XS_NUMBER_KIND) {
3132
- mxStack->value.number = -mxStack->value.number;
3133
- mxFloatingPointOp("minus");
3134
- }
3135
- else {
3136
- mxSaveState;
3137
- if (fxToNumericNumberUnary(the, mxStack, gxTypeBigInt._neg)) {
3138
- mxStack->value.number = -mxStack->value.number;
3139
- mxFloatingPointOp("minus");
3140
- }
3141
- mxRestoreState;
3142
- }
3143
- mxNextCode(1);
3144
- mxBreak;
3145
- mxCase(XS_CODE_PLUS)
3146
- if (mxStack->kind != XS_INTEGER_KIND) {
3147
- mxToNumber(mxStack);
3148
- }
3149
- mxNextCode(1);
3150
- mxBreak;
3151
-
3152
- mxCase(XS_CODE_TO_NUMERIC)
3153
- if ((mxStack->kind != XS_INTEGER_KIND) && (mxStack->kind != XS_NUMBER_KIND)) {
3154
- mxSaveState;
3155
- fxToNumericNumber(the, mxStack);
3156
- mxRestoreState;
3157
- }
3158
- mxNextCode(1);
3159
- mxBreak;
3160
- mxCase(XS_CODE_DECREMENT)
3161
- if (mxStack->kind == XS_INTEGER_KIND) {
3162
- if (mxStack->value.integer != -2147483647)
3163
- mxStack->value.integer--;
3164
- else {
3165
- mxStack->kind = XS_NUMBER_KIND;
3166
- mxStack->value.number = mxStack->value.integer;
3167
- mxStack->value.number--;
3168
- mxFloatingPointOp("decrement");
3169
- }
3170
- }
3171
- else if (mxStack->kind == XS_NUMBER_KIND) {
3172
- mxStack->value.number--;
3173
- mxFloatingPointOp("decrement");
3174
- }
3175
- else {
3176
- mxSaveState;
3177
- if (fxToNumericNumberUnary(the, mxStack, gxTypeBigInt._dec)) {
3178
- mxStack->value.number--;
3179
- mxFloatingPointOp("decrement");
3180
- }
3181
- mxRestoreState;
3182
- }
3183
- mxNextCode(1);
3184
- mxBreak;
3185
- mxCase(XS_CODE_INCREMENT)
3186
- if (mxStack->kind == XS_INTEGER_KIND) {
3187
- if (mxStack->value.integer != 2147483647)
3188
- mxStack->value.integer++;
3189
- else {
3190
- mxStack->kind = XS_NUMBER_KIND;
3191
- mxStack->value.number = mxStack->value.integer;
3192
- mxStack->value.number++;
3193
- mxFloatingPointOp("increment");
3194
- }
3195
- }
3196
- else if (mxStack->kind == XS_NUMBER_KIND) {
3197
- mxStack->value.number++;
3198
- mxFloatingPointOp("increment");
3199
- }
3200
- else {
3201
- mxSaveState;
3202
- if (fxToNumericNumberUnary(the, mxStack, gxTypeBigInt._inc)) {
3203
- mxStack->value.number++;
3204
- mxFloatingPointOp("increment");
3205
- }
3206
- mxRestoreState;
3207
- }
3208
- mxNextCode(1);
3209
- mxBreak;
3210
-
3211
- mxCase(XS_CODE_ADD)
3212
- slot = mxStack + 1;
3213
- if (slot->kind == XS_INTEGER_KIND) {
3214
- if (mxStack->kind == XS_INTEGER_KIND) {
3215
- #if __has_builtin(__builtin_add_overflow)
3216
- if (__builtin_add_overflow(slot->value.integer, mxStack->value.integer, &scratch.value.integer)) {
3217
- slot->kind = XS_NUMBER_KIND;
3218
- slot->value.number = (txNumber)(slot->value.integer) + (txNumber)(mxStack->value.integer);
3219
- }
3220
- else
3221
- slot->value.integer = scratch.value.integer;
3222
- #else
3223
- txInteger a = slot->value.integer;
3224
- txInteger b = mxStack->value.integer;
3225
- txInteger c = a + b;
3226
- if (((a ^ c) & (b ^ c)) < 0) {
3227
- slot->kind = XS_NUMBER_KIND;
3228
- slot->value.number = (txNumber)(slot->value.integer) + (txNumber)(mxStack->value.integer);
3229
- mxFloatingPointOp("add");
3230
- }
3231
- else
3232
- slot->value.integer = c;
3233
- #endif
3234
- }
3235
- else if (mxStack->kind == XS_NUMBER_KIND) {
3236
- slot->kind = XS_NUMBER_KIND;
3237
- slot->value.number = (txNumber)(slot->value.integer) + mxStack->value.number;
3238
- mxFloatingPointOp("add");
3239
- }
3240
- else
3241
- goto XS_CODE_ADD_GENERAL;
3242
- }
3243
- else if (slot->kind == XS_NUMBER_KIND) {
3244
- if (mxStack->kind == XS_INTEGER_KIND) {
3245
- slot->value.number += (txNumber)(mxStack->value.integer);
3246
- mxFloatingPointOp("add");
3247
- }
3248
- else if (mxStack->kind == XS_NUMBER_KIND) {
3249
- slot->value.number += mxStack->value.number;
3250
- mxFloatingPointOp("add");
3251
- }
3252
- else
3253
- goto XS_CODE_ADD_GENERAL;
3254
- }
3255
- else {
3256
- XS_CODE_ADD_GENERAL:
3257
- mxSaveState;
3258
- fxToPrimitive(the, slot, XS_NO_HINT);
3259
- fxToPrimitive(the, mxStack, XS_NO_HINT);
3260
- if ((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND) || (mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND)) {
3261
- fxToString(the, slot);
3262
- fxToString(the, mxStack);
3263
- fxConcatString(the, slot, mxStack);
3264
- }
3265
- else {
3266
- if (fxToNumericNumberBinary(the, slot, mxStack, gxTypeBigInt._add)) {
3267
- slot->value.number += mxStack->value.number;
3268
- mxFloatingPointOp("add");
3269
- }
3270
- }
3271
- mxRestoreState;
3272
- }
3273
- mxStack++;
3274
- mxNextCode(1);
3275
- mxBreak;
3276
- mxCase(XS_CODE_SUBTRACT)
3277
- slot = mxStack + 1;
3278
- if (slot->kind == XS_INTEGER_KIND) {
3279
- if (mxStack->kind == XS_INTEGER_KIND) {
3280
- #if __has_builtin(__builtin_sub_overflow)
3281
- if (__builtin_sub_overflow(slot->value.integer, mxStack->value.integer, &scratch.value.integer)) {
3282
- slot->kind = XS_NUMBER_KIND;
3283
- slot->value.number = (txNumber)(slot->value.integer) - (txNumber)(mxStack->value.integer);
3284
- }
3285
- else
3286
- slot->value.integer = scratch.value.integer;
3287
- #else
3288
- txInteger a = slot->value.integer;
3289
- txInteger b = -mxStack->value.integer;
3290
- txInteger c = a + b;
3291
- if (((a ^ c) & (b ^ c)) < 0) {
3292
- slot->kind = XS_NUMBER_KIND;
3293
- slot->value.number = (txNumber)(slot->value.integer) - (txNumber)(mxStack->value.integer);
3294
- }
3295
- else
3296
- slot->value.integer = c;
3297
- #endif
3298
- }
3299
- else if (mxStack->kind == XS_NUMBER_KIND) {
3300
- slot->kind = XS_NUMBER_KIND;
3301
- slot->value.number = (txNumber)(slot->value.integer) - mxStack->value.number;
3302
- mxFloatingPointOp("subtract");
3303
- }
3304
- else
3305
- goto XS_CODE_SUBTRACT_GENERAL;
3306
- }
3307
- else if (slot->kind == XS_NUMBER_KIND) {
3308
- if (mxStack->kind == XS_INTEGER_KIND) {
3309
- slot->value.number -= (txNumber)(mxStack->value.integer);
3310
- mxFloatingPointOp("subtract");
3311
- }
3312
- else if (mxStack->kind == XS_NUMBER_KIND) {
3313
- slot->value.number -= mxStack->value.number;
3314
- mxFloatingPointOp("subtract");
3315
- }
3316
- else
3317
- goto XS_CODE_SUBTRACT_GENERAL;
3318
- }
3319
- else {
3320
- XS_CODE_SUBTRACT_GENERAL:
3321
- mxSaveState;
3322
- if (fxToNumericNumberBinary(the, slot, mxStack, gxTypeBigInt._sub)) {
3323
- slot->value.number -= mxStack->value.number;
3324
- mxFloatingPointOp("subtract");
3325
- }
3326
- mxRestoreState;
3327
- }
3328
- mxStack++;
3329
- mxNextCode(1);
3330
- mxBreak;
3331
-
3332
- mxCase(XS_CODE_DIVIDE)
3333
- slot = mxStack + 1;
3334
- if (slot->kind == XS_INTEGER_KIND) {
3335
- if (mxStack->kind == XS_INTEGER_KIND) {
3336
- slot->kind = XS_NUMBER_KIND;
3337
- slot->value.number = (txNumber)(slot->value.integer) / (txNumber)(mxStack->value.integer);
3338
- }
3339
- else if (mxStack->kind == XS_NUMBER_KIND) {
3340
- slot->kind = XS_NUMBER_KIND;
3341
- slot->value.number = (txNumber)(slot->value.integer) / mxStack->value.number;
3342
- }
3343
- else
3344
- goto XS_CODE_DIVIDE_GENERAL;
3345
- }
3346
- else if (slot->kind == XS_NUMBER_KIND) {
3347
- if (mxStack->kind == XS_INTEGER_KIND)
3348
- slot->value.number /= (txNumber)(mxStack->value.integer);
3349
- else if (mxStack->kind == XS_NUMBER_KIND)
3350
- slot->value.number /= mxStack->value.number;
3351
- else
3352
- goto XS_CODE_DIVIDE_GENERAL;
3353
- }
3354
- else {
3355
- XS_CODE_DIVIDE_GENERAL:
3356
- mxSaveState;
3357
- if (fxToNumericNumberBinary(the, slot, mxStack, gxTypeBigInt._div))
3358
- slot->value.number /= mxStack->value.number;
3359
- mxRestoreState;
3360
- }
3361
- mxFloatingPointOp("divide");
3362
- mxStack++;
3363
- mxNextCode(1);
3364
- mxBreak;
3365
- mxCase(XS_CODE_EXPONENTIATION)
3366
- slot = mxStack + 1;
3367
- if (slot->kind == XS_INTEGER_KIND) {
3368
- if (mxStack->kind == XS_INTEGER_KIND) {
3369
- slot->kind = XS_NUMBER_KIND;
3370
- slot->value.number = fx_pow((txNumber)(slot->value.integer), (txNumber)(mxStack->value.integer));
3371
- }
3372
- else if (mxStack->kind == XS_NUMBER_KIND) {
3373
- slot->kind = XS_NUMBER_KIND;
3374
- slot->value.number = fx_pow((txNumber)(slot->value.integer), mxStack->value.number);
3375
- }
3376
- else
3377
- goto XS_CODE_EXPONENTIATION_GENERAL;
3378
- }
3379
- else if (slot->kind == XS_NUMBER_KIND) {
3380
- if (mxStack->kind == XS_INTEGER_KIND)
3381
- slot->value.number = fx_pow(slot->value.number, (txNumber)(mxStack->value.integer));
3382
- else if (mxStack->kind == XS_NUMBER_KIND)
3383
- slot->value.number = fx_pow(slot->value.number, mxStack->value.number);
3384
- else
3385
- goto XS_CODE_EXPONENTIATION_GENERAL;
3386
- }
3387
- else {
3388
- XS_CODE_EXPONENTIATION_GENERAL:
3389
- mxSaveState;
3390
- if (fxToNumericNumberBinary(the, slot, mxStack, gxTypeBigInt._exp))
3391
- slot->value.number = fx_pow(slot->value.number, mxStack->value.number);
3392
- mxRestoreState;
3393
- }
3394
- mxFloatingPointOp("exponent");
3395
- mxStack++;
3396
- mxNextCode(1);
3397
- mxBreak;
3398
- mxCase(XS_CODE_MULTIPLY)
3399
- slot = mxStack + 1;
3400
- if (slot->kind == XS_INTEGER_KIND) {
3401
- if (mxStack->kind == XS_INTEGER_KIND) {
3402
- #ifdef mxMinusZero
3403
- if (slot->value.integer == 0) {
3404
- if (mxStack->value.integer < 0) {
3405
- slot->kind = XS_NUMBER_KIND;
3406
- slot->value.number = -0.0;
3407
- }
3408
- }
3409
- else if (mxStack->value.integer == 0) {
3410
- if (slot->value.integer < 0) {
3411
- slot->kind = XS_NUMBER_KIND;
3412
- slot->value.number = -0.0;
3413
- }
3414
- else
3415
- slot->value.integer = 0;
3416
- }
3417
- else {
3418
- #endif
3419
- #if __has_builtin(__builtin_mul_overflow)
3420
- if (__builtin_mul_overflow(slot->value.integer, mxStack->value.integer, &scratch.value.integer)) {
3421
- slot->kind = XS_NUMBER_KIND;
3422
- slot->value.number = (txNumber)(slot->value.integer) * (txNumber)(mxStack->value.integer);
3423
- }
3424
- else
3425
- slot->value.integer = scratch.value.integer;
3426
- #else
3427
- slot->kind = XS_NUMBER_KIND;
3428
- slot->value.number = (txNumber)(slot->value.integer) * (txNumber)(mxStack->value.integer);
3429
- #endif
3430
- #ifdef mxMinusZero
3431
- }
3432
- #endif
3433
- }
3434
- else if (mxStack->kind == XS_NUMBER_KIND) {
3435
- slot->kind = XS_NUMBER_KIND;
3436
- slot->value.number = (txNumber)(slot->value.integer) * mxStack->value.number;
3437
- mxFloatingPointOp("multiply");
3438
- }
3439
- else
3440
- goto XS_CODE_MULTIPLY_GENERAL;
3441
- }
3442
- else if (slot->kind == XS_NUMBER_KIND) {
3443
- if (mxStack->kind == XS_INTEGER_KIND) {
3444
- slot->value.number *= (txNumber)(mxStack->value.integer);
3445
- mxFloatingPointOp("multiply");
3446
- }
3447
- else if (mxStack->kind == XS_NUMBER_KIND) {
3448
- slot->value.number *= mxStack->value.number;
3449
- mxFloatingPointOp("multiply");
3450
- }
3451
- else
3452
- goto XS_CODE_MULTIPLY_GENERAL;
3453
- }
3454
- else {
3455
- XS_CODE_MULTIPLY_GENERAL:
3456
- mxSaveState;
3457
- if (fxToNumericNumberBinary(the, slot, mxStack, gxTypeBigInt._mul))
3458
- slot->value.number *= mxStack->value.number;
3459
- mxRestoreState;
3460
- }
3461
- mxStack++;
3462
- mxNextCode(1);
3463
- mxBreak;
3464
- mxCase(XS_CODE_MODULO)
3465
- slot = mxStack + 1;
3466
- if (slot->kind == XS_INTEGER_KIND) {
3467
- if (mxStack->kind == XS_INTEGER_KIND) {
3468
- if (mxStack->value.integer == 0) {
3469
- slot->kind = XS_NUMBER_KIND;
3470
- slot->value.number = C_NAN;
3471
- }
3472
- #if mxIntegerDivideOverflowException
3473
- else if ((-1 == mxStack->value.integer) && ((txInteger)0x80000000 == slot->value.integer)) {
3474
- slot->kind = XS_NUMBER_KIND;
3475
- slot->value.number = -0.0;
3476
- }
3477
- #endif
3478
- #ifdef mxMinusZero
3479
- else if (slot->value.integer < 0) {
3480
- slot->value.integer %= mxStack->value.integer;
3481
- if (slot->value.integer == 0) {
3482
- slot->kind = XS_NUMBER_KIND;
3483
- slot->value.number = -0.0;
3484
- }
3485
- }
3486
- #endif
3487
- else
3488
- slot->value.integer %= mxStack->value.integer;
3489
- }
3490
- else if (mxStack->kind == XS_NUMBER_KIND) {
3491
- slot->kind = XS_NUMBER_KIND;
3492
- slot->value.number = c_fmod((txNumber)(slot->value.integer), mxStack->value.number);
3493
- mxFloatingPointOp("modulo");
3494
- }
3495
- else
3496
- goto XS_CODE_MODULO_GENERAL;
3497
- }
3498
- else if (slot->kind == XS_NUMBER_KIND) {
3499
- if (mxStack->kind == XS_INTEGER_KIND) {
3500
- slot->value.number = c_fmod(slot->value.number, (txNumber)(mxStack->value.integer));
3501
- mxFloatingPointOp("modulo");
3502
- }
3503
- else if (mxStack->kind == XS_NUMBER_KIND) {
3504
- slot->value.number = c_fmod(slot->value.number, mxStack->value.number);
3505
- mxFloatingPointOp("modulo");
3506
- }
3507
- else
3508
- goto XS_CODE_MODULO_GENERAL;
3509
- }
3510
- else {
3511
- XS_CODE_MODULO_GENERAL:
3512
- mxSaveState;
3513
- if (fxToNumericNumberBinary(the, slot, mxStack, gxTypeBigInt._rem)) {
3514
- slot->value.number = c_fmod(slot->value.number, mxStack->value.number);
3515
- mxFloatingPointOp("modulo");
3516
- }
3517
- mxRestoreState;
3518
- }
3519
- mxStack++;
3520
- mxNextCode(1);
3521
- mxBreak;
3522
-
3523
- mxCase(XS_CODE_NOT)
3524
- mxToBoolean(mxStack);
3525
- mxStack->value.boolean = !mxStack->value.boolean;
3526
- mxNextCode(1);
3527
- mxBreak;
3528
- mxCase(XS_CODE_LESS)
3529
- slot = mxStack + 1;
3530
- if (slot->kind == XS_INTEGER_KIND) {
3531
- if (mxStack->kind == XS_INTEGER_KIND)
3532
- offset = slot->value.integer < mxStack->value.integer;
3533
- else if (mxStack->kind == XS_NUMBER_KIND) {
3534
- offset = (!c_isnan(mxStack->value.number)) && ((txNumber)(slot->value.integer) < mxStack->value.number);
3535
- mxFloatingPointOp("less");
3536
- }
3537
- else
3538
- goto XS_CODE_LESS_GENERAL;
3539
- }
3540
- else if (slot->kind == XS_NUMBER_KIND) {
3541
- if (mxStack->kind == XS_INTEGER_KIND) {
3542
- offset = (!c_isnan(slot->value.number)) && (slot->value.number < (txNumber)(mxStack->value.integer));
3543
- mxFloatingPointOp("less");
3544
- }
3545
- else if (mxStack->kind == XS_NUMBER_KIND) {
3546
- offset = (!c_isnan(slot->value.number)) && (!c_isnan(mxStack->value.number)) && (slot->value.number < mxStack->value.number);
3547
- mxFloatingPointOp("less");
3548
- }
3549
- else
3550
- goto XS_CODE_LESS_GENERAL;
3551
- }
3552
- else {
3553
- XS_CODE_LESS_GENERAL:
3554
- mxSaveState;
3555
- fxToPrimitive(the, slot, XS_NUMBER_HINT);
3556
- fxToPrimitive(the, mxStack, XS_NUMBER_HINT);
3557
- if (((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) && ((mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND)))
3558
- offset = fxUTF8Compare(slot->value.string, mxStack->value.string) < 0;
3559
- else if ((slot->kind == XS_BIGINT_KIND) || (slot->kind == XS_BIGINT_X_KIND))
3560
- offset = gxTypeBigInt.compare(the, 1, 0, 0, slot, mxStack);
3561
- else if ((mxStack->kind == XS_BIGINT_KIND) || (mxStack->kind == XS_BIGINT_X_KIND))
3562
- offset = gxTypeBigInt.compare(the, 0, 0, 1, mxStack, slot);
3563
- else {
3564
- fxToNumber(the, slot);
3565
- fxToNumber(the, mxStack);
3566
- offset = (!c_isnan(slot->value.number)) && (!c_isnan(mxStack->value.number)) && (slot->value.number < mxStack->value.number);
3567
- mxFloatingPointOp("less");
3568
- }
3569
- mxRestoreState;
3570
- }
3571
- slot->kind = XS_BOOLEAN_KIND;
3572
- slot->value.boolean = offset;
3573
- mxStack++;
3574
- mxNextCode(1);
3575
- mxBreak;
3576
- mxCase(XS_CODE_LESS_EQUAL)
3577
- slot = mxStack + 1;
3578
- if (slot->kind == XS_INTEGER_KIND) {
3579
- if (mxStack->kind == XS_INTEGER_KIND)
3580
- offset = slot->value.integer <= mxStack->value.integer;
3581
- else if (mxStack->kind == XS_NUMBER_KIND) {
3582
- offset = (!c_isnan(mxStack->value.number)) && ((txNumber)(slot->value.integer) <= mxStack->value.number);
3583
- mxFloatingPointOp("less or equal");
3584
- }
3585
- else
3586
- goto XS_CODE_LESS_EQUAL_GENERAL;
3587
- }
3588
- else if (slot->kind == XS_NUMBER_KIND) {
3589
- if (mxStack->kind == XS_INTEGER_KIND) {
3590
- offset = (!c_isnan(slot->value.number)) && (slot->value.number <= (txNumber)(mxStack->value.integer));
3591
- mxFloatingPointOp("less or equal");
3592
- }
3593
- else if (mxStack->kind == XS_NUMBER_KIND) {
3594
- offset = (!c_isnan(slot->value.number)) && (!c_isnan(mxStack->value.number)) && (slot->value.number <= mxStack->value.number);
3595
- mxFloatingPointOp("less or equal");
3596
- }
3597
- else
3598
- goto XS_CODE_LESS_EQUAL_GENERAL;
3599
- }
3600
- else {
3601
- XS_CODE_LESS_EQUAL_GENERAL:
3602
- mxSaveState;
3603
- fxToPrimitive(the, slot, XS_NUMBER_HINT);
3604
- fxToPrimitive(the, mxStack, XS_NUMBER_HINT);
3605
- if (((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) && ((mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND)))
3606
- offset = fxUTF8Compare(slot->value.string, mxStack->value.string) <= 0;
3607
- else if ((slot->kind == XS_BIGINT_KIND) || (slot->kind == XS_BIGINT_X_KIND))
3608
- offset = gxTypeBigInt.compare(the, 1, 1, 0, slot, mxStack);
3609
- else if ((mxStack->kind == XS_BIGINT_KIND) || (mxStack->kind == XS_BIGINT_X_KIND))
3610
- offset = gxTypeBigInt.compare(the, 0, 1, 1, mxStack, slot);
3611
- else {
3612
- fxToNumber(the, slot);
3613
- fxToNumber(the, mxStack);
3614
- offset = (!c_isnan(slot->value.number)) && (!c_isnan(mxStack->value.number)) && (slot->value.number <= mxStack->value.number);
3615
- mxFloatingPointOp("less or equal");
3616
- }
3617
- mxRestoreState;
3618
- }
3619
- slot->kind = XS_BOOLEAN_KIND;
3620
- slot->value.boolean = offset;
3621
- mxStack++;
3622
- mxNextCode(1);
3623
- mxBreak;
3624
- mxCase(XS_CODE_MORE)
3625
- slot = mxStack + 1;
3626
- if (slot->kind == XS_INTEGER_KIND) {
3627
- if (mxStack->kind == XS_INTEGER_KIND)
3628
- offset = slot->value.integer > mxStack->value.integer;
3629
- else if (mxStack->kind == XS_NUMBER_KIND) {
3630
- offset = (!c_isnan(mxStack->value.number)) && ((txNumber)(slot->value.integer) > mxStack->value.number);
3631
- mxFloatingPointOp("more");
3632
- }
3633
- else
3634
- goto XS_CODE_MORE_GENERAL;
3635
- }
3636
- else if (slot->kind == XS_NUMBER_KIND) {
3637
- if (mxStack->kind == XS_INTEGER_KIND) {
3638
- offset = (!c_isnan(slot->value.number)) && (slot->value.number > (txNumber)(mxStack->value.integer));
3639
- mxFloatingPointOp("more");
3640
- }
3641
- else if (mxStack->kind == XS_NUMBER_KIND) {
3642
- offset = (!c_isnan(slot->value.number)) && (!c_isnan(mxStack->value.number)) && (slot->value.number > mxStack->value.number);
3643
- mxFloatingPointOp("more");
3644
- }
3645
- else
3646
- goto XS_CODE_MORE_GENERAL;
3647
- }
3648
- else {
3649
- XS_CODE_MORE_GENERAL:
3650
- mxSaveState;
3651
- fxToPrimitive(the, slot, XS_NUMBER_HINT);
3652
- fxToPrimitive(the, mxStack, XS_NUMBER_HINT);
3653
- if (((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) && ((mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND)))
3654
- offset = fxUTF8Compare(slot->value.string, mxStack->value.string) > 0;
3655
- else if ((slot->kind == XS_BIGINT_KIND) || (slot->kind == XS_BIGINT_X_KIND))
3656
- offset = gxTypeBigInt.compare(the, 0, 0, 1, slot, mxStack);
3657
- else if ((mxStack->kind == XS_BIGINT_KIND) || (mxStack->kind == XS_BIGINT_X_KIND))
3658
- offset = gxTypeBigInt.compare(the, 1, 0, 0, mxStack, slot);
3659
- else {
3660
- fxToNumber(the, slot);
3661
- fxToNumber(the, mxStack);
3662
- offset = (!c_isnan(slot->value.number)) && (!c_isnan(mxStack->value.number)) && (slot->value.number > mxStack->value.number);
3663
- mxFloatingPointOp("more");
3664
- }
3665
- mxRestoreState;
3666
- }
3667
- slot->kind = XS_BOOLEAN_KIND;
3668
- slot->value.boolean = offset;
3669
- mxStack++;
3670
- mxNextCode(1);
3671
- mxBreak;
3672
- mxCase(XS_CODE_MORE_EQUAL)
3673
- slot = mxStack + 1;
3674
- if (slot->kind == XS_INTEGER_KIND) {
3675
- if (mxStack->kind == XS_INTEGER_KIND)
3676
- offset = slot->value.integer >= mxStack->value.integer;
3677
- else if (mxStack->kind == XS_NUMBER_KIND) {
3678
- offset = (!c_isnan(mxStack->value.number)) && ((txNumber)(slot->value.integer) >= mxStack->value.number);
3679
- mxFloatingPointOp("more or equal");
3680
- }
3681
- else
3682
- goto XS_CODE_MORE_EQUAL_GENERAL;
3683
- }
3684
- else if (slot->kind == XS_NUMBER_KIND) {
3685
- if (mxStack->kind == XS_INTEGER_KIND) {
3686
- offset = (!c_isnan(slot->value.number)) && (slot->value.number >= (txNumber)(mxStack->value.integer));
3687
- mxFloatingPointOp("more or equal");
3688
- }
3689
- else if (mxStack->kind == XS_NUMBER_KIND) {
3690
- offset = (!c_isnan(slot->value.number)) && (!c_isnan(mxStack->value.number)) && (slot->value.number >= mxStack->value.number);
3691
- mxFloatingPointOp("more or equal");
3692
- }
3693
- else
3694
- goto XS_CODE_MORE_EQUAL_GENERAL;
3695
- }
3696
- else {
3697
- XS_CODE_MORE_EQUAL_GENERAL:
3698
- mxSaveState;
3699
- fxToPrimitive(the, slot, XS_NUMBER_HINT);
3700
- fxToPrimitive(the, mxStack, XS_NUMBER_HINT);
3701
- if (((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) && ((mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND)))
3702
- offset = fxUTF8Compare(slot->value.string, mxStack->value.string) >= 0;
3703
- else if ((slot->kind == XS_BIGINT_KIND) || (slot->kind == XS_BIGINT_X_KIND))
3704
- offset = gxTypeBigInt.compare(the, 0, 1, 1, slot, mxStack);
3705
- else if ((mxStack->kind == XS_BIGINT_KIND) || (mxStack->kind == XS_BIGINT_X_KIND))
3706
- offset = gxTypeBigInt.compare(the, 1, 1, 0, mxStack, slot);
3707
- else {
3708
- fxToNumber(the, slot);
3709
- fxToNumber(the, mxStack);
3710
- offset = (!c_isnan(slot->value.number)) && (!c_isnan(mxStack->value.number)) && (slot->value.number >= mxStack->value.number);
3711
- mxFloatingPointOp("more or equal");
3712
- }
3713
- mxRestoreState;
3714
- }
3715
- slot->kind = XS_BOOLEAN_KIND;
3716
- slot->value.boolean = offset;
3717
- mxStack++;
3718
- mxNextCode(1);
3719
- mxBreak;
3720
-
3721
- mxCase(XS_CODE_EQUAL)
3722
- mxCase(XS_CODE_STRICT_EQUAL)
3723
- slot = mxStack + 1;
3724
- XS_CODE_EQUAL_AGAIN:
3725
- if (slot->kind == mxStack->kind) {
3726
- if ((XS_UNDEFINED_KIND == slot->kind) || (XS_NULL_KIND == slot->kind))
3727
- offset = 1;
3728
- else if (XS_BOOLEAN_KIND == slot->kind)
3729
- offset = slot->value.boolean == stack->value.boolean;
3730
- else if (XS_INTEGER_KIND == slot->kind)
3731
- offset = slot->value.integer == stack->value.integer;
3732
- else if (XS_NUMBER_KIND == slot->kind) {
3733
- offset = (!c_isnan(slot->value.number)) && (!c_isnan(mxStack->value.number)) && (slot->value.number == mxStack->value.number);
3734
- mxFloatingPointOp("equal");
3735
- }
3736
- else if ((XS_STRING_KIND == slot->kind) || (XS_STRING_X_KIND == slot->kind))
3737
- offset = c_strcmp(slot->value.string, mxStack->value.string) == 0;
3738
- else if (XS_SYMBOL_KIND == slot->kind)
3739
- offset = slot->value.symbol == mxStack->value.symbol;
3740
- else if (XS_REFERENCE_KIND == slot->kind)
3741
- offset = fxIsSameReference(the, slot, mxStack);
3742
- #ifdef mxHostFunctionPrimitive
3743
- else if (XS_HOST_FUNCTION_KIND == slot->kind)
3744
- offset = slot->value.hostFunction.builder == mxStack->value.hostFunction.builder;
3745
- #endif
3746
- else if ((XS_BIGINT_KIND == slot->kind) || (XS_BIGINT_X_KIND == slot->kind))
3747
- offset = gxTypeBigInt.compare(the, 0, 1, 0, slot, mxStack);
3748
- else
3749
- offset = 0;
3750
- }
3751
- else if ((XS_INTEGER_KIND == slot->kind) && (XS_NUMBER_KIND == mxStack->kind)) {
3752
- offset = (!c_isnan(mxStack->value.number)) && ((txNumber)(slot->value.integer) == stack->value.number);
3753
- mxFloatingPointOp("equal");
3754
- }
3755
- else if ((XS_NUMBER_KIND == slot->kind) && (XS_INTEGER_KIND == mxStack->kind)) {
3756
- offset = (!c_isnan(slot->value.number)) && (slot->value.number == (txNumber)(mxStack->value.integer));
3757
- mxFloatingPointOp("equal");
3758
- }
3759
- else if ((XS_STRING_KIND == slot->kind) && (XS_STRING_X_KIND == mxStack->kind))
3760
- offset = c_strcmp(slot->value.string, mxStack->value.string) == 0;
3761
- else if ((XS_STRING_X_KIND == slot->kind) && (XS_STRING_KIND == mxStack->kind))
3762
- offset = c_strcmp(slot->value.string, mxStack->value.string) == 0;
3763
- else if (XS_CODE_EQUAL == byte) {
3764
- if ((slot->kind == XS_UNDEFINED_KIND) && (mxStack->kind == XS_NULL_KIND))
3765
- offset = 1;
3766
- else if ((slot->kind == XS_NULL_KIND) && (mxStack->kind == XS_UNDEFINED_KIND))
3767
- offset = 1;
3768
- else if (((XS_INTEGER_KIND == slot->kind) || (XS_NUMBER_KIND == slot->kind)) && ((mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND))) {
3769
- mxToNumber(mxStack);
3770
- goto XS_CODE_EQUAL_AGAIN;
3771
- }
3772
- else if (((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) && ((XS_INTEGER_KIND == mxStack->kind) || (XS_NUMBER_KIND == mxStack->kind))) {
3773
- mxToNumber(slot);
3774
- goto XS_CODE_EQUAL_AGAIN;
3775
- }
3776
- else if (XS_BOOLEAN_KIND == slot->kind) {
3777
- mxToNumber(slot);
3778
- goto XS_CODE_EQUAL_AGAIN;
3779
- }
3780
- else if (XS_BOOLEAN_KIND == mxStack->kind) {
3781
- mxToNumber(mxStack);
3782
- goto XS_CODE_EQUAL_AGAIN;
3783
- }
3784
- else if (((slot->kind == XS_INTEGER_KIND) || (slot->kind == XS_NUMBER_KIND) || (slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND) || (slot->kind == XS_SYMBOL_KIND) || (slot->kind == XS_BIGINT_KIND) || (slot->kind == XS_BIGINT_X_KIND)) && mxIsReference(mxStack)) {
3785
- mxSaveState;
3786
- fxToPrimitive(the, mxStack, XS_NO_HINT);
3787
- mxRestoreState;
3788
- goto XS_CODE_EQUAL_AGAIN;
3789
- }
3790
- else if (mxIsReference(slot) && ((mxStack->kind == XS_INTEGER_KIND) || (mxStack->kind == XS_NUMBER_KIND) || (mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND) || (mxStack->kind == XS_SYMBOL_KIND) || (mxStack->kind == XS_BIGINT_KIND) || (mxStack->kind == XS_BIGINT_X_KIND))) {
3791
- mxSaveState;
3792
- fxToPrimitive(the, slot, XS_NO_HINT);
3793
- mxRestoreState;
3794
- goto XS_CODE_EQUAL_AGAIN;
3795
- }
3796
- else if (((XS_BIGINT_KIND == slot->kind) || (XS_BIGINT_X_KIND == slot->kind)) && ((mxStack->kind == XS_INTEGER_KIND) || (mxStack->kind == XS_NUMBER_KIND) || (mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND))) {
3797
- mxSaveState;
3798
- offset = gxTypeBigInt.compare(the, 0, 1, 0, slot, mxStack);
3799
- mxRestoreState;
3800
- }
3801
- else if (((slot->kind == XS_INTEGER_KIND) || (slot->kind == XS_NUMBER_KIND) || (slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) && ((XS_BIGINT_KIND == mxStack->kind) || (XS_BIGINT_X_KIND == mxStack->kind))) {
3802
- mxSaveState;
3803
- offset = gxTypeBigInt.compare(the, 0, 1, 0, mxStack, slot);
3804
- mxRestoreState;
3805
- }
3806
- else
3807
- offset = 0;
3808
- }
3809
- else
3810
- offset = 0;
3811
- slot->kind = XS_BOOLEAN_KIND;
3812
- slot->value.boolean = offset;
3813
- mxStack++;
3814
- mxNextCode(1);
3815
- mxBreak;
3816
- mxCase(XS_CODE_NOT_EQUAL)
3817
- mxCase(XS_CODE_STRICT_NOT_EQUAL)
3818
- slot = mxStack + 1;
3819
- XS_CODE_NOT_EQUAL_AGAIN:
3820
- if (slot->kind == mxStack->kind) {
3821
- if ((XS_UNDEFINED_KIND == slot->kind) || (XS_NULL_KIND == slot->kind))
3822
- offset = 0;
3823
- else if (XS_BOOLEAN_KIND == slot->kind)
3824
- offset = slot->value.boolean != stack->value.boolean;
3825
- else if (XS_INTEGER_KIND == slot->kind)
3826
- offset = slot->value.integer != stack->value.integer;
3827
- else if (XS_NUMBER_KIND == slot->kind) {
3828
- offset = (c_isnan(slot->value.number)) || (c_isnan(mxStack->value.number)) || (slot->value.number != mxStack->value.number);
3829
- mxFloatingPointOp("not equal");
3830
- }
3831
- else if ((XS_STRING_KIND == slot->kind) || (XS_STRING_X_KIND == slot->kind))
3832
- offset = c_strcmp(slot->value.string, mxStack->value.string) != 0;
3833
- else if (XS_SYMBOL_KIND == slot->kind)
3834
- offset = slot->value.symbol != mxStack->value.symbol;
3835
- else if (XS_REFERENCE_KIND == slot->kind)
3836
- offset = !fxIsSameReference(the, slot, mxStack);
3837
- #ifdef mxHostFunctionPrimitive
3838
- else if (XS_HOST_FUNCTION_KIND == slot->kind)
3839
- offset = slot->value.hostFunction.builder != mxStack->value.hostFunction.builder;
3840
- #endif
3841
- else if ((XS_BIGINT_KIND == slot->kind) || (XS_BIGINT_X_KIND == slot->kind))
3842
- offset = gxTypeBigInt.compare(the, 1, 0, 1, slot, mxStack);
3843
- else
3844
- offset = 1;
3845
- }
3846
- else if ((XS_INTEGER_KIND == slot->kind) && (XS_NUMBER_KIND == mxStack->kind)) {
3847
- offset = (c_isnan(mxStack->value.number)) || ((txNumber)(slot->value.integer) != stack->value.number);
3848
- mxFloatingPointOp("not equal");
3849
- }
3850
- else if ((XS_NUMBER_KIND == slot->kind) && (XS_INTEGER_KIND == mxStack->kind)) {
3851
- offset = (c_isnan(slot->value.number)) || (slot->value.number != (txNumber)(mxStack->value.integer));
3852
- mxFloatingPointOp("not equal");
3853
- }
3854
- else if ((XS_STRING_KIND == slot->kind) && (XS_STRING_X_KIND == mxStack->kind))
3855
- offset = c_strcmp(slot->value.string, mxStack->value.string) != 0;
3856
- else if ((XS_STRING_X_KIND == slot->kind) && (XS_STRING_KIND == mxStack->kind))
3857
- offset = c_strcmp(slot->value.string, mxStack->value.string) != 0;
3858
- else if (XS_CODE_NOT_EQUAL == byte) {
3859
- if ((slot->kind == XS_UNDEFINED_KIND) && (mxStack->kind == XS_NULL_KIND))
3860
- offset = 0;
3861
- else if ((slot->kind == XS_NULL_KIND) && (mxStack->kind == XS_UNDEFINED_KIND))
3862
- offset = 0;
3863
- else if (((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) && ((XS_INTEGER_KIND == mxStack->kind) || (XS_NUMBER_KIND == mxStack->kind))) {
3864
- mxToNumber(slot);
3865
- goto XS_CODE_NOT_EQUAL_AGAIN;
3866
- }
3867
- else if (((mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND)) && ((XS_INTEGER_KIND == slot->kind) || (XS_NUMBER_KIND == slot->kind))) {
3868
- mxToNumber(mxStack);
3869
- goto XS_CODE_NOT_EQUAL_AGAIN;
3870
- }
3871
- else if (XS_BOOLEAN_KIND == slot->kind) {
3872
- mxToNumber(slot);
3873
- goto XS_CODE_NOT_EQUAL_AGAIN;
3874
- }
3875
- else if (XS_BOOLEAN_KIND == mxStack->kind) {
3876
- mxToNumber(mxStack);
3877
- goto XS_CODE_NOT_EQUAL_AGAIN;
3878
- }
3879
- else if (((slot->kind == XS_INTEGER_KIND) || (slot->kind == XS_NUMBER_KIND) || (slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND) || (slot->kind == XS_SYMBOL_KIND) || (slot->kind == XS_BIGINT_KIND) || (slot->kind == XS_BIGINT_X_KIND)) && mxIsReference(mxStack)) {
3880
- mxSaveState;
3881
- fxToPrimitive(the, mxStack, XS_NO_HINT);
3882
- mxRestoreState;
3883
- goto XS_CODE_NOT_EQUAL_AGAIN;
3884
- }
3885
- else if (mxIsReference(slot) && ((mxStack->kind == XS_INTEGER_KIND) || (mxStack->kind == XS_NUMBER_KIND) || (mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND) || (mxStack->kind == XS_SYMBOL_KIND) || (mxStack->kind == XS_BIGINT_KIND) || (mxStack->kind == XS_BIGINT_X_KIND))) {
3886
- mxSaveState;
3887
- fxToPrimitive(the, slot, XS_NO_HINT);
3888
- mxRestoreState;
3889
- goto XS_CODE_NOT_EQUAL_AGAIN;
3890
- }
3891
- else if (((XS_BIGINT_KIND == slot->kind) || (XS_BIGINT_X_KIND == slot->kind)) && ((mxStack->kind == XS_INTEGER_KIND) || (mxStack->kind == XS_NUMBER_KIND) || (mxStack->kind == XS_STRING_KIND) || (mxStack->kind == XS_STRING_X_KIND))) {
3892
- mxSaveState;
3893
- offset = gxTypeBigInt.compare(the, 1, 0, 1, slot, mxStack);
3894
- mxRestoreState;
3895
- }
3896
- else if (((slot->kind == XS_INTEGER_KIND) || (slot->kind == XS_NUMBER_KIND) || (slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) && ((XS_BIGINT_KIND == mxStack->kind) || (XS_BIGINT_X_KIND == mxStack->kind))) {
3897
- mxSaveState;
3898
- offset = gxTypeBigInt.compare(the, 1, 0, 1, mxStack, slot);
3899
- mxRestoreState;
3900
- }
3901
- else
3902
- offset = 1;
3903
- }
3904
- else
3905
- offset = 1;
3906
- slot->kind = XS_BOOLEAN_KIND;
3907
- slot->value.boolean = offset;
3908
- mxStack++;
3909
- mxNextCode(1);
3910
- mxBreak;
3911
-
3912
- mxCase(XS_CODE_FOR_AWAIT_OF)
3913
- mxNextCode(1);
3914
- mxSaveState;
3915
- gxDefaults.runForAwaitOf(the);
3916
- mxRestoreState;
3917
- mxBreak;
3918
- mxCase(XS_CODE_FOR_IN)
3919
- mxSkipCode(1);
3920
- /* FUNCTION */
3921
- mxAllocStack(1);
3922
- *mxStack = mxEnumeratorFunction;
3923
- slot = fxGetInstance(the, mxStack);
3924
- /* TARGET */
3925
- mxPushKind(XS_UNDEFINED_KIND);
3926
- /* RESULT */
3927
- mxPushKind(XS_UNDEFINED_KIND);
3928
- mxPushKind(XS_UNDEFINED_KIND);
3929
- mxPushKind(XS_UNDEFINED_KIND);
3930
- offset = 0;
3931
- goto XS_CODE_RUN_ALL;
3932
-
3933
- mxCase(XS_CODE_FOR_OF)
3934
- mxNextCode(1);
3935
- mxSaveState;
3936
- fxRunForOf(the);
3937
- mxRestoreState;
3938
- mxBreak;
3939
-
3940
- mxCase(XS_CODE_IN)
3941
- mxNextCode(1);
3942
- if (!mxIsReference(mxStack))
3943
- mxRunDebug(XS_TYPE_ERROR, "in: no reference");
3944
- mxSaveState;
3945
- fxRunIn(the);
3946
- mxRestoreState;
3947
- mxBreak;
3948
- mxCase(XS_CODE_INSTANCEOF)
3949
- mxNextCode(1);
3950
- mxSaveState;
3951
- fxRunInstanceOf(the);
3952
- mxRestoreState;
3953
- mxBreak;
3954
- mxCase(XS_CODE_TYPEOF)
3955
- byte = mxStack->kind;
3956
- if (XS_UNDEFINED_KIND == byte)
3957
- *mxStack = mxUndefinedString;
3958
- else if (XS_NULL_KIND == byte)
3959
- *mxStack = mxObjectString;
3960
- else if (XS_BOOLEAN_KIND == byte)
3961
- *mxStack = mxBooleanString;
3962
- else if ((XS_INTEGER_KIND == byte) || (XS_NUMBER_KIND == byte))
3963
- *mxStack = mxNumberString;
3964
- else if ((XS_STRING_KIND == byte) || (XS_STRING_X_KIND == byte))
3965
- *mxStack = mxStringString;
3966
- else if (XS_SYMBOL_KIND == byte)
3967
- *mxStack = mxSymbolString;
3968
- else if ((XS_BIGINT_KIND == byte) || (XS_BIGINT_X_KIND == byte))
3969
- *mxStack = mxBigIntString;
3970
- else if (XS_REFERENCE_KIND == byte) {
3971
- slot = fxGetInstance(the, mxStack);
3972
- if (slot->flag & XS_CAN_CALL_FLAG)
3973
- *mxStack = mxFunctionString;
3974
- else
3975
- *mxStack = mxObjectString;
3976
- }
3977
- #ifdef mxHostFunctionPrimitive
3978
- else if (slot->kind == XS_HOST_FUNCTION_KIND)
3979
- *mxStack = mxFunctionString;
3980
- #endif
3981
- mxNextCode(1);
3982
- mxBreak;
3983
- mxCase(XS_CODE_VOID)
3984
- mxNextCode(1);
3985
- mxStack->kind = XS_UNDEFINED_KIND;
3986
- mxBreak;
3987
-
3988
- /* DEBUG */
3989
- mxCase(XS_CODE_DEBUGGER)
3990
- mxNextCode(1);
3991
- #ifdef mxDebug
3992
- mxSaveState;
3993
- fxDebugLoop(the, C_NULL, 0, "debugger");
3994
- mxRestoreState;
3995
- #endif
3996
- mxBreak;
3997
- mxCase(XS_CODE_FILE)
3998
- #ifdef mxDebug
3999
- count = mxRunID(1);
4000
- #ifdef mxTrace
4001
- if (gxDoTrace) fxTraceID(the, count, 0);
4002
- #endif
4003
- mxEnvironment->ID = count;
4004
- #endif
4005
- mxNextCode(1 + sizeof(txID));
4006
- mxBreak;
4007
- mxCase(XS_CODE_LINE)
4008
- #ifdef mxDebug
4009
- count = mxRunS2(1);
4010
- #ifdef mxTrace
4011
- if (gxDoTrace) fxTraceInteger(the, count);
4012
- #endif
4013
- mxEnvironment->value.environment.line = count;
4014
- if (fxIsReadable(the)) {
4015
- mxSaveState;
4016
- fxDebugCommand(the);
4017
- mxRestoreState;
4018
- }
4019
- if ((mxEnvironment->ID != XS_NO_ID) && ((mxFrame->flag & XS_STEP_OVER_FLAG) || mxBreakpoints.value.list.first)) {
4020
- mxSaveState;
4021
- fxDebugLine(the, mxEnvironment->ID, count);
4022
- mxRestoreState;
4023
- }
4024
- #endif
4025
- #if defined(mxInstrument) || defined(mxProfile)
4026
- fxCheckProfiler(the, mxFrame);
4027
- #endif
4028
- mxNextCode(3);
4029
- mxBreak;
4030
-
4031
- /* MODULE */
4032
- mxCase(XS_CODE_IMPORT)
4033
- slot = mxFunctionInstanceHome(mxFrameFunction->value.reference)->value.home.module;
4034
- slot = mxModuleInstanceInternal(slot);
4035
- variable = slot->value.module.realm;
4036
- if (!variable) variable = mxModuleInstanceInternal(mxProgram.value.reference)->value.module.realm;
4037
- mxSaveState;
4038
- gxDefaults.runImport(the, variable, slot->value.module.id);
4039
- mxRestoreState;
4040
- mxNextCode(1);
4041
- mxBreak;
4042
- mxCase(XS_CODE_IMPORT_META)
4043
- variable = mxFunctionInstanceHome(mxFrameFunction->value.reference);
4044
- slot = mxModuleInstanceMeta(variable->value.home.module);
4045
- mxPushKind(XS_REFERENCE_KIND);
4046
- mxStack->value.reference = slot->value.reference;
4047
- mxNextCode(1);
4048
- mxBreak;
4049
- mxCase(XS_CODE_TRANSFER)
4050
- mxSaveState;
4051
- fxPrepareTransfer(the);
4052
- mxRestoreState;
4053
- mxNextCode(1);
4054
- mxBreak;
4055
- mxCase(XS_CODE_MODULE)
4056
- byte = mxRunU1(1);
4057
- mxSaveState;
4058
- fxPrepareModule(the, byte);
4059
- mxRestoreState;
4060
- mxNextCode(2);
4061
- mxBreak;
4062
-
4063
- /* EVAL, PROGRAM & WITH */
4064
- mxCase(XS_CODE_EVAL)
4065
- offset = mxStack->value.integer;
4066
- slot = mxStack + 1 + offset + 4;
4067
- if (slot->value.reference == mxEvalFunction.value.reference) {
4068
- mxSaveState;
4069
- gxDefaults.runEval(the);
4070
- mxRestoreState;
4071
- mxNextCode(1);
4072
- mxBreak;
4073
- }
4074
- mxSkipCode(1);
4075
- mxStack++;
4076
- goto XS_CODE_RUN_ALL;
4077
- mxCase(XS_CODE_EVAL_TAIL)
4078
- offset = mxStack->value.integer;
4079
- slot = mxStack + 1 + offset + 4;
4080
- if (slot->value.reference == mxEvalFunction.value.reference) {
4081
- mxSaveState;
4082
- gxDefaults.runEval(the);
4083
- mxRestoreState;
4084
- mxNextCode(1);
4085
- mxBreak;
4086
- }
4087
- mxSkipCode(1);
4088
- mxStack++;
4089
- goto XS_CODE_RUN_TAIL_ALL;
4090
- mxCase(XS_CODE_EVAL_ENVIRONMENT)
4091
- mxNextCode(1);
4092
- mxSaveState;
4093
- gxDefaults.runEvalEnvironment(the);
4094
- mxRestoreState;
4095
- mxBreak;
4096
- mxCase(XS_CODE_EVAL_PRIVATE)
4097
- offset = mxRunID(1);
4098
- #ifdef mxTrace
4099
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
4100
- #endif
4101
- mxNextCode(1 + sizeof(txID));
4102
- variable = mxEnvironment;
4103
- if (variable->kind == XS_REFERENCE_KIND) {
4104
- variable = variable->value.reference;
4105
- XS_CODE_EVAL_PRIVATE_AGAIN:
4106
- if (variable) {
4107
- slot = mxBehaviorGetProperty(the, variable, (txID)offset, 0, XS_OWN);
4108
- if (slot) {
4109
- mxPushKind(slot->kind);
4110
- mxStack->value = slot->value;
4111
- mxBreak;
4112
- }
4113
- variable = variable->value.instance.prototype;
4114
- goto XS_CODE_EVAL_PRIVATE_AGAIN;
4115
- }
4116
- }
4117
- mxRunDebugID(XS_SYNTAX_ERROR, "eval %s: undefined private property", (txID)offset);
4118
- mxBreak;
4119
- mxCase(XS_CODE_EVAL_REFERENCE)
4120
- offset = mxRunID(1);
4121
- #ifdef mxTrace
4122
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
4123
- #endif
4124
- mxNextCode(1 + sizeof(txID));
4125
- variable = mxEnvironment;
4126
- if (variable->kind == XS_REFERENCE_KIND) {
4127
- variable = variable->value.reference;
4128
- XS_CODE_EVAL_REFERENCE_AGAIN:
4129
- if (variable->value.instance.prototype) {
4130
- slot = variable->next;
4131
- if (slot->kind == XS_REFERENCE_KIND) {
4132
- slot = slot->value.reference;
4133
- mxSaveState;
4134
- index = fxIsScopableSlot(the, slot, (txID)offset);
4135
- mxRestoreState;
4136
- if (index) {
4137
- if (XS_CODE_GET_THIS_VARIABLE == byte) {
4138
- mxStack->kind = XS_REFERENCE_KIND;
4139
- mxStack->value.reference = slot;
4140
- }
4141
- mxPushKind(XS_REFERENCE_KIND);
4142
- mxStack->value.reference = slot;
4143
- mxBreak;
4144
- }
4145
- }
4146
- else if (mxBehaviorHasProperty(the, variable, (txID)offset, 0)) {
4147
- mxPushKind(XS_REFERENCE_KIND);
4148
- mxStack->value.reference = variable;
4149
- mxBreak;
4150
- }
4151
- variable = variable->value.instance.prototype;
4152
- goto XS_CODE_EVAL_REFERENCE_AGAIN;
4153
- }
4154
- if (mxBehaviorHasProperty(the, variable, (txID)offset, 0)) {
4155
- mxPushKind(XS_REFERENCE_KIND);
4156
- mxStack->value.reference = variable;
4157
- mxBreak;
4158
- }
4159
- }
4160
- mxPushKind(XS_REFERENCE_KIND);
4161
- variable = mxFunctionInstanceHome(mxFrameFunction->value.reference)->value.home.module;
4162
- variable = mxModuleInstanceInternal(variable)->value.module.realm;
4163
- if (!variable) variable = mxModuleInstanceInternal(mxProgram.value.reference)->value.module.realm;
4164
- mxStack->value.reference = mxRealmGlobal(variable)->value.reference;
4165
- mxBreak;
4166
- mxCase(XS_CODE_FUNCTION_ENVIRONMENT)
4167
- variable = mxEnvironment;
4168
- mxPushKind(XS_UNDEFINED_KIND);
4169
- mxSaveState;
4170
- slot = fxNewEnvironmentInstance(the, variable);
4171
- mxRestoreState;
4172
- variable = mxFunctionInstanceCode((mxStack + 1)->value.reference);
4173
- variable->value.code.closures = slot;
4174
- mxNextCode(1);
4175
- mxBreak;
4176
- mxCase(XS_CODE_PROGRAM_ENVIRONMENT)
4177
- mxNextCode(1);
4178
- mxSaveState;
4179
- gxDefaults.runProgramEnvironment(the);
4180
- mxRestoreState;
4181
- mxBreak;
4182
- mxCase(XS_CODE_PROGRAM_REFERENCE)
4183
- offset = mxRunID(1);
4184
- #ifdef mxTrace
4185
- if (gxDoTrace) fxTraceID(the, (txID)offset, 0);
4186
- #endif
4187
- mxNextCode(1 + sizeof(txID));
4188
- variable = mxFunctionInstanceHome(mxFrameFunction->value.reference)->value.home.module;
4189
- variable = mxModuleInstanceInternal(variable)->value.module.realm;
4190
- if (!variable) variable = mxModuleInstanceInternal(mxProgram.value.reference)->value.module.realm;
4191
- slot = mxRealmClosures(variable)->value.reference;
4192
- if (mxBehaviorHasProperty(the, slot, (txID)offset, 0)) {
4193
- mxPushKind(XS_REFERENCE_KIND);
4194
- mxStack->value.reference = slot;
4195
- mxBreak;
4196
- }
4197
- mxPushKind(XS_REFERENCE_KIND);
4198
- mxStack->value.reference = mxRealmGlobal(variable)->value.reference;
4199
- mxBreak;
4200
- mxCase(XS_CODE_WITH)
4201
- variable = mxEnvironment;
4202
- mxSaveState;
4203
- slot = fxNewEnvironmentInstance(the, variable);
4204
- mxRestoreState;
4205
- variable->kind = XS_REFERENCE_KIND;
4206
- variable->value.reference = slot;
4207
- mxNextCode(1);
4208
- mxBreak;
4209
- mxCase(XS_CODE_WITHOUT)
4210
- variable = mxEnvironment;
4211
- slot = variable->value.reference->value.instance.prototype;
4212
- if (slot) {
4213
- variable->kind = XS_REFERENCE_KIND;
4214
- variable->value.reference = slot;
4215
- }
4216
- else
4217
- variable->kind = XS_NULL_KIND;
4218
- mxNextCode(1);
4219
- mxBreak;
4220
- }
4221
- }
4222
- }
4223
-
4224
- #ifdef mxMetering
4225
-
4226
- void fxBeginMetering(txMachine* the, txBoolean (*callback)(txMachine*, txU4), txU4 interval)
4227
- {
4228
- the->meterCallback = callback;
4229
- the->meterCount = interval;
4230
- the->meterIndex = 0;
4231
- the->meterInterval = interval;
4232
- }
4233
-
4234
- void fxEndMetering(txMachine* the)
4235
- {
4236
- the->meterCallback = C_NULL;
4237
- the->meterIndex = 0;
4238
- the->meterInterval = 0;
4239
- the->meterCount = 0;
4240
- }
4241
-
4242
- void fxCheckMetering(txMachine* the)
4243
- {
4244
- txU4 interval = the->meterInterval;
4245
- the->meterInterval = 0;
4246
- if ((*the->meterCallback)(the, the->meterIndex)) {
4247
- the->meterCount = the->meterIndex + interval;
4248
- if (the->meterCount < the->meterIndex) {
4249
- the->meterIndex = 0;
4250
- the->meterCount = interval;
4251
- }
4252
- the->meterInterval = interval;
4253
- }
4254
- else {
4255
- fxAbort(the, XS_TOO_MUCH_COMPUTATION_EXIT);
4256
- }
4257
- }
4258
- #endif
4259
-
4260
- void fxRunArguments(txMachine* the, txIndex offset)
4261
- {
4262
- txSlot* array;
4263
- txIndex length = (txIndex)mxArgc;
4264
- txIndex index;
4265
- txSlot* address;
4266
- mxPush(mxArrayPrototype);
4267
- array = fxNewArrayInstance(the)->next;
4268
- if (offset < length) {
4269
- length -= offset;
4270
- fxSetIndexSize(the, array, length, XS_CHUNK);
4271
- index = 0;
4272
- address = array->value.array.address;
4273
- while (index < length) {
4274
- txSlot* property = mxArgv(offset + index);
4275
- *((txIndex*)address) = index;
4276
- address->ID = XS_NO_ID;
4277
- address->kind = property->kind;
4278
- address->value = property->value;
4279
- index++;
4280
- address++;
4281
- }
4282
- }
4283
- }
4284
-
4285
- void fxRunBase(txMachine* the)
4286
- {
4287
- if (mxIsUndefined(mxTarget))
4288
- mxTypeError("call: class");
4289
- fxRunConstructor(the);
4290
- }
4291
-
4292
- void fxRunConstructor(txMachine* the)
4293
- {
4294
- txSlot* target;
4295
- txSlot* prototype;
4296
- target = mxTarget;
4297
- mxPushUndefined();
4298
- prototype = the->stack;
4299
- fxBeginHost(the);
4300
- mxPushSlot(target);
4301
- fxGetPrototypeFromConstructor(the, &mxObjectPrototype);
4302
- *prototype = *the->stack;
4303
- fxEndHost(the);
4304
- fxNewHostInstance(the);
4305
- mxPullSlot(mxThis);
4306
- }
4307
-
4308
- txBoolean fxRunDefine(txMachine* the, txSlot* instance, txSlot* check, txID id, txIndex index, txSlot* slot, txFlag mask)
4309
- {
4310
- txBoolean result;
4311
- if (check) {
4312
- result = gxDefaults.definePrivateProperty(the, instance, check, id, slot, mask);
4313
- }
4314
- else {
4315
- fxBeginHost(the);
4316
- mxCheck(the, instance->kind == XS_INSTANCE_KIND);
4317
- result = mxBehaviorDefineOwnProperty(the, instance, id, index, slot, mask);
4318
- fxEndHost(the);
4319
- }
4320
- return result;
4321
- }
4322
-
4323
-
4324
- txBoolean fxRunDelete(txMachine* the, txSlot* instance, txID id, txIndex index)
4325
- {
4326
- txBoolean result;
4327
- fxBeginHost(the);
4328
- mxCheck(the, instance->kind == XS_INSTANCE_KIND);
4329
- result = mxBehaviorDeleteProperty(the, instance, id, index);
4330
- fxEndHost(the);
4331
- return result;
4332
- }
4333
-
4334
- void fxRunDerived(txMachine* the)
4335
- {
4336
- txSlot* slot;
4337
- if (mxIsUndefined(mxTarget))
4338
- mxTypeError("call: class");
4339
- slot = fxNewSlot(the);
4340
- slot->kind = XS_UNINITIALIZED_KIND;
4341
- mxPushClosure(slot);
4342
- mxPullSlot(mxThis);
4343
- }
4344
-
4345
- void fxRunExtends(txMachine* the)
4346
- {
4347
- txSlot* constructor;
4348
- txSlot* prototype;
4349
-
4350
- constructor = fxGetInstance(the, the->stack);
4351
- if (!mxIsConstructor(constructor))
4352
- mxTypeError("extends: no constructor");
4353
- mxPushUndefined();
4354
- prototype = the->stack;
4355
- fxBeginHost(the);
4356
- mxPushReference(constructor);
4357
- mxGetID(mxID(_prototype));
4358
- *prototype = *the->stack;
4359
- fxEndHost(the);
4360
- if (the->stack->kind == XS_NULL_KIND) {
4361
- mxPop();
4362
- fxNewInstance(the);
4363
- }
4364
- else if (the->stack->kind == XS_REFERENCE_KIND) {
4365
- if (the->stack->value.reference->value.instance.prototype == mxGeneratorPrototype.value.reference)
4366
- mxTypeError("extends: generator");
4367
- fxNewHostInstance(the);
4368
- }
4369
- else
4370
- mxTypeError("extends: no prototype");
4371
- }
4372
-
4373
- void fxRunEval(txMachine* the)
4374
- {
4375
- txStringStream aStream;
4376
- txUnsigned flags;
4377
- txSlot* function;
4378
- txSlot* home;
4379
- txSlot* closures;
4380
- if (the->stack->value.integer == 0)
4381
- the->stack->kind = XS_UNDEFINED_KIND;
4382
- else
4383
- the->stack += the->stack->value.integer;
4384
- the->stack[6] = the->stack[0];
4385
- the->stack += 6;
4386
- if ((the->stack->kind == XS_STRING_KIND) || (the->stack->kind == XS_STRING_X_KIND)) {
4387
- aStream.slot = the->stack;
4388
- aStream.offset = 0;
4389
- aStream.size = mxStringLength(fxToString(the, aStream.slot));
4390
- flags = mxProgramFlag | mxEvalFlag;
4391
- if (the->frame->flag & XS_STRICT_FLAG)
4392
- flags |= mxStrictFlag;
4393
- if (the->frame->flag & XS_FIELD_FLAG)
4394
- flags |= mxFieldFlag;
4395
- function = mxFunction->value.reference;
4396
- if (function->flag & XS_CAN_CONSTRUCT_FLAG)
4397
- flags |= mxTargetFlag;
4398
- home = mxFunctionInstanceHome(function);
4399
- if (home->value.home.object)
4400
- flags |= mxSuperFlag;
4401
- closures = mxFrameToEnvironment(the->frame);
4402
- if (closures->kind == XS_REFERENCE_KIND)
4403
- closures = closures->value.reference;
4404
- else
4405
- closures = C_NULL;
4406
- fxRunScript(the, fxParseScript(the, &aStream, fxStringGetter, flags), mxThis, mxTarget, closures, home->value.home.object, home->value.home.module);
4407
- aStream.slot->kind = the->stack->kind;
4408
- aStream.slot->value = the->stack->value;
4409
- mxPop();
4410
- }
4411
- }
4412
-
4413
- void fxRunForAwaitOf(txMachine* the)
4414
- {
4415
- txSlot* slot = the->stack;
4416
- fxBeginHost(the);
4417
- mxPushSlot(slot);
4418
- mxDub();
4419
- mxGetID(mxID(_Symbol_asyncIterator));
4420
- if (mxIsUndefined(the->stack) || mxIsNull(the->stack)) {
4421
- mxPop();
4422
- mxPop();
4423
- fxGetIterator(the, slot, the->stack, C_NULL, 0);
4424
- fxNewAsyncFromSyncIteratorInstance(the);
4425
- }
4426
- else {
4427
- mxCall();
4428
- mxRunCount(0);
4429
- }
4430
- mxPullSlot(slot);
4431
- fxEndHost(the);
4432
- }
4433
-
4434
- void fxRunForOf(txMachine* the)
4435
- {
4436
- txSlot* slot = the->stack;
4437
- fxBeginHost(the);
4438
- fxGetIterator(the, slot, slot, C_NULL, 0);
4439
- fxEndHost(the);
4440
- }
4441
-
4442
- txBoolean fxRunHas(txMachine* the, txSlot* instance, txID id, txIndex index)
4443
- {
4444
- txBoolean result;
4445
- fxBeginHost(the);
4446
- result = mxBehaviorHasProperty(the, instance, id, index);
4447
- fxEndHost(the);
4448
- return result;
4449
- }
4450
-
4451
- void fxRunIn(txMachine* the)
4452
- {
4453
- txSlot* left = the->stack + 1;
4454
- txSlot* right = the->stack;
4455
- fxBeginHost(the);
4456
- mxPushSlot(right);
4457
- mxPushSlot(left);
4458
- left->value.boolean = fxHasAt(the);
4459
- left->kind = XS_BOOLEAN_KIND;
4460
- fxEndHost(the);
4461
- mxPop();
4462
- }
4463
-
4464
- void fxRunInstanceOf(txMachine* the)
4465
- {
4466
- txSlot* left = the->stack + 1;
4467
- txSlot* right = the->stack;
4468
- fxBeginHost(the);
4469
- mxPushSlot(right);
4470
- mxDub();
4471
- mxGetID(mxID(_Symbol_hasInstance));
4472
- mxCall();
4473
- mxPushSlot(left);
4474
- mxRunCount(1);
4475
- fxToBoolean(the, the->stack);
4476
- mxPullSlot(left);
4477
- fxEndHost(the);
4478
- mxPop();
4479
- }
4480
-
4481
- void fxRunInstantiate(txMachine* the)
4482
- {
4483
- if (the->stack->kind == XS_NULL_KIND) {
4484
- mxPop();
4485
- fxNewInstance(the);
4486
- }
4487
- else if (the->stack->kind == XS_REFERENCE_KIND) {
4488
- fxNewHostInstance(the);
4489
- }
4490
- else {
4491
- mxPop();
4492
- mxPush(mxObjectPrototype);
4493
- fxNewObjectInstance(the);
4494
- }
4495
- }
4496
-
4497
- void fxRunProxy(txMachine* the, txSlot* instance)
4498
- {
4499
- txSlot* array;
4500
- txIndex length = (txIndex)mxArgc;
4501
- txIndex index;
4502
- txSlot* address;
4503
- mxPush(mxArrayPrototype);
4504
- array = fxNewArrayInstance(the)->next;
4505
- fxSetIndexSize(the, array, length, XS_CHUNK);
4506
- index = 0;
4507
- address = array->value.array.address;
4508
- while (index < length) {
4509
- txSlot* property = mxArgv(index);
4510
- *((txIndex*)address) = index;
4511
- address->ID = XS_NO_ID;
4512
- address->kind = property->kind;
4513
- address->value = property->value;
4514
- index++;
4515
- address++;
4516
- }
4517
- if (mxTarget->kind == XS_UNDEFINED_KIND)
4518
- mxBehaviorCall(the, instance, mxThis, the->stack);
4519
- else if (instance->flag & XS_CAN_CONSTRUCT_FLAG)
4520
- mxBehaviorConstruct(the, instance, the->stack, mxTarget);
4521
- else
4522
- mxTypeError("no constructor");
4523
- mxPop();
4524
- }
4525
-
4526
- txBoolean fxIsSameReference(txMachine* the, txSlot* a, txSlot* b)
4527
- {
4528
- a = a->value.reference;
4529
- b = b->value.reference;
4530
- if (a == b)
4531
- return 1;
4532
- if (a->ID) {
4533
- txSlot* alias = the->aliasArray[a->ID];
4534
- if (alias) {
4535
- a = alias;
4536
- if (a == b)
4537
- return 1;
4538
- }
4539
- }
4540
- if (b->ID) {
4541
- txSlot* alias = the->aliasArray[b->ID];
4542
- if (alias) {
4543
- b = alias;
4544
- if (a == b)
4545
- return 1;
4546
- }
4547
- }
4548
- return 0;
4549
- }
4550
-
4551
- txBoolean fxIsSameSlot(txMachine* the, txSlot* a, txSlot* b)
4552
- {
4553
- txBoolean result = 0;
4554
- if (a->kind == b->kind) {
4555
- if ((XS_UNDEFINED_KIND == a->kind) || (XS_NULL_KIND == a->kind))
4556
- result = 1;
4557
- else if (XS_BOOLEAN_KIND == a->kind)
4558
- result = a->value.boolean == b->value.boolean;
4559
- else if (XS_INTEGER_KIND == a->kind)
4560
- result = a->value.integer == b->value.integer;
4561
- else if (XS_NUMBER_KIND == a->kind) {
4562
- result = (!c_isnan(a->value.number)) && (!c_isnan(b->value.number)) && (a->value.number == b->value.number);
4563
- mxFloatingPointOp("same slot");
4564
- }
4565
- else if ((XS_STRING_KIND == a->kind) || (XS_STRING_X_KIND == a->kind))
4566
- result = c_strcmp(a->value.string, b->value.string) == 0;
4567
- else if (XS_SYMBOL_KIND == a->kind)
4568
- result = a->value.symbol == b->value.symbol;
4569
- else if ((XS_BIGINT_KIND == a->kind) || (XS_BIGINT_X_KIND == a->kind))
4570
- result = gxTypeBigInt.compare(the, 0, 1, 0, a, b);
4571
- else if (XS_REFERENCE_KIND == a->kind)
4572
- result = fxIsSameReference(the, a, b);
4573
- }
4574
- else if ((XS_INTEGER_KIND == a->kind) && (XS_NUMBER_KIND == b->kind)) {
4575
- result = (!c_isnan(b->value.number)) && ((txNumber)(a->value.integer) == b->value.number);
4576
- mxFloatingPointOp("same slot");
4577
- }
4578
- else if ((XS_NUMBER_KIND == a->kind) && (XS_INTEGER_KIND == b->kind)) {
4579
- result = (!c_isnan(a->value.number)) && (a->value.number == (txNumber)(b->value.integer));
4580
- mxFloatingPointOp("same slot");
4581
- }
4582
- else if ((XS_STRING_KIND == a->kind) && (XS_STRING_X_KIND == b->kind))
4583
- result = c_strcmp(a->value.string, b->value.string) == 0;
4584
- else if ((XS_STRING_X_KIND == a->kind) && (XS_STRING_KIND == b->kind))
4585
- result = c_strcmp(a->value.string, b->value.string) == 0;
4586
- else if ((XS_BIGINT_KIND == a->kind) && (XS_BIGINT_X_KIND == b->kind))
4587
- result = gxTypeBigInt.compare(the, 0, 1, 0, a, b);
4588
- else if ((XS_BIGINT_X_KIND == a->kind) && (XS_BIGINT_KIND == b->kind))
4589
- result = gxTypeBigInt.compare(the, 0, 1, 0, a, b);
4590
- return result;
4591
- }
4592
-
4593
- txBoolean fxIsSameValue(txMachine* the, txSlot* a, txSlot* b, txBoolean zero)
4594
- {
4595
- txBoolean result = 0;
4596
- if (a->kind == b->kind) {
4597
- if ((XS_UNDEFINED_KIND == a->kind) || (XS_NULL_KIND == a->kind))
4598
- result = 1;
4599
- else if (XS_BOOLEAN_KIND == a->kind)
4600
- result = a->value.boolean == b->value.boolean;
4601
- else if (XS_INTEGER_KIND == a->kind)
4602
- result = a->value.integer == b->value.integer;
4603
- else if (XS_NUMBER_KIND == a->kind) {
4604
- result = ((c_isnan(a->value.number) && c_isnan(b->value.number)) || ((a->value.number == b->value.number) && (zero || (c_signbit(a->value.number) == c_signbit(b->value.number)))));
4605
- mxFloatingPointOp("same value");
4606
- }
4607
- else if ((XS_STRING_KIND == a->kind) || (XS_STRING_X_KIND == a->kind))
4608
- result = c_strcmp(a->value.string, b->value.string) == 0;
4609
- else if (XS_SYMBOL_KIND == a->kind)
4610
- result = a->value.symbol == b->value.symbol;
4611
- else if ((XS_BIGINT_KIND == a->kind) || (XS_BIGINT_X_KIND == a->kind))
4612
- result = gxTypeBigInt.compare(the, 0, 1, 0, a, b);
4613
- else if (XS_REFERENCE_KIND == a->kind)
4614
- result = fxIsSameReference(the, a, b);
4615
- }
4616
- else if ((XS_INTEGER_KIND == a->kind) && (XS_NUMBER_KIND == b->kind)) {
4617
- txNumber aNumber = a->value.integer;
4618
- result = (aNumber == b->value.number) && (zero || (signbit(aNumber) == signbit(b->value.number)));
4619
- mxFloatingPointOp("same value");
4620
- }
4621
- else if ((XS_NUMBER_KIND == a->kind) && (XS_INTEGER_KIND == b->kind)) {
4622
- txNumber bNumber = b->value.integer;
4623
- result = (a->value.number == bNumber) && (zero || (signbit(a->value.number) == signbit(bNumber)));
4624
- mxFloatingPointOp("same value");
4625
- }
4626
- else if ((XS_STRING_KIND == a->kind) && (XS_STRING_X_KIND == b->kind))
4627
- result = c_strcmp(a->value.string, b->value.string) == 0;
4628
- else if ((XS_STRING_X_KIND == a->kind) && (XS_STRING_KIND == b->kind))
4629
- result = c_strcmp(a->value.string, b->value.string) == 0;
4630
- else if ((XS_BIGINT_KIND == a->kind) && (XS_BIGINT_X_KIND == b->kind))
4631
- result = gxTypeBigInt.compare(the, 0, 1, 0, a, b);
4632
- else if ((XS_BIGINT_X_KIND == a->kind) && (XS_BIGINT_KIND == b->kind))
4633
- result = gxTypeBigInt.compare(the, 0, 1, 0, a, b);
4634
- return result;
4635
- }
4636
-
4637
- txBoolean fxIsScopableSlot(txMachine* the, txSlot* instance, txID id)
4638
- {
4639
- txBoolean result;
4640
- fxBeginHost(the);
4641
- mxPushReference(instance);
4642
- result = mxHasID(id);
4643
- if (result) {
4644
- mxPushReference(instance);
4645
- mxGetID(mxID(_Symbol_unscopables));
4646
- if (mxIsReference(the->stack)) {
4647
- mxGetID(id);
4648
- result = fxToBoolean(the, the->stack) ? 0 : 1;
4649
- }
4650
- mxPop();
4651
- }
4652
- fxEndHost(the);
4653
- return result;
4654
- }
4655
-
4656
- void fxRemapIDs(txMachine* the, txByte* codeBuffer, txSize codeSize, txID* theIDs)
4657
- {
4658
- register const txS1* bytes = gxCodeSizes;
4659
- register txByte* p = codeBuffer;
4660
- register txByte* q = codeBuffer + codeSize;
4661
- register txS1 offset;
4662
- txID id;
4663
- while (p < q) {
4664
- //fprintf(stderr, "%s", gxCodeNames[*((txU1*)p)]);
4665
- offset = (txS1)c_read8(bytes + c_read8(p));
4666
- if (0 < offset)
4667
- p += offset;
4668
- else if (0 == offset) {
4669
- p++;
4670
- mxDecodeID(p, id);
4671
- if (id != XS_NO_ID) {
4672
- id = theIDs[id];
4673
- p -= sizeof(txID);
4674
- mxEncodeID(p, id);
4675
- }
4676
- }
4677
- else if (-1 == offset) {
4678
- txU1 index;
4679
- p++;
4680
- index = *((txU1*)p);
4681
- p += 1 + index;
4682
- }
4683
- else if (-2 == offset) {
4684
- txU2 index;
4685
- p++;
4686
- mxDecode2(p, index);
4687
- p += index;
4688
- }
4689
- else if (-4 == offset) {
4690
- txS4 index;
4691
- p++;
4692
- mxDecode4(p, index);
4693
- p += index;
4694
- }
4695
- //fprintf(stderr, "\n");
4696
- }
4697
- }
4698
-
4699
- txBoolean fxToNumericInteger(txMachine* the, txSlot* theSlot)
4700
- {
4701
- if (theSlot->kind == XS_REFERENCE_KIND)
4702
- fxToPrimitive(the, theSlot, XS_NUMBER_HINT);
4703
- if ((theSlot->kind == XS_BIGINT_KIND) || (theSlot->kind == XS_BIGINT_X_KIND))
4704
- return 0;
4705
- fxToInteger(the, theSlot);
4706
- return 1;
4707
- }
4708
-
4709
- txBoolean fxToNumericIntegerUnary(txMachine* the, txSlot* a, txBigIntUnary op)
4710
- {
4711
- if (fxToNumericInteger(the, a))
4712
- return 1;
4713
- a->value.bigint = *(*op)(the, C_NULL, &a->value.bigint);
4714
- a->kind = XS_BIGINT_KIND;
4715
- the->stack = a;
4716
- return 0;
4717
- }
4718
-
4719
- txBoolean fxToNumericIntegerBinary(txMachine* the, txSlot* a, txSlot* b, txBigIntBinary op)
4720
- {
4721
- txBoolean ra = fxToNumericInteger(the, a);
4722
- txBoolean rb = fxToNumericInteger(the, b);
4723
- if (ra) {
4724
- if (rb)
4725
- return 1;
4726
- mxTypeError("Cannot coerce left operand to bigint");
4727
- }
4728
- else if (rb)
4729
- mxTypeError("Cannot coerce right operand to bigint");
4730
- a->value.bigint = *(*op)(the, C_NULL, &a->value.bigint, &b->value.bigint);
4731
- a->kind = XS_BIGINT_KIND;
4732
- the->stack = b;
4733
- return 0;
4734
- }
4735
-
4736
- txBoolean fxToNumericNumber(txMachine* the, txSlot* theSlot)
4737
- {
4738
- if (theSlot->kind == XS_REFERENCE_KIND)
4739
- fxToPrimitive(the, theSlot, XS_NUMBER_HINT);
4740
- if ((theSlot->kind == XS_BIGINT_KIND) || (theSlot->kind == XS_BIGINT_X_KIND))
4741
- return 0;
4742
- fxToNumber(the, theSlot);
4743
- return 1;
4744
- }
4745
-
4746
- txBoolean fxToNumericNumberUnary(txMachine* the, txSlot* a, txBigIntUnary op)
4747
- {
4748
- if (fxToNumericNumber(the, a))
4749
- return 1;
4750
- a->value.bigint = *(*op)(the, C_NULL, &a->value.bigint);
4751
- a->kind = XS_BIGINT_KIND;
4752
- the->stack = a;
4753
- return 0;
4754
- }
4755
-
4756
- txBoolean fxToNumericNumberBinary(txMachine* the, txSlot* a, txSlot* b, txBigIntBinary op)
4757
- {
4758
- txBoolean ra = fxToNumericNumber(the, a);
4759
- txBoolean rb = fxToNumericNumber(the, b);
4760
- if (ra) {
4761
- if (rb)
4762
- return 1;
4763
- mxTypeError("Cannot coerce left operand to bigint");
4764
- }
4765
- else if (rb)
4766
- mxTypeError("Cannot coerce right operand to bigint");
4767
- a->value.bigint = *(*op)(the, C_NULL, &a->value.bigint, &b->value.bigint);
4768
- a->kind = XS_BIGINT_KIND;
4769
- the->stack = b;
4770
- return 0;
4771
- }
4772
-
4773
- void fxRunScript(txMachine* the, txScript* script, txSlot* _this, txSlot* _target, txSlot* closures, txSlot* object, txSlot* module)
4774
- {
4775
- if (script) {
4776
- mxTry(the) {
4777
- txSlot* instance;
4778
- txSlot* property;
4779
- __JUMP__.code = C_NULL;
4780
- mxPushUndefined();
4781
- if (script->symbolsBuffer) {
4782
- txByte* p = script->symbolsBuffer;
4783
- txID c, i;
4784
- mxDecodeID(p, c);
4785
- the->stack->value.callback.address = C_NULL;
4786
- the->stack->value.IDs = (txID*)fxNewChunk(the, c * sizeof(txID));
4787
- the->stack->kind = XS_IDS_KIND;
4788
- the->stack->value.IDs[0] = XS_NO_ID;
4789
- for (i = 1; i < c; i++) {
4790
- txID id = fxNewNameC(the, (txString)p);
4791
- the->stack->value.IDs[i] = id;
4792
- p += mxStringLength((char*)p) + 1;
4793
- }
4794
- fxRemapIDs(the, script->codeBuffer, script->codeSize, the->stack->value.IDs);
4795
- the->stack->value.IDs = C_NULL;
4796
- }
4797
- else {
4798
- the->stack->value.IDs = C_NULL;
4799
- the->stack->kind = XS_IDS_KIND;
4800
- }
4801
- if (script->callback) {
4802
- property = the->stack;
4803
- /* THIS */
4804
- if (_this)
4805
- mxPushSlot(_this);
4806
- else
4807
- mxPushUndefined();
4808
- the->stack->ID = XS_NO_ID;
4809
- /* FUNCTION */
4810
- mxPush(mxFunctionPrototype);
4811
- instance = fxNewFunctionInstance(the, closures ? mxID(_eval) : XS_NO_ID);
4812
- instance->next->kind = XS_CALLBACK_KIND;
4813
- instance->next->value.callback.address = script->callback;
4814
- instance->next->value.callback.closures = C_NULL;
4815
- property = mxFunctionInstanceHome(instance);
4816
- property->value.home.object = object;
4817
- property->value.home.module = module;
4818
- /* TARGET */
4819
- mxPushUndefined();
4820
- /* RESULT */
4821
- mxPushUndefined();
4822
- /* FRAME */
4823
- mxPushUninitialized();
4824
- /* COUNT */
4825
- mxPushUninitialized();
4826
- mxRunCount(0);
4827
- }
4828
- else {
4829
- mxPushUndefined();
4830
- }
4831
- mxPull(mxHosts);
4832
- mxPop();
4833
-
4834
- /* THIS */
4835
- if (_this)
4836
- mxPushSlot(_this);
4837
- else
4838
- mxPushUndefined();
4839
- the->stack->ID = XS_NO_ID;
4840
- /* FUNCTION */
4841
- mxPush(mxFunctionPrototype);
4842
- instance = fxNewFunctionInstance(the, XS_NO_ID);
4843
- instance->next->kind = XS_CODE_X_KIND;
4844
- instance->next->value.code.address = script->codeBuffer;
4845
- instance->next->value.code.closures = closures;
4846
- property = mxFunctionInstanceHome(instance);
4847
- property->ID = fxGenerateProfileID(the);
4848
- property->value.home.object = object;
4849
- property->value.home.module = module;
4850
- /* TARGET */
4851
- if (_target)
4852
- mxPushSlot(_target);
4853
- else
4854
- mxPushUndefined();
4855
- /* RESULT */
4856
- mxPushUndefined();
4857
- /* FRAME */
4858
- mxPushUninitialized();
4859
- /* COUNT */
4860
- mxPushUninitialized();
4861
- mxRunCount(0);
4862
-
4863
- mxPushUndefined();
4864
- mxPull(mxHosts);
4865
- if (script->symbolsBuffer)
4866
- fxDeleteScript(script);
4867
- }
4868
- mxCatch(the) {
4869
- if (script->symbolsBuffer)
4870
- fxDeleteScript(script);
4871
- fxJump(the);
4872
- }
4873
- }
4874
- else {
4875
- mxSyntaxError("invalid script");
4876
- }
4877
- }
4878
-
4879
-
4880
-
4881
-
4882
-
4883
-
4884
-
4885
-
4886
-
4887
-
4888
-
4889
-