greybel-interpreter 0.2.0 → 0.2.1
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/LICENSE +21 -21
- package/README.md +2 -2
- package/dist/context.d.ts +81 -73
- package/dist/context.js +412 -405
- package/dist/cps.d.ts +15 -15
- package/dist/cps.js +849 -816
- package/dist/custom-types/boolean.d.ts +10 -10
- package/dist/custom-types/boolean.js +41 -41
- package/dist/custom-types/list.d.ts +25 -25
- package/dist/custom-types/list.js +292 -292
- package/dist/custom-types/map.d.ts +28 -28
- package/dist/custom-types/map.js +289 -289
- package/dist/custom-types/nil.d.ts +8 -8
- package/dist/custom-types/nil.js +38 -38
- package/dist/custom-types/number.d.ts +10 -10
- package/dist/custom-types/number.js +41 -41
- package/dist/custom-types/string.d.ts +21 -21
- package/dist/custom-types/string.js +131 -131
- package/dist/expressions/assign.d.ts +13 -13
- package/dist/expressions/assign.js +174 -174
- package/dist/expressions/binary-negated-expression.d.ts +19 -19
- package/dist/expressions/binary-negated-expression.js +131 -131
- package/dist/expressions/call.d.ts +14 -14
- package/dist/expressions/call.js +211 -208
- package/dist/expressions/import.d.ts +14 -0
- package/dist/expressions/import.js +155 -0
- package/dist/expressions/include.d.ts +13 -0
- package/dist/expressions/include.js +132 -0
- package/dist/expressions/list.d.ts +14 -14
- package/dist/expressions/list.js +134 -134
- package/dist/expressions/logical-and-binary.d.ts +23 -23
- package/dist/expressions/logical-and-binary.js +212 -212
- package/dist/expressions/map.d.ts +19 -19
- package/dist/expressions/map.js +196 -196
- package/dist/expressions/path.d.ts +31 -31
- package/dist/expressions/path.js +364 -364
- package/dist/index.d.ts +37 -37
- package/dist/index.js +91 -91
- package/dist/interpreter.d.ts +22 -22
- package/dist/interpreter.js +121 -121
- package/dist/operations/argument.d.ts +8 -8
- package/dist/operations/argument.js +129 -129
- package/dist/operations/body.d.ts +8 -8
- package/dist/operations/body.js +144 -144
- package/dist/operations/break.d.ts +7 -7
- package/dist/operations/break.js +34 -34
- package/dist/operations/continue.d.ts +7 -7
- package/dist/operations/continue.js +34 -34
- package/dist/operations/debugger.d.ts +7 -7
- package/dist/operations/debugger.js +32 -32
- package/dist/operations/else-if.d.ts +12 -12
- package/dist/operations/else-if.js +31 -31
- package/dist/operations/else.d.ts +10 -10
- package/dist/operations/else.js +30 -30
- package/dist/operations/for.d.ts +16 -16
- package/dist/operations/for.js +143 -139
- package/dist/operations/function.d.ts +21 -21
- package/dist/operations/function.js +129 -125
- package/dist/operations/if-statement.d.ts +8 -8
- package/dist/operations/if-statement.js +138 -138
- package/dist/operations/if.d.ts +12 -12
- package/dist/operations/if.js +31 -31
- package/dist/operations/new.d.ts +11 -11
- package/dist/operations/new.js +96 -96
- package/dist/operations/not.d.ts +11 -11
- package/dist/operations/not.js +95 -95
- package/dist/operations/reference.d.ts +11 -11
- package/dist/operations/reference.js +102 -102
- package/dist/operations/return.d.ts +11 -11
- package/dist/operations/return.js +102 -102
- package/dist/operations/top.d.ts +12 -12
- package/dist/operations/top.js +87 -84
- package/dist/operations/while.d.ts +14 -14
- package/dist/operations/while.js +127 -123
- package/dist/resource.d.ts +9 -9
- package/dist/resource.js +29 -29
- package/dist/typer.d.ts +6 -6
- package/dist/typer.js +95 -95
- package/dist/types/custom-type.d.ts +19 -19
- package/dist/types/custom-type.js +58 -58
- package/dist/types/expression.d.ts +6 -6
- package/dist/types/expression.js +9 -9
- package/dist/types/operation.d.ts +9 -9
- package/dist/types/operation.js +38 -38
- package/package.json +45 -45
package/dist/custom-types/map.js
CHANGED
|
@@ -1,289 +1,289 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
54
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
55
|
-
if (!m) return o;
|
|
56
|
-
var i = m.call(o), r, ar = [], e;
|
|
57
|
-
try {
|
|
58
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
59
|
-
}
|
|
60
|
-
catch (error) { e = { error: error }; }
|
|
61
|
-
finally {
|
|
62
|
-
try {
|
|
63
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
64
|
-
}
|
|
65
|
-
finally { if (e) throw e.error; }
|
|
66
|
-
}
|
|
67
|
-
return ar;
|
|
68
|
-
};
|
|
69
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
70
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
71
|
-
if (ar || !(i in from)) {
|
|
72
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
73
|
-
ar[i] = from[i];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
77
|
-
};
|
|
78
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
|
-
exports.CustomMapIterator = void 0;
|
|
80
|
-
var custom_type_1 = require("../types/custom-type");
|
|
81
|
-
var operation_1 = require("../types/operation");
|
|
82
|
-
var CustomMapIterator = /** @class */ (function () {
|
|
83
|
-
function CustomMapIterator(value) {
|
|
84
|
-
var me = this;
|
|
85
|
-
me.value = value;
|
|
86
|
-
me.index = 0;
|
|
87
|
-
}
|
|
88
|
-
CustomMapIterator.prototype.next = function () {
|
|
89
|
-
var me = this;
|
|
90
|
-
var keys = Object.keys(me.value);
|
|
91
|
-
if (me.index === keys.length) {
|
|
92
|
-
return {
|
|
93
|
-
value: null,
|
|
94
|
-
done: true
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
var key = keys[me.index++];
|
|
98
|
-
return {
|
|
99
|
-
value: {
|
|
100
|
-
key: key,
|
|
101
|
-
value: me.value[key]
|
|
102
|
-
},
|
|
103
|
-
done: false
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
return CustomMapIterator;
|
|
107
|
-
}());
|
|
108
|
-
exports.CustomMapIterator = CustomMapIterator;
|
|
109
|
-
var CustomMap = /** @class */ (function (_super) {
|
|
110
|
-
__extends(CustomMap, _super);
|
|
111
|
-
function CustomMap(value) {
|
|
112
|
-
var _this = _super.call(this) || this;
|
|
113
|
-
var me = _this;
|
|
114
|
-
me.value = new Map(__spreadArray([], __read(value.entries()), false));
|
|
115
|
-
me.isInstance = false;
|
|
116
|
-
return _this;
|
|
117
|
-
}
|
|
118
|
-
CustomMap.prototype[Symbol.iterator] = function () {
|
|
119
|
-
return new CustomMapIterator(this.value);
|
|
120
|
-
};
|
|
121
|
-
CustomMap.prototype.extend = function (value) {
|
|
122
|
-
var me = this;
|
|
123
|
-
me.value = new Map(__spreadArray(__spreadArray([], __read(me.value.entries()), false), __read(value.entries()), false));
|
|
124
|
-
return me;
|
|
125
|
-
};
|
|
126
|
-
CustomMap.prototype.set = function (path, value) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
var me, traversalPath, refs, last, current, origin;
|
|
129
|
-
return __generator(this, function (_a) {
|
|
130
|
-
me = this;
|
|
131
|
-
traversalPath = [].concat(path);
|
|
132
|
-
refs = me.value;
|
|
133
|
-
last = traversalPath.pop();
|
|
134
|
-
current = traversalPath.shift();
|
|
135
|
-
origin = refs;
|
|
136
|
-
if (current != null) {
|
|
137
|
-
if (origin.has(current)) {
|
|
138
|
-
origin = origin.get(current);
|
|
139
|
-
if (origin instanceof custom_type_1.CustomObjectType) {
|
|
140
|
-
return [2 /*return*/, origin.set(traversalPath.concat(last), value)];
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (origin) {
|
|
148
|
-
if (value instanceof operation_1.FunctionOperationBase) {
|
|
149
|
-
origin.set(last, value.fork(me));
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
origin.set(last, value);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
157
|
-
}
|
|
158
|
-
return [2 /*return*/];
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
CustomMap.prototype.get = function (path) {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
164
|
-
var me, traversalPath, refs, current, currentValue, origin;
|
|
165
|
-
return __generator(this, function (_a) {
|
|
166
|
-
me = this;
|
|
167
|
-
if (path.length === 0) {
|
|
168
|
-
return [2 /*return*/, me];
|
|
169
|
-
}
|
|
170
|
-
traversalPath = [].concat(path);
|
|
171
|
-
refs = me.value;
|
|
172
|
-
current = traversalPath.shift();
|
|
173
|
-
currentValue = current.valueOf();
|
|
174
|
-
origin = refs;
|
|
175
|
-
if (currentValue != null) {
|
|
176
|
-
if (origin.has(currentValue)) {
|
|
177
|
-
origin = origin.get(currentValue);
|
|
178
|
-
if (traversalPath.length > 0 && origin instanceof custom_type_1.CustomObjectType) {
|
|
179
|
-
return [2 /*return*/, origin.get(traversalPath)];
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
else if (path.length === 1 && CustomMap.intrinsics.has(currentValue)) {
|
|
183
|
-
return [2 /*return*/, CustomMap.intrinsics.get(currentValue).bind(null, me)];
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
return [2 /*return*/, null];
|
|
191
|
-
}
|
|
192
|
-
return [2 /*return*/, origin];
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
};
|
|
196
|
-
CustomMap.prototype.getCallable = function (path) {
|
|
197
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
-
var me, traversalPath, refs, current, origin, context;
|
|
199
|
-
return __generator(this, function (_a) {
|
|
200
|
-
me = this;
|
|
201
|
-
traversalPath = [].concat(path);
|
|
202
|
-
refs = me.value;
|
|
203
|
-
current = traversalPath.shift();
|
|
204
|
-
origin = refs;
|
|
205
|
-
if (current != null) {
|
|
206
|
-
if (origin.has(current)) {
|
|
207
|
-
context = origin;
|
|
208
|
-
origin = origin.get(current);
|
|
209
|
-
if (origin instanceof custom_type_1.CustomObjectType) {
|
|
210
|
-
return [2 /*return*/, origin.getCallable(traversalPath)];
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
else if (path.length === 1 && CustomMap.intrinsics.has(current)) {
|
|
214
|
-
return [2 /*return*/, {
|
|
215
|
-
origin: CustomMap.intrinsics.get(current).bind(null, me),
|
|
216
|
-
context: me
|
|
217
|
-
}];
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return [2 /*return*/, {
|
|
224
|
-
origin: origin,
|
|
225
|
-
context: context
|
|
226
|
-
}];
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
CustomMap.prototype.callMethod = function (method) {
|
|
231
|
-
var _a;
|
|
232
|
-
var args = [];
|
|
233
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
234
|
-
args[_i - 1] = arguments[_i];
|
|
235
|
-
}
|
|
236
|
-
if (method.length === 0) {
|
|
237
|
-
throw new Error('Unexpected method length');
|
|
238
|
-
}
|
|
239
|
-
var me = this;
|
|
240
|
-
var key = method[0].valueOf();
|
|
241
|
-
if (method.length > 1) {
|
|
242
|
-
if (me.value.has(key)) {
|
|
243
|
-
return (_a = me.value.get(key)).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
|
|
244
|
-
}
|
|
245
|
-
throw new Error("Unexpected method path");
|
|
246
|
-
}
|
|
247
|
-
if (!CustomMap.intrinsics.has(key)) {
|
|
248
|
-
throw new Error("Cannot access ".concat(key, " in map"));
|
|
249
|
-
}
|
|
250
|
-
return CustomMap.intrinsics.get(key).apply(void 0, __spreadArray([me], __read(args), false));
|
|
251
|
-
};
|
|
252
|
-
CustomMap.prototype.createInstancefunction = function () {
|
|
253
|
-
var me = this;
|
|
254
|
-
var value = new Map();
|
|
255
|
-
var newInstance = new CustomMap(value);
|
|
256
|
-
newInstance.isInstance = true;
|
|
257
|
-
me.value.forEach(function (item, key) {
|
|
258
|
-
value.set(key, item instanceof operation_1.FunctionOperationBase
|
|
259
|
-
? item.fork(newInstance)
|
|
260
|
-
: item);
|
|
261
|
-
});
|
|
262
|
-
return newInstance;
|
|
263
|
-
};
|
|
264
|
-
CustomMap.prototype.getType = function () {
|
|
265
|
-
var me = this;
|
|
266
|
-
return me.value.get('classID') || 'map';
|
|
267
|
-
};
|
|
268
|
-
CustomMap.prototype.valueOf = function () {
|
|
269
|
-
var me = this;
|
|
270
|
-
var value = me.value;
|
|
271
|
-
return value.size === 0 ? null : me;
|
|
272
|
-
};
|
|
273
|
-
CustomMap.prototype.toString = function () {
|
|
274
|
-
var me = this;
|
|
275
|
-
var body = Object
|
|
276
|
-
.entries(me.value)
|
|
277
|
-
.map(function (_a) {
|
|
278
|
-
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
279
|
-
return "\"".concat(key, "\": ").concat(value.valueOf().toString());
|
|
280
|
-
});
|
|
281
|
-
return "{".concat(body.join(','), "}");
|
|
282
|
-
};
|
|
283
|
-
CustomMap.prototype.fork = function () {
|
|
284
|
-
return new CustomMap(this.value);
|
|
285
|
-
};
|
|
286
|
-
CustomMap.intrinsics = new Map();
|
|
287
|
-
return CustomMap;
|
|
288
|
-
}(custom_type_1.CustomObjectType));
|
|
289
|
-
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
54
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
55
|
+
if (!m) return o;
|
|
56
|
+
var i = m.call(o), r, ar = [], e;
|
|
57
|
+
try {
|
|
58
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
59
|
+
}
|
|
60
|
+
catch (error) { e = { error: error }; }
|
|
61
|
+
finally {
|
|
62
|
+
try {
|
|
63
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
64
|
+
}
|
|
65
|
+
finally { if (e) throw e.error; }
|
|
66
|
+
}
|
|
67
|
+
return ar;
|
|
68
|
+
};
|
|
69
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
70
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
71
|
+
if (ar || !(i in from)) {
|
|
72
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
73
|
+
ar[i] = from[i];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
77
|
+
};
|
|
78
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
|
+
exports.CustomMapIterator = void 0;
|
|
80
|
+
var custom_type_1 = require("../types/custom-type");
|
|
81
|
+
var operation_1 = require("../types/operation");
|
|
82
|
+
var CustomMapIterator = /** @class */ (function () {
|
|
83
|
+
function CustomMapIterator(value) {
|
|
84
|
+
var me = this;
|
|
85
|
+
me.value = value;
|
|
86
|
+
me.index = 0;
|
|
87
|
+
}
|
|
88
|
+
CustomMapIterator.prototype.next = function () {
|
|
89
|
+
var me = this;
|
|
90
|
+
var keys = Object.keys(me.value);
|
|
91
|
+
if (me.index === keys.length) {
|
|
92
|
+
return {
|
|
93
|
+
value: null,
|
|
94
|
+
done: true
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
var key = keys[me.index++];
|
|
98
|
+
return {
|
|
99
|
+
value: {
|
|
100
|
+
key: key,
|
|
101
|
+
value: me.value[key]
|
|
102
|
+
},
|
|
103
|
+
done: false
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
return CustomMapIterator;
|
|
107
|
+
}());
|
|
108
|
+
exports.CustomMapIterator = CustomMapIterator;
|
|
109
|
+
var CustomMap = /** @class */ (function (_super) {
|
|
110
|
+
__extends(CustomMap, _super);
|
|
111
|
+
function CustomMap(value) {
|
|
112
|
+
var _this = _super.call(this) || this;
|
|
113
|
+
var me = _this;
|
|
114
|
+
me.value = new Map(__spreadArray([], __read(value.entries()), false));
|
|
115
|
+
me.isInstance = false;
|
|
116
|
+
return _this;
|
|
117
|
+
}
|
|
118
|
+
CustomMap.prototype[Symbol.iterator] = function () {
|
|
119
|
+
return new CustomMapIterator(this.value);
|
|
120
|
+
};
|
|
121
|
+
CustomMap.prototype.extend = function (value) {
|
|
122
|
+
var me = this;
|
|
123
|
+
me.value = new Map(__spreadArray(__spreadArray([], __read(me.value.entries()), false), __read(value.entries()), false));
|
|
124
|
+
return me;
|
|
125
|
+
};
|
|
126
|
+
CustomMap.prototype.set = function (path, value) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
+
var me, traversalPath, refs, last, current, origin;
|
|
129
|
+
return __generator(this, function (_a) {
|
|
130
|
+
me = this;
|
|
131
|
+
traversalPath = [].concat(path);
|
|
132
|
+
refs = me.value;
|
|
133
|
+
last = traversalPath.pop();
|
|
134
|
+
current = traversalPath.shift();
|
|
135
|
+
origin = refs;
|
|
136
|
+
if (current != null) {
|
|
137
|
+
if (origin.has(current)) {
|
|
138
|
+
origin = origin.get(current);
|
|
139
|
+
if (origin instanceof custom_type_1.CustomObjectType) {
|
|
140
|
+
return [2 /*return*/, origin.set(traversalPath.concat(last), value)];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (origin) {
|
|
148
|
+
if (value instanceof operation_1.FunctionOperationBase) {
|
|
149
|
+
origin.set(last, value.fork(me));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
origin.set(last, value);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
157
|
+
}
|
|
158
|
+
return [2 /*return*/];
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
CustomMap.prototype.get = function (path) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
164
|
+
var me, traversalPath, refs, current, currentValue, origin;
|
|
165
|
+
return __generator(this, function (_a) {
|
|
166
|
+
me = this;
|
|
167
|
+
if (path.length === 0) {
|
|
168
|
+
return [2 /*return*/, me];
|
|
169
|
+
}
|
|
170
|
+
traversalPath = [].concat(path);
|
|
171
|
+
refs = me.value;
|
|
172
|
+
current = traversalPath.shift();
|
|
173
|
+
currentValue = current.valueOf();
|
|
174
|
+
origin = refs;
|
|
175
|
+
if (currentValue != null) {
|
|
176
|
+
if (origin.has(currentValue)) {
|
|
177
|
+
origin = origin.get(currentValue);
|
|
178
|
+
if (traversalPath.length > 0 && origin instanceof custom_type_1.CustomObjectType) {
|
|
179
|
+
return [2 /*return*/, origin.get(traversalPath)];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else if (path.length === 1 && CustomMap.intrinsics.has(currentValue)) {
|
|
183
|
+
return [2 /*return*/, CustomMap.intrinsics.get(currentValue).bind(null, me)];
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
return [2 /*return*/, null];
|
|
191
|
+
}
|
|
192
|
+
return [2 /*return*/, origin];
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
CustomMap.prototype.getCallable = function (path) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
+
var me, traversalPath, refs, current, origin, context;
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
me = this;
|
|
201
|
+
traversalPath = [].concat(path);
|
|
202
|
+
refs = me.value;
|
|
203
|
+
current = traversalPath.shift();
|
|
204
|
+
origin = refs;
|
|
205
|
+
if (current != null) {
|
|
206
|
+
if (origin.has(current)) {
|
|
207
|
+
context = origin;
|
|
208
|
+
origin = origin.get(current);
|
|
209
|
+
if (origin instanceof custom_type_1.CustomObjectType) {
|
|
210
|
+
return [2 /*return*/, origin.getCallable(traversalPath)];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (path.length === 1 && CustomMap.intrinsics.has(current)) {
|
|
214
|
+
return [2 /*return*/, {
|
|
215
|
+
origin: CustomMap.intrinsics.get(current).bind(null, me),
|
|
216
|
+
context: me
|
|
217
|
+
}];
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return [2 /*return*/, {
|
|
224
|
+
origin: origin,
|
|
225
|
+
context: context
|
|
226
|
+
}];
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
CustomMap.prototype.callMethod = function (method) {
|
|
231
|
+
var _a;
|
|
232
|
+
var args = [];
|
|
233
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
234
|
+
args[_i - 1] = arguments[_i];
|
|
235
|
+
}
|
|
236
|
+
if (method.length === 0) {
|
|
237
|
+
throw new Error('Unexpected method length');
|
|
238
|
+
}
|
|
239
|
+
var me = this;
|
|
240
|
+
var key = method[0].valueOf();
|
|
241
|
+
if (method.length > 1) {
|
|
242
|
+
if (me.value.has(key)) {
|
|
243
|
+
return (_a = me.value.get(key)).callMethod.apply(_a, __spreadArray([method.slice(1)], __read(args), false));
|
|
244
|
+
}
|
|
245
|
+
throw new Error("Unexpected method path");
|
|
246
|
+
}
|
|
247
|
+
if (!CustomMap.intrinsics.has(key)) {
|
|
248
|
+
throw new Error("Cannot access ".concat(key, " in map"));
|
|
249
|
+
}
|
|
250
|
+
return CustomMap.intrinsics.get(key).apply(void 0, __spreadArray([me], __read(args), false));
|
|
251
|
+
};
|
|
252
|
+
CustomMap.prototype.createInstancefunction = function () {
|
|
253
|
+
var me = this;
|
|
254
|
+
var value = new Map();
|
|
255
|
+
var newInstance = new CustomMap(value);
|
|
256
|
+
newInstance.isInstance = true;
|
|
257
|
+
me.value.forEach(function (item, key) {
|
|
258
|
+
value.set(key, item instanceof operation_1.FunctionOperationBase
|
|
259
|
+
? item.fork(newInstance)
|
|
260
|
+
: item);
|
|
261
|
+
});
|
|
262
|
+
return newInstance;
|
|
263
|
+
};
|
|
264
|
+
CustomMap.prototype.getType = function () {
|
|
265
|
+
var me = this;
|
|
266
|
+
return me.value.get('classID') || 'map';
|
|
267
|
+
};
|
|
268
|
+
CustomMap.prototype.valueOf = function () {
|
|
269
|
+
var me = this;
|
|
270
|
+
var value = me.value;
|
|
271
|
+
return value.size === 0 ? null : me;
|
|
272
|
+
};
|
|
273
|
+
CustomMap.prototype.toString = function () {
|
|
274
|
+
var me = this;
|
|
275
|
+
var body = Object
|
|
276
|
+
.entries(me.value)
|
|
277
|
+
.map(function (_a) {
|
|
278
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
279
|
+
return "\"".concat(key, "\": ").concat(value.valueOf().toString());
|
|
280
|
+
});
|
|
281
|
+
return "{".concat(body.join(','), "}");
|
|
282
|
+
};
|
|
283
|
+
CustomMap.prototype.fork = function () {
|
|
284
|
+
return new CustomMap(this.value);
|
|
285
|
+
};
|
|
286
|
+
CustomMap.intrinsics = new Map();
|
|
287
|
+
return CustomMap;
|
|
288
|
+
}(custom_type_1.CustomObjectType));
|
|
289
|
+
exports.default = CustomMap;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CustomLiteralType } from '../types/custom-type';
|
|
2
|
-
export default class CustomNil extends CustomLiteralType {
|
|
3
|
-
static intrinsics: Map<string, Function>;
|
|
4
|
-
value: null;
|
|
5
|
-
getType(): string;
|
|
6
|
-
valueOf(): null;
|
|
7
|
-
toString(): string;
|
|
8
|
-
}
|
|
1
|
+
import { CustomLiteralType } from '../types/custom-type';
|
|
2
|
+
export default class CustomNil extends CustomLiteralType {
|
|
3
|
+
static intrinsics: Map<string, Function>;
|
|
4
|
+
value: null;
|
|
5
|
+
getType(): string;
|
|
6
|
+
valueOf(): null;
|
|
7
|
+
toString(): string;
|
|
8
|
+
}
|