greybel-interpreter 1.3.5 → 1.3.7
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/dist/types/function.d.ts +1 -1
- package/dist/types/map.d.ts +6 -4
- package/dist/types/map.js +106 -29
- package/package.json +1 -1
package/dist/types/function.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import OperationContext from '../context';
|
|
|
2
2
|
import Operation from '../operations/operation';
|
|
3
3
|
import { CustomValue } from './generics';
|
|
4
4
|
export interface Callback {
|
|
5
|
-
(ctx: OperationContext, self: CustomValue, args: Map<string, CustomValue>): Promise<CustomValue
|
|
5
|
+
(ctx: OperationContext, self: CustomValue, args: Map<string, CustomValue>): Promise<NonNullable<CustomValue>>;
|
|
6
6
|
}
|
|
7
7
|
export declare class Argument {
|
|
8
8
|
readonly name: string;
|
package/dist/types/map.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ import CustomFunction from './function';
|
|
|
4
4
|
import { CustomObject, CustomValue } from './generics';
|
|
5
5
|
import CustomString from './string';
|
|
6
6
|
export declare const CLASS_ID_PROPERTY: CustomString;
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
7
|
+
export declare const ISA_PROPERTY: CustomString;
|
|
8
|
+
export declare const getValue: (map: Map<CustomValue, CustomValue>, mapKey: CustomValue) => CustomValue;
|
|
9
|
+
export declare const hasValue: (map: Map<CustomValue, CustomValue>, mapKey: CustomValue) => boolean;
|
|
10
|
+
export declare const setValue: (map: Map<CustomValue, CustomValue>, mapKey: CustomValue, mapValue: CustomValue) => void;
|
|
10
11
|
export declare class CustomMapIterator implements Iterator<CustomValue> {
|
|
11
12
|
value: Map<CustomValue, CustomValue>;
|
|
12
13
|
index: number;
|
|
@@ -18,8 +19,9 @@ export default class CustomMap extends CustomObject {
|
|
|
18
19
|
static getIntrinsics(): IntrinsicsContainer;
|
|
19
20
|
static addIntrinsic(name: string, fn: CustomFunction): void;
|
|
20
21
|
readonly value: Map<CustomValue, CustomValue>;
|
|
22
|
+
readonly isa: Map<CustomValue, CustomValue>;
|
|
21
23
|
private isInstance;
|
|
22
|
-
constructor(value?: Map<CustomValue, CustomValue>);
|
|
24
|
+
constructor(value?: Map<CustomValue, CustomValue>, isa?: Map<CustomValue, CustomValue>);
|
|
23
25
|
getCustomType(): string;
|
|
24
26
|
toString(): string;
|
|
25
27
|
fork(): CustomMap;
|
package/dist/types/map.js
CHANGED
|
@@ -41,23 +41,33 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
41
41
|
}
|
|
42
42
|
return ar;
|
|
43
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
|
+
};
|
|
44
53
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
54
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
55
|
};
|
|
47
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.CustomMapIterator = exports.setValue = exports.hasValue = exports.getValue = exports.CLASS_ID_PROPERTY = void 0;
|
|
57
|
+
exports.CustomMapIterator = exports.setValue = exports.hasValue = exports.getValue = exports.ISA_PROPERTY = exports.CLASS_ID_PROPERTY = void 0;
|
|
49
58
|
var intrinsics_container_1 = __importDefault(require("../intrinsics-container"));
|
|
59
|
+
var deep_equal_1 = __importDefault(require("../utils/deep-equal"));
|
|
50
60
|
var path_1 = __importDefault(require("../utils/path"));
|
|
51
61
|
var default_1 = __importDefault(require("./default"));
|
|
52
62
|
var generics_1 = require("./generics");
|
|
53
63
|
var nil_1 = __importDefault(require("./nil"));
|
|
54
64
|
var string_1 = __importDefault(require("./string"));
|
|
55
|
-
var deep_equal_1 = __importDefault(require("../utils/deep-equal"));
|
|
56
65
|
exports.CLASS_ID_PROPERTY = new string_1.default('classID');
|
|
66
|
+
exports.ISA_PROPERTY = new string_1.default('__isa');
|
|
57
67
|
var getValue = function (map, mapKey) {
|
|
58
68
|
var e_1, _a;
|
|
59
69
|
try {
|
|
60
|
-
for (var _b = __values(map.
|
|
70
|
+
for (var _b = __values(map.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
61
71
|
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
62
72
|
if ((0, deep_equal_1.default)(key, mapKey)) {
|
|
63
73
|
return value;
|
|
@@ -77,7 +87,7 @@ exports.getValue = getValue;
|
|
|
77
87
|
var hasValue = function (map, mapKey) {
|
|
78
88
|
var e_2, _a;
|
|
79
89
|
try {
|
|
80
|
-
for (var _b = __values(map.
|
|
90
|
+
for (var _b = __values(map.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
81
91
|
var key = _c.value;
|
|
82
92
|
if ((0, deep_equal_1.default)(key, mapKey)) {
|
|
83
93
|
return true;
|
|
@@ -97,10 +107,10 @@ exports.hasValue = hasValue;
|
|
|
97
107
|
var setValue = function (map, mapKey, mapValue) {
|
|
98
108
|
var e_3, _a;
|
|
99
109
|
try {
|
|
100
|
-
for (var _b = __values(map.
|
|
110
|
+
for (var _b = __values(map.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
101
111
|
var key = _c.value;
|
|
102
112
|
if ((0, deep_equal_1.default)(key, mapKey)) {
|
|
103
|
-
map.
|
|
113
|
+
map.set(key, mapValue);
|
|
104
114
|
return;
|
|
105
115
|
}
|
|
106
116
|
}
|
|
@@ -112,7 +122,7 @@ var setValue = function (map, mapKey, mapValue) {
|
|
|
112
122
|
}
|
|
113
123
|
finally { if (e_3) throw e_3.error; }
|
|
114
124
|
}
|
|
115
|
-
map.
|
|
125
|
+
map.set(mapKey, mapValue);
|
|
116
126
|
};
|
|
117
127
|
exports.setValue = setValue;
|
|
118
128
|
var CustomMapIterator = /** @class */ (function () {
|
|
@@ -144,11 +154,13 @@ var CustomMapIterator = /** @class */ (function () {
|
|
|
144
154
|
exports.CustomMapIterator = CustomMapIterator;
|
|
145
155
|
var CustomMap = /** @class */ (function (_super) {
|
|
146
156
|
__extends(CustomMap, _super);
|
|
147
|
-
function CustomMap(value) {
|
|
157
|
+
function CustomMap(value, isa) {
|
|
148
158
|
if (value === void 0) { value = new Map(); }
|
|
159
|
+
if (isa === void 0) { isa = new Map(); }
|
|
149
160
|
var _this = _super.call(this) || this;
|
|
150
161
|
_this.isInstance = false;
|
|
151
162
|
_this.value = new Map(value);
|
|
163
|
+
_this.isa = isa;
|
|
152
164
|
return _this;
|
|
153
165
|
}
|
|
154
166
|
CustomMap.getIntrinsics = function () {
|
|
@@ -158,28 +170,41 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
158
170
|
this.intrinsics.add(name, fn);
|
|
159
171
|
};
|
|
160
172
|
CustomMap.prototype.getCustomType = function () {
|
|
161
|
-
if ((0, exports.hasValue)(this, exports.CLASS_ID_PROPERTY)) {
|
|
162
|
-
return (0, exports.getValue)(this, exports.CLASS_ID_PROPERTY).toString();
|
|
173
|
+
if ((0, exports.hasValue)(this.value, exports.CLASS_ID_PROPERTY)) {
|
|
174
|
+
return (0, exports.getValue)(this.value, exports.CLASS_ID_PROPERTY).toString();
|
|
163
175
|
}
|
|
164
176
|
return 'map';
|
|
165
177
|
};
|
|
166
178
|
CustomMap.prototype.toString = function () {
|
|
167
|
-
var e_4,
|
|
168
|
-
var
|
|
179
|
+
var _a, e_4, _b, e_5, _c;
|
|
180
|
+
var json = (_a = {}, _a[exports.ISA_PROPERTY.toString()] = {}, _a);
|
|
169
181
|
try {
|
|
170
|
-
for (var
|
|
171
|
-
var
|
|
172
|
-
|
|
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();
|
|
173
185
|
}
|
|
174
186
|
}
|
|
175
187
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
176
188
|
finally {
|
|
177
189
|
try {
|
|
178
|
-
if (
|
|
190
|
+
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
179
191
|
}
|
|
180
192
|
finally { if (e_4) throw e_4.error; }
|
|
181
193
|
}
|
|
182
|
-
|
|
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);
|
|
183
208
|
};
|
|
184
209
|
CustomMap.prototype.fork = function () {
|
|
185
210
|
return new CustomMap(this.value);
|
|
@@ -197,22 +222,22 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
197
222
|
return new CustomMapIterator(this.value);
|
|
198
223
|
};
|
|
199
224
|
CustomMap.prototype.extend = function (map) {
|
|
200
|
-
var
|
|
225
|
+
var e_6, _a;
|
|
201
226
|
if (map instanceof CustomMap) {
|
|
202
227
|
map = map.value;
|
|
203
228
|
}
|
|
204
229
|
try {
|
|
205
230
|
for (var map_1 = __values(map), map_1_1 = map_1.next(); !map_1_1.done; map_1_1 = map_1.next()) {
|
|
206
231
|
var _b = __read(map_1_1.value, 2), key = _b[0], value = _b[1];
|
|
207
|
-
(0, exports.setValue)(this, key, value);
|
|
232
|
+
(0, exports.setValue)(this.value, key, value);
|
|
208
233
|
}
|
|
209
234
|
}
|
|
210
|
-
catch (
|
|
235
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
211
236
|
finally {
|
|
212
237
|
try {
|
|
213
238
|
if (map_1_1 && !map_1_1.done && (_a = map_1.return)) _a.call(map_1);
|
|
214
239
|
}
|
|
215
|
-
finally { if (
|
|
240
|
+
finally { if (e_6) throw e_6.error; }
|
|
216
241
|
}
|
|
217
242
|
return this;
|
|
218
243
|
};
|
|
@@ -223,8 +248,16 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
223
248
|
var traversalPath = path.clone();
|
|
224
249
|
var current = traversalPath.next();
|
|
225
250
|
if (current !== null) {
|
|
226
|
-
if ((0, exports.hasValue)(this, current)) {
|
|
227
|
-
var sub = (0, exports.getValue)(this, current);
|
|
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);
|
|
228
261
|
if (traversalPath.count() > 0 &&
|
|
229
262
|
sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
230
263
|
return sub.has(traversalPath);
|
|
@@ -242,8 +275,8 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
242
275
|
var last = traversalPath.last();
|
|
243
276
|
var current = traversalPath.next();
|
|
244
277
|
if (current !== null) {
|
|
245
|
-
if ((0, exports.hasValue)(this, current)) {
|
|
246
|
-
var sub = (0, exports.getValue)(this, current);
|
|
278
|
+
if ((0, exports.hasValue)(this.value, current)) {
|
|
279
|
+
var sub = (0, exports.getValue)(this.value, current);
|
|
247
280
|
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
248
281
|
sub.set(traversalPath, newValue);
|
|
249
282
|
return;
|
|
@@ -251,7 +284,7 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
251
284
|
}
|
|
252
285
|
throw new Error("Cannot set path ".concat(path.toString(), "."));
|
|
253
286
|
}
|
|
254
|
-
(0, exports.setValue)(this, last, newValue);
|
|
287
|
+
(0, exports.setValue)(this.value, last, newValue);
|
|
255
288
|
};
|
|
256
289
|
CustomMap.prototype.get = function (path) {
|
|
257
290
|
if (path instanceof generics_1.CustomValue) {
|
|
@@ -260,8 +293,8 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
260
293
|
var traversalPath = path.clone();
|
|
261
294
|
var current = traversalPath.next();
|
|
262
295
|
if (current !== null) {
|
|
263
|
-
if ((0, exports.hasValue)(this, current)) {
|
|
264
|
-
var sub = (0, exports.getValue)(this, current);
|
|
296
|
+
if ((0, exports.hasValue)(this.value, current)) {
|
|
297
|
+
var sub = (0, exports.getValue)(this.value, current);
|
|
265
298
|
if (traversalPath.count() > 0) {
|
|
266
299
|
if (sub instanceof generics_1.CustomValueWithIntrinsics) {
|
|
267
300
|
return sub.get(traversalPath);
|
|
@@ -271,6 +304,36 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
271
304
|
return sub;
|
|
272
305
|
}
|
|
273
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
|
+
}
|
|
274
337
|
else if (path.count() === 1 &&
|
|
275
338
|
CustomMap.getIntrinsics().has(current.toString())) {
|
|
276
339
|
return CustomMap.getIntrinsics().get(current.toString());
|
|
@@ -279,7 +342,21 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
279
342
|
throw new Error("Unknown path in map ".concat(path.toString(), "."));
|
|
280
343
|
};
|
|
281
344
|
CustomMap.prototype.createInstance = function () {
|
|
282
|
-
var
|
|
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
|
+
}
|
|
283
360
|
newInstance.isInstance = true;
|
|
284
361
|
return newInstance;
|
|
285
362
|
};
|