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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +3 -3
  2. package/api.js +4 -2
  3. package/build.env +1 -1
  4. package/moddable/modules/data/base64/base64.js +28 -0
  5. package/moddable/modules/data/base64/manifest.json +11 -0
  6. package/moddable/modules/data/base64/modBase64.c +188 -0
  7. package/moddable/modules/data/binaryMessage/BinaryMessage.js +106 -0
  8. package/moddable/modules/data/crc/crc.c +205 -0
  9. package/moddable/modules/data/crc/crc.js +36 -0
  10. package/moddable/modules/data/crc/manifest.json +8 -0
  11. package/moddable/modules/data/hex/hex.js +28 -0
  12. package/moddable/modules/data/hex/manifest.json +11 -0
  13. package/moddable/modules/data/hex/modHex.c +139 -0
  14. package/moddable/modules/data/logical/logical.js +32 -0
  15. package/moddable/modules/data/logical/modLogical.c +98 -0
  16. package/moddable/modules/data/qrcode/manifest.json +9 -0
  17. package/moddable/modules/data/qrcode/qrcode.c +93 -0
  18. package/moddable/modules/data/qrcode/qrcode.js +23 -0
  19. package/moddable/modules/data/qrcode/qrcodegen.c +1025 -0
  20. package/moddable/modules/data/qrcode/qrcodegen.h +267 -0
  21. package/moddable/modules/data/text/decoder/manifest.json +8 -0
  22. package/moddable/modules/data/text/decoder/textdecoder.c +480 -0
  23. package/moddable/modules/data/text/decoder/textdecoder.js +27 -0
  24. package/moddable/modules/data/text/encoder/manifest.json +8 -0
  25. package/moddable/modules/data/text/encoder/textencoder.c +232 -0
  26. package/moddable/modules/data/text/encoder/textencoder.js +24 -0
  27. package/moddable/modules/data/tinyint/tinyint.c +150 -0
  28. package/moddable/modules/data/tinyint/tinyint.js +53 -0
  29. package/moddable/modules/data/url/manifest.json +17 -0
  30. package/moddable/modules/data/url/url.c +1959 -0
  31. package/moddable/modules/data/url/url.js +210 -0
  32. package/moddable/modules/data/wavreader/manifest.json +8 -0
  33. package/moddable/modules/data/wavreader/wavreader.js +128 -0
  34. package/moddable/modules/data/zlib/deflate.c +161 -0
  35. package/moddable/modules/data/zlib/deflate.js +63 -0
  36. package/moddable/modules/data/zlib/inflate.c +145 -0
  37. package/moddable/modules/data/zlib/inflate.js +66 -0
  38. package/moddable/modules/data/zlib/manifest_deflate.json +9 -0
  39. package/moddable/modules/data/zlib/manifest_inflate.json +9 -0
  40. package/moddable/modules/data/zlib/miniz.c +4924 -0
  41. package/moddable/xs/includes/xs.d.ts +73 -0
  42. package/moddable/xs/includes/xs.h +1533 -0
  43. package/moddable/xs/includes/xsmc.h +206 -0
  44. package/moddable/xs/makefiles/lin/makefile +33 -0
  45. package/moddable/xs/makefiles/lin/xsc.mk +118 -0
  46. package/moddable/xs/makefiles/lin/xsid.mk +90 -0
  47. package/moddable/xs/makefiles/lin/xsl.mk +168 -0
  48. package/moddable/xs/makefiles/lin/xst.mk +201 -0
  49. package/moddable/xs/makefiles/mac/makefile +33 -0
  50. package/moddable/xs/makefiles/mac/xsc.mk +130 -0
  51. package/moddable/xs/makefiles/mac/xsid.mk +102 -0
  52. package/moddable/xs/makefiles/mac/xsl.mk +177 -0
  53. package/moddable/xs/makefiles/mac/xst.mk +203 -0
  54. package/moddable/xs/makefiles/mac/xst_no_asan.txt +52 -0
  55. package/moddable/xs/makefiles/win/build.bat +26 -0
  56. package/moddable/xs/makefiles/win/xsc.mak +142 -0
  57. package/moddable/xs/makefiles/win/xsid.mak +113 -0
  58. package/moddable/xs/makefiles/win/xsl.mak +186 -0
  59. package/moddable/xs/makefiles/win/xst.mak +195 -0
  60. package/moddable/xs/platforms/lin_xs.h +99 -0
  61. package/moddable/xs/platforms/mac_xs.h +97 -0
  62. package/moddable/xs/platforms/wasm_xs.h +79 -0
  63. package/moddable/xs/platforms/win_xs.h +104 -0
  64. package/moddable/xs/platforms/xsHost.h +63 -0
  65. package/moddable/xs/platforms/xsPlatform.h +618 -0
  66. package/moddable/xs/sources/xsAPI.c +2555 -0
  67. package/moddable/xs/sources/xsAll.c +294 -0
  68. package/moddable/xs/sources/xsAll.h +2741 -0
  69. package/moddable/xs/sources/xsArguments.c +222 -0
  70. package/moddable/xs/sources/xsArray.c +2657 -0
  71. package/moddable/xs/sources/xsAtomics.c +844 -0
  72. package/moddable/xs/sources/xsBigInt.c +1859 -0
  73. package/moddable/xs/sources/xsBoolean.c +109 -0
  74. package/moddable/xs/sources/xsCode.c +4493 -0
  75. package/moddable/xs/sources/xsCommon.c +1710 -0
  76. package/moddable/xs/sources/xsCommon.h +1142 -0
  77. package/moddable/xs/sources/xsDataView.c +2890 -0
  78. package/moddable/xs/sources/xsDate.c +1541 -0
  79. package/moddable/xs/sources/xsDebug.c +2710 -0
  80. package/moddable/xs/sources/xsDefaults.c +134 -0
  81. package/moddable/xs/sources/xsError.c +353 -0
  82. package/moddable/xs/sources/xsFunction.c +776 -0
  83. package/moddable/xs/sources/xsGenerator.c +865 -0
  84. package/moddable/xs/sources/xsGlobal.c +839 -0
  85. package/moddable/xs/sources/xsJSON.c +1091 -0
  86. package/moddable/xs/sources/xsLexical.c +1969 -0
  87. package/moddable/xs/sources/xsLockdown.c +933 -0
  88. package/moddable/xs/sources/xsMapSet.c +1649 -0
  89. package/moddable/xs/sources/xsMarshall.c +1020 -0
  90. package/moddable/xs/sources/xsMath.c +624 -0
  91. package/moddable/xs/sources/xsMemory.c +1941 -0
  92. package/moddable/xs/sources/xsModule.c +3101 -0
  93. package/moddable/xs/sources/xsNumber.c +560 -0
  94. package/moddable/xs/sources/xsObject.c +1102 -0
  95. package/moddable/xs/sources/xsPlatforms.c +480 -0
  96. package/moddable/xs/sources/xsProfile.c +577 -0
  97. package/moddable/xs/sources/xsPromise.c +1199 -0
  98. package/moddable/xs/sources/xsProperty.c +636 -0
  99. package/moddable/xs/sources/xsProxy.c +1014 -0
  100. package/moddable/xs/sources/xsRegExp.c +1168 -0
  101. package/moddable/xs/sources/xsRun.c +4889 -0
  102. package/moddable/xs/sources/xsScope.c +1293 -0
  103. package/moddable/xs/sources/xsScript.c +288 -0
  104. package/moddable/xs/sources/xsScript.h +1186 -0
  105. package/moddable/xs/sources/xsSnapshot.c +2161 -0
  106. package/moddable/xs/sources/xsSnapshot.h +51 -0
  107. package/moddable/xs/sources/xsSourceMap.c +218 -0
  108. package/moddable/xs/sources/xsString.c +3332 -0
  109. package/moddable/xs/sources/xsSymbol.c +503 -0
  110. package/moddable/xs/sources/xsSyntaxical.c +4193 -0
  111. package/moddable/xs/sources/xsTree.c +1893 -0
  112. package/moddable/xs/sources/xsType.c +1488 -0
  113. package/moddable/xs/sources/xsdtoa.c +6672 -0
  114. package/moddable/xs/sources/xsmc.c +340 -0
  115. package/moddable/xs/sources/xsre.c +7578 -0
  116. package/package.json +37 -20
  117. package/scripts/get_xsnap_version.sh +14 -0
  118. package/scripts/test-package.sh +21 -0
  119. package/src/avaAssertXS.js +6 -2
  120. package/src/avaHandler.cjs +2 -5
  121. package/src/avaXS.js +7 -8
  122. package/src/build.js +161 -28
  123. package/src/replay.js +0 -3
  124. package/src/xsnap.js +105 -91
  125. package/src/xsrepl.js +2 -3
  126. package/xsnap-native/xsnap/makefiles/lin/makefile +10 -0
  127. package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +156 -0
  128. package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +144 -0
  129. package/xsnap-native/xsnap/makefiles/mac/makefile +10 -0
  130. package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +165 -0
  131. package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +153 -0
  132. package/xsnap-native/xsnap/sources/xsnap-worker.c +1008 -0
  133. package/xsnap-native/xsnap/sources/xsnap.c +717 -0
  134. package/xsnap-native/xsnap/sources/xsnap.h +142 -0
  135. package/xsnap-native/xsnap/sources/xsnapPlatform.c +1501 -0
  136. package/xsnap-native/xsnap/sources/xsnapPlatform.h +105 -0
  137. package/CHANGELOG.md +0 -654
