@agoric/xsnap 0.14.3-dev-b047af2.0 → 0.14.3-dev-3eb4230.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api.js +1 -1
- package/package.json +16 -23
- package/src/build.js +4 -61
- package/moddable/modules/data/base64/base64.js +0 -28
- package/moddable/modules/data/base64/manifest.json +0 -11
- package/moddable/modules/data/base64/modBase64.c +0 -188
- package/moddable/modules/data/binaryMessage/BinaryMessage.js +0 -106
- package/moddable/modules/data/crc/crc.c +0 -205
- package/moddable/modules/data/crc/crc.js +0 -36
- package/moddable/modules/data/crc/manifest.json +0 -8
- package/moddable/modules/data/hex/hex.js +0 -28
- package/moddable/modules/data/hex/manifest.json +0 -11
- package/moddable/modules/data/hex/modHex.c +0 -139
- package/moddable/modules/data/logical/logical.js +0 -32
- package/moddable/modules/data/logical/modLogical.c +0 -98
- package/moddable/modules/data/qrcode/manifest.json +0 -9
- package/moddable/modules/data/qrcode/qrcode.c +0 -93
- package/moddable/modules/data/qrcode/qrcode.js +0 -23
- package/moddable/modules/data/qrcode/qrcodegen.c +0 -1025
- package/moddable/modules/data/qrcode/qrcodegen.h +0 -267
- package/moddable/modules/data/text/decoder/manifest.json +0 -8
- package/moddable/modules/data/text/decoder/textdecoder.c +0 -480
- package/moddable/modules/data/text/decoder/textdecoder.js +0 -27
- package/moddable/modules/data/text/encoder/manifest.json +0 -8
- package/moddable/modules/data/text/encoder/textencoder.c +0 -232
- package/moddable/modules/data/text/encoder/textencoder.js +0 -24
- package/moddable/modules/data/tinyint/tinyint.c +0 -150
- package/moddable/modules/data/tinyint/tinyint.js +0 -53
- package/moddable/modules/data/url/manifest.json +0 -17
- package/moddable/modules/data/url/url.c +0 -1959
- package/moddable/modules/data/url/url.js +0 -210
- package/moddable/modules/data/wavreader/manifest.json +0 -8
- package/moddable/modules/data/wavreader/wavreader.js +0 -128
- package/moddable/modules/data/zlib/deflate.c +0 -161
- package/moddable/modules/data/zlib/deflate.js +0 -63
- package/moddable/modules/data/zlib/inflate.c +0 -145
- package/moddable/modules/data/zlib/inflate.js +0 -66
- package/moddable/modules/data/zlib/manifest_deflate.json +0 -9
- package/moddable/modules/data/zlib/manifest_inflate.json +0 -9
- package/moddable/modules/data/zlib/miniz.c +0 -4924
- package/moddable/xs/includes/xs.d.ts +0 -73
- package/moddable/xs/includes/xs.h +0 -1533
- package/moddable/xs/includes/xsmc.h +0 -206
- package/moddable/xs/makefiles/lin/makefile +0 -33
- package/moddable/xs/makefiles/lin/xsc.mk +0 -118
- package/moddable/xs/makefiles/lin/xsid.mk +0 -90
- package/moddable/xs/makefiles/lin/xsl.mk +0 -168
- package/moddable/xs/makefiles/lin/xst.mk +0 -201
- package/moddable/xs/makefiles/mac/makefile +0 -33
- package/moddable/xs/makefiles/mac/xsc.mk +0 -130
- package/moddable/xs/makefiles/mac/xsid.mk +0 -102
- package/moddable/xs/makefiles/mac/xsl.mk +0 -177
- package/moddable/xs/makefiles/mac/xst.mk +0 -203
- package/moddable/xs/makefiles/mac/xst_no_asan.txt +0 -52
- package/moddable/xs/makefiles/win/build.bat +0 -26
- package/moddable/xs/makefiles/win/xsc.mak +0 -142
- package/moddable/xs/makefiles/win/xsid.mak +0 -113
- package/moddable/xs/makefiles/win/xsl.mak +0 -186
- package/moddable/xs/makefiles/win/xst.mak +0 -195
- package/moddable/xs/platforms/lin_xs.h +0 -99
- package/moddable/xs/platforms/mac_xs.h +0 -97
- package/moddable/xs/platforms/wasm_xs.h +0 -79
- package/moddable/xs/platforms/win_xs.h +0 -104
- package/moddable/xs/platforms/xsHost.h +0 -63
- package/moddable/xs/platforms/xsPlatform.h +0 -618
- package/moddable/xs/sources/xsAPI.c +0 -2555
- package/moddable/xs/sources/xsAll.c +0 -294
- package/moddable/xs/sources/xsAll.h +0 -2741
- package/moddable/xs/sources/xsArguments.c +0 -222
- package/moddable/xs/sources/xsArray.c +0 -2657
- package/moddable/xs/sources/xsAtomics.c +0 -844
- package/moddable/xs/sources/xsBigInt.c +0 -1859
- package/moddable/xs/sources/xsBoolean.c +0 -109
- package/moddable/xs/sources/xsCode.c +0 -4493
- package/moddable/xs/sources/xsCommon.c +0 -1710
- package/moddable/xs/sources/xsCommon.h +0 -1142
- package/moddable/xs/sources/xsDataView.c +0 -2890
- package/moddable/xs/sources/xsDate.c +0 -1541
- package/moddable/xs/sources/xsDebug.c +0 -2710
- package/moddable/xs/sources/xsDefaults.c +0 -134
- package/moddable/xs/sources/xsError.c +0 -353
- package/moddable/xs/sources/xsFunction.c +0 -776
- package/moddable/xs/sources/xsGenerator.c +0 -865
- package/moddable/xs/sources/xsGlobal.c +0 -839
- package/moddable/xs/sources/xsJSON.c +0 -1091
- package/moddable/xs/sources/xsLexical.c +0 -1969
- package/moddable/xs/sources/xsLockdown.c +0 -933
- package/moddable/xs/sources/xsMapSet.c +0 -1649
- package/moddable/xs/sources/xsMarshall.c +0 -1020
- package/moddable/xs/sources/xsMath.c +0 -624
- package/moddable/xs/sources/xsMemory.c +0 -1941
- package/moddable/xs/sources/xsModule.c +0 -3101
- package/moddable/xs/sources/xsNumber.c +0 -560
- package/moddable/xs/sources/xsObject.c +0 -1102
- package/moddable/xs/sources/xsPlatforms.c +0 -480
- package/moddable/xs/sources/xsProfile.c +0 -577
- package/moddable/xs/sources/xsPromise.c +0 -1199
- package/moddable/xs/sources/xsProperty.c +0 -636
- package/moddable/xs/sources/xsProxy.c +0 -1014
- package/moddable/xs/sources/xsRegExp.c +0 -1168
- package/moddable/xs/sources/xsRun.c +0 -4889
- package/moddable/xs/sources/xsScope.c +0 -1293
- package/moddable/xs/sources/xsScript.c +0 -288
- package/moddable/xs/sources/xsScript.h +0 -1186
- package/moddable/xs/sources/xsSnapshot.c +0 -2161
- package/moddable/xs/sources/xsSnapshot.h +0 -51
- package/moddable/xs/sources/xsSourceMap.c +0 -218
- package/moddable/xs/sources/xsString.c +0 -3332
- package/moddable/xs/sources/xsSymbol.c +0 -503
- package/moddable/xs/sources/xsSyntaxical.c +0 -4193
- package/moddable/xs/sources/xsTree.c +0 -1893
- package/moddable/xs/sources/xsType.c +0 -1488
- package/moddable/xs/sources/xsdtoa.c +0 -6672
- package/moddable/xs/sources/xsmc.c +0 -340
- package/moddable/xs/sources/xsre.c +0 -7578
- package/xsnap-native/xsnap/makefiles/lin/makefile +0 -10
- package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +0 -153
- package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +0 -144
- package/xsnap-native/xsnap/makefiles/mac/makefile +0 -10
- package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +0 -162
- package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +0 -153
- package/xsnap-native/xsnap/sources/xsnap-worker.c +0 -996
- package/xsnap-native/xsnap/sources/xsnap.c +0 -716
- package/xsnap-native/xsnap/sources/xsnap.h +0 -142
- package/xsnap-native/xsnap/sources/xsnapPlatform.c +0 -1496
- package/xsnap-native/xsnap/sources/xsnapPlatform.h +0 -105
|
@@ -1,503 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2016-2017 Moddable Tech, Inc.
|
|
3
|
-
*
|
|
4
|
-
* This file is part of the Moddable SDK Runtime.
|
|
5
|
-
*
|
|
6
|
-
* The Moddable SDK Runtime is free software: you can redistribute it and/or modify
|
|
7
|
-
* it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
* (at your option) any later version.
|
|
10
|
-
*
|
|
11
|
-
* The Moddable SDK Runtime is distributed in the hope that it will be useful,
|
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
* GNU Lesser General Public License for more details.
|
|
15
|
-
*
|
|
16
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
* along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*
|
|
19
|
-
* This file incorporates work covered by the following copyright and
|
|
20
|
-
* permission notice:
|
|
21
|
-
*
|
|
22
|
-
* Copyright (C) 2010-2016 Marvell International Ltd.
|
|
23
|
-
* Copyright (C) 2002-2010 Kinoma, Inc.
|
|
24
|
-
*
|
|
25
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
26
|
-
* you may not use this file except in compliance with the License.
|
|
27
|
-
* You may obtain a copy of the License at
|
|
28
|
-
*
|
|
29
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
30
|
-
*
|
|
31
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
32
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
33
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
34
|
-
* See the License for the specific language governing permissions and
|
|
35
|
-
* limitations under the License.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
#include "xsAll.h"
|
|
39
|
-
|
|
40
|
-
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
|
-
}
|