@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,503 @@
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
+ static txSlot* fxCheckSymbol(txMachine* the, txSlot* it);
41
+
42
+ void fxBuildSymbol(txMachine* the)
43
+ {
44
+ txSlot* slot;
45
+ mxPush(mxObjectPrototype);
46
+ slot = fxLastProperty(the, fxNewObjectInstance(the));
47
+ slot = fxNextHostAccessorProperty(the, slot, mxCallback(fx_Symbol_prototype_get_description), C_NULL, mxID(_description), XS_DONT_ENUM_FLAG);
48
+ slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Symbol_prototype_toString), 0, mxID(_toString), XS_DONT_ENUM_FLAG);
49
+ slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Symbol_prototype_valueOf), 0, mxID(_valueOf), XS_DONT_ENUM_FLAG);
50
+ slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Symbol_prototype_toPrimitive), 1, mxID(_Symbol_toPrimitive), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
51
+ slot = fxNextStringXProperty(the, slot, "Symbol", mxID(_Symbol_toStringTag), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
52
+ mxSymbolPrototype = *the->stack;
53
+ slot = fxBuildHostConstructor(the, mxCallback(fx_Symbol), 0, mxID(_Symbol));
54
+ mxSymbolConstructor = *the->stack;
55
+ slot = fxLastProperty(the, slot);
56
+ slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Symbol_for), 1, mxID(_for), XS_DONT_ENUM_FLAG);
57
+ slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Symbol_keyFor), 1, mxID(_keyFor), XS_DONT_ENUM_FLAG);
58
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_asyncIterator), mxID(_asyncIterator), XS_GET_ONLY);
59
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_hasInstance), mxID(_hasInstance), XS_GET_ONLY);
60
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_isConcatSpreadable), mxID(_isConcatSpreadable), XS_GET_ONLY);
61
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_iterator), mxID(_iterator), XS_GET_ONLY);
62
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_match), mxID(_match), XS_GET_ONLY);
63
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_matchAll), mxID(_matchAll), XS_GET_ONLY);
64
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_replace), mxID(_replace), XS_GET_ONLY);
65
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_search), mxID(_search), XS_GET_ONLY);
66
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_species), mxID(_species), XS_GET_ONLY);
67
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_split), mxID(_split), XS_GET_ONLY);
68
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_toPrimitive), mxID(_toPrimitive), XS_GET_ONLY);
69
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_toStringTag), mxID(_toStringTag), XS_GET_ONLY);
70
+ slot = fxNextSymbolProperty(the, slot, mxID(_Symbol_unscopables), mxID(_unscopables), XS_GET_ONLY);
71
+ mxPop();
72
+ }
73
+
74
+ txSlot* fxNewSymbolInstance(txMachine* the)
75
+ {
76
+ txSlot* instance;
77
+ instance = fxNewObjectInstance(the);
78
+ fxNextSymbolProperty(the, instance, XS_NO_ID, XS_NO_ID, XS_INTERNAL_FLAG);
79
+ return instance;
80
+ }
81
+
82
+ void fx_Symbol(txMachine* the)
83
+ {
84
+ txID id;
85
+ txSlot* description;
86
+ if (mxTarget->kind != XS_UNDEFINED_KIND)
87
+ mxTypeError("new Symbol");
88
+ if ((mxArgc > 0) && (mxArgv(0)->kind != XS_UNDEFINED_KIND)) {
89
+ fxToString(the, mxArgv(0));
90
+ description = fxNewSlot(the);
91
+ description->kind = mxArgv(0)->kind;
92
+ description->value.string = mxArgv(0)->value.string;
93
+ }
94
+ else
95
+ description = C_NULL;
96
+ id = the->keyIndex;
97
+ if (id == the->keyCount)
98
+ fxGrowKeys(the, 1);
99
+ the->keyArray[id - the->keyOffset] = description;
100
+ the->keyIndex++;
101
+ mxResult->kind = XS_SYMBOL_KIND;
102
+ mxResult->value.symbol = id;
103
+ }
104
+
105
+ void fx_Symbol_for(txMachine* the)
106
+ {
107
+ txString string;
108
+ txU1* p;
109
+ txU4 sum;
110
+ txU4 modulo;
111
+ txSlot* result;
112
+ txID id;
113
+ if (mxArgc < 1)
114
+ mxSyntaxError("no key parameter");
115
+ string = fxToString(the, mxArgv(0));
116
+ p = (txU1*)string;
117
+ sum = 0;
118
+ while(*p != 0) {
119
+ sum = (sum << 1) + *p++;
120
+ }
121
+ sum &= 0x7FFFFFFF;
122
+ modulo = sum % the->symbolModulo;
123
+ result = the->symbolTable[modulo];
124
+ while (result != C_NULL) {
125
+ if (result->value.key.sum == sum)
126
+ if (c_strcmp(result->value.key.string, string) == 0)
127
+ break;
128
+ result = result->next;
129
+ }
130
+ if (result == C_NULL) {
131
+ id = the->keyIndex;
132
+ if (id == the->keyCount)
133
+ fxGrowKeys(the, 1);
134
+ result = fxNewSlot(the);
135
+ result->next = the->symbolTable[modulo];
136
+ result->kind = (mxArgv(0)->kind == XS_STRING_X_KIND) ? XS_KEY_X_KIND : XS_KEY_KIND;
137
+ result->ID = id;
138
+ result->value.key.string = mxArgv(0)->value.string;
139
+ result->value.key.sum = sum;
140
+ the->keyArray[id - the->keyOffset] = result;
141
+ the->keyIndex++;
142
+ the->symbolTable[modulo] = result;
143
+ }
144
+ mxResult->kind = XS_SYMBOL_KIND;
145
+ mxResult->value.symbol = result->ID;
146
+ }
147
+
148
+ void fx_Symbol_keyFor(txMachine* the)
149
+ {
150
+ txSlot* key;
151
+ if ((mxArgc == 0) || (mxArgv(0)->kind != XS_SYMBOL_KIND))
152
+ mxTypeError("sym is no symbol");
153
+ key = fxGetKey(the, mxArgv(0)->value.symbol);
154
+ if (key && ((key->kind == XS_KEY_KIND) || (key->kind == XS_KEY_X_KIND)) && ((key->flag & XS_DONT_ENUM_FLAG) == 0)) {
155
+ mxResult->kind = (key->kind == XS_KEY_KIND) ? XS_STRING_KIND : XS_STRING_X_KIND;
156
+ mxResult->value.string = key->value.key.string;
157
+ }
158
+ }
159
+
160
+ void fx_Symbol_prototype_get_description(txMachine* the)
161
+ {
162
+ txSlot* slot = fxCheckSymbol(the, mxThis);
163
+ if (!slot) mxTypeError("this is no symbol");
164
+ slot = fxGetKey(the, slot->value.symbol);
165
+ if (slot) {
166
+ if ((slot->kind == XS_KEY_KIND) || (slot->kind == XS_KEY_X_KIND)) {
167
+ mxResult->kind = (slot->kind == XS_KEY_KIND) ? XS_STRING_KIND : XS_STRING_X_KIND;
168
+ mxResult->value.string = slot->value.key.string;
169
+ }
170
+ else if ((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) {
171
+ mxResult->kind = slot->kind;
172
+ mxResult->value = slot->value;
173
+ }
174
+ }
175
+ }
176
+
177
+ void fx_Symbol_prototype_toPrimitive(txMachine* the)
178
+ {
179
+ txSlot* slot = fxCheckSymbol(the, mxThis);
180
+ if (!slot) mxTypeError("this is no symbol");
181
+ mxResult->kind = slot->kind;
182
+ mxResult->value = slot->value;
183
+ }
184
+
185
+ void fx_Symbol_prototype_toString(txMachine* the)
186
+ {
187
+ txSlot* slot = fxCheckSymbol(the, mxThis);
188
+ if (!slot) mxTypeError("this is no symbol");
189
+ mxResult->kind = slot->kind;
190
+ mxResult->value = slot->value;
191
+ fxSymbolToString(the, mxResult);
192
+ }
193
+
194
+ void fx_Symbol_prototype_valueOf(txMachine* the)
195
+ {
196
+ txSlot* slot = fxCheckSymbol(the, mxThis);
197
+ if (!slot) mxTypeError("this is no symbol");
198
+ mxResult->kind = slot->kind;
199
+ mxResult->value = slot->value;
200
+ }
201
+
202
+ txSlot* fxCheckSymbol(txMachine* the, txSlot* it)
203
+ {
204
+ txSlot* result = C_NULL;
205
+ if (it->kind == XS_SYMBOL_KIND)
206
+ result = it;
207
+ else if (it->kind == XS_REFERENCE_KIND) {
208
+ txSlot* instance = it->value.reference;
209
+ it = instance->next;
210
+ if ((it) && (it->flag & XS_INTERNAL_FLAG) && (it->kind == XS_SYMBOL_KIND))
211
+ result = it;
212
+ }
213
+ return result;
214
+ }
215
+
216
+ void fxSymbolToString(txMachine* the, txSlot* slot)
217
+ {
218
+ txSlot* key = fxGetKey(the, slot->value.symbol);
219
+ fxStringX(the, slot, "Symbol(");
220
+ if (key) {
221
+ if ((key->kind == XS_KEY_KIND) || (key->kind == XS_KEY_X_KIND))
222
+ fxConcatString(the, slot, key);
223
+ else if ((key->kind == XS_STRING_KIND) || (key->kind == XS_STRING_X_KIND))
224
+ fxConcatString(the, slot, key);
225
+ }
226
+ fxConcatStringC(the, slot, ")");
227
+ }
228
+
229
+ txSlot* fxGetKey(txMachine* the, txID theID)
230
+ {
231
+ if ((0 < theID) && (theID < the->keyCount)) {
232
+ if (theID < the->keyOffset)
233
+ return the->keyArrayHost[theID];
234
+ else
235
+ return the->keyArray[theID - the->keyOffset];
236
+ }
237
+ return C_NULL;
238
+ }
239
+
240
+ char* fxGetKeyName(txMachine* the, txID theID)
241
+ {
242
+ txSlot* key;
243
+ if ((0 < theID) && (theID < the->keyCount)) {
244
+ if (theID < the->keyOffset)
245
+ key = the->keyArrayHost[theID];
246
+ else
247
+ key = the->keyArray[theID - the->keyOffset];
248
+ if (key)
249
+ return key->value.string;
250
+ }
251
+ return C_NULL;
252
+ }
253
+
254
+ txID fxFindName(txMachine* the, txString theString)
255
+ {
256
+ txU1* aString;
257
+ txU4 aSum;
258
+ txU4 aModulo;
259
+ txSlot* result;
260
+
261
+ aString = (txU1*)theString;
262
+ aSum = 0;
263
+ while (*aString != 0) {
264
+ aSum = (aSum << 1) + *aString++;
265
+ }
266
+ aSum &= 0x7FFFFFFF;
267
+ aModulo = aSum % the->nameModulo;
268
+ result = the->nameTable[aModulo];
269
+ while (result != C_NULL) {
270
+ if (result->value.key.sum == aSum)
271
+ if (c_strcmp(result->value.key.string, theString) == 0)
272
+ return mxGetKeySlotID(result);
273
+ result = result->next;
274
+ }
275
+ return 0;
276
+ }
277
+
278
+ txBoolean fxIsKeyName(txMachine* the, txID theID)
279
+ {
280
+ txSlot* key = fxGetKey(the, theID);
281
+ return (key && (key->flag & XS_DONT_ENUM_FLAG)) ? 1 : 0;
282
+ }
283
+
284
+ txBoolean fxIsKeySymbol(txMachine* the, txID theID)
285
+ {
286
+ txSlot* key = fxGetKey(the, theID);
287
+ return (!key || !(key->flag & XS_DONT_ENUM_FLAG)) ? 1 : 0;
288
+ }
289
+
290
+ txID fxNewName(txMachine* the, txSlot* theSlot)
291
+ {
292
+ txU1* string;
293
+ txU4 sum;
294
+ txU4 modulo;
295
+ txSlot* result;
296
+ txID id;
297
+
298
+ string = (txU1*)theSlot->value.string;
299
+ sum = 0;
300
+ while(*string != 0) {
301
+ sum = (sum << 1) + *string++;
302
+ }
303
+ sum &= 0x7FFFFFFF;
304
+ modulo = sum % the->nameModulo;
305
+ result = the->nameTable[modulo];
306
+ while (result != C_NULL) {
307
+ if (result->value.key.sum == sum) {
308
+ if (c_strcmp(result->value.key.string, theSlot->value.string) == 0)
309
+ return mxGetKeySlotID(result);
310
+ }
311
+ result = result->next;
312
+ }
313
+
314
+ id = the->keyIndex;
315
+ if (id == the->keyCount)
316
+ fxGrowKeys(the, 1);
317
+ result = fxNewSlot(the);
318
+ result->next = the->nameTable[modulo];
319
+ result->flag = XS_DONT_ENUM_FLAG;
320
+ result->kind = XS_KEY_KIND;
321
+ result->ID = id;
322
+ result->value.key.string = theSlot->value.string;
323
+ result->value.key.sum = sum;
324
+ the->keyArray[id - the->keyOffset] = result;
325
+ the->keyIndex++;
326
+ the->nameTable[modulo] = result;
327
+ return result->ID;
328
+ }
329
+
330
+ txID fxNewNameC(txMachine* the, txString theString)
331
+ {
332
+ txU1* string;
333
+ txU4 sum;
334
+ txU4 modulo;
335
+ txSlot* result;
336
+ txID id;
337
+
338
+ string = (txU1*)theString;
339
+ sum = 0;
340
+ while(c_read8(string) != 0) {
341
+ sum = (sum << 1) + c_read8(string++);
342
+ }
343
+ sum &= 0x7FFFFFFF;
344
+ modulo = sum % the->nameModulo;
345
+ result = the->nameTable[modulo];
346
+ while (result != C_NULL) {
347
+ if (result->value.key.sum == sum) {
348
+ if (c_strcmp(result->value.key.string, theString) == 0)
349
+ return mxGetKeySlotID(result);
350
+ }
351
+ result = result->next;
352
+ }
353
+
354
+ id = the->keyIndex;
355
+ if (id == the->keyCount)
356
+ fxGrowKeys(the, 1);
357
+ result = fxNewSlot(the);
358
+ result->next = the->nameTable[modulo];
359
+ result->flag = XS_DONT_ENUM_FLAG;
360
+ result->kind = XS_KEY_KIND;
361
+ result->ID = id;
362
+ result->value.key.string = C_NULL;
363
+ result->value.key.sum = sum;
364
+ the->keyArray[id - the->keyOffset] = result;
365
+ the->keyIndex++;
366
+ the->nameTable[modulo] = result;
367
+ result->value.key.string = (txString)fxNewChunk(the, mxStringLength(theString) + 1);
368
+ c_strcpy(result->value.key.string, theString);
369
+ return result->ID;
370
+ }
371
+
372
+ txID fxNewNameX(txMachine* the, txString theString)
373
+ {
374
+ txU1* string;
375
+ txU4 sum;
376
+ txU4 modulo;
377
+ txSlot* result;
378
+ txID id;
379
+
380
+ string = (txU1*)theString;
381
+ sum = 0;
382
+ while (c_read8(string) != 0) {
383
+ sum = (sum << 1) + c_read8(string++);
384
+ }
385
+ sum &= 0x7FFFFFFF;
386
+ modulo = sum % the->nameModulo;
387
+ result = the->nameTable[modulo];
388
+ while (result != C_NULL) {
389
+ if (result->value.key.sum == sum) {
390
+ if (c_strcmp(result->value.key.string, theString) == 0)
391
+ return mxGetKeySlotID(result);
392
+ }
393
+ result = result->next;
394
+ }
395
+
396
+ id = the->keyIndex;
397
+ if (id == the->keyCount)
398
+ fxGrowKeys(the, 1);
399
+ result = fxNewSlot(the);
400
+ result->next = the->nameTable[modulo];
401
+ result->flag = XS_DONT_ENUM_FLAG;
402
+ result->kind = XS_KEY_X_KIND;
403
+ result->ID = id;
404
+ result->value.key.string = theString;
405
+ result->value.key.sum = sum;
406
+ the->keyArray[id - the->keyOffset] = result;
407
+ the->keyIndex++;
408
+ the->nameTable[modulo] = result;
409
+ return result->ID;
410
+ }
411
+
412
+ txSlot* fxAt(txMachine* the, txSlot* slot)
413
+ {
414
+ txIndex index;
415
+ txString string;
416
+ again:
417
+ if ((slot->kind == XS_INTEGER_KIND) && fxIntegerToIndex(the->dtoa, slot->value.integer, &index)) {
418
+ slot->value.at.id = XS_NO_ID;
419
+ slot->value.at.index = index;
420
+ }
421
+ else if ((slot->kind == XS_NUMBER_KIND) && fxNumberToIndex(the->dtoa, slot->value.number, &index)) {
422
+ slot->value.at.id = XS_NO_ID;
423
+ slot->value.at.index = index;
424
+ }
425
+ else if (slot->kind == XS_SYMBOL_KIND) {
426
+ slot->value.at.id = slot->value.symbol;
427
+ slot->value.at.index = 0;
428
+ }
429
+ else {
430
+ if (slot->kind == XS_REFERENCE_KIND) {
431
+ fxToPrimitive(the, slot, XS_STRING_HINT);
432
+ goto again;
433
+ }
434
+ string = fxToString(the, slot);
435
+ if (fxStringToIndex(the->dtoa, string, &index)) {
436
+ slot->value.at.id = XS_NO_ID;
437
+ slot->value.at.index = index;
438
+ }
439
+ else {
440
+ txID id;
441
+ if (slot->kind == XS_STRING_X_KIND)
442
+ id = fxNewNameX(the, string);
443
+ else
444
+ id = fxNewName(the, slot);
445
+ slot->value.at.id = id;
446
+ slot->value.at.index = 0;
447
+ }
448
+ }
449
+ slot->kind = XS_AT_KIND;
450
+ return slot;
451
+ }
452
+
453
+ void fxKeyAt(txMachine* the, txID id, txIndex index, txSlot* slot)
454
+ {
455
+ if (id) {
456
+ txSlot* key = fxGetKey(the, id);
457
+ if (key && (key->flag & XS_DONT_ENUM_FLAG)) {
458
+ if (key->kind == XS_KEY_KIND) {
459
+ slot->kind = XS_STRING_KIND;
460
+ slot->value.string = key->value.key.string;
461
+ }
462
+ else{
463
+ slot->kind = XS_STRING_X_KIND;
464
+ slot->value.string = key->value.key.string;
465
+ }
466
+ }
467
+ else {
468
+ slot->kind = XS_SYMBOL_KIND;
469
+ slot->value.symbol = id;
470
+ }
471
+ }
472
+ else {
473
+ char buffer[16];
474
+ fxCopyStringC(the, slot, fxNumberToString(the->dtoa, index, buffer, sizeof(buffer), 0, 0));
475
+ }
476
+ }
477
+
478
+ void fxIDToString(txMachine* the, txID id, txString theBuffer, txSize theSize)
479
+ {
480
+ if ((0 < id) && (id < the->keyCount)) {
481
+ txSlot* key;
482
+
483
+ if (id < the->keyOffset)
484
+ key = the->keyArrayHost[id];
485
+ else
486
+ key = the->keyArray[id - the->keyOffset];
487
+ if (key) {
488
+ txKind kind = mxGetKeySlotKind(key);
489
+ if ((kind == XS_KEY_KIND) || (kind == XS_KEY_X_KIND))
490
+ c_snprintf(theBuffer, theSize, "%s", key->value.key.string);
491
+ else if ((kind == XS_STRING_KIND) || (kind == XS_STRING_X_KIND))
492
+ c_snprintf(theBuffer, theSize, "[%s]", key->value.string);
493
+ else
494
+ *theBuffer = 0;
495
+ }
496
+ else
497
+ *theBuffer = 0;
498
+ }
499
+ else {
500
+ theBuffer[0] = '?';
501
+ theBuffer[1] = 0;
502
+ }
503
+ }