@@ -0,0 +1,2161 @@
1
+ /*
2
+ * Copyright (c) 2016-2018 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
+ */
20
+
21
+ #define _GNU_SOURCE
22
+ #include "xsSnapshot.h"
23
+ #if mxMacOSX || mxLinux
24
+ #include <dlfcn.h>
25
+ #endif
26
+
27
+ static void fxIndexInstance(txMachine* the, txSnapshot* snapshot, txSlot* theCurrent);
28
+ static void fxIndexReference(txMachine* the, txSnapshot* snapshot, txSlot* theSlot);
29
+ static void fxIndexSlot(txMachine* the, txSnapshot* snapshot, txSlot* slot);
30
+ static void fxIndexSlots(txMachine* the, txSnapshot* snapshot);
31
+
32
+ static void fxLinkChunks(txMachine* the);
33
+
34
+ static void fxMeasureSlot(txMachine* the, txSnapshot* snapshot, txSlot* slot, txSize* chunkSize);
35
+ static void fxMeasureChunk(txMachine* the, txSnapshot* snapshot, void* address, txSize* chunkSize);
36
+ static void fxMeasureChunkArray(txMachine* the, txSnapshot* snapshot, txSlot* address, txSize* chunkSize);
37
+
38
+ static txCallback fxProjectCallback(txMachine* the, txSnapshot* snapshot, txCallback callback);
39
+ static void* fxProjectChunk(txMachine* the, void* address);
40
+ static txSlot* fxProjectSlot(txMachine* the, txProjection* firstProjection, txSlot* slot);
41
+ static txTypeAtomics* fxProjectTypeAtomics(txMachine* the, txTypeAtomics* atomics);
42
+ static txTypeDispatch* fxProjectTypeDispatch(txMachine* the, txTypeDispatch* dispatch);
43
+
44
+ static void fxReadAtom(txMachine* the, txSnapshot* snapshot, Atom* atom, txString type);
45
+ static void fxReadMapSet(txMachine* the, txSlot* table, txBoolean paired);
46
+ static void fxReadSlot(txMachine* the, txSnapshot* snapshot, txSlot* slot, txFlag flag);
47
+ static void fxReadSlotArray(txMachine* the, txSnapshot* snapshot, txSlot* address, txSize length);
48
+ static void fxReadSlotTable(txMachine* the, txSnapshot* snapshot, txSlot** address, txSize length);
49
+
50
+ static void fxUnlinkChunks(txMachine* the);
51
+
52
+ #define mxUnprojectChunk(ADDRESS) (snapshot->firstChunk + ((size_t)ADDRESS));
53
+ static txCallback fxUnprojectCallback(txMachine* the, txSnapshot* snapshot, txCallback callback);
54
+ static txSlot* fxUnprojectSlot(txMachine* the, txSnapshot* snapshot, txSlot* slot);
55
+
56
+ static void fxWriteChunk(txMachine* the, txSnapshot* snapshot, txSlot* slot);
57
+ static void fxWriteChunkArray(txMachine* the, txSnapshot* snapshot, txSlot* address, txSize length, txFlag flag);
58
+ static void fxWriteChunkBigInt(txMachine* the, txSnapshot* snapshot, void* address, txSize size);
59
+ static void fxWriteChunkData(txMachine* the, txSnapshot* snapshot, void* address);
60
+ static void fxWriteChunkTable(txMachine* the, txSnapshot* snapshot, txSlot** address, txSize length);
61
+ static void fxWriteChunkZero(txMachine* the, txSnapshot* snapshot, txSize size);
62
+ static void fxWriteChunks(txMachine* the, txSnapshot* snapshot);
63
+ static void fxWriteSlot(txMachine* the, txSnapshot* snapshot, txSlot* slot, txFlag flag);
64
+ static void fxWriteSlotTable(txMachine* the, txSnapshot* snapshot, txSlot** address, txSize length);
65
+ static void fxWriteSlots(txMachine* the, txSnapshot* snapshot);
66
+ static void fxWriteStack(txMachine* the, txSnapshot* snapshot);
67
+
68
+ #define mxAssert(_ASSERTION,...) { if (!(_ASSERTION)) { fxReport(the, __VA_ARGS__); snapshot->error = C_EINVAL; fxJump(the); } }
69
+ #define mxThrowIf(_ERROR) { if (_ERROR) { snapshot->error = _ERROR; fxJump(the); } }
70
+ #define mxChunkFlag 0x80000000
71
+
72
+ #define mxCallbacksLength 496
73
+ static txCallback gxCallbacks[mxCallbacksLength] = {
74
+ fx_AggregateError,
75
+ fx_Array_from,
76
+ fx_Array_isArray,
77
+ fx_Array_of,
78
+ fx_Array_prototype_at,
79
+ fx_Array_prototype_concat,
80
+ fx_Array_prototype_copyWithin,
81
+ fx_Array_prototype_entries,
82
+ fx_Array_prototype_every,
83
+ fx_Array_prototype_fill,
84
+ fx_Array_prototype_filter,
85
+ fx_Array_prototype_find,
86
+ fx_Array_prototype_findIndex,
87
+ fx_Array_prototype_findLast,
88
+ fx_Array_prototype_findLastIndex,
89
+ fx_Array_prototype_flat,
90
+ fx_Array_prototype_flatMap,
91
+ fx_Array_prototype_forEach,
92
+ fx_Array_prototype_includes,
93
+ fx_Array_prototype_indexOf,
94
+ fx_Array_prototype_join,
95
+ fx_Array_prototype_keys,
96
+ fx_Array_prototype_lastIndexOf,
97
+ fx_Array_prototype_map,
98
+ fx_Array_prototype_pop,
99
+ fx_Array_prototype_push,
100
+ fx_Array_prototype_reduce,
101
+ fx_Array_prototype_reduceRight,
102
+ fx_Array_prototype_reverse,
103
+ fx_Array_prototype_shift,
104
+ fx_Array_prototype_slice,
105
+ fx_Array_prototype_some,
106
+ fx_Array_prototype_sort,
107
+ fx_Array_prototype_splice,
108
+ fx_Array_prototype_toLocaleString,
109
+ fx_Array_prototype_toString,
110
+ fx_Array_prototype_unshift,
111
+ fx_Array_prototype_values,
112
+ fx_Array,
113
+ fx_ArrayBuffer_fromBigInt,
114
+ fx_ArrayBuffer_isView,
115
+ fx_ArrayBuffer_prototype_concat,
116
+ fx_ArrayBuffer_prototype_get_byteLength,
117
+ fx_ArrayBuffer_prototype_get_maxByteLength,
118
+ fx_ArrayBuffer_prototype_get_resizable,
119
+ fx_ArrayBuffer_prototype_resize,
120
+ fx_ArrayBuffer_prototype_slice,
121
+ fx_ArrayBuffer_prototype_transfer,
122
+ fx_ArrayBuffer,
123
+ fx_ArrayIterator_prototype_next,
124
+ fx_AsyncFromSyncIterator_prototype_next,
125
+ fx_AsyncFromSyncIterator_prototype_return,
126
+ fx_AsyncFromSyncIterator_prototype_throw,
127
+ fx_AsyncFunction,
128
+ fx_AsyncGenerator_prototype_next,
129
+ fx_AsyncGenerator_prototype_return,
130
+ fx_AsyncGenerator_prototype_throw,
131
+ fx_AsyncGenerator,
132
+ fx_AsyncGeneratorFunction,
133
+ fx_AsyncIterator_asyncIterator,
134
+ fx_Atomics_add,
135
+ fx_Atomics_and,
136
+ fx_Atomics_compareExchange,
137
+ fx_Atomics_exchange,
138
+ fx_Atomics_isLockFree,
139
+ fx_Atomics_load,
140
+ fx_Atomics_notify,
141
+ fx_Atomics_or,
142
+ fx_Atomics_store,
143
+ fx_Atomics_sub,
144
+ fx_Atomics_wait,
145
+ fx_Atomics_xor,
146
+ fx_BigInt_asIntN,
147
+ fx_BigInt_asUintN,
148
+ fx_BigInt_bitLength,
149
+ fx_BigInt_fromArrayBuffer,
150
+ fx_BigInt_prototype_toString,
151
+ fx_BigInt_prototype_valueOf,
152
+ fx_BigInt,
153
+ fx_Boolean_prototype_toString,
154
+ fx_Boolean_prototype_valueOf,
155
+ fx_Boolean,
156
+ fx_Compartment_prototype_evaluate,
157
+ fx_Compartment_prototype_get_globalThis,
158
+ fx_Compartment_prototype_import,
159
+ fx_Compartment_prototype_importNow,
160
+ fx_Compartment,
161
+ fx_DataView_prototype_buffer_get,
162
+ fx_DataView_prototype_byteLength_get,
163
+ fx_DataView_prototype_byteOffset_get,
164
+ fx_DataView_prototype_getBigInt64,
165
+ fx_DataView_prototype_getBigUint64,
166
+ fx_DataView_prototype_getFloat32,
167
+ fx_DataView_prototype_getFloat64,
168
+ fx_DataView_prototype_getInt8,
169
+ fx_DataView_prototype_getInt16,
170
+ fx_DataView_prototype_getInt32,
171
+ fx_DataView_prototype_getUint8,
172
+ fx_DataView_prototype_getUint16,
173
+ fx_DataView_prototype_getUint32,
174
+ fx_DataView_prototype_setBigInt64,
175
+ fx_DataView_prototype_setBigUint64,
176
+ fx_DataView_prototype_setFloat32,
177
+ fx_DataView_prototype_setFloat64,
178
+ fx_DataView_prototype_setInt8,
179
+ fx_DataView_prototype_setInt16,
180
+ fx_DataView_prototype_setInt32,
181
+ fx_DataView_prototype_setUint8,
182
+ fx_DataView_prototype_setUint16,
183
+ fx_DataView_prototype_setUint32,
184
+ fx_DataView,
185
+ fx_Date_now,
186
+ fx_Date_now_secure,
187
+ fx_Date_parse,
188
+ fx_Date_prototype_getDate,
189
+ fx_Date_prototype_getDay,
190
+ fx_Date_prototype_getFullYear,
191
+ fx_Date_prototype_getHours,
192
+ fx_Date_prototype_getMilliseconds,
193
+ fx_Date_prototype_getMinutes,
194
+ fx_Date_prototype_getMonth,
195
+ fx_Date_prototype_getSeconds,
196
+ fx_Date_prototype_getTimezoneOffset,
197
+ fx_Date_prototype_getUTCDate,
198
+ fx_Date_prototype_getUTCDay,
199
+ fx_Date_prototype_getUTCFullYear,
200
+ fx_Date_prototype_getUTCHours,
201
+ fx_Date_prototype_getUTCMilliseconds,
202
+ fx_Date_prototype_getUTCMinutes,
203
+ fx_Date_prototype_getUTCMonth,
204
+ fx_Date_prototype_getUTCSeconds,
205
+ fx_Date_prototype_getYear,
206
+ fx_Date_prototype_setDate,
207
+ fx_Date_prototype_setFullYear,
208
+ fx_Date_prototype_setHours,
209
+ fx_Date_prototype_setMilliseconds,
210
+ fx_Date_prototype_setMinutes,
211
+ fx_Date_prototype_setMonth,
212
+ fx_Date_prototype_setSeconds,
213
+ fx_Date_prototype_setTime,
214
+ fx_Date_prototype_setUTCDate,
215
+ fx_Date_prototype_setUTCFullYear,
216
+ fx_Date_prototype_setUTCHours,
217
+ fx_Date_prototype_setUTCMilliseconds,
218
+ fx_Date_prototype_setUTCMinutes,
219
+ fx_Date_prototype_setUTCMonth,
220
+ fx_Date_prototype_setUTCSeconds,
221
+ fx_Date_prototype_setYear,
222
+ fx_Date_prototype_toDateString,
223
+ fx_Date_prototype_toISOString,
224
+ fx_Date_prototype_toJSON,
225
+ fx_Date_prototype_toPrimitive,
226
+ fx_Date_prototype_toString,
227
+ fx_Date_prototype_toTimeString,
228
+ fx_Date_prototype_toUTCString,
229
+ fx_Date_prototype_valueOf,
230
+ fx_Date_UTC,
231
+ fx_Date,
232
+ fx_Date_secure,
233
+ fx_decodeURI,
234
+ fx_decodeURIComponent,
235
+ fx_encodeURI,
236
+ fx_encodeURIComponent,
237
+ fx_Enumerator_next,
238
+ fx_Enumerator,
239
+ fx_Error_prototype_get_stack,
240
+ fx_Error_toString,
241
+ fx_Error,
242
+ fx_escape,
243
+ fx_eval,
244
+ fx_EvalError,
245
+ // fx_FinalizationRegistry_prototype_cleanupSome,
246
+ fx_FinalizationRegistry_prototype_register,
247
+ fx_FinalizationRegistry_prototype_unregister,
248
+ fx_FinalizationRegistry,
249
+ fx_Function_prototype_apply,
250
+ fx_Function_prototype_bind,
251
+ fx_Function_prototype_bound,
252
+ fx_Function_prototype_call,
253
+ fx_Function_prototype_hasInstance,
254
+ fx_Function_prototype_toString,
255
+ fx_Function,
256
+ fx_Generator_prototype_next,
257
+ fx_Generator_prototype_return,
258
+ fx_Generator_prototype_throw,
259
+ fx_Generator,
260
+ fx_GeneratorFunction,
261
+ fx_isFinite,
262
+ fx_isNaN,
263
+ fx_Iterator_iterator,
264
+ fx_JSON_parse,
265
+ fx_JSON_stringify,
266
+ fx_Map_prototype_clear,
267
+ fx_Map_prototype_delete,
268
+ fx_Map_prototype_entries,
269
+ fx_Map_prototype_forEach,
270
+ fx_Map_prototype_get,
271
+ fx_Map_prototype_has,
272
+ fx_Map_prototype_keys,
273
+ fx_Map_prototype_set,
274
+ fx_Map_prototype_size,
275
+ fx_Map_prototype_values,
276
+ fx_Map,
277
+ fx_MapIterator_prototype_next,
278
+ fx_Math_abs,
279
+ fx_Math_acos,
280
+ fx_Math_acosh,
281
+ fx_Math_asin,
282
+ fx_Math_asinh,
283
+ fx_Math_atan,
284
+ fx_Math_atan2,
285
+ fx_Math_atanh,
286
+ fx_Math_cbrt,
287
+ fx_Math_ceil,
288
+ fx_Math_clz32,
289
+ fx_Math_cos,
290
+ fx_Math_cosh,
291
+ fx_Math_exp,
292
+ fx_Math_expm1,
293
+ fx_Math_floor,
294
+ fx_Math_fround,
295
+ fx_Math_hypot,
296
+ fx_Math_idiv,
297
+ fx_Math_idivmod,
298
+ fx_Math_imod,
299
+ fx_Math_imul,
300
+ fx_Math_imuldiv,
301
+ fx_Math_irem,
302
+ fx_Math_log,
303
+ fx_Math_log1p,
304
+ fx_Math_log2,
305
+ fx_Math_log10,
306
+ fx_Math_max,
307
+ fx_Math_min,
308
+ fx_Math_mod,
309
+ fx_Math_pow,
310
+ fx_Math_random,
311
+ fx_Math_random_secure,
312
+ fx_Math_round,
313
+ fx_Math_sign,
314
+ fx_Math_sin,
315
+ fx_Math_sinh,
316
+ fx_Math_sqrt,
317
+ fx_Math_tan,
318
+ fx_Math_tanh,
319
+ fx_Math_trunc,
320
+ fx_ModuleSource,
321
+ fx_ModuleSource_prototype_get_bindings,
322
+ fx_ModuleSource_prototype_get_needsImport,
323
+ fx_ModuleSource_prototype_get_needsImportMeta,
324
+ fx_Number_isFinite,
325
+ fx_Number_isInteger,
326
+ fx_Number_isNaN,
327
+ fx_Number_isSafeInteger,
328
+ fx_Number_prototype_toExponential,
329
+ fx_Number_prototype_toFixed,
330
+ fx_Number_prototype_toLocaleString,
331
+ fx_Number_prototype_toPrecision,
332
+ fx_Number_prototype_toString,
333
+ fx_Number_prototype_valueOf,
334
+ fx_Number,
335
+ fx_Object_assign,
336
+ fx_Object_copy,
337
+ fx_Object_create,
338
+ fx_Object_defineProperties,
339
+ fx_Object_defineProperty,
340
+ fx_Object_entries,
341
+ fx_Object_freeze,
342
+ fx_Object_fromEntries,
343
+ fx_Object_getOwnPropertyDescriptor,
344
+ fx_Object_getOwnPropertyDescriptors,
345
+ fx_Object_getOwnPropertyNames,
346
+ fx_Object_getOwnPropertySymbols,
347
+ fx_Object_getPrototypeOf,
348
+ fx_Object_hasOwn,
349
+ fx_Object_is,
350
+ fx_Object_isExtensible,
351
+ fx_Object_isFrozen,
352
+ fx_Object_isSealed,
353
+ fx_Object_keys,
354
+ fx_Object_preventExtensions,
355
+ fx_Object_prototype___defineGetter__,
356
+ fx_Object_prototype___defineSetter__,
357
+ fx_Object_prototype___lookupGetter__,
358
+ fx_Object_prototype___lookupSetter__,
359
+ fx_Object_prototype___proto__get,
360
+ fx_Object_prototype___proto__set,
361
+ fx_Object_prototype_hasOwnProperty,
362
+ fx_Object_prototype_isPrototypeOf,
363
+ fx_Object_prototype_propertyIsEnumerable,
364
+ fx_Object_prototype_toLocaleString,
365
+ fx_Object_prototype_toString,
366
+ fx_Object_prototype_valueOf,
367
+ fx_Object_seal,
368
+ fx_Object_setPrototypeOf,
369
+ fx_Object_values,
370
+ fx_Object,
371
+ fx_parseFloat,
372
+ fx_parseInt,
373
+ fx_Promise_all,
374
+ fx_Promise_allSettled,
375
+ fx_Promise_any,
376
+ fx_Promise_prototype_catch,
377
+ fx_Promise_prototype_finally,
378
+ fx_Promise_prototype_then,
379
+ fx_Promise_race,
380
+ fx_Promise_reject,
381
+ fx_Promise_resolve,
382
+ fx_Promise,
383
+ fx_Proxy_revocable,
384
+ fx_Proxy_revoke,
385
+ fx_Proxy,
386
+ fx_RangeError,
387
+ fx_ReferenceError,
388
+ fx_Reflect_apply,
389
+ fx_Reflect_construct,
390
+ fx_Reflect_defineProperty,
391
+ fx_Reflect_deleteProperty,
392
+ fx_Reflect_get,
393
+ fx_Reflect_getOwnPropertyDescriptor,
394
+ fx_Reflect_getPrototypeOf,
395
+ fx_Reflect_has,
396
+ fx_Reflect_isExtensible,
397
+ fx_Reflect_ownKeys,
398
+ fx_Reflect_preventExtensions,
399
+ fx_Reflect_set,
400
+ fx_Reflect_setPrototypeOf,
401
+ fx_RegExp_prototype_compile,
402
+ fx_RegExp_prototype_exec,
403
+ fx_RegExp_prototype_get_dotAll,
404
+ fx_RegExp_prototype_get_flags,
405
+ fx_RegExp_prototype_get_global,
406
+ fx_RegExp_prototype_get_hasIndices,
407
+ fx_RegExp_prototype_get_ignoreCase,
408
+ fx_RegExp_prototype_get_multiline,
409
+ fx_RegExp_prototype_get_source,
410
+ fx_RegExp_prototype_get_sticky,
411
+ fx_RegExp_prototype_get_unicode,
412
+ fx_RegExp_prototype_match,
413
+ fx_RegExp_prototype_matchAll_next,
414
+ fx_RegExp_prototype_matchAll,
415
+ fx_RegExp_prototype_replace,
416
+ fx_RegExp_prototype_search,
417
+ fx_RegExp_prototype_split,
418
+ fx_RegExp_prototype_test,
419
+ fx_RegExp_prototype_toString,
420
+ fx_RegExp,
421
+ fx_Set_prototype_add,
422
+ fx_Set_prototype_clear,
423
+ fx_Set_prototype_delete,
424
+ fx_Set_prototype_entries,
425
+ fx_Set_prototype_forEach,
426
+ fx_Set_prototype_has,
427
+ fx_Set_prototype_size,
428
+ fx_Set_prototype_values,
429
+ fx_Set,
430
+ fx_SetIterator_prototype_next,
431
+ fx_SharedArrayBuffer_prototype_get_byteLength,
432
+ fx_SharedArrayBuffer_prototype_get_growable,
433
+ fx_SharedArrayBuffer_prototype_get_maxByteLength,
434
+ fx_SharedArrayBuffer_prototype_grow,
435
+ fx_SharedArrayBuffer_prototype_slice,
436
+ fx_SharedArrayBuffer,
437
+ fx_species_get,
438
+ fx_String_fromCharCode,
439
+ fx_String_fromCodePoint,
440
+ fx_String_prototype_at,
441
+ fx_String_prototype_charAt,
442
+ fx_String_prototype_charCodeAt,
443
+ fx_String_prototype_codePointAt,
444
+ fx_String_prototype_compare,
445
+ fx_String_prototype_concat,
446
+ fx_String_prototype_endsWith,
447
+ fx_String_prototype_includes,
448
+ fx_String_prototype_indexOf,
449
+ fx_String_prototype_iterator_next,
450
+ fx_String_prototype_iterator,
451
+ fx_String_prototype_lastIndexOf,
452
+ fx_String_prototype_localeCompare,
453
+ fx_String_prototype_match,
454
+ fx_String_prototype_matchAll,
455
+ fx_String_prototype_normalize,
456
+ fx_String_prototype_padEnd,
457
+ fx_String_prototype_padStart,
458
+ fx_String_prototype_repeat,
459
+ fx_String_prototype_replace,
460
+ fx_String_prototype_replaceAll,
461
+ fx_String_prototype_search,
462
+ fx_String_prototype_slice,
463
+ fx_String_prototype_split,
464
+ fx_String_prototype_startsWith,
465
+ fx_String_prototype_substr,
466
+ fx_String_prototype_substring,
467
+ fx_String_prototype_toLowerCase,
468
+ fx_String_prototype_toUpperCase,
469
+ fx_String_prototype_trim,
470
+ fx_String_prototype_trimEnd,
471
+ fx_String_prototype_trimStart,
472
+ fx_String_prototype_valueOf,
473
+ fx_String_raw,
474
+ fx_String,
475
+ fx_Symbol_for,
476
+ fx_Symbol_keyFor,
477
+ fx_Symbol_prototype_get_description,
478
+ fx_Symbol_prototype_toPrimitive,
479
+ fx_Symbol_prototype_toString,
480
+ fx_Symbol_prototype_valueOf,
481
+ fx_Symbol,
482
+ fx_SyntaxError,
483
+ fx_trace_center,
484
+ fx_trace_left,
485
+ fx_trace_right,
486
+ fx_trace,
487
+ fx_TypedArray_from,
488
+ fx_TypedArray_of,
489
+ fx_TypedArray_prototype_at,
490
+ fx_TypedArray_prototype_buffer_get,
491
+ fx_TypedArray_prototype_byteLength_get,
492
+ fx_TypedArray_prototype_byteOffset_get,
493
+ fx_TypedArray_prototype_copyWithin,
494
+ fx_TypedArray_prototype_entries,
495
+ fx_TypedArray_prototype_every,
496
+ fx_TypedArray_prototype_fill,
497
+ fx_TypedArray_prototype_filter,
498
+ fx_TypedArray_prototype_find,
499
+ fx_TypedArray_prototype_findIndex,
500
+ fx_TypedArray_prototype_findLast,
501
+ fx_TypedArray_prototype_findLastIndex,
502
+ fx_TypedArray_prototype_forEach,
503
+ fx_TypedArray_prototype_includes,
504
+ fx_TypedArray_prototype_indexOf,
505
+ fx_TypedArray_prototype_join,
506
+ fx_TypedArray_prototype_keys,
507
+ fx_TypedArray_prototype_lastIndexOf,
508
+ fx_TypedArray_prototype_length_get,
509
+ fx_TypedArray_prototype_map,
510
+ fx_TypedArray_prototype_reduce,
511
+ fx_TypedArray_prototype_reduceRight,
512
+ fx_TypedArray_prototype_reverse,
513
+ fx_TypedArray_prototype_set,
514
+ fx_TypedArray_prototype_slice,
515
+ fx_TypedArray_prototype_some,
516
+ fx_TypedArray_prototype_sort,
517
+ fx_TypedArray_prototype_subarray,
518
+ fx_TypedArray_prototype_toLocaleString,
519
+ fx_TypedArray_prototype_toStringTag_get,
520
+ fx_TypedArray_prototype_values,
521
+ fx_TypedArray,
522
+ fx_TypeError,
523
+ fx_unescape,
524
+ fx_URIError,
525
+ fx_WeakMap_prototype_delete,
526
+ fx_WeakMap_prototype_get,
527
+ fx_WeakMap_prototype_has,
528
+ fx_WeakMap_prototype_set,
529
+ fx_WeakMap,
530
+ fx_WeakRef_prototype_deref,
531
+ fx_WeakRef,
532
+ fx_WeakSet_prototype_add,
533
+ fx_WeakSet_prototype_delete,
534
+ fx_WeakSet_prototype_has,
535
+ fx_WeakSet,
536
+ fxAsyncGeneratorRejectAwait,
537
+ fxAsyncGeneratorRejectYield,
538
+ fxAsyncGeneratorResolveAwait,
539
+ fxAsyncGeneratorResolveYield,
540
+ fxAsyncFromSyncIteratorDone,
541
+ fxArrayLengthGetter,
542
+ fxArrayLengthSetter,
543
+ fxExecuteModulesFulfilled,
544
+ fxExecuteModulesRejected,
545
+ fxExecuteVirtualModuleSource,
546
+ fxExecuteVirtualModuleSourceImport,
547
+ fxInitializeRegExp,
548
+ fxLoadModulesFulfilled,
549
+ fxLoadModulesRejected,
550
+ fxModuleGetter,
551
+ fxOnRejectedPromise,
552
+ fxOnResolvedPromise,
553
+ fxOnThenable,
554
+ fxOrdinaryToPrimitive,
555
+ fxProxyGetter,
556
+ fxProxySetter,
557
+ fxStringAccessorGetter,
558
+ fxStringAccessorSetter,
559
+ fxThrowTypeError,
560
+ fxTypedArrayGetter,
561
+ fxTypedArraySetter,
562
+ fxCombinePromisesCallback,
563
+ fxNewPromiseCapabilityCallback,
564
+ fxRejectAwait,
565
+ fxRejectPromise,
566
+ fxResolveAwait,
567
+ fxResolvePromise,
568
+ fx_Promise_prototype_finallyAux,
569
+ fx_Promise_prototype_finallyReturn,
570
+ fx_Promise_prototype_finallyThrow,
571
+ };
572
+ extern const txTypeDispatch gxTypeDispatches[];
573
+ extern const txTypeAtomics gxTypeAtomics[];
574
+
575
+ void fxIndexInstance(txMachine* the, txSnapshot* snapshot, txSlot* theCurrent)
576
+ {
577
+ txSlot* aProperty;
578
+ txSlot* aTemporary;
579
+
580
+ mxCheck(the, theCurrent->kind == XS_INSTANCE_KIND);
581
+ aProperty = theCurrent;
582
+ theCurrent->value.instance.garbage = C_NULL;
583
+ for (;;) {
584
+ if (aProperty) {
585
+ if (!(aProperty->flag & XS_MARK_FLAG)) {
586
+ fxIndexSlot(the, snapshot, aProperty);
587
+
588
+ switch (aProperty->kind) {
589
+ case XS_INSTANCE_KIND:
590
+ aTemporary = aProperty->value.instance.prototype;
591
+ if (aTemporary && !(aTemporary->flag & XS_MARK_FLAG)) {
592
+ aProperty->value.instance.prototype = theCurrent;
593
+ theCurrent = aTemporary;
594
+ theCurrent->value.instance.garbage = aProperty;
595
+ aProperty = theCurrent;
596
+ }
597
+ else
598
+ aProperty = aProperty->next;
599
+ break;
600
+ case XS_REFERENCE_KIND:
601
+ aTemporary = aProperty->value.reference;
602
+ if (!(aTemporary->flag & XS_MARK_FLAG)) {
603
+ aProperty->value.reference = theCurrent;
604
+ theCurrent = aTemporary;
605
+ theCurrent->value.instance.garbage = aProperty;
606
+ aProperty = theCurrent;
607
+ }
608
+ else
609
+ aProperty = aProperty->next;
610
+ break;
611
+
612
+ case XS_PROXY_KIND:
613
+ aTemporary = aProperty->value.proxy.handler;
614
+ if (aTemporary && !(aTemporary->flag & XS_MARK_FLAG)) {
615
+ aProperty->flag |= XS_INSPECTOR_FLAG;
616
+ aProperty->value.proxy.handler = theCurrent;
617
+ theCurrent = aTemporary;
618
+ theCurrent->value.instance.garbage = aProperty;
619
+ aProperty = theCurrent;
620
+ }
621
+ else {
622
+ aTemporary = aProperty->value.proxy.target;
623
+ if (aTemporary && !(aTemporary->flag & XS_MARK_FLAG)) {
624
+ aProperty->value.proxy.target = theCurrent;
625
+ theCurrent = aTemporary;
626
+ theCurrent->value.instance.garbage = aProperty;
627
+ aProperty = theCurrent;
628
+ }
629
+ else
630
+ aProperty = aProperty->next;
631
+ }
632
+ break;
633
+
634
+ case XS_CLOSURE_KIND:
635
+ aTemporary = aProperty->value.closure;
636
+ if (aTemporary && !(aTemporary->flag & XS_MARK_FLAG)) {
637
+ fxIndexSlot(the, snapshot, aTemporary);
638
+ if (aTemporary->kind == XS_REFERENCE_KIND) {
639
+ aTemporary = aTemporary->value.reference;
640
+ if (!(aTemporary->flag & XS_MARK_FLAG)) {
641
+ aProperty->value.closure->value.reference = theCurrent;
642
+ theCurrent = aTemporary;
643
+ theCurrent->value.instance.garbage = aProperty;
644
+ aProperty = theCurrent;
645
+
646
+ }
647
+ }
648
+ else {
649
+ fxIndexReference(the, snapshot, aTemporary);
650
+ aProperty = aProperty->next;
651
+ }
652
+ }
653
+ else
654
+ aProperty = aProperty->next;
655
+ break;
656
+
657
+ default:
658
+ fxIndexReference(the, snapshot, aProperty);
659
+ aProperty = aProperty->next;
660
+ break;
661
+ }
662
+ }
663
+ else
664
+ aProperty = aProperty->next;
665
+ }
666
+ else if (theCurrent->value.instance.garbage) {
667
+ aProperty = theCurrent->value.instance.garbage;
668
+ theCurrent->value.instance.garbage = C_NULL;
669
+ switch (aProperty->kind) {
670
+ case XS_INSTANCE_KIND:
671
+ aTemporary = aProperty->value.instance.prototype;
672
+ aProperty->value.instance.prototype = theCurrent;
673
+ theCurrent = aTemporary;
674
+ aProperty = aProperty->next;
675
+ break;
676
+ case XS_REFERENCE_KIND:
677
+ aTemporary = aProperty->value.reference;
678
+ aProperty->value.reference = theCurrent;
679
+ theCurrent = aTemporary;
680
+ aProperty = aProperty->next;
681
+ break;
682
+ case XS_PROXY_KIND:
683
+ if (aProperty->flag & XS_INSPECTOR_FLAG) {
684
+ aProperty->flag &= ~XS_INSPECTOR_FLAG;
685
+ aTemporary = aProperty->value.proxy.handler;
686
+ aProperty->value.proxy.handler = theCurrent;
687
+ theCurrent = aTemporary;
688
+
689
+ aTemporary = aProperty->value.proxy.target;
690
+ if (aTemporary && !(aTemporary->flag & XS_MARK_FLAG)) {
691
+ aProperty->value.proxy.target = theCurrent;
692
+ theCurrent = aTemporary;
693
+ theCurrent->value.instance.garbage = aProperty;
694
+ aProperty = theCurrent;
695
+ }
696
+ else {
697
+ aProperty = aProperty->next;
698
+ }
699
+ }
700
+ else {
701
+ aTemporary = aProperty->value.proxy.target;
702
+ aProperty->value.proxy.target = theCurrent;
703
+ theCurrent = aTemporary;
704
+ aProperty = aProperty->next;
705
+ }
706
+ break;
707
+ case XS_CLOSURE_KIND:
708
+ aTemporary = aProperty->value.closure->value.reference;
709
+ aProperty->value.closure->value.reference = theCurrent;
710
+ theCurrent = aTemporary;
711
+ aProperty = aProperty->next;
712
+ break;
713
+ }
714
+ }
715
+ else
716
+ break;
717
+ }
718
+ }
719
+
720
+ void fxIndexReference(txMachine* the, txSnapshot* snapshot, txSlot* theSlot)
721
+ {
722
+ txSlot* aSlot;
723
+ switch (theSlot->kind) {
724
+ case XS_REFERENCE_KIND:
725
+ aSlot = theSlot->value.reference;
726
+ if (!(aSlot->flag & XS_MARK_FLAG))
727
+ fxIndexInstance(the, snapshot, aSlot);
728
+ break;
729
+ case XS_CLOSURE_KIND:
730
+ aSlot = theSlot->value.closure;
731
+ if (aSlot && (!(aSlot->flag & XS_MARK_FLAG))) {
732
+ fxIndexSlot(the, snapshot, aSlot);
733
+ fxIndexReference(the, snapshot, aSlot);
734
+ }
735
+ break;
736
+ case XS_INSTANCE_KIND:
737
+ if (!(theSlot->flag & XS_MARK_FLAG))
738
+ fxIndexInstance(the, snapshot, theSlot);
739
+ break;
740
+ case XS_ACCESSOR_KIND:
741
+ aSlot = theSlot->value.accessor.getter;
742
+ if (aSlot && !(aSlot->flag & XS_MARK_FLAG))
743
+ fxIndexInstance(the, snapshot, aSlot);
744
+ aSlot = theSlot->value.accessor.setter;
745
+ if (aSlot && !(aSlot->flag & XS_MARK_FLAG))
746
+ fxIndexInstance(the, snapshot, aSlot);
747
+ break;
748
+ case XS_ARGUMENTS_SLOPPY_KIND:
749
+ case XS_ARGUMENTS_STRICT_KIND:
750
+ case XS_ARRAY_KIND:
751
+ case XS_STACK_KIND:
752
+ fxCheckCStack(the);
753
+ if ((aSlot = theSlot->value.array.address)) {
754
+ txIndex aLength = (((txChunk*)(((txByte*)aSlot) - sizeof(txChunk)))->size) / sizeof(txSlot);
755
+ while (aLength) {
756
+ fxIndexReference(the, snapshot, aSlot);
757
+ aSlot++;
758
+ aLength--;
759
+ }
760
+ }
761
+ break;
762
+ case XS_CODE_KIND:
763
+ case XS_CODE_X_KIND:
764
+ aSlot = theSlot->value.code.closures;
765
+ if (aSlot && !(aSlot->flag & XS_MARK_FLAG)) {
766
+ fxCheckCStack(the);
767
+ fxIndexInstance(the, snapshot, aSlot);
768
+ }
769
+ break;
770
+ case XS_HOME_KIND:
771
+ aSlot = theSlot->value.home.object;
772
+ if (aSlot && !(aSlot->flag & XS_MARK_FLAG)) {
773
+ fxCheckCStack(the);
774
+ fxIndexInstance(the, snapshot, aSlot);
775
+ }
776
+ aSlot = theSlot->value.home.module;
777
+ if (aSlot && !(aSlot->flag & XS_MARK_FLAG)) {
778
+ fxCheckCStack(the);
779
+ fxIndexInstance(the, snapshot, aSlot);
780
+ }
781
+ break;
782
+ case XS_MODULE_KIND:
783
+ case XS_PROGRAM_KIND:
784
+ fxCheckCStack(the);
785
+ aSlot = theSlot->value.module.realm;
786
+ if (aSlot && !(aSlot->flag & XS_MARK_FLAG))
787
+ fxIndexInstance(the, snapshot, aSlot);
788
+ break;
789
+ case XS_EXPORT_KIND:
790
+ aSlot = theSlot->value.export.closure;
791
+ if (aSlot && !(aSlot->flag & XS_MARK_FLAG)) {
792
+ fxIndexSlot(the, snapshot, aSlot);
793
+ fxIndexReference(the, snapshot, aSlot);
794
+ }
795
+ aSlot = theSlot->value.export.module;
796
+ if (aSlot && !(aSlot->flag & XS_MARK_FLAG))
797
+ fxIndexInstance(the, snapshot, aSlot);
798
+ break;
799
+ case XS_HOST_KIND:
800
+ // ??
801
+ break;
802
+ case XS_PROXY_KIND:
803
+ aSlot = theSlot->value.proxy.handler;
804
+ if (aSlot && !(aSlot->flag & XS_MARK_FLAG))
805
+ fxIndexInstance(the, snapshot, aSlot);
806
+ aSlot = theSlot->value.proxy.target;
807
+ if (aSlot && !(aSlot->flag & XS_MARK_FLAG))
808
+ fxIndexInstance(the, snapshot, aSlot);
809
+ break;
810
+
811
+ case XS_ERROR_KIND:
812
+ aSlot = theSlot->value.error.info;
813
+ if (aSlot && (!(aSlot->flag & XS_MARK_FLAG)))
814
+ fxIndexInstance(the, snapshot, aSlot);
815
+ break;
816
+ case XS_LIST_KIND:
817
+ aSlot = theSlot->value.list.first;
818
+ while (aSlot) {
819
+ if (!(aSlot->flag & XS_MARK_FLAG)) {
820
+ fxIndexSlot(the, snapshot, aSlot);
821
+ fxIndexReference(the, snapshot, aSlot);
822
+ }
823
+ aSlot = aSlot->next;
824
+ }
825
+ break;
826
+
827
+ case XS_PRIVATE_KIND:
828
+ aSlot = theSlot->value.private.check;
829
+ if (!(aSlot->flag & XS_MARK_FLAG))
830
+ fxIndexInstance(the, snapshot, aSlot);
831
+ aSlot = theSlot->value.private.first;
832
+ while (aSlot) {
833
+ fxIndexSlot(the, snapshot, aSlot);
834
+ fxIndexReference(the, snapshot, aSlot);
835
+ aSlot = aSlot->next;
836
+ }
837
+ break;
838
+
839
+ case XS_WEAK_MAP_KIND:
840
+ case XS_WEAK_SET_KIND:
841
+ aSlot = theSlot->value.weakList.first;
842
+ while (aSlot) {
843
+ if (!(aSlot->flag & XS_MARK_FLAG)) {
844
+ fxIndexSlot(the, snapshot, aSlot);
845
+ fxIndexReference(the, snapshot, aSlot);
846
+ }
847
+ aSlot = aSlot->next;
848
+ }
849
+ break;
850
+ case XS_WEAK_ENTRY_KIND:
851
+ aSlot = theSlot->value.weakEntry.check;
852
+ if (aSlot->flag & XS_MARK_FLAG) {
853
+ aSlot = theSlot->value.weakEntry.value;
854
+ if (!(aSlot->flag & XS_MARK_FLAG)) {
855
+ fxIndexSlot(the, snapshot, aSlot);
856
+ fxIndexReference(the, snapshot, aSlot);
857
+ }
858
+ }
859
+ break;
860
+ case XS_FINALIZATION_REGISTRY_KIND:
861
+ aSlot = theSlot->value.finalizationRegistry.callback;
862
+ if (aSlot) {
863
+ fxIndexSlot(the, snapshot, aSlot);
864
+ fxIndexReference(the, snapshot, aSlot);
865
+ aSlot = aSlot->next;
866
+ while (aSlot) {
867
+ fxIndexSlot(the, snapshot, aSlot);
868
+ fxIndexReference(the, snapshot, aSlot); // holdings
869
+ aSlot = aSlot->next;
870
+ if (aSlot) {
871
+ fxIndexSlot(the, snapshot, aSlot);
872
+ // weak target and token
873
+ aSlot = aSlot->next;
874
+ }
875
+ }
876
+ }
877
+ break;
878
+
879
+ case XS_HOST_INSPECTOR_KIND:
880
+ aSlot = theSlot->value.hostInspector.cache;
881
+ if (!(aSlot->flag & XS_MARK_FLAG))
882
+ fxIndexInstance(the, snapshot, aSlot);
883
+ break;
884
+ }
885
+ }
886
+
887
+ void fxIndexSlot(txMachine* the, txSnapshot* snapshot, txSlot* slot)
888
+ {
889
+ slot->flag |= XS_MARK_FLAG;
890
+ txProjection* projection = snapshot->firstProjection;
891
+ while (projection) {
892
+ txSlot* heap = projection->heap;
893
+ txSlot* limit = projection->limit;
894
+ if ((heap < slot) && (slot < limit)) {
895
+ projection->indexes[slot - heap] = snapshot->slotSize;
896
+ snapshot->slotSize++;
897
+ return;
898
+ }
899
+ projection = projection->nextProjection;
900
+ }
901
+ }
902
+
903
+ void fxIndexSlots(txMachine* the, txSnapshot* snapshot)
904
+ {
905
+ txSlot* heap;
906
+ txSlot* limit;
907
+ txProjection** projectionAddress = &(snapshot->firstProjection);
908
+ txProjection* projection;
909
+ txSlot* slot;
910
+ txSlot** slotAddress;
911
+ txID id;
912
+ size_t* indexAddress;
913
+
914
+ heap = the->firstHeap;
915
+ while (heap) {
916
+ limit = heap->value.reference;
917
+ projection = c_calloc(sizeof(txProjection) + (limit - heap - 1) * sizeof(size_t), 1);
918
+ if (!projection) { snapshot->error = C_ENOMEM; fxJump(the); }
919
+ projection->heap = heap;
920
+ projection->limit = limit;
921
+ *projectionAddress = projection;
922
+ projectionAddress = &projection->nextProjection;
923
+ heap = heap->next;
924
+ }
925
+
926
+ snapshot->slotSize = 1;
927
+ slotAddress = the->keyArray;
928
+ id = the->keyIndex;
929
+ while (id) {
930
+ if ((slot = *slotAddress)) {
931
+ fxIndexSlot(the, snapshot, slot);
932
+ fxIndexReference(the, snapshot, slot);
933
+ }
934
+ slotAddress++;
935
+ id--;
936
+ }
937
+ slot = the->stackTop;
938
+ while (slot > the->stack) {
939
+ slot--;
940
+ fxIndexReference(the, snapshot, slot);
941
+ }
942
+
943
+ snapshot->slots = c_calloc(sizeof(txSlot*) * snapshot->slotSize, 1);
944
+ if (!snapshot->slots) { snapshot->error = C_ENOMEM; fxJump(the); }
945
+ projection = snapshot->firstProjection;
946
+ while (projection) {
947
+ heap = projection->heap;
948
+ limit = projection->limit;
949
+ slot = heap + 1;
950
+ indexAddress = &projection->indexes[1];
951
+ while (slot < limit) {
952
+ if (slot->flag & XS_MARK_FLAG) {
953
+ slot->flag &= ~XS_MARK_FLAG;
954
+ snapshot->slots[*indexAddress] = slot;
955
+ }
956
+ slot++;
957
+ indexAddress++;
958
+ }
959
+ projection = projection->nextProjection;
960
+ }
961
+
962
+ slot = the->stackTop;
963
+ while (slot > the->stack) {
964
+ slot--;
965
+ slot->flag &= ~XS_MARK_FLAG;
966
+ }
967
+ }
968
+
969
+ void fxLinkChunks(txMachine* the)
970
+ {
971
+ txBlock* block = the->firstBlock;
972
+ while (block) {
973
+ txByte* current = ((txByte*)block) + sizeof(txBlock);
974
+ txByte* limit = block->current;
975
+ while (current < limit) {
976
+ txSize size = ((txChunk*)current)->size;
977
+ size &= ~mxChunkFlag;
978
+ ((txChunk*)current)->size = size;
979
+ txByte* next = current + size;
980
+ ((txChunk*)current)->temporary = next;
981
+ current = next;
982
+ }
983
+ block = block->nextBlock;
984
+ }
985
+ }
986
+
987
+ void fxMeasureSlot(txMachine* the, txSnapshot* snapshot, txSlot* slot, txSize* chunkSize)
988
+ {
989
+ switch (slot->kind) {
990
+ case XS_STRING_KIND:
991
+ fxMeasureChunk(the, snapshot, slot->value.string, chunkSize);
992
+ break;
993
+ case XS_BIGINT_KIND:
994
+ fxMeasureChunk(the, snapshot, slot->value.bigint.data, chunkSize);
995
+ break;
996
+ case XS_ARGUMENTS_SLOPPY_KIND:
997
+ case XS_ARGUMENTS_STRICT_KIND:
998
+ case XS_ARRAY_KIND:
999
+ case XS_STACK_KIND:
1000
+ if (slot->value.array.address)
1001
+ fxMeasureChunkArray(the, snapshot, slot->value.array.address, chunkSize);
1002
+ break;
1003
+ case XS_ARRAY_BUFFER_KIND:
1004
+ if (slot->value.arrayBuffer.address)
1005
+ fxMeasureChunk(the, snapshot, slot->value.arrayBuffer.address, chunkSize);
1006
+ break;
1007
+
1008
+ case XS_CODE_KIND:
1009
+ fxMeasureChunk(the, snapshot, slot->value.code.address, chunkSize);
1010
+ break;
1011
+
1012
+ case XS_REGEXP_KIND:
1013
+ if (slot->value.regexp.code)
1014
+ fxMeasureChunk(the, snapshot, slot->value.regexp.code, chunkSize);
1015
+ if (slot->value.regexp.data)
1016
+ fxMeasureChunk(the, snapshot, slot->value.regexp.data, chunkSize);
1017
+ break;
1018
+ case XS_KEY_KIND:
1019
+ if (slot->value.key.string)
1020
+ fxMeasureChunk(the, snapshot, slot->value.key.string, chunkSize);
1021
+ break;
1022
+ case XS_GLOBAL_KIND:
1023
+ case XS_MAP_KIND:
1024
+ case XS_SET_KIND:
1025
+ fxMeasureChunk(the, snapshot, slot->value.table.address, chunkSize);
1026
+ break;
1027
+
1028
+ case XS_HOST_KIND:
1029
+ #if mxMacOSX || mxLinux
1030
+ if (slot->value.host.variant.destructor) {
1031
+ txDestructor destructor;
1032
+ Dl_info info;
1033
+ if (slot->flag & XS_HOST_HOOKS_FLAG)
1034
+ destructor = slot->value.host.variant.hooks->destructor;
1035
+ else
1036
+ destructor = slot->value.host.variant.destructor;
1037
+ if (dladdr(destructor, &info)) {
1038
+ mxAssert(0, "# snapshot: no host destructor: %s!\n", info.dli_sname);
1039
+ }
1040
+ else {
1041
+ mxAssert(0, "# snapshot: no host destructor!\n");
1042
+ }
1043
+ }
1044
+ #else
1045
+ mxAssert(slot->value.host.variant.destructor == C_NULL, "# snapshot: no host destructor!\n");
1046
+ #endif
1047
+ if (slot->value.host.data) {
1048
+ mxAssert(slot->flag & XS_HOST_CHUNK_FLAG, "# snapshot: no host data!\n");
1049
+ fxMeasureChunk(the, snapshot, slot->value.host.data, chunkSize);
1050
+ }
1051
+ break;
1052
+ // case XS_PROMISE_KIND:
1053
+ // mxAssert(slot->value.integer != mxPendingStatus, "# snapshot: no pending promise instances!\n");
1054
+ // break;
1055
+ case XS_STRING_X_KIND:
1056
+ mxAssert(0, "# snapshot: external string %s!\n", slot->value.string);
1057
+ break;
1058
+ }
1059
+ }
1060
+
1061
+ void fxMeasureChunk(txMachine* the, txSnapshot* snapshot, void* address, txSize* chunkSize)
1062
+ {
1063
+ txChunk* chunk = (txChunk*)(((txByte*)(address)) - sizeof(txChunk));
1064
+ if (!(chunk->size & mxChunkFlag)) {
1065
+ chunk->temporary = (txByte*)(*chunkSize + sizeof(txChunk));
1066
+ *chunkSize += chunk->size;
1067
+ chunk->size |= mxChunkFlag;
1068
+ }
1069
+ }
1070
+
1071
+ void fxMeasureChunkArray(txMachine* the, txSnapshot* snapshot, txSlot* address, txSize* chunkSize)
1072
+ {
1073
+ txChunk* chunk = (txChunk*)(((txByte*)(address)) - sizeof(txChunk));
1074
+ if (!(chunk->size & mxChunkFlag)) {
1075
+ txSize size = chunk->size - sizeof(txChunk);
1076
+ chunk->temporary = (txByte*)(*chunkSize + sizeof(txChunk));
1077
+ *chunkSize += chunk->size;
1078
+ chunk->size |= mxChunkFlag;
1079
+ while (size > 0) {
1080
+ fxMeasureSlot(the, snapshot, address, chunkSize);
1081
+ address++;
1082
+ size -= sizeof(txSlot);
1083
+ }
1084
+ }
1085
+ }
1086
+
1087
+ txCallback fxProjectCallback(txMachine* the, txSnapshot* snapshot, txCallback callback)
1088
+ {
1089
+ if (callback) {
1090
+ size_t callbackIndex = 0;
1091
+ txCallback* callbackItem = (txCallback*)(gxCallbacks);
1092
+ while (callbackIndex < mxCallbacksLength) {
1093
+ if (*callbackItem == callback)
1094
+ return (txCallback)callbackIndex;
1095
+ callbackIndex++;
1096
+ callbackItem++;
1097
+ }
1098
+ callbackIndex = 0;
1099
+ callbackItem = snapshot->callbacks;
1100
+ while (callbackIndex < (size_t)snapshot->callbacksLength) {
1101
+ if (*callbackItem == callback)
1102
+ return (txCallback)(mxCallbacksLength + callbackIndex);
1103
+ callbackIndex++;
1104
+ callbackItem++;
1105
+ }
1106
+ {
1107
+ #if mxMacOSX || mxLinux
1108
+ Dl_info info;
1109
+ if (dladdr(callback, &info)) {
1110
+ mxAssert(0, "# snapshot: unknown callback: %s!\n", info.dli_sname);
1111
+ }
1112
+ else
1113
+ #endif
1114
+ mxAssert(0, "# snapshot: unknown callback!\n");
1115
+ }
1116
+ }
1117
+ return C_NULL;
1118
+ }
1119
+
1120
+ void* fxProjectChunk(txMachine* the, void* address)
1121
+ {
1122
+ if (address) {
1123
+ txChunk* chunk = (txChunk*)(((txByte*)(address)) - sizeof(txChunk));
1124
+ return chunk->temporary;
1125
+ }
1126
+ return C_NULL;
1127
+ }
1128
+
1129
+ txSlot* fxProjectSlot(txMachine* the, txProjection* firstProjection, txSlot* slot)
1130
+ {
1131
+ txSlot* address = NULL;
1132
+ if (slot) {
1133
+ txProjection* projection = firstProjection;
1134
+ while (projection) {
1135
+ if ((projection->heap < slot) && (slot < projection->limit)) {
1136
+ address = (txSlot*)(projection->indexes[slot - projection->heap]);
1137
+ break;
1138
+ }
1139
+ projection = projection->nextProjection;
1140
+ }
1141
+ }
1142
+ return address;
1143
+ }
1144
+
1145
+ txTypeDispatch* fxProjectTypeDispatch(txMachine* the, txTypeDispatch* dispatch)
1146
+ {
1147
+ size_t i = 0;
1148
+ while (i < mxTypeArrayCount) {
1149
+ if (dispatch == &gxTypeDispatches[i])
1150
+ return (txTypeDispatch*)i;
1151
+ i++;
1152
+ }
1153
+ fprintf(stderr, "dispatch %p %p\n", dispatch, &gxTypeDispatches[0]);
1154
+ return C_NULL;
1155
+ }
1156
+
1157
+ txTypeAtomics* fxProjectTypeAtomics(txMachine* the, txTypeAtomics* atomics)
1158
+ {
1159
+ size_t i = 0;
1160
+ while (i < mxTypeArrayCount) {
1161
+ if (atomics == &gxTypeAtomics[i])
1162
+ return (txTypeAtomics*)i;
1163
+ i++;
1164
+ }
1165
+ fprintf(stderr, "atomics %p %p\n", atomics, &gxTypeAtomics[0]);
1166
+ return C_NULL;
1167
+ }
1168
+
1169
+ void fxReadAtom(txMachine* the, txSnapshot* snapshot, Atom* atom, txString type)
1170
+ {
1171
+ txString check = (txString)&(atom->atomType);
1172
+ mxThrowIf((*snapshot->read)(snapshot->stream, atom, sizeof(Atom)));
1173
+ atom->atomSize = ntohl(atom->atomSize) - 8;
1174
+ mxAssert((check[0] == type[0]) && (check[1] == type[1]) && (check[2] == type[2]) && (check[3] == type[3]), "snapshot: invalid atom %s\n", type);
1175
+ }
1176
+
1177
+ void fxReadMapSet(txMachine* the, txSlot* table, txBoolean paired)
1178
+ {
1179
+ txSlot* list = table->next;
1180
+ txSlot* key = list->value.list.first;
1181
+ while (key) {
1182
+ txU4 sum = fxSumEntry(the, key);
1183
+ txU4 index = sum & (table->value.table.length - 1);
1184
+ txSlot* entry = fxNewSlot(the);
1185
+ txSlot** address = &(table->value.table.address[index]);
1186
+ entry->next = *address;
1187
+ entry->kind = XS_ENTRY_KIND;
1188
+ entry->value.entry.slot = key;
1189
+ entry->value.entry.sum = sum;
1190
+ *address = entry;
1191
+ key = key->next;
1192
+ if (paired)
1193
+ key = key->next;
1194
+ }
1195
+ }
1196
+
1197
+ txMachine* fxReadSnapshot(txSnapshot* snapshot, txString theName, void* theContext)
1198
+ {
1199
+ Atom atom;
1200
+ txByte byte;
1201
+ txString signature;
1202
+ txCreation creation;
1203
+ txSlot* slot;
1204
+
1205
+ txMachine* the = (txMachine* )c_calloc(sizeof(txMachine), 1);
1206
+ if (the) {
1207
+ txJump aJump;
1208
+ snapshot->error = 0;
1209
+ aJump.nextJump = C_NULL;
1210
+ aJump.stack = C_NULL;
1211
+ aJump.scope = C_NULL;
1212
+ aJump.frame = C_NULL;
1213
+ aJump.code = C_NULL;
1214
+ aJump.flag = 0;
1215
+ the->firstJump = &aJump;
1216
+ if (c_setjmp(aJump.buffer) == 0) {
1217
+ if (gxDefaults.initializeSharedCluster)
1218
+ gxDefaults.initializeSharedCluster();
1219
+
1220
+ the->dtoa = fxNew_dtoa(the);
1221
+ the->context = theContext;
1222
+ fxCreateMachinePlatform(the);
1223
+
1224
+ #ifdef mxDebug
1225
+ the->name = theName;
1226
+ #endif
1227
+
1228
+ fxReadAtom(the, snapshot, &atom, "XS_M");
1229
+ fxReadAtom(the, snapshot, &atom, "VERS");
1230
+ mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1231
+ mxAssert(byte == XS_MAJOR_VERSION, "snapshot: invalid major version %d\n", byte);
1232
+ mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1233
+ mxAssert(byte == XS_MINOR_VERSION, "snapshot: invalid minor version %d\n", byte);
1234
+ mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1235
+ // mxAssert(byte == XS_PATCH_VERSION, "snapshot: invalid patch version %d\n", byte);
1236
+ mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1237
+ #if mxBigEndian
1238
+ mxAssert(byte == -((txByte)sizeof(txSlot)), "snapshot: invalid architecture %d\n", byte);
1239
+ #else
1240
+ mxAssert(byte == (txByte)sizeof(txSlot), "snapshot: invalid architecture %d\n", byte);
1241
+ #endif
1242
+
1243
+ fxReadAtom(the, snapshot, &atom, "SIGN");
1244
+ mxAssert(atom.atomSize == snapshot->signatureLength, "snapshot: invalid signature length %d\n", atom.atomSize);
1245
+ signature = snapshot->signature;
1246
+ while (atom.atomSize) {
1247
+ mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1248
+ mxAssert(byte == *signature, "snapshot: invalid signature byte %d\n", byte);
1249
+ atom.atomSize--;
1250
+ signature++;
1251
+ }
1252
+
1253
+ fxReadAtom(the, snapshot, &atom, "CREA");
1254
+ mxThrowIf((*snapshot->read)(snapshot->stream, &creation, sizeof(txCreation)));
1255
+ fxAllocate(the, &creation);
1256
+ mxThrowIf((*snapshot->read)(snapshot->stream, &(the->profileID), sizeof(txID)));
1257
+ mxThrowIf((*snapshot->read)(snapshot->stream, &(the->tag), sizeof(txInteger)));
1258
+
1259
+ snapshot->firstChunk = the->firstBlock->current;
1260
+ snapshot->firstSlot = the->firstHeap;
1261
+
1262
+ fxReadAtom(the, snapshot, &atom, "BLOC");
1263
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->firstBlock->current, atom.atomSize));
1264
+ the->currentChunksSize = atom.atomSize;
1265
+ the->firstBlock->current += atom.atomSize;
1266
+
1267
+ fxReadAtom(the, snapshot, &atom, "HEAP");
1268
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->freeHeap, atom.atomSize));
1269
+ the->currentHeapCount = (atom.atomSize / sizeof(txSlot));
1270
+ the->freeHeap = the->freeHeap + the->currentHeapCount;
1271
+
1272
+ slot = the->firstHeap + 1;
1273
+ while (slot < the->freeHeap) {
1274
+ fxReadSlot(the, snapshot, slot, 1);
1275
+ slot++;
1276
+ }
1277
+
1278
+ slot = the->firstHeap + 1;
1279
+ while (slot < the->freeHeap) {
1280
+ switch (slot->kind) {
1281
+ case XS_MAP_KIND:
1282
+ fxReadMapSet(the, slot, 1);
1283
+ break;
1284
+ case XS_SET_KIND:
1285
+ fxReadMapSet(the, slot, 0);
1286
+ break;
1287
+ }
1288
+ slot++;
1289
+ }
1290
+
1291
+ fxReadAtom(the, snapshot, &atom, "STAC");
1292
+ the->stack = the->stackTop - (atom.atomSize / sizeof(txSlot));
1293
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->stack, atom.atomSize));
1294
+
1295
+ slot = the->stack;
1296
+ while (slot < the->stackTop) {
1297
+ fxReadSlot(the, snapshot, slot, 0);
1298
+ slot++;
1299
+ }
1300
+
1301
+ fxReadAtom(the, snapshot, &atom, "KEYS");
1302
+ the->keyIndex = atom.atomSize / sizeof(txSlot*);
1303
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->keyArray, atom.atomSize));
1304
+ fxReadSlotTable(the, snapshot, the->keyArray, the->keyIndex);
1305
+
1306
+ fxReadAtom(the, snapshot, &atom, "NAME");
1307
+ the->nameModulo = atom.atomSize / sizeof(txSlot*);
1308
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->nameTable, atom.atomSize));
1309
+ fxReadSlotTable(the, snapshot, the->nameTable, the->nameModulo);
1310
+
1311
+ fxReadAtom(the, snapshot, &atom, "SYMB");
1312
+ the->symbolModulo = atom.atomSize / sizeof(txSlot*);
1313
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->symbolTable, atom.atomSize));
1314
+ fxReadSlotTable(the, snapshot, the->symbolTable, the->symbolModulo);
1315
+
1316
+ slot = &mxDuringJobs;
1317
+ the->collectFlag = XS_COLLECTING_FLAG;
1318
+
1319
+ fxLinkChunks(the);
1320
+
1321
+ #ifdef mxDebug
1322
+ fxLogin(the);
1323
+ #endif
1324
+
1325
+ the->firstJump = C_NULL;
1326
+ }
1327
+ else {
1328
+ fxFree(the);
1329
+ c_free(the);
1330
+ the = NULL;
1331
+
1332
+ if (gxDefaults.terminateSharedCluster)
1333
+ gxDefaults.terminateSharedCluster();
1334
+ }
1335
+ }
1336
+ else {
1337
+ snapshot->error = C_ENOMEM;
1338
+ }
1339
+ return the;
1340
+ }
1341
+
1342
+
1343
+ void fxReadSlot(txMachine* the, txSnapshot* snapshot, txSlot* slot, txFlag flag)
1344
+ {
1345
+ if (flag)
1346
+ slot->next = fxUnprojectSlot(the, snapshot, slot->next);
1347
+ switch (slot->kind) {
1348
+ case XS_STRING_KIND:
1349
+ slot->value.string = (txString)mxUnprojectChunk(slot->value.string);
1350
+ break;
1351
+ case XS_BIGINT_KIND:
1352
+ slot->value.bigint.data = (txU4*)mxUnprojectChunk(slot->value.bigint.data);
1353
+ break;
1354
+ case XS_REFERENCE_KIND:
1355
+ slot->value.reference = fxUnprojectSlot(the, snapshot, slot->value.reference);
1356
+ break;
1357
+ case XS_CLOSURE_KIND:
1358
+ slot->value.closure = fxUnprojectSlot(the, snapshot, slot->value.closure);
1359
+ break;
1360
+ case XS_INSTANCE_KIND:
1361
+ slot->value.instance.prototype = fxUnprojectSlot(the, snapshot, slot->value.instance.prototype);
1362
+ break;
1363
+
1364
+ case XS_ARRAY_KIND:
1365
+ case XS_ARGUMENTS_SLOPPY_KIND:
1366
+ case XS_ARGUMENTS_STRICT_KIND:
1367
+ case XS_STACK_KIND:
1368
+ if (slot->value.array.address) {
1369
+ slot->value.array.address = (txSlot*)mxUnprojectChunk(slot->value.array.address);
1370
+ fxReadSlotArray(the, snapshot, slot->value.array.address, slot->value.array.length);
1371
+ }
1372
+ break;
1373
+ case XS_ARRAY_BUFFER_KIND:
1374
+ if (slot->value.array.address)
1375
+ slot->value.arrayBuffer.address = (txByte*)mxUnprojectChunk(slot->value.arrayBuffer.address);
1376
+ break;
1377
+ case XS_CALLBACK_KIND:
1378
+ slot->value.callback.address = fxUnprojectCallback(the, snapshot, slot->value.callback.address);
1379
+ break;
1380
+ case XS_CODE_KIND:
1381
+ slot->value.code.address = (txByte*)mxUnprojectChunk(slot->value.code.address);
1382
+ slot->value.code.closures = fxUnprojectSlot(the, snapshot, slot->value.code.closures);
1383
+ break;
1384
+ case XS_CODE_X_KIND:
1385
+ slot->value.code.address = (txByte*)gxNoCode;
1386
+ break;
1387
+ case XS_FINALIZATION_CELL_KIND:
1388
+ slot->value.finalizationCell.target = fxUnprojectSlot(the, snapshot, slot->value.finalizationCell.target);
1389
+ slot->value.finalizationCell.token = fxUnprojectSlot(the, snapshot, slot->value.finalizationCell.token);
1390
+ break;
1391
+ case XS_FINALIZATION_REGISTRY_KIND:
1392
+ slot->value.finalizationRegistry.callback = fxUnprojectSlot(the, snapshot, slot->value.finalizationRegistry.callback);
1393
+ break;
1394
+ case XS_TYPED_ARRAY_KIND:
1395
+ slot->value.typedArray.dispatch = (txTypeDispatch*)&gxTypeDispatches[(size_t)slot->value.typedArray.dispatch];
1396
+ slot->value.typedArray.atomics = (txTypeAtomics*)&gxTypeAtomics[(size_t)slot->value.typedArray.atomics];
1397
+ break;
1398
+ case XS_GLOBAL_KIND:
1399
+ case XS_MAP_KIND:
1400
+ case XS_SET_KIND:
1401
+ slot->value.table.address = (txSlot**)mxUnprojectChunk(slot->value.table.address);
1402
+ fxReadSlotTable(the, snapshot, slot->value.table.address, slot->value.table.length);
1403
+ break;
1404
+
1405
+ case XS_WEAK_MAP_KIND:
1406
+ case XS_WEAK_SET_KIND:
1407
+ slot->value.weakList.first = fxUnprojectSlot(the, snapshot, slot->value.weakList.first);
1408
+ slot->value.weakList.link = the->firstWeakListLink;
1409
+ the->firstWeakListLink = slot;
1410
+ break;
1411
+ case XS_WEAK_ENTRY_KIND:
1412
+ slot->value.weakEntry.check = fxUnprojectSlot(the, snapshot, slot->value.weakEntry.check);
1413
+ slot->value.weakEntry.value = fxUnprojectSlot(the, snapshot, slot->value.weakEntry.value);
1414
+ break;
1415
+ case XS_WEAK_REF_KIND:
1416
+ slot->value.weakRef.target = fxUnprojectSlot(the, snapshot, slot->value.weakRef.target);
1417
+ slot->value.weakRef.link = fxUnprojectSlot(the, snapshot, slot->value.weakRef.link);
1418
+ break;
1419
+
1420
+ case XS_MODULE_KIND:
1421
+ case XS_PROGRAM_KIND:
1422
+ case XS_MODULE_SOURCE_KIND:
1423
+ slot->value.module.realm = fxUnprojectSlot(the, snapshot, slot->value.module.realm);
1424
+ break;
1425
+
1426
+ case XS_PROXY_KIND:
1427
+ slot->value.proxy.handler = fxUnprojectSlot(the, snapshot, slot->value.proxy.handler);
1428
+ slot->value.proxy.target = fxUnprojectSlot(the, snapshot, slot->value.proxy.target);
1429
+ break;
1430
+ case XS_REGEXP_KIND:
1431
+ if (slot->value.regexp.code)
1432
+ slot->value.regexp.code = (void*)mxUnprojectChunk(slot->value.regexp.code);
1433
+ if (slot->value.regexp.data)
1434
+ slot->value.regexp.data = (void*)mxUnprojectChunk(slot->value.regexp.data);
1435
+ break;
1436
+
1437
+ case XS_ACCESSOR_KIND:
1438
+ slot->value.accessor.getter = fxUnprojectSlot(the, snapshot, slot->value.accessor.getter);
1439
+ slot->value.accessor.setter = fxUnprojectSlot(the, snapshot, slot->value.accessor.setter);
1440
+ break;
1441
+ case XS_ENTRY_KIND:
1442
+ slot->value.entry.slot = fxUnprojectSlot(the, snapshot, slot->value.entry.slot);
1443
+ break;
1444
+ case XS_ERROR_KIND:
1445
+ slot->value.error.info = fxUnprojectSlot(the, snapshot, slot->value.error.info);
1446
+ break;
1447
+ case XS_HOME_KIND:
1448
+ slot->value.home.object = fxUnprojectSlot(the, snapshot, slot->value.home.object);
1449
+ slot->value.home.module = fxUnprojectSlot(the, snapshot, slot->value.home.module);
1450
+ break;
1451
+ case XS_KEY_KIND:
1452
+ if (slot->value.key.string)
1453
+ slot->value.key.string = (txString)mxUnprojectChunk(slot->value.key.string);
1454
+ break;
1455
+ case XS_LIST_KIND:
1456
+ slot->value.list.first = fxUnprojectSlot(the, snapshot, slot->value.list.first);
1457
+ slot->value.list.last = fxUnprojectSlot(the, snapshot, slot->value.list.last);
1458
+ break;
1459
+ case XS_PRIVATE_KIND:
1460
+ slot->value.private.check = fxUnprojectSlot(the, snapshot, slot->value.private.check);
1461
+ slot->value.private.first = fxUnprojectSlot(the, snapshot, slot->value.private.first);
1462
+ break;
1463
+ case XS_EXPORT_KIND:
1464
+ slot->value.export.closure = fxUnprojectSlot(the, snapshot, slot->value.export.closure);
1465
+ slot->value.export.module = fxUnprojectSlot(the, snapshot, slot->value.export.module);
1466
+ break;
1467
+
1468
+ case XS_HOST_KIND:
1469
+ if (slot->value.host.data)
1470
+ slot->value.host.data = (txByte*)mxUnprojectChunk(slot->value.host.data);
1471
+ break;
1472
+ }
1473
+ }
1474
+
1475
+ void fxReadSlotArray(txMachine* the, txSnapshot* snapshot, txSlot* address, txSize length)
1476
+ {
1477
+ txChunk* chunk = (txChunk*)(((txByte*)(address)) - sizeof(txChunk));
1478
+ txSize size = chunk->size - sizeof(txChunk);
1479
+ while (size > 0) {
1480
+ fxReadSlot(the, snapshot, address, 0);
1481
+ address++;
1482
+ size -= sizeof(txSlot);
1483
+ }
1484
+ }
1485
+
1486
+ void fxReadSlotTable(txMachine* the, txSnapshot* snapshot, txSlot** address, txSize length)
1487
+ {
1488
+ while (length > 0) {
1489
+ *address = fxUnprojectSlot(the, snapshot, *address);
1490
+ address++;
1491
+ length--;
1492
+ }
1493
+ }
1494
+
1495
+ void fxUnlinkChunks(txMachine* the)
1496
+ {
1497
+ txBlock* block = the->firstBlock;
1498
+ while (block) {
1499
+ txByte* current = ((txByte*)block) + sizeof(txBlock);
1500
+ txByte* limit = block->current;
1501
+ while (current < limit) {
1502
+ txSize size = ((txChunk*)current)->size;
1503
+ txByte* next = current + size;
1504
+ ((txChunk*)current)->temporary = C_NULL;
1505
+ current = next;
1506
+ }
1507
+ block = block->nextBlock;
1508
+ }
1509
+ }
1510
+
1511
+ txCallback fxUnprojectCallback(txMachine* the, txSnapshot* snapshot, txCallback callback)
1512
+ {
1513
+ size_t callbackIndex = (size_t)callback;
1514
+ if (callbackIndex < mxCallbacksLength)
1515
+ return gxCallbacks[callbackIndex];
1516
+ callbackIndex -= mxCallbacksLength;
1517
+ if (callbackIndex < (size_t)snapshot->callbacksLength)
1518
+ return snapshot->callbacks[callbackIndex];
1519
+ mxAssert(0, "# snapshot: unknown callback!\n");
1520
+ return C_NULL;
1521
+ }
1522
+
1523
+ txSlot* fxUnprojectSlot(txMachine* the, txSnapshot* snapshot, txSlot* slot)
1524
+ {
1525
+ if (slot)
1526
+ slot = snapshot->firstSlot + ((size_t)slot);
1527
+ return slot;
1528
+ }
1529
+
1530
+ int fxUseSnapshot(txMachine* the, txSnapshot* snapshot)
1531
+ {
1532
+ Atom atom;
1533
+ txByte byte;
1534
+ txCreation creation;
1535
+ txID profileID;
1536
+ txInteger tag;
1537
+ txByte* buffer;
1538
+ txSize size;
1539
+ txSlot* slot;
1540
+ mxTry(the) {
1541
+ snapshot->error = 0;
1542
+
1543
+ fxReadAtom(the, snapshot, &atom, "XS_M");
1544
+ fxReadAtom(the, snapshot, &atom, "VERS");
1545
+ mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1546
+ mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1547
+ mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1548
+ mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1549
+ fxReadAtom(the, snapshot, &atom, "SIGN");
1550
+ while (atom.atomSize) {
1551
+ mxThrowIf((*snapshot->read)(snapshot->stream, &byte, 1));
1552
+ atom.atomSize--;
1553
+ }
1554
+ fxReadAtom(the, snapshot, &atom, "CREA");
1555
+ mxThrowIf((*snapshot->read)(snapshot->stream, &creation, sizeof(txCreation)));
1556
+ mxThrowIf((*snapshot->read)(snapshot->stream, &profileID, sizeof(txID)));
1557
+ mxThrowIf((*snapshot->read)(snapshot->stream, &tag, sizeof(txInteger)));
1558
+
1559
+ buffer = (txByte*)the->firstBlock;
1560
+ size = the->firstBlock->limit - buffer;
1561
+ c_memset(buffer, 0, size);
1562
+ the->firstBlock->current = buffer + sizeof(txBlock);
1563
+ the->firstBlock->limit = buffer + size;
1564
+
1565
+ the->freeHeap = slot = the->firstHeap + 1;
1566
+ size = the->maximumHeapCount - 1;
1567
+ while (size--) {
1568
+ txSlot* next = slot + 1;
1569
+ slot->next = next;
1570
+ slot->flag = XS_NO_FLAG;
1571
+ slot->kind = XS_UNDEFINED_KIND;
1572
+ slot = next;
1573
+ }
1574
+ slot->next = C_NULL;
1575
+ slot->flag = XS_NO_FLAG;
1576
+ slot->kind = XS_UNDEFINED_KIND;
1577
+ the->firstWeakListLink = C_NULL;
1578
+
1579
+ snapshot->firstChunk = the->firstBlock->current;
1580
+ snapshot->firstSlot = the->firstHeap;
1581
+
1582
+ fxReadAtom(the, snapshot, &atom, "BLOC");
1583
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->firstBlock->current, atom.atomSize));
1584
+ the->currentChunksSize = atom.atomSize;
1585
+ the->firstBlock->current += atom.atomSize;
1586
+
1587
+ fxReadAtom(the, snapshot, &atom, "HEAP");
1588
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->freeHeap, atom.atomSize));
1589
+ the->currentHeapCount = (atom.atomSize / sizeof(txSlot));
1590
+ the->freeHeap = the->freeHeap + the->currentHeapCount;
1591
+
1592
+ slot = the->firstHeap + 1;
1593
+ while (slot < the->freeHeap) {
1594
+ fxReadSlot(the, snapshot, slot, 1);
1595
+ slot++;
1596
+ }
1597
+
1598
+ slot = the->firstHeap + 1;
1599
+ while (slot < the->freeHeap) {
1600
+ switch (slot->kind) {
1601
+ case XS_MAP_KIND:
1602
+ fxReadMapSet(the, slot, 1);
1603
+ break;
1604
+ case XS_SET_KIND:
1605
+ fxReadMapSet(the, slot, 0);
1606
+ break;
1607
+ }
1608
+ slot++;
1609
+ }
1610
+
1611
+ fxReadAtom(the, snapshot, &atom, "STAC");
1612
+ the->stack = the->stackTop - (atom.atomSize / sizeof(txSlot));
1613
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->stack, atom.atomSize));
1614
+
1615
+ slot = the->stack;
1616
+ while (slot < the->stackTop) {
1617
+ fxReadSlot(the, snapshot, slot, 0);
1618
+ slot++;
1619
+ }
1620
+
1621
+ fxReadAtom(the, snapshot, &atom, "KEYS");
1622
+ the->keyIndex = atom.atomSize / sizeof(txSlot*);
1623
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->keyArray, atom.atomSize));
1624
+ fxReadSlotTable(the, snapshot, the->keyArray, the->keyIndex);
1625
+
1626
+ fxReadAtom(the, snapshot, &atom, "NAME");
1627
+ the->nameModulo = atom.atomSize / sizeof(txSlot*);
1628
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->nameTable, atom.atomSize));
1629
+ fxReadSlotTable(the, snapshot, the->nameTable, the->nameModulo);
1630
+
1631
+ fxReadAtom(the, snapshot, &atom, "SYMB");
1632
+ the->symbolModulo = atom.atomSize / sizeof(txSlot*);
1633
+ mxThrowIf((*snapshot->read)(snapshot->stream, the->symbolTable, atom.atomSize));
1634
+ fxReadSlotTable(the, snapshot, the->symbolTable, the->symbolModulo);
1635
+
1636
+ fxLinkChunks(the);
1637
+ }
1638
+ mxCatch(the) {
1639
+
1640
+ }
1641
+ return (snapshot->error) ? 0 : 1;
1642
+ }
1643
+
1644
+ void fxWriteChunk(txMachine* the, txSnapshot* snapshot, txSlot* slot)
1645
+ {
1646
+ switch (slot->kind) {
1647
+ case XS_STRING_KIND:
1648
+ fxWriteChunkData(the, snapshot, slot->value.string);
1649
+ break;
1650
+ case XS_BIGINT_KIND:
1651
+ fxWriteChunkBigInt(the, snapshot, slot->value.bigint.data, slot->value.bigint.size);
1652
+ break;
1653
+ case XS_ARGUMENTS_SLOPPY_KIND:
1654
+ case XS_ARGUMENTS_STRICT_KIND:
1655
+ case XS_ARRAY_KIND:
1656
+ if (slot->value.array.address)
1657
+ fxWriteChunkArray(the, snapshot, slot->value.array.address, slot->value.array.length, 2);
1658
+ break;
1659
+ case XS_STACK_KIND:
1660
+ if (slot->value.array.address)
1661
+ fxWriteChunkArray(the, snapshot, slot->value.array.address, slot->value.array.length, 0);
1662
+ break;
1663
+ case XS_ARRAY_BUFFER_KIND:
1664
+ if (slot->value.arrayBuffer.address)
1665
+ fxWriteChunkData(the, snapshot, slot->value.arrayBuffer.address);
1666
+ break;
1667
+
1668
+ case XS_CODE_KIND:
1669
+ fxWriteChunkData(the, snapshot, slot->value.code.address);
1670
+ break;
1671
+
1672
+ case XS_REGEXP_KIND:
1673
+ if (slot->value.regexp.code)
1674
+ fxWriteChunkData(the, snapshot, slot->value.regexp.code);
1675
+ if (slot->value.regexp.data)
1676
+ fxWriteChunkData(the, snapshot, slot->value.regexp.data);
1677
+ break;
1678
+ case XS_KEY_KIND:
1679
+ if (slot->value.key.string)
1680
+ fxWriteChunkData(the, snapshot, slot->value.key.string);
1681
+ break;
1682
+ case XS_GLOBAL_KIND:
1683
+ case XS_MAP_KIND:
1684
+ case XS_SET_KIND:
1685
+ fxWriteChunkTable(the, snapshot, slot->value.table.address, slot->value.table.length);
1686
+ break;
1687
+
1688
+ case XS_HOST_KIND:
1689
+ if (slot->value.host.data)
1690
+ fxWriteChunkData(the, snapshot, slot->value.host.data);
1691
+ break;
1692
+ }
1693
+ }
1694
+
1695
+ void fxWriteChunkArray(txMachine* the, txSnapshot* snapshot, txSlot* address, txSize length, txFlag flag)
1696
+ {
1697
+ txChunk* chunk = (txChunk*)(((txByte*)(address)) - sizeof(txChunk));
1698
+ if (chunk->size & mxChunkFlag) {
1699
+ txByte* temporary = chunk->temporary;
1700
+ chunk->size &= ~mxChunkFlag;
1701
+ chunk->temporary = C_NULL;
1702
+ txSize size;
1703
+ mxThrowIf((*snapshot->write)(snapshot->stream, chunk, sizeof(txChunk)));
1704
+ chunk->temporary = temporary;
1705
+ size = chunk->size - sizeof(txChunk);
1706
+ while (size > 0) {
1707
+ fxWriteSlot(the, snapshot, address, flag);
1708
+ address++;
1709
+ size -= sizeof(txSlot);
1710
+ }
1711
+ address = (txSlot*)(((txByte*)(chunk)) + sizeof(txChunk));
1712
+ size = chunk->size - sizeof(txChunk);
1713
+ while (size > 0) {
1714
+ fxWriteChunk(the, snapshot, address);
1715
+ address++;
1716
+ size -= sizeof(txSlot);
1717
+ }
1718
+ }
1719
+ }
1720
+
1721
+ void fxWriteChunkBigInt(txMachine* the, txSnapshot* snapshot, void* address, txSize size)
1722
+ {
1723
+ txChunk* chunk = (txChunk*)(((txByte*)(address)) - sizeof(txChunk));
1724
+ if (chunk->size & mxChunkFlag) {
1725
+ txByte* temporary = chunk->temporary;
1726
+ size <<= 2;
1727
+ chunk->size &= ~mxChunkFlag;
1728
+ chunk->temporary = C_NULL;
1729
+ mxThrowIf((*snapshot->write)(snapshot->stream, chunk, sizeof(txChunk) + size));
1730
+ chunk->temporary = temporary;
1731
+ fxWriteChunkZero(the, snapshot, chunk->size - sizeof(txChunk) - size);
1732
+ }
1733
+ }
1734
+
1735
+ void fxWriteChunkData(txMachine* the, txSnapshot* snapshot, void* address)
1736
+ {
1737
+ txChunk* chunk = (txChunk*)(((txByte*)(address)) - sizeof(txChunk));
1738
+ if (chunk->size & mxChunkFlag) {
1739
+ txByte* temporary = chunk->temporary;
1740
+ chunk->size &= ~mxChunkFlag;
1741
+ chunk->temporary = C_NULL;
1742
+ mxThrowIf((*snapshot->write)(snapshot->stream, chunk, chunk->size));
1743
+ chunk->temporary = temporary;
1744
+ }
1745
+ }
1746
+
1747
+ void fxWriteChunkTable(txMachine* the, txSnapshot* snapshot, txSlot** address, txSize length)
1748
+ {
1749
+ txChunk* chunk = (txChunk*)(((txByte*)(address)) - sizeof(txChunk));
1750
+ if (chunk->size & mxChunkFlag) {
1751
+ txByte* temporary = chunk->temporary;
1752
+ chunk->size &= ~mxChunkFlag;
1753
+ chunk->temporary = C_NULL;
1754
+ mxThrowIf((*snapshot->write)(snapshot->stream, chunk, sizeof(txChunk)));
1755
+ chunk->temporary = temporary;
1756
+ fxWriteSlotTable(the, snapshot, address, length);
1757
+ fxWriteChunkZero(the, snapshot, chunk->size - sizeof(txChunk) - (length * sizeof(txSlot*)));
1758
+ }
1759
+ }
1760
+
1761
+ void fxWriteChunkZero(txMachine* the, txSnapshot* snapshot, txSize size)
1762
+ {
1763
+ txByte zero = 0;
1764
+ while (size > 0) {
1765
+ mxThrowIf((*snapshot->write)(snapshot->stream, &zero, sizeof(txByte)));
1766
+ size--;
1767
+ }
1768
+ }
1769
+
1770
+ void fxWriteChunks(txMachine* the, txSnapshot* snapshot)
1771
+ {
1772
+ size_t slotSize = snapshot->slotSize;
1773
+ txSlot** slots = snapshot->slots;
1774
+ txSlot* stack = the->stackTop - 1;
1775
+ while (stack >= the->stack) {
1776
+ fxWriteChunk(the, snapshot, stack);
1777
+ stack--;
1778
+ }
1779
+ slotSize--;
1780
+ slots++;
1781
+ while (slotSize) {
1782
+ txSlot* slot = *slots;
1783
+ fxWriteChunk(the, snapshot, slot);
1784
+ slotSize--;
1785
+ slots++;
1786
+ }
1787
+ }
1788
+
1789
+ void fxWriteSlot(txMachine* the, txSnapshot* snapshot, txSlot* slot, txFlag flag)
1790
+ {
1791
+ txSlot buffer;
1792
+ c_memset(&buffer, 0, sizeof(buffer));
1793
+ if (flag == 1)
1794
+ buffer.next = fxProjectSlot(the, snapshot->firstProjection, slot->next);
1795
+ else if (flag == 2)
1796
+ *((txIndex*)&buffer) = *((txIndex*)slot);
1797
+ buffer.ID = slot->ID;
1798
+ buffer.flag = slot->flag;
1799
+ buffer.kind = slot->kind;
1800
+ switch (slot->kind) {
1801
+ case XS_UNINITIALIZED_KIND:
1802
+ case XS_UNDEFINED_KIND:
1803
+ case XS_NULL_KIND:
1804
+ break;
1805
+ case XS_BOOLEAN_KIND:
1806
+ buffer.value.boolean = slot->value.boolean;
1807
+ break;
1808
+ case XS_INTEGER_KIND:
1809
+ buffer.value.integer = slot->value.integer;
1810
+ break;
1811
+ case XS_NUMBER_KIND:
1812
+ buffer.value.number = slot->value.number;
1813
+ break;
1814
+ case XS_STRING_KIND:
1815
+ buffer.value.string = (txString)fxProjectChunk(the, slot->value.string);
1816
+ break;
1817
+ case XS_SYMBOL_KIND:
1818
+ buffer.value.symbol = slot->value.symbol;
1819
+ break;
1820
+ case XS_BIGINT_KIND:
1821
+ buffer.value.bigint.data = (txU4*)fxProjectChunk(the, slot->value.bigint.data);
1822
+ buffer.value.bigint.size = slot->value.bigint.size;
1823
+ buffer.value.bigint.sign = slot->value.bigint.sign;
1824
+ break;
1825
+ case XS_REFERENCE_KIND:
1826
+ buffer.value.reference = fxProjectSlot(the, snapshot->firstProjection, slot->value.reference);
1827
+ break;
1828
+ case XS_CLOSURE_KIND:
1829
+ buffer.value.closure = fxProjectSlot(the, snapshot->firstProjection, slot->value.closure);
1830
+ break;
1831
+ case XS_INSTANCE_KIND:
1832
+ buffer.value.instance.prototype = fxProjectSlot(the, snapshot->firstProjection, slot->value.instance.prototype);
1833
+ break;
1834
+
1835
+ case XS_ARRAY_KIND:
1836
+ case XS_ARGUMENTS_SLOPPY_KIND:
1837
+ case XS_ARGUMENTS_STRICT_KIND:
1838
+ case XS_STACK_KIND:
1839
+ buffer.value.array.address = (txSlot*)fxProjectChunk(the, slot->value.array.address);
1840
+ buffer.value.array.length = slot->value.array.length;
1841
+ break;
1842
+ case XS_ARRAY_BUFFER_KIND:
1843
+ buffer.value.arrayBuffer.address = (txByte*)fxProjectChunk(the, slot->value.arrayBuffer.address);
1844
+ break;
1845
+ case XS_BUFFER_INFO_KIND:
1846
+ buffer.value.bufferInfo.length = slot->value.bufferInfo.length;
1847
+ buffer.value.bufferInfo.maxLength = slot->value.bufferInfo.maxLength;
1848
+ break;
1849
+ case XS_CALLBACK_KIND:
1850
+ buffer.value.callback.address = fxProjectCallback(the, snapshot, slot->value.callback.address);
1851
+ break;
1852
+ case XS_CODE_KIND:
1853
+ buffer.value.code.address = (txByte*)fxProjectChunk(the, slot->value.code.address);
1854
+ buffer.value.code.closures = fxProjectSlot(the, snapshot->firstProjection, slot->value.code.closures);
1855
+ break;
1856
+ case XS_CODE_X_KIND:
1857
+ break;
1858
+ case XS_DATE_KIND:
1859
+ buffer.value.number = slot->value.number;
1860
+ break;
1861
+ case XS_DATA_VIEW_KIND:
1862
+ buffer.value.dataView.offset = slot->value.dataView.offset;
1863
+ buffer.value.dataView.size = slot->value.dataView.size;
1864
+ break;
1865
+ case XS_FINALIZATION_CELL_KIND:
1866
+ buffer.value.finalizationCell.target = fxProjectSlot(the, snapshot->firstProjection, slot->value.finalizationCell.target);
1867
+ buffer.value.finalizationCell.token = fxProjectSlot(the, snapshot->firstProjection, slot->value.finalizationCell.token);
1868
+ break;
1869
+ case XS_FINALIZATION_REGISTRY_KIND:
1870
+ buffer.value.finalizationRegistry.callback = fxProjectSlot(the, snapshot->firstProjection, slot->value.finalizationRegistry.callback);
1871
+ buffer.value.finalizationRegistry.flags = slot->value.finalizationRegistry.flags;
1872
+ break;
1873
+ case XS_TYPED_ARRAY_KIND:
1874
+ buffer.value.typedArray.dispatch = fxProjectTypeDispatch(the, slot->value.typedArray.dispatch);
1875
+ buffer.value.typedArray.atomics = fxProjectTypeAtomics(the, slot->value.typedArray.atomics);
1876
+ break;
1877
+ case XS_GLOBAL_KIND:
1878
+ case XS_MAP_KIND:
1879
+ case XS_SET_KIND:
1880
+ buffer.value.table.address = (txSlot**)fxProjectChunk(the, slot->value.table.address);
1881
+ buffer.value.table.length = slot->value.table.length;
1882
+ break;
1883
+
1884
+ case XS_WEAK_MAP_KIND:
1885
+ case XS_WEAK_SET_KIND:
1886
+ buffer.value.weakList.first = fxProjectSlot(the, snapshot->firstProjection, slot->value.weakList.first);
1887
+ buffer.value.weakList.link = C_NULL;
1888
+ break;
1889
+ case XS_WEAK_ENTRY_KIND:
1890
+ buffer.value.weakEntry.check = fxProjectSlot(the, snapshot->firstProjection, slot->value.weakEntry.check);
1891
+ buffer.value.weakEntry.value = fxProjectSlot(the, snapshot->firstProjection, slot->value.weakEntry.value);
1892
+ break;
1893
+ case XS_WEAK_REF_KIND:
1894
+ buffer.value.weakRef.target = fxProjectSlot(the, snapshot->firstProjection, slot->value.weakRef.target);
1895
+ buffer.value.weakRef.link = fxProjectSlot(the, snapshot->firstProjection, slot->value.weakRef.link);
1896
+ break;
1897
+
1898
+ case XS_MODULE_KIND:
1899
+ case XS_PROGRAM_KIND:
1900
+ case XS_MODULE_SOURCE_KIND:
1901
+ buffer.value.module.realm = fxProjectSlot(the, snapshot->firstProjection, slot->value.module.realm);
1902
+ buffer.value.module.id = slot->value.module.id;
1903
+ break;
1904
+
1905
+ case XS_PROMISE_KIND:
1906
+ buffer.value.integer = slot->value.integer;
1907
+ break;
1908
+ case XS_PROXY_KIND:
1909
+ buffer.value.proxy.handler = fxProjectSlot(the, snapshot->firstProjection, slot->value.proxy.handler);
1910
+ buffer.value.proxy.target = fxProjectSlot(the, snapshot->firstProjection, slot->value.proxy.target);
1911
+ break;
1912
+ case XS_REGEXP_KIND:
1913
+ buffer.value.regexp.code = (void*)fxProjectChunk(the, slot->value.regexp.code);
1914
+ buffer.value.regexp.data = (void*)fxProjectChunk(the, slot->value.regexp.data);
1915
+ break;
1916
+
1917
+ case XS_ACCESSOR_KIND:
1918
+ buffer.value.accessor.getter = fxProjectSlot(the, snapshot->firstProjection, slot->value.accessor.getter);
1919
+ buffer.value.accessor.setter = fxProjectSlot(the, snapshot->firstProjection, slot->value.accessor.setter);
1920
+ break;
1921
+ case XS_AT_KIND:
1922
+ buffer.value.at.index = slot->value.at.index;
1923
+ buffer.value.at.id = slot->value.at.id;
1924
+ break;
1925
+ case XS_ENTRY_KIND:
1926
+ buffer.value.entry.slot = fxProjectSlot(the, snapshot->firstProjection, slot->value.entry.slot);
1927
+ buffer.value.entry.sum = slot->value.entry.sum;
1928
+ break;
1929
+ case XS_ERROR_KIND:
1930
+ buffer.value.error.info = fxProjectSlot(the, snapshot->firstProjection, slot->value.error.info);
1931
+ buffer.value.error.which = slot->value.error.which;
1932
+ break;
1933
+ case XS_HOME_KIND:
1934
+ buffer.value.home.object = fxProjectSlot(the, snapshot->firstProjection, slot->value.home.object);
1935
+ buffer.value.home.module = fxProjectSlot(the, snapshot->firstProjection, slot->value.home.module);
1936
+ break;
1937
+ case XS_KEY_KIND:
1938
+ case XS_KEY_X_KIND:
1939
+ buffer.value.key.string = (txString)fxProjectChunk(the, slot->value.key.string);
1940
+ buffer.value.key.sum = slot->value.key.sum;
1941
+ break;
1942
+ case XS_LIST_KIND:
1943
+ buffer.value.list.first = fxProjectSlot(the, snapshot->firstProjection, slot->value.list.first);
1944
+ buffer.value.list.last = fxProjectSlot(the, snapshot->firstProjection, slot->value.list.last);
1945
+ break;
1946
+ case XS_PRIVATE_KIND:
1947
+ buffer.value.private.check = fxProjectSlot(the, snapshot->firstProjection, slot->value.private.check);
1948
+ buffer.value.private.first = fxProjectSlot(the, snapshot->firstProjection, slot->value.private.first);
1949
+ break;
1950
+ case XS_EXPORT_KIND:
1951
+ buffer.value.export.closure = fxProjectSlot(the, snapshot->firstProjection, slot->value.export.closure);
1952
+ buffer.value.export.module = fxProjectSlot(the, snapshot->firstProjection, slot->value.export.module);
1953
+ break;
1954
+ case XS_FRAME_KIND:
1955
+ buffer.next = C_NULL;
1956
+ break;
1957
+
1958
+ case XS_HOST_KIND:
1959
+ buffer.value.host.data = fxProjectChunk(the, slot->value.host.data);
1960
+ buffer.value.host.variant.destructor = C_NULL;
1961
+ break;
1962
+ default:
1963
+ fxReport(the, "# snapshot: invalid slot %d!\n", slot->kind);
1964
+ break;
1965
+ }
1966
+ mxThrowIf((*snapshot->write)(snapshot->stream, &buffer, sizeof(buffer)));
1967
+ }
1968
+
1969
+ void fxWriteSlotTable(txMachine* the, txSnapshot* snapshot, txSlot** address, txSize length)
1970
+ {
1971
+ while (length > 0) {
1972
+ txSlot* buffer = fxProjectSlot(the, snapshot->firstProjection, *address);
1973
+ mxThrowIf((*snapshot->write)(snapshot->stream, &buffer, sizeof(txSlot*)));
1974
+ address++;
1975
+ length--;
1976
+ }
1977
+ }
1978
+
1979
+ void fxWriteSlots(txMachine* the, txSnapshot* snapshot)
1980
+ {
1981
+ size_t slotSize = snapshot->slotSize;
1982
+ txSlot** slots = snapshot->slots;
1983
+ slotSize--;
1984
+ slots++;
1985
+ while (slotSize) {
1986
+ txSlot* slot = *slots;
1987
+ fxWriteSlot(the, snapshot, slot, 1);
1988
+ slotSize--;
1989
+ slots++;
1990
+ }
1991
+ }
1992
+
1993
+ void fxWriteStack(txMachine* the, txSnapshot* snapshot)
1994
+ {
1995
+ txSlot* slot = the->stack;
1996
+ while (slot < the->stackTop) {
1997
+ fxWriteSlot(the, snapshot, slot, 0);
1998
+ slot++;
1999
+ }
2000
+ }
2001
+
2002
+ int fxWriteSnapshot(txMachine* the, txSnapshot* snapshot)
2003
+ {
2004
+ txSlot* heap;
2005
+ txSlot* stack;
2006
+ txSlot** slots;
2007
+ txSize size;
2008
+ txByte byte;
2009
+ txProjection** projectionAddress = &(snapshot->firstProjection);
2010
+ txProjection* projection;
2011
+ txSize chunkSize = 0;
2012
+ txSize namesSize = the->nameModulo * sizeof(txSlot*);
2013
+ txSize keysSize = the->keyIndex * sizeof(txSlot*);
2014
+ txSize slotSize = 0;
2015
+ txSize stackSize = (txSize)((the->stackTop - the->stack) * sizeof(txSlot));
2016
+ txSize symbolsSize = the->symbolModulo * sizeof(txSlot*);
2017
+ txCreation creation;
2018
+
2019
+ mxTry(the) {
2020
+ snapshot->error = 0;
2021
+ fxCollectGarbage(the);
2022
+ fxUnlinkChunks(the);
2023
+
2024
+ fxIndexSlots(the, snapshot);
2025
+
2026
+ stack = the->stackTop - 1;
2027
+ while (stack >= the->stack) {
2028
+ fxMeasureSlot(the, snapshot, stack, &chunkSize);
2029
+ stack--;
2030
+ }
2031
+ slotSize = snapshot->slotSize;
2032
+ slots = snapshot->slots;
2033
+ slotSize--;
2034
+ slots++;
2035
+ while (slotSize) {
2036
+ txSlot* slot = *slots;
2037
+ fxMeasureSlot(the, snapshot, slot, &chunkSize);
2038
+ slotSize--;
2039
+ slots++;
2040
+ }
2041
+
2042
+ slotSize = (snapshot->slotSize - 1) * sizeof(txSlot);
2043
+
2044
+ creation.initialChunkSize = the->maximumChunksSize;
2045
+ creation.incrementalChunkSize = the->minimumChunksSize;
2046
+ creation.initialHeapCount = the->maximumHeapCount + 1;
2047
+ creation.incrementalHeapCount = the->minimumHeapCount;
2048
+ creation.stackCount = (txSize)(the->stackTop - the->stackBottom);
2049
+ creation.initialKeyCount = the->keyCount;
2050
+ creation.incrementalKeyCount = the->keyDelta;
2051
+ creation.nameModulo = the->nameModulo;
2052
+ creation.symbolModulo = the->symbolModulo;
2053
+ creation.parserBufferSize = the->parserBufferSize;
2054
+ creation.parserTableModulo = the->parserTableModulo;
2055
+ creation.staticSize = 0;
2056
+
2057
+ size = 8
2058
+ + 8 + 4
2059
+ + 8 + snapshot->signatureLength
2060
+ + 8 + sizeof(txCreation)
2061
+ + 8 + chunkSize
2062
+ + 8 + slotSize
2063
+ + 8 + stackSize
2064
+ + 8 + keysSize
2065
+ + 8 + namesSize
2066
+ + 8 + symbolsSize
2067
+ ;
2068
+
2069
+ size = htonl(size);
2070
+ mxThrowIf((*snapshot->write)(snapshot->stream, &size, 4));
2071
+ mxThrowIf((*snapshot->write)(snapshot->stream, "XS_M", 4));
2072
+
2073
+ size = 8 + 4;
2074
+ size = htonl(size);
2075
+ mxThrowIf((*snapshot->write)(snapshot->stream, &size, 4));
2076
+ mxThrowIf((*snapshot->write)(snapshot->stream, "VERS", 4));
2077
+ byte = XS_MAJOR_VERSION;
2078
+ mxThrowIf((*snapshot->write)(snapshot->stream, &byte, 1));
2079
+ byte = XS_MINOR_VERSION;
2080
+ mxThrowIf((*snapshot->write)(snapshot->stream, &byte, 1));
2081
+ byte = XS_PATCH_VERSION;
2082
+ mxThrowIf((*snapshot->write)(snapshot->stream, &byte, 1));
2083
+ #if mxBigEndian
2084
+ byte = -((txByte)sizeof(txSlot));
2085
+ #else
2086
+ byte = (txByte)sizeof(txSlot);
2087
+ #endif
2088
+ mxThrowIf((*snapshot->write)(snapshot->stream, &byte, 1));
2089
+
2090
+ size = 8 + snapshot->signatureLength;
2091
+ size = htonl(size);
2092
+ mxThrowIf((*snapshot->write)(snapshot->stream, &size, 4));
2093
+ mxThrowIf((*snapshot->write)(snapshot->stream, "SIGN", 4));
2094
+ mxThrowIf((*snapshot->write)(snapshot->stream, snapshot->signature, snapshot->signatureLength));
2095
+
2096
+ size = 8 + sizeof(txCreation) + sizeof(txID) + sizeof(txInteger);
2097
+ size = htonl(size);
2098
+ mxThrowIf((*snapshot->write)(snapshot->stream, &size, 4));
2099
+ mxThrowIf((*snapshot->write)(snapshot->stream, "CREA", 4));
2100
+ mxThrowIf((*snapshot->write)(snapshot->stream, &creation, sizeof(txCreation)));
2101
+ mxThrowIf((*snapshot->write)(snapshot->stream, &(the->profileID), sizeof(txID)));
2102
+ mxThrowIf((*snapshot->write)(snapshot->stream, &(the->tag), sizeof(txInteger)));
2103
+
2104
+ size = 8 + chunkSize;
2105
+ size = htonl(size);
2106
+ mxThrowIf((*snapshot->write)(snapshot->stream, &size, 4));
2107
+ mxThrowIf((*snapshot->write)(snapshot->stream, "BLOC", 4));
2108
+ fxWriteChunks(the, snapshot);
2109
+
2110
+ size = 8 + slotSize;
2111
+ size = htonl(size);
2112
+ mxThrowIf((*snapshot->write)(snapshot->stream, &size, 4));
2113
+ mxThrowIf((*snapshot->write)(snapshot->stream, "HEAP", 4));
2114
+ fxWriteSlots(the, snapshot);
2115
+
2116
+ size = 8 + stackSize;
2117
+ size = htonl(size);
2118
+ mxThrowIf((*snapshot->write)(snapshot->stream, &size, 4));
2119
+ mxThrowIf((*snapshot->write)(snapshot->stream, "STAC", 4));
2120
+ fxWriteStack(the, snapshot);
2121
+
2122
+ size = 8 + keysSize;
2123
+ size = htonl(size);
2124
+ mxThrowIf((*snapshot->write)(snapshot->stream, &size, 4));
2125
+ mxThrowIf((*snapshot->write)(snapshot->stream, "KEYS", 4));
2126
+ fxWriteSlotTable(the, snapshot, the->keyArray, the->keyIndex);
2127
+
2128
+ size = 8 + namesSize;
2129
+ size = htonl(size);
2130
+ mxThrowIf((*snapshot->write)(snapshot->stream, &size, 4));
2131
+ mxThrowIf((*snapshot->write)(snapshot->stream, "NAME", 4));
2132
+ fxWriteSlotTable(the, snapshot, the->nameTable, the->nameModulo);
2133
+
2134
+ size = 8 + symbolsSize;
2135
+ size = htonl(size);
2136
+ mxThrowIf((*snapshot->write)(snapshot->stream, &size, 4));
2137
+ mxThrowIf((*snapshot->write)(snapshot->stream, "SYMB", 4));
2138
+ fxWriteSlotTable(the, snapshot, the->symbolTable, the->symbolModulo);
2139
+ }
2140
+ mxCatch(the) {
2141
+
2142
+ }
2143
+ if (snapshot->slots)
2144
+ c_free(snapshot->slots);
2145
+
2146
+ projectionAddress = &(snapshot->firstProjection);
2147
+ while ((projection = *projectionAddress)) {
2148
+ *projectionAddress = projection->nextProjection;
2149
+ c_free(projection);
2150
+ }
2151
+
2152
+ heap = the->freeHeap;
2153
+ while (heap) {
2154
+ heap->flag &= ~XS_MARK_FLAG;
2155
+ heap = heap->next;
2156
+ }
2157
+
2158
+ fxLinkChunks(the);
2159
+
2160
+ return (snapshot->error) ? 0 : 1;
2161
+ }