greybel-interpreter 1.3.7 → 1.3.8
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/.editorconfig +14 -14
- package/.eslintrc +47 -47
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +109 -109
- package/dist/context.js +383 -382
- package/dist/cps.d.ts +14 -14
- package/dist/cps.js +213 -213
- package/dist/handler/error.d.ts +6 -6
- package/dist/handler/error.js +35 -35
- package/dist/handler/output.d.ts +18 -18
- package/dist/handler/output.js +52 -52
- package/dist/handler/resource.d.ts +12 -12
- package/dist/handler/resource.js +51 -51
- package/dist/handler-container.d.ts +14 -14
- package/dist/handler-container.js +16 -16
- package/dist/index.d.ts +45 -45
- package/dist/index.js +131 -131
- package/dist/interpreter.d.ts +41 -41
- package/dist/interpreter.js +312 -312
- package/dist/intrinsics-container.d.ts +7 -7
- package/dist/intrinsics-container.js +19 -19
- package/dist/operations/assign.d.ts +13 -13
- package/dist/operations/assign.js +111 -111
- package/dist/operations/block.d.ts +12 -12
- package/dist/operations/block.js +108 -108
- package/dist/operations/break.d.ts +10 -10
- package/dist/operations/break.js +41 -41
- package/dist/operations/call.d.ts +13 -13
- package/dist/operations/call.js +124 -124
- package/dist/operations/chunk.d.ts +12 -12
- package/dist/operations/chunk.js +85 -85
- package/dist/operations/continue.d.ts +10 -10
- package/dist/operations/continue.js +41 -41
- package/dist/operations/debugger-statement.d.ts +10 -10
- package/dist/operations/debugger-statement.js +39 -39
- package/dist/operations/evaluate.d.ts +41 -39
- package/dist/operations/evaluate.js +433 -367
- package/dist/operations/for.d.ts +14 -14
- package/dist/operations/for.js +152 -152
- package/dist/operations/function-reference.d.ts +12 -12
- package/dist/operations/function-reference.js +103 -103
- package/dist/operations/function.d.ts +14 -14
- package/dist/operations/function.js +200 -200
- package/dist/operations/if-statement.d.ts +19 -19
- package/dist/operations/if-statement.js +181 -181
- package/dist/operations/import.d.ts +17 -17
- package/dist/operations/import.js +119 -119
- package/dist/operations/include.d.ts +13 -13
- package/dist/operations/include.js +95 -95
- package/dist/operations/list.d.ts +11 -11
- package/dist/operations/list.js +111 -111
- package/dist/operations/literal.d.ts +11 -11
- package/dist/operations/literal.js +58 -58
- package/dist/operations/map.d.ts +11 -11
- package/dist/operations/map.js +171 -171
- package/dist/operations/negated-binary.d.ts +11 -11
- package/dist/operations/negated-binary.js +109 -109
- package/dist/operations/new-instance.d.ts +11 -11
- package/dist/operations/new-instance.js +100 -100
- package/dist/operations/noop.d.ts +9 -9
- package/dist/operations/noop.js +36 -36
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +96 -96
- package/dist/operations/operation.d.ts +13 -13
- package/dist/operations/operation.js +11 -11
- package/dist/operations/reference.d.ts +9 -9
- package/dist/operations/reference.js +37 -37
- package/dist/operations/resolve.d.ts +38 -38
- package/dist/operations/resolve.js +330 -330
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +107 -107
- package/dist/operations/while.d.ts +13 -13
- package/dist/operations/while.js +136 -136
- package/dist/types/boolean.d.ts +11 -11
- package/dist/types/boolean.js +46 -46
- package/dist/types/default.d.ts +11 -11
- package/dist/types/default.js +20 -20
- package/dist/types/function.d.ts +32 -32
- package/dist/types/function.js +174 -174
- package/dist/types/generics.d.ts +18 -18
- package/dist/types/generics.js +40 -40
- package/dist/types/interface.d.ts +23 -23
- package/dist/types/interface.js +103 -103
- package/dist/types/list.d.ts +31 -31
- package/dist/types/list.js +209 -209
- package/dist/types/map.d.ts +37 -37
- package/dist/types/map.js +366 -366
- package/dist/types/nil.d.ts +10 -10
- package/dist/types/nil.js +46 -46
- package/dist/types/number.d.ts +11 -11
- package/dist/types/number.js +46 -46
- package/dist/types/string.d.ts +33 -33
- package/dist/types/string.js +145 -145
- package/dist/utils/deep-equal.d.ts +1 -1
- package/dist/utils/deep-equal.js +62 -62
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/path.js +59 -59
- package/package.json +58 -58
package/dist/types/map.js
CHANGED
|
@@ -1,366 +1,366 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __values = (this && this.__values) || function(o) {
|
|
18
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
-
if (m) return m.call(o);
|
|
20
|
-
if (o && typeof o.length === "number") return {
|
|
21
|
-
next: function () {
|
|
22
|
-
if (o && i >= o.length) o = void 0;
|
|
23
|
-
return { value: o && o[i++], done: !o };
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
-
};
|
|
28
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
29
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30
|
-
if (!m) return o;
|
|
31
|
-
var i = m.call(o), r, ar = [], e;
|
|
32
|
-
try {
|
|
33
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
34
|
-
}
|
|
35
|
-
catch (error) { e = { error: error }; }
|
|
36
|
-
finally {
|
|
37
|
-
try {
|
|
38
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
39
|
-
}
|
|
40
|
-
finally { if (e) throw e.error; }
|
|
41
|
-
}
|
|
42
|
-
return ar;
|
|
43
|
-
};
|
|
44
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
45
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
46
|
-
if (ar || !(i in from)) {
|
|
47
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
48
|
-
ar[i] = from[i];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
52
|
-
};
|
|
53
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
-
};
|
|
56
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
exports.CustomMapIterator = exports.setValue = exports.hasValue = exports.getValue = exports.ISA_PROPERTY = exports.CLASS_ID_PROPERTY = void 0;
|
|
58
|
-
var intrinsics_container_1 = __importDefault(require("../intrinsics-container"));
|
|
59
|
-
var deep_equal_1 = __importDefault(require("../utils/deep-equal"));
|
|
60
|
-
var path_1 = __importDefault(require("../utils/path"));
|
|
61
|
-
var default_1 = __importDefault(require("./default"));
|
|
62
|
-
var generics_1 = require("./generics");
|
|
63
|
-
var nil_1 = __importDefault(require("./nil"));
|
|
64
|
-
var string_1 = __importDefault(require("./string"));
|
|
65
|
-
exports.CLASS_ID_PROPERTY = new string_1.default('classID');
|
|
66
|
-
exports.ISA_PROPERTY = new string_1.default('__isa');
|
|
67
|
-
var getValue = function (map, mapKey) {
|
|
68
|
-
var e_1, _a;
|
|
69
|
-
try {
|
|
70
|
-
for (var _b = __values(map.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
71
|
-
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
72
|
-
if ((0, deep_equal_1.default)(key, mapKey)) {
|
|
73
|
-
return value;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
78
|
-
finally {
|
|
79
|
-
try {
|
|
80
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
81
|
-
}
|
|
82
|
-
finally { if (e_1) throw e_1.error; }
|
|
83
|
-
}
|
|
84
|
-
return default_1.default.Void;
|
|
85
|
-
};
|
|
86
|
-
exports.getValue = getValue;
|
|
87
|
-
var hasValue = function (map, mapKey) {
|
|
88
|
-
var e_2, _a;
|
|
89
|
-
try {
|
|
90
|
-
for (var _b = __values(map.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
91
|
-
var key = _c.value;
|
|
92
|
-
if ((0, deep_equal_1.default)(key, mapKey)) {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
98
|
-
finally {
|
|
99
|
-
try {
|
|
100
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
101
|
-
}
|
|
102
|
-
finally { if (e_2) throw e_2.error; }
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
};
|
|
106
|
-
exports.hasValue = hasValue;
|
|
107
|
-
var setValue = function (map, mapKey, mapValue) {
|
|
108
|
-
var e_3, _a;
|
|
109
|
-
try {
|
|
110
|
-
for (var _b = __values(map.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
111
|
-
var key = _c.value;
|
|
112
|
-
if ((0, deep_equal_1.default)(key, mapKey)) {
|
|
113
|
-
map.set(key, mapValue);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
119
|
-
finally {
|
|
120
|
-
try {
|
|
121
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
122
|
-
}
|
|
123
|
-
finally { if (e_3) throw e_3.error; }
|
|
124
|
-
}
|
|
125
|
-
map.set(mapKey, mapValue);
|
|
126
|
-
};
|
|
127
|
-
exports.setValue = setValue;
|
|
128
|
-
var CustomMapIterator = /** @class */ (function () {
|
|
129
|
-
function CustomMapIterator(value) {
|
|
130
|
-
var me = this;
|
|
131
|
-
me.value = value;
|
|
132
|
-
me.index = 0;
|
|
133
|
-
}
|
|
134
|
-
CustomMapIterator.prototype.next = function () {
|
|
135
|
-
var me = this;
|
|
136
|
-
var keys = Array.from(me.value.keys());
|
|
137
|
-
if (me.index === keys.length) {
|
|
138
|
-
return {
|
|
139
|
-
value: new nil_1.default(),
|
|
140
|
-
done: true
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
var key = keys[me.index++];
|
|
144
|
-
return {
|
|
145
|
-
value: new CustomMap(new Map([
|
|
146
|
-
[new string_1.default('key'), key],
|
|
147
|
-
[new string_1.default('value'), me.value.get(key)]
|
|
148
|
-
])),
|
|
149
|
-
done: false
|
|
150
|
-
};
|
|
151
|
-
};
|
|
152
|
-
return CustomMapIterator;
|
|
153
|
-
}());
|
|
154
|
-
exports.CustomMapIterator = CustomMapIterator;
|
|
155
|
-
var CustomMap = /** @class */ (function (_super) {
|
|
156
|
-
__extends(CustomMap, _super);
|
|
157
|
-
function CustomMap(value, isa) {
|
|
158
|
-
if (value === void 0) { value = new Map(); }
|
|
159
|
-
if (isa === void 0) { isa = new Map(); }
|
|
160
|
-
var _this = _super.call(this) || this;
|
|
161
|
-
_this.isInstance = false;
|
|
162
|
-
_this.value = new Map(value);
|
|
163
|
-
_this.isa = isa;
|
|
164
|
-
return _this;
|
|
165
|
-
}
|
|
166
|
-
CustomMap.getIntrinsics = function () {
|
|
167
|
-
return this.intrinsics;
|
|
168
|
-
};
|
|
169
|
-
CustomMap.addIntrinsic = function (name, fn) {
|
|
170
|
-
this.intrinsics.add(name, fn);
|
|
171
|
-
};
|
|
172
|
-
CustomMap.prototype.getCustomType = function () {
|
|
173
|
-
if ((0, exports.hasValue)(this.value, exports.CLASS_ID_PROPERTY)) {
|
|
174
|
-
return (0, exports.getValue)(this.value, exports.CLASS_ID_PROPERTY).toString();
|
|
175
|
-
}
|
|
176
|
-
return 'map';
|
|
177
|
-
};
|
|
178
|
-
CustomMap.prototype.toString = function () {
|
|
179
|
-
var _a, e_4, _b, e_5, _c;
|
|
180
|
-
var json = (_a = {}, _a[exports.ISA_PROPERTY.toString()] = {}, _a);
|
|
181
|
-
try {
|
|
182
|
-
for (var _d = __values(this.isa.entries()), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
183
|
-
var _f = __read(_e.value, 2), key = _f[0], value = _f[1];
|
|
184
|
-
json.__isa[key.toString()] = value.toString();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
188
|
-
finally {
|
|
189
|
-
try {
|
|
190
|
-
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
191
|
-
}
|
|
192
|
-
finally { if (e_4) throw e_4.error; }
|
|
193
|
-
}
|
|
194
|
-
try {
|
|
195
|
-
for (var _g = __values(this.value.entries()), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
196
|
-
var _j = __read(_h.value, 2), key = _j[0], value = _j[1];
|
|
197
|
-
json[key.toString()] = value.toString();
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
201
|
-
finally {
|
|
202
|
-
try {
|
|
203
|
-
if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
|
|
204
|
-
}
|
|
205
|
-
finally { if (e_5) throw e_5.error; }
|
|
206
|
-
}
|
|
207
|
-
return JSON.stringify(json);
|
|
208
|
-
};
|
|
209
|
-
CustomMap.prototype.fork = function () {
|
|
210
|
-
return new CustomMap(this.value);
|
|
211
|
-
};
|
|
212
|
-
CustomMap.prototype.toNumber = function () {
|
|
213
|
-
return 0;
|
|
214
|
-
};
|
|
215
|
-
CustomMap.prototype.toInt = function () {
|
|
216
|
-
return 0;
|
|
217
|
-
};
|
|
218
|
-
CustomMap.prototype.toTruthy = function () {
|
|
219
|
-
return this.value.size > 0;
|
|
220
|
-
};
|
|
221
|
-
CustomMap.prototype[Symbol.iterator] = function () {
|
|
222
|
-
return new CustomMapIterator(this.value);
|
|
223
|
-
};
|
|
224
|
-
CustomMap.prototype.extend = function (map) {
|
|
225
|
-
var e_6, _a;
|
|
226
|
-
if (map instanceof CustomMap) {
|
|
227
|
-
map = map.value;
|
|
228
|
-
}
|
|
229
|
-
try {
|
|
230
|
-
for (var map_1 = __values(map), map_1_1 = map_1.next(); !map_1_1.done; map_1_1 = map_1.next()) {
|
|
231
|
-
var _b = __read(map_1_1.value, 2), key = _b[0], value = _b[1];
|
|
232
|
-
(0, exports.setValue)(this.value, key, value);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
236
|
-
finally {
|
|
237
|
-
try {
|
|
238
|
-
if (map_1_1 && !map_1_1.done && (_a = map_1.return)) _a.call(map_1);
|
|
239
|
-
}
|
|
240
|
-
finally { if (e_6) throw e_6.error; }
|
|
241
|
-
}
|
|
242
|
-
return this;
|
|
243
|
-
};
|
|
244
|
-
CustomMap.prototype.has = function (path) {
|
|
245
|
-
if (path instanceof generics_1.CustomValue) {
|
|
246
|
-
return this.has(new path_1.default([path]));
|
|
247
|
-
}
|
|
248
|
-
var traversalPath = path.clone();
|
|
249
|
-
var current = traversalPath.next();
|
|
250
|
-
if (current !== null) {
|
|
251
|
-
if ((0, exports.hasValue)(this.value, current)) {
|
|
252
|
-
var sub = (0, exports.getValue)(this.value, current);
|
|
253
|
-
if (traversalPath.count() > 0 &&
|
|
254
|
-
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
255
|
-
return sub.has(traversalPath);
|
|
256
|
-
}
|
|
257
|
-
return traversalPath.count() === 0;
|
|
258
|
-
}
|
|
259
|
-
else if ((0, exports.hasValue)(this.isa, current)) {
|
|
260
|
-
var sub = (0, exports.getValue)(this.isa, current);
|
|
261
|
-
if (traversalPath.count() > 0 &&
|
|
262
|
-
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
263
|
-
return sub.has(traversalPath);
|
|
264
|
-
}
|
|
265
|
-
return traversalPath.count() === 0;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return false;
|
|
269
|
-
};
|
|
270
|
-
CustomMap.prototype.set = function (path, newValue) {
|
|
271
|
-
if (path instanceof generics_1.CustomValue) {
|
|
272
|
-
return this.set(new path_1.default([path]), newValue);
|
|
273
|
-
}
|
|
274
|
-
var traversalPath = path.clone();
|
|
275
|
-
var last = traversalPath.last();
|
|
276
|
-
var current = traversalPath.next();
|
|
277
|
-
if (current !== null) {
|
|
278
|
-
if ((0, exports.hasValue)(this.value, current)) {
|
|
279
|
-
var sub = (0, exports.getValue)(this.value, current);
|
|
280
|
-
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
281
|
-
sub.set(traversalPath, newValue);
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
throw new Error("Cannot set path ".concat(path.toString(), "."));
|
|
286
|
-
}
|
|
287
|
-
(0, exports.setValue)(this.value, last, newValue);
|
|
288
|
-
};
|
|
289
|
-
CustomMap.prototype.get = function (path) {
|
|
290
|
-
if (path instanceof generics_1.CustomValue) {
|
|
291
|
-
return this.get(new path_1.default([path]));
|
|
292
|
-
}
|
|
293
|
-
var traversalPath = path.clone();
|
|
294
|
-
var current = traversalPath.next();
|
|
295
|
-
if (current !== null) {
|
|
296
|
-
if ((0, exports.hasValue)(this.value, current)) {
|
|
297
|
-
var sub = (0, exports.getValue)(this.value, current);
|
|
298
|
-
if (traversalPath.count() > 0) {
|
|
299
|
-
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
300
|
-
return sub.get(traversalPath);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
else if (traversalPath.count() === 0) {
|
|
304
|
-
return sub;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
else if ((0, exports.hasValue)(this.isa, current)) {
|
|
308
|
-
var sub = (0, exports.getValue)(this.isa, current);
|
|
309
|
-
if (traversalPath.count() > 0) {
|
|
310
|
-
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
311
|
-
return sub.get(traversalPath);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
else if (traversalPath.count() === 0) {
|
|
315
|
-
return sub;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
else if (current.toString() === exports.ISA_PROPERTY.toString()) {
|
|
319
|
-
if (path.count() === 1) {
|
|
320
|
-
return new CustomMap(this.isa);
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
var ahead = traversalPath.next();
|
|
324
|
-
if ((0, exports.hasValue)(this.isa, ahead)) {
|
|
325
|
-
var sub = (0, exports.getValue)(this.isa, ahead);
|
|
326
|
-
if (traversalPath.count() > 0) {
|
|
327
|
-
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
328
|
-
return sub.get(traversalPath);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
else if (traversalPath.count() === 0) {
|
|
332
|
-
return sub;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
else if (path.count() === 1 &&
|
|
338
|
-
CustomMap.getIntrinsics().has(current.toString())) {
|
|
339
|
-
return CustomMap.getIntrinsics().get(current.toString());
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
throw new Error("Unknown path in map ".concat(path.toString(), "."));
|
|
343
|
-
};
|
|
344
|
-
CustomMap.prototype.createInstance = function () {
|
|
345
|
-
var e_7, _a;
|
|
346
|
-
var newInstance = new CustomMap(new Map(), new Map(__spreadArray([], __read(this.isa), false)));
|
|
347
|
-
try {
|
|
348
|
-
for (var _b = __values(this.value.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
349
|
-
var _d = __read(_c.value, 2), k = _d[0], v = _d[1];
|
|
350
|
-
(0, exports.setValue)(newInstance.isa, k, v);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
354
|
-
finally {
|
|
355
|
-
try {
|
|
356
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
357
|
-
}
|
|
358
|
-
finally { if (e_7) throw e_7.error; }
|
|
359
|
-
}
|
|
360
|
-
newInstance.isInstance = true;
|
|
361
|
-
return newInstance;
|
|
362
|
-
};
|
|
363
|
-
CustomMap.intrinsics = new intrinsics_container_1.default();
|
|
364
|
-
return CustomMap;
|
|
365
|
-
}(generics_1.CustomObject));
|
|
366
|
-
exports.default = CustomMap;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __values = (this && this.__values) || function(o) {
|
|
18
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
+
if (m) return m.call(o);
|
|
20
|
+
if (o && typeof o.length === "number") return {
|
|
21
|
+
next: function () {
|
|
22
|
+
if (o && i >= o.length) o = void 0;
|
|
23
|
+
return { value: o && o[i++], done: !o };
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
+
};
|
|
28
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
29
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30
|
+
if (!m) return o;
|
|
31
|
+
var i = m.call(o), r, ar = [], e;
|
|
32
|
+
try {
|
|
33
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
34
|
+
}
|
|
35
|
+
catch (error) { e = { error: error }; }
|
|
36
|
+
finally {
|
|
37
|
+
try {
|
|
38
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
39
|
+
}
|
|
40
|
+
finally { if (e) throw e.error; }
|
|
41
|
+
}
|
|
42
|
+
return ar;
|
|
43
|
+
};
|
|
44
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
45
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
46
|
+
if (ar || !(i in from)) {
|
|
47
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
48
|
+
ar[i] = from[i];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.CustomMapIterator = exports.setValue = exports.hasValue = exports.getValue = exports.ISA_PROPERTY = exports.CLASS_ID_PROPERTY = void 0;
|
|
58
|
+
var intrinsics_container_1 = __importDefault(require("../intrinsics-container"));
|
|
59
|
+
var deep_equal_1 = __importDefault(require("../utils/deep-equal"));
|
|
60
|
+
var path_1 = __importDefault(require("../utils/path"));
|
|
61
|
+
var default_1 = __importDefault(require("./default"));
|
|
62
|
+
var generics_1 = require("./generics");
|
|
63
|
+
var nil_1 = __importDefault(require("./nil"));
|
|
64
|
+
var string_1 = __importDefault(require("./string"));
|
|
65
|
+
exports.CLASS_ID_PROPERTY = new string_1.default('classID');
|
|
66
|
+
exports.ISA_PROPERTY = new string_1.default('__isa');
|
|
67
|
+
var getValue = function (map, mapKey) {
|
|
68
|
+
var e_1, _a;
|
|
69
|
+
try {
|
|
70
|
+
for (var _b = __values(map.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
71
|
+
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
72
|
+
if ((0, deep_equal_1.default)(key, mapKey)) {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
78
|
+
finally {
|
|
79
|
+
try {
|
|
80
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
81
|
+
}
|
|
82
|
+
finally { if (e_1) throw e_1.error; }
|
|
83
|
+
}
|
|
84
|
+
return default_1.default.Void;
|
|
85
|
+
};
|
|
86
|
+
exports.getValue = getValue;
|
|
87
|
+
var hasValue = function (map, mapKey) {
|
|
88
|
+
var e_2, _a;
|
|
89
|
+
try {
|
|
90
|
+
for (var _b = __values(map.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
91
|
+
var key = _c.value;
|
|
92
|
+
if ((0, deep_equal_1.default)(key, mapKey)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
98
|
+
finally {
|
|
99
|
+
try {
|
|
100
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
101
|
+
}
|
|
102
|
+
finally { if (e_2) throw e_2.error; }
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
};
|
|
106
|
+
exports.hasValue = hasValue;
|
|
107
|
+
var setValue = function (map, mapKey, mapValue) {
|
|
108
|
+
var e_3, _a;
|
|
109
|
+
try {
|
|
110
|
+
for (var _b = __values(map.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
111
|
+
var key = _c.value;
|
|
112
|
+
if ((0, deep_equal_1.default)(key, mapKey)) {
|
|
113
|
+
map.set(key, mapValue);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
119
|
+
finally {
|
|
120
|
+
try {
|
|
121
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
122
|
+
}
|
|
123
|
+
finally { if (e_3) throw e_3.error; }
|
|
124
|
+
}
|
|
125
|
+
map.set(mapKey, mapValue);
|
|
126
|
+
};
|
|
127
|
+
exports.setValue = setValue;
|
|
128
|
+
var CustomMapIterator = /** @class */ (function () {
|
|
129
|
+
function CustomMapIterator(value) {
|
|
130
|
+
var me = this;
|
|
131
|
+
me.value = value;
|
|
132
|
+
me.index = 0;
|
|
133
|
+
}
|
|
134
|
+
CustomMapIterator.prototype.next = function () {
|
|
135
|
+
var me = this;
|
|
136
|
+
var keys = Array.from(me.value.keys());
|
|
137
|
+
if (me.index === keys.length) {
|
|
138
|
+
return {
|
|
139
|
+
value: new nil_1.default(),
|
|
140
|
+
done: true
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
var key = keys[me.index++];
|
|
144
|
+
return {
|
|
145
|
+
value: new CustomMap(new Map([
|
|
146
|
+
[new string_1.default('key'), key],
|
|
147
|
+
[new string_1.default('value'), me.value.get(key)]
|
|
148
|
+
])),
|
|
149
|
+
done: false
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
return CustomMapIterator;
|
|
153
|
+
}());
|
|
154
|
+
exports.CustomMapIterator = CustomMapIterator;
|
|
155
|
+
var CustomMap = /** @class */ (function (_super) {
|
|
156
|
+
__extends(CustomMap, _super);
|
|
157
|
+
function CustomMap(value, isa) {
|
|
158
|
+
if (value === void 0) { value = new Map(); }
|
|
159
|
+
if (isa === void 0) { isa = new Map(); }
|
|
160
|
+
var _this = _super.call(this) || this;
|
|
161
|
+
_this.isInstance = false;
|
|
162
|
+
_this.value = new Map(value);
|
|
163
|
+
_this.isa = isa;
|
|
164
|
+
return _this;
|
|
165
|
+
}
|
|
166
|
+
CustomMap.getIntrinsics = function () {
|
|
167
|
+
return this.intrinsics;
|
|
168
|
+
};
|
|
169
|
+
CustomMap.addIntrinsic = function (name, fn) {
|
|
170
|
+
this.intrinsics.add(name, fn);
|
|
171
|
+
};
|
|
172
|
+
CustomMap.prototype.getCustomType = function () {
|
|
173
|
+
if ((0, exports.hasValue)(this.value, exports.CLASS_ID_PROPERTY)) {
|
|
174
|
+
return (0, exports.getValue)(this.value, exports.CLASS_ID_PROPERTY).toString();
|
|
175
|
+
}
|
|
176
|
+
return 'map';
|
|
177
|
+
};
|
|
178
|
+
CustomMap.prototype.toString = function () {
|
|
179
|
+
var _a, e_4, _b, e_5, _c;
|
|
180
|
+
var json = (_a = {}, _a[exports.ISA_PROPERTY.toString()] = {}, _a);
|
|
181
|
+
try {
|
|
182
|
+
for (var _d = __values(this.isa.entries()), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
183
|
+
var _f = __read(_e.value, 2), key = _f[0], value = _f[1];
|
|
184
|
+
json.__isa[key.toString()] = value.toString();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
188
|
+
finally {
|
|
189
|
+
try {
|
|
190
|
+
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
191
|
+
}
|
|
192
|
+
finally { if (e_4) throw e_4.error; }
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
for (var _g = __values(this.value.entries()), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
196
|
+
var _j = __read(_h.value, 2), key = _j[0], value = _j[1];
|
|
197
|
+
json[key.toString()] = value.toString();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
201
|
+
finally {
|
|
202
|
+
try {
|
|
203
|
+
if (_h && !_h.done && (_c = _g.return)) _c.call(_g);
|
|
204
|
+
}
|
|
205
|
+
finally { if (e_5) throw e_5.error; }
|
|
206
|
+
}
|
|
207
|
+
return JSON.stringify(json);
|
|
208
|
+
};
|
|
209
|
+
CustomMap.prototype.fork = function () {
|
|
210
|
+
return new CustomMap(this.value);
|
|
211
|
+
};
|
|
212
|
+
CustomMap.prototype.toNumber = function () {
|
|
213
|
+
return 0;
|
|
214
|
+
};
|
|
215
|
+
CustomMap.prototype.toInt = function () {
|
|
216
|
+
return 0;
|
|
217
|
+
};
|
|
218
|
+
CustomMap.prototype.toTruthy = function () {
|
|
219
|
+
return this.value.size > 0;
|
|
220
|
+
};
|
|
221
|
+
CustomMap.prototype[Symbol.iterator] = function () {
|
|
222
|
+
return new CustomMapIterator(this.value);
|
|
223
|
+
};
|
|
224
|
+
CustomMap.prototype.extend = function (map) {
|
|
225
|
+
var e_6, _a;
|
|
226
|
+
if (map instanceof CustomMap) {
|
|
227
|
+
map = map.value;
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
for (var map_1 = __values(map), map_1_1 = map_1.next(); !map_1_1.done; map_1_1 = map_1.next()) {
|
|
231
|
+
var _b = __read(map_1_1.value, 2), key = _b[0], value = _b[1];
|
|
232
|
+
(0, exports.setValue)(this.value, key, value);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
236
|
+
finally {
|
|
237
|
+
try {
|
|
238
|
+
if (map_1_1 && !map_1_1.done && (_a = map_1.return)) _a.call(map_1);
|
|
239
|
+
}
|
|
240
|
+
finally { if (e_6) throw e_6.error; }
|
|
241
|
+
}
|
|
242
|
+
return this;
|
|
243
|
+
};
|
|
244
|
+
CustomMap.prototype.has = function (path) {
|
|
245
|
+
if (path instanceof generics_1.CustomValue) {
|
|
246
|
+
return this.has(new path_1.default([path]));
|
|
247
|
+
}
|
|
248
|
+
var traversalPath = path.clone();
|
|
249
|
+
var current = traversalPath.next();
|
|
250
|
+
if (current !== null) {
|
|
251
|
+
if ((0, exports.hasValue)(this.value, current)) {
|
|
252
|
+
var sub = (0, exports.getValue)(this.value, current);
|
|
253
|
+
if (traversalPath.count() > 0 &&
|
|
254
|
+
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
255
|
+
return sub.has(traversalPath);
|
|
256
|
+
}
|
|
257
|
+
return traversalPath.count() === 0;
|
|
258
|
+
}
|
|
259
|
+
else if ((0, exports.hasValue)(this.isa, current)) {
|
|
260
|
+
var sub = (0, exports.getValue)(this.isa, current);
|
|
261
|
+
if (traversalPath.count() > 0 &&
|
|
262
|
+
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
263
|
+
return sub.has(traversalPath);
|
|
264
|
+
}
|
|
265
|
+
return traversalPath.count() === 0;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
};
|
|
270
|
+
CustomMap.prototype.set = function (path, newValue) {
|
|
271
|
+
if (path instanceof generics_1.CustomValue) {
|
|
272
|
+
return this.set(new path_1.default([path]), newValue);
|
|
273
|
+
}
|
|
274
|
+
var traversalPath = path.clone();
|
|
275
|
+
var last = traversalPath.last();
|
|
276
|
+
var current = traversalPath.next();
|
|
277
|
+
if (current !== null) {
|
|
278
|
+
if ((0, exports.hasValue)(this.value, current)) {
|
|
279
|
+
var sub = (0, exports.getValue)(this.value, current);
|
|
280
|
+
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
281
|
+
sub.set(traversalPath, newValue);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
throw new Error("Cannot set path ".concat(path.toString(), "."));
|
|
286
|
+
}
|
|
287
|
+
(0, exports.setValue)(this.value, last, newValue);
|
|
288
|
+
};
|
|
289
|
+
CustomMap.prototype.get = function (path) {
|
|
290
|
+
if (path instanceof generics_1.CustomValue) {
|
|
291
|
+
return this.get(new path_1.default([path]));
|
|
292
|
+
}
|
|
293
|
+
var traversalPath = path.clone();
|
|
294
|
+
var current = traversalPath.next();
|
|
295
|
+
if (current !== null) {
|
|
296
|
+
if ((0, exports.hasValue)(this.value, current)) {
|
|
297
|
+
var sub = (0, exports.getValue)(this.value, current);
|
|
298
|
+
if (traversalPath.count() > 0) {
|
|
299
|
+
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
300
|
+
return sub.get(traversalPath);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else if (traversalPath.count() === 0) {
|
|
304
|
+
return sub;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
else if ((0, exports.hasValue)(this.isa, current)) {
|
|
308
|
+
var sub = (0, exports.getValue)(this.isa, current);
|
|
309
|
+
if (traversalPath.count() > 0) {
|
|
310
|
+
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
311
|
+
return sub.get(traversalPath);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else if (traversalPath.count() === 0) {
|
|
315
|
+
return sub;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
else if (current.toString() === exports.ISA_PROPERTY.toString()) {
|
|
319
|
+
if (path.count() === 1) {
|
|
320
|
+
return new CustomMap(this.isa);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
var ahead = traversalPath.next();
|
|
324
|
+
if ((0, exports.hasValue)(this.isa, ahead)) {
|
|
325
|
+
var sub = (0, exports.getValue)(this.isa, ahead);
|
|
326
|
+
if (traversalPath.count() > 0) {
|
|
327
|
+
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
328
|
+
return sub.get(traversalPath);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
else if (traversalPath.count() === 0) {
|
|
332
|
+
return sub;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
else if (path.count() === 1 &&
|
|
338
|
+
CustomMap.getIntrinsics().has(current.toString())) {
|
|
339
|
+
return CustomMap.getIntrinsics().get(current.toString());
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
throw new Error("Unknown path in map ".concat(path.toString(), "."));
|
|
343
|
+
};
|
|
344
|
+
CustomMap.prototype.createInstance = function () {
|
|
345
|
+
var e_7, _a;
|
|
346
|
+
var newInstance = new CustomMap(new Map(), new Map(__spreadArray([], __read(this.isa), false)));
|
|
347
|
+
try {
|
|
348
|
+
for (var _b = __values(this.value.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
349
|
+
var _d = __read(_c.value, 2), k = _d[0], v = _d[1];
|
|
350
|
+
(0, exports.setValue)(newInstance.isa, k, v);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
354
|
+
finally {
|
|
355
|
+
try {
|
|
356
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
357
|
+
}
|
|
358
|
+
finally { if (e_7) throw e_7.error; }
|
|
359
|
+
}
|
|
360
|
+
newInstance.isInstance = true;
|
|
361
|
+
return newInstance;
|
|
362
|
+
};
|
|
363
|
+
CustomMap.intrinsics = new intrinsics_container_1.default();
|
|
364
|
+
return CustomMap;
|
|
365
|
+
}(generics_1.CustomObject));
|
|
366
|
+
exports.default = CustomMap;
|