greybel-interpreter 0.2.3 → 0.2.4
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/context.d.ts +6 -8
- package/dist/context.js +161 -135
- package/dist/custom-types/map.d.ts +2 -2
- package/dist/custom-types/map.js +83 -133
- package/dist/interpreter.js +3 -1
- package/dist/operations/top.js +0 -1
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import CustomMap from './custom-types/map';
|
|
1
2
|
import { Operation } from './types/operation';
|
|
2
3
|
import { Expression } from './types/expression';
|
|
3
4
|
import { Callable } from './types/custom-type';
|
|
@@ -16,12 +17,9 @@ export declare enum ContextState {
|
|
|
16
17
|
TEMPORARY = "TEMPORARY",
|
|
17
18
|
DEFAULT = "DEFAULT"
|
|
18
19
|
}
|
|
19
|
-
export declare class Scope {
|
|
20
|
+
export declare class Scope extends CustomMap {
|
|
20
21
|
context: OperationContext;
|
|
21
|
-
refs: Map<string, any>;
|
|
22
22
|
constructor(context: OperationContext);
|
|
23
|
-
valueOf(): Map<string, any>;
|
|
24
|
-
extend(map?: Map<string, any>): Scope;
|
|
25
23
|
set(path: string[], value: any): Promise<void>;
|
|
26
24
|
get(path: string[]): Promise<any>;
|
|
27
25
|
getCallable(path: string[]): Promise<Callable>;
|
|
@@ -71,12 +69,12 @@ export declare class OperationContext {
|
|
|
71
69
|
cps: CPS | null;
|
|
72
70
|
processState: OperationContextProcessState;
|
|
73
71
|
constructor(options: OperationContextOptions);
|
|
74
|
-
valueOf():
|
|
72
|
+
valueOf(): CustomMap;
|
|
75
73
|
extend(map: Map<string, any>): OperationContext;
|
|
76
|
-
set(path: any[], value: any): Promise<
|
|
77
|
-
get(path: any[]): any
|
|
74
|
+
set(path: any[], value: any): Promise<void>;
|
|
75
|
+
get(path: any[]): Promise<any>;
|
|
76
|
+
getCallable(path: string[]): Promise<Callable>;
|
|
78
77
|
setMemory(key: string, value: any): OperationContext;
|
|
79
78
|
getMemory(key: string): any;
|
|
80
|
-
getCallable(path: string[]): Promise<Callable>;
|
|
81
79
|
fork({ type, state, target }: OperationContextForkOptions): OperationContext;
|
|
82
80
|
}
|
package/dist/context.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
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
|
+
})();
|
|
2
17
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
18
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
19
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -65,11 +80,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
65
80
|
};
|
|
66
81
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
82
|
exports.OperationContext = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
|
|
68
|
-
var
|
|
69
|
-
var number_1 = __importDefault(require("./custom-types/number"));
|
|
70
|
-
var string_1 = __importDefault(require("./custom-types/string"));
|
|
71
|
-
var nil_1 = __importDefault(require("./custom-types/nil"));
|
|
72
|
-
var custom_type_1 = require("./types/custom-type");
|
|
83
|
+
var map_1 = __importDefault(require("./custom-types/map"));
|
|
73
84
|
var greybel_core_1 = require("greybel-core");
|
|
74
85
|
var ContextType;
|
|
75
86
|
(function (ContextType) {
|
|
@@ -87,128 +98,158 @@ var ContextState;
|
|
|
87
98
|
ContextState["TEMPORARY"] = "TEMPORARY";
|
|
88
99
|
ContextState["DEFAULT"] = "DEFAULT";
|
|
89
100
|
})(ContextState = exports.ContextState || (exports.ContextState = {}));
|
|
90
|
-
var Scope = /** @class */ (function () {
|
|
101
|
+
var Scope = /** @class */ (function (_super) {
|
|
102
|
+
__extends(Scope, _super);
|
|
91
103
|
function Scope(context) {
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
104
|
+
var _this = _super.call(this) || this;
|
|
105
|
+
_this.context = context;
|
|
106
|
+
return _this;
|
|
95
107
|
}
|
|
96
|
-
Scope.prototype.valueOf = function () {
|
|
97
|
-
return this.refs;
|
|
98
|
-
};
|
|
99
|
-
Scope.prototype.extend = function (map) {
|
|
100
|
-
if (map === void 0) { map = new Map(); }
|
|
101
|
-
var me = this;
|
|
102
|
-
me.refs = new Map(__spreadArray(__spreadArray([], __read(me.refs.entries()), false), __read(map.entries()), false));
|
|
103
|
-
return me;
|
|
104
|
-
};
|
|
105
108
|
Scope.prototype.set = function (path, value) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
current = traversalPath.shift();
|
|
114
|
-
origin = refs;
|
|
115
|
-
if (current != null) {
|
|
116
|
-
if (origin.has(current)) {
|
|
117
|
-
origin = origin.get(current);
|
|
118
|
-
if (origin instanceof custom_type_1.CustomObjectType ||
|
|
119
|
-
origin instanceof Scope) {
|
|
120
|
-
return [2 /*return*/, origin.set(traversalPath.concat([last]), value)];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else if (me.context.previous && !me.context.previous.isProtected) {
|
|
124
|
-
me.context.previous.set(path, value);
|
|
125
|
-
return [2 /*return*/];
|
|
126
|
-
}
|
|
127
|
-
else if (traversalPath.length > 0) {
|
|
128
|
-
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
129
|
-
}
|
|
109
|
+
var me = this;
|
|
110
|
+
var traversalPath = [].concat(path);
|
|
111
|
+
var current = traversalPath.shift();
|
|
112
|
+
if (current != null) {
|
|
113
|
+
if (current === 'globals') {
|
|
114
|
+
if (me.context.type === ContextType.GLOBAL) {
|
|
115
|
+
return me.set(traversalPath, value);
|
|
130
116
|
}
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
!(origin instanceof string_1.default) &&
|
|
134
|
-
!(origin instanceof number_1.default) &&
|
|
135
|
-
!(origin instanceof nil_1.default)) {
|
|
136
|
-
origin.set(last, value);
|
|
117
|
+
else if (me.context.previous && !me.context.previous.isProtected) {
|
|
118
|
+
return me.context.previous.set(traversalPath, value);
|
|
137
119
|
}
|
|
138
120
|
else {
|
|
139
|
-
throw new Error("Cannot set
|
|
121
|
+
throw new Error("Cannot set globals scope for ".concat(path.join('.')));
|
|
140
122
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
123
|
+
}
|
|
124
|
+
else if (current === 'locals') {
|
|
125
|
+
if (me.context.type === ContextType.GLOBAL ||
|
|
126
|
+
me.context.type === ContextType.FUNCTION) {
|
|
127
|
+
return me.set(traversalPath, value);
|
|
128
|
+
}
|
|
129
|
+
else if (me.context.previous && !me.context.previous.isProtected) {
|
|
130
|
+
return me.context.previous.set(traversalPath, value);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
throw new Error("Cannot set locals scope for ".concat(path.join('.')));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return _super.prototype.set.call(this, path, value);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
144
140
|
};
|
|
145
141
|
Scope.prototype.get = function (path) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
origin instanceof Scope)) {
|
|
161
|
-
return [2 /*return*/, origin.get(traversalPath)];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else if (me.context.previous) {
|
|
165
|
-
return [2 /*return*/, me.context.previous.get(path)];
|
|
142
|
+
var me = this;
|
|
143
|
+
var traversalPath = [].concat(path);
|
|
144
|
+
var current = traversalPath.shift();
|
|
145
|
+
if (current != null) {
|
|
146
|
+
if (me.value.has(current)) {
|
|
147
|
+
return _super.prototype.get.call(this, path);
|
|
148
|
+
}
|
|
149
|
+
else if (path.length === 1 && map_1.default.intrinsics.has(current)) {
|
|
150
|
+
return map_1.default.intrinsics.get(current).bind(null, me);
|
|
151
|
+
}
|
|
152
|
+
else if (current === 'globals') {
|
|
153
|
+
if (me.context.type === ContextType.GLOBAL) {
|
|
154
|
+
if (path.length === 1) {
|
|
155
|
+
return Promise.resolve(me);
|
|
166
156
|
}
|
|
167
|
-
|
|
168
|
-
|
|
157
|
+
return me.get(traversalPath);
|
|
158
|
+
}
|
|
159
|
+
else if (me.context.previous) {
|
|
160
|
+
return me.context.previous.get(traversalPath);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
throw new Error("Cannot find globals scope for ".concat(path.join('.')));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else if (current === 'locals') {
|
|
167
|
+
if (me.context.type === ContextType.GLOBAL ||
|
|
168
|
+
me.context.type === ContextType.FUNCTION) {
|
|
169
|
+
if (path.length === 1) {
|
|
170
|
+
return Promise.resolve(me);
|
|
169
171
|
}
|
|
172
|
+
return me.get(traversalPath);
|
|
173
|
+
}
|
|
174
|
+
else if (me.context.previous) {
|
|
175
|
+
return me.context.previous.get(traversalPath);
|
|
170
176
|
}
|
|
171
177
|
else {
|
|
172
|
-
|
|
178
|
+
throw new Error("Cannot find locals scope for ".concat(path.join('.')));
|
|
173
179
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
180
|
+
}
|
|
181
|
+
else if (me.context.previous) {
|
|
182
|
+
return me.context.previous.get(path);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
177
189
|
};
|
|
178
190
|
Scope.prototype.getCallable = function (path) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
191
|
+
var me = this;
|
|
192
|
+
var traversalPath = [].concat(path);
|
|
193
|
+
var current = traversalPath.shift();
|
|
194
|
+
if (current != null) {
|
|
195
|
+
if (me.value.has(current)) {
|
|
196
|
+
return _super.prototype.getCallable.call(this, path);
|
|
197
|
+
}
|
|
198
|
+
else if (path.length === 1 && map_1.default.intrinsics.has(current)) {
|
|
199
|
+
return Promise.resolve({
|
|
200
|
+
origin: map_1.default.intrinsics.get(current).bind(null, me),
|
|
201
|
+
context: me
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
else if (current === 'globals') {
|
|
205
|
+
if (me.context.type === ContextType.GLOBAL) {
|
|
206
|
+
if (path.length === 1) {
|
|
207
|
+
return Promise.resolve({
|
|
208
|
+
origin: me,
|
|
209
|
+
context: null
|
|
210
|
+
});
|
|
198
211
|
}
|
|
199
|
-
|
|
200
|
-
|
|
212
|
+
return me.getCallable(traversalPath);
|
|
213
|
+
}
|
|
214
|
+
else if (me.context.previous) {
|
|
215
|
+
return me.context.previous.getCallable(traversalPath);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
throw new Error("Cannot find callable in globals scope for ".concat(path.join('.')));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else if (current === 'locals') {
|
|
222
|
+
if (me.context.type === ContextType.GLOBAL ||
|
|
223
|
+
me.context.type === ContextType.FUNCTION) {
|
|
224
|
+
if (path.length === 1) {
|
|
225
|
+
return Promise.resolve({
|
|
226
|
+
origin: me,
|
|
227
|
+
context: null
|
|
228
|
+
});
|
|
201
229
|
}
|
|
230
|
+
return me.getCallable(traversalPath);
|
|
202
231
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
232
|
+
else if (me.context.previous) {
|
|
233
|
+
return me.context.previous.getCallable(traversalPath);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
throw new Error("Cannot find callable in locals scope for ".concat(path.join('.')));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else if (me.context.previous) {
|
|
240
|
+
return me.context.previous.getCallable(path);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
throw new Error("Cannot get callable path ".concat(path.join('.')));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return Promise.resolve({
|
|
247
|
+
origin: me,
|
|
248
|
+
context: null
|
|
208
249
|
});
|
|
209
250
|
};
|
|
210
251
|
return Scope;
|
|
211
|
-
}());
|
|
252
|
+
}(map_1.default));
|
|
212
253
|
exports.Scope = Scope;
|
|
213
254
|
var Debugger = /** @class */ (function () {
|
|
214
255
|
function Debugger() {
|
|
@@ -340,25 +381,13 @@ var OperationContext = /** @class */ (function () {
|
|
|
340
381
|
};
|
|
341
382
|
OperationContext.prototype.set = function (path, value) {
|
|
342
383
|
var _a;
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
return [4 /*yield*/, ((_a = me.previous) === null || _a === void 0 ? void 0 : _a.set(path, value))];
|
|
351
|
-
case 1:
|
|
352
|
-
_b.sent();
|
|
353
|
-
return [3 /*break*/, 4];
|
|
354
|
-
case 2: return [4 /*yield*/, me.scope.set(path, value)];
|
|
355
|
-
case 3:
|
|
356
|
-
_b.sent();
|
|
357
|
-
_b.label = 4;
|
|
358
|
-
case 4: return [2 /*return*/, me];
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
});
|
|
384
|
+
var me = this;
|
|
385
|
+
if (me.state === ContextState.TEMPORARY) {
|
|
386
|
+
return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.set(path, value);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
return me.scope.set(path, value);
|
|
390
|
+
}
|
|
362
391
|
};
|
|
363
392
|
OperationContext.prototype.get = function (path) {
|
|
364
393
|
var _a;
|
|
@@ -368,6 +397,14 @@ var OperationContext = /** @class */ (function () {
|
|
|
368
397
|
}
|
|
369
398
|
return me.scope.get(path);
|
|
370
399
|
};
|
|
400
|
+
OperationContext.prototype.getCallable = function (path) {
|
|
401
|
+
var _a;
|
|
402
|
+
var me = this;
|
|
403
|
+
if (me.state === ContextState.TEMPORARY) {
|
|
404
|
+
return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.getCallable(path);
|
|
405
|
+
}
|
|
406
|
+
return me.scope.getCallable(path);
|
|
407
|
+
};
|
|
371
408
|
OperationContext.prototype.setMemory = function (key, value) {
|
|
372
409
|
var me = this;
|
|
373
410
|
me.memory.set(key, value);
|
|
@@ -377,14 +414,6 @@ var OperationContext = /** @class */ (function () {
|
|
|
377
414
|
var me = this;
|
|
378
415
|
return me.memory.get(key);
|
|
379
416
|
};
|
|
380
|
-
OperationContext.prototype.getCallable = function (path) {
|
|
381
|
-
var _a;
|
|
382
|
-
var me = this;
|
|
383
|
-
if (me.state === ContextState.TEMPORARY) {
|
|
384
|
-
return (_a = me.previous) === null || _a === void 0 ? void 0 : _a.getCallable(path);
|
|
385
|
-
}
|
|
386
|
-
return me.scope.getCallable(path);
|
|
387
|
-
};
|
|
388
417
|
OperationContext.prototype.fork = function (_a) {
|
|
389
418
|
var type = _a.type, state = _a.state, target = _a.target;
|
|
390
419
|
var me = this;
|
|
@@ -397,9 +426,6 @@ var OperationContext = /** @class */ (function () {
|
|
|
397
426
|
cps: me.cps,
|
|
398
427
|
processState: me.processState
|
|
399
428
|
});
|
|
400
|
-
if (me.type === ContextType.FUNCTION || me.type === ContextType.GLOBAL) {
|
|
401
|
-
opc.scope.refs.set('locals', opc.scope);
|
|
402
|
-
}
|
|
403
429
|
if (type !== ContextType.FUNCTION) {
|
|
404
430
|
if (type !== ContextType.LOOP) {
|
|
405
431
|
opc.setMemory('loopContext', me.getMemory('loopContext'));
|
|
@@ -13,14 +13,14 @@ export default class CustomMap extends CustomObjectType implements Iterable<Cust
|
|
|
13
13
|
static intrinsics: Map<string, Function>;
|
|
14
14
|
value: Map<string, any>;
|
|
15
15
|
isInstance: boolean;
|
|
16
|
-
constructor(value
|
|
16
|
+
constructor(value?: Map<string, any>);
|
|
17
17
|
[Symbol.iterator](): CustomMapIterator;
|
|
18
18
|
extend(value: Map<string, any>): CustomMap;
|
|
19
19
|
set(path: string[], value: any): Promise<void>;
|
|
20
20
|
get(path: string[]): Promise<any>;
|
|
21
21
|
getCallable(path: string[]): Promise<Callable>;
|
|
22
22
|
callMethod(method: string[], ...args: any[]): any;
|
|
23
|
-
|
|
23
|
+
createInstance(): CustomMap;
|
|
24
24
|
getType(): string;
|
|
25
25
|
valueOf(): CustomMap | null;
|
|
26
26
|
toString(): string;
|
package/dist/custom-types/map.js
CHANGED
|
@@ -14,42 +14,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
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
17
|
var __read = (this && this.__read) || function (o, n) {
|
|
54
18
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
55
19
|
if (!m) return o;
|
|
@@ -111,7 +75,7 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
111
75
|
function CustomMap(value) {
|
|
112
76
|
var _this = _super.call(this) || this;
|
|
113
77
|
var me = _this;
|
|
114
|
-
me.value = new Map(
|
|
78
|
+
me.value = value || new Map();
|
|
115
79
|
me.isInstance = false;
|
|
116
80
|
return _this;
|
|
117
81
|
}
|
|
@@ -124,107 +88,92 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
124
88
|
return me;
|
|
125
89
|
};
|
|
126
90
|
CustomMap.prototype.set = function (path, value) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
origin =
|
|
136
|
-
if (
|
|
137
|
-
|
|
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('.')));
|
|
91
|
+
var me = this;
|
|
92
|
+
var traversalPath = [].concat(path);
|
|
93
|
+
var refs = me.value;
|
|
94
|
+
var last = traversalPath.pop();
|
|
95
|
+
var current = traversalPath.shift();
|
|
96
|
+
var origin = refs;
|
|
97
|
+
if (current != null) {
|
|
98
|
+
if (origin.has(current)) {
|
|
99
|
+
origin = origin.get(current);
|
|
100
|
+
if (origin instanceof custom_type_1.CustomObjectType) {
|
|
101
|
+
return origin.set(traversalPath.concat(last), value);
|
|
157
102
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (origin) {
|
|
109
|
+
if (value instanceof operation_1.FunctionOperationBase) {
|
|
110
|
+
origin.set(last, value.fork(me));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
origin.set(last, value);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
throw new Error("Cannot set path ".concat(path.join('.')));
|
|
118
|
+
}
|
|
161
119
|
};
|
|
162
120
|
CustomMap.prototype.get = function (path) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
origin =
|
|
175
|
-
if (
|
|
176
|
-
|
|
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];
|
|
121
|
+
var me = this;
|
|
122
|
+
if (path.length === 0) {
|
|
123
|
+
return Promise.resolve(me);
|
|
124
|
+
}
|
|
125
|
+
var traversalPath = [].concat(path);
|
|
126
|
+
var refs = me.value;
|
|
127
|
+
var current = traversalPath.shift();
|
|
128
|
+
var currentValue = current.valueOf();
|
|
129
|
+
var origin = refs;
|
|
130
|
+
if (currentValue != null) {
|
|
131
|
+
if (origin.has(currentValue)) {
|
|
132
|
+
origin = origin.get(currentValue);
|
|
133
|
+
if (traversalPath.length > 0 && origin instanceof custom_type_1.CustomObjectType) {
|
|
134
|
+
return origin.get(traversalPath);
|
|
191
135
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
136
|
+
}
|
|
137
|
+
else if (path.length === 1 && CustomMap.intrinsics.has(currentValue)) {
|
|
138
|
+
return Promise.resolve(CustomMap.intrinsics.get(currentValue).bind(null, me));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
return Promise.resolve(origin);
|
|
195
148
|
};
|
|
196
149
|
CustomMap.prototype.getCallable = function (path) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
}
|
|
150
|
+
var me = this;
|
|
151
|
+
var traversalPath = [].concat(path);
|
|
152
|
+
var refs = me.value;
|
|
153
|
+
var current = traversalPath.shift();
|
|
154
|
+
var origin = refs;
|
|
155
|
+
var context;
|
|
156
|
+
if (current != null) {
|
|
157
|
+
if (origin.has(current)) {
|
|
158
|
+
context = origin;
|
|
159
|
+
origin = origin.get(current);
|
|
160
|
+
if (origin instanceof custom_type_1.CustomObjectType) {
|
|
161
|
+
return origin.getCallable(traversalPath);
|
|
222
162
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
163
|
+
}
|
|
164
|
+
else if (path.length === 1 && CustomMap.intrinsics.has(current)) {
|
|
165
|
+
return Promise.resolve({
|
|
166
|
+
origin: CustomMap.intrinsics.get(current).bind(null, me),
|
|
167
|
+
context: me
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return Promise.resolve({
|
|
175
|
+
origin: origin,
|
|
176
|
+
context: context
|
|
228
177
|
});
|
|
229
178
|
};
|
|
230
179
|
CustomMap.prototype.callMethod = function (method) {
|
|
@@ -249,7 +198,7 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
249
198
|
}
|
|
250
199
|
return CustomMap.intrinsics.get(key).apply(void 0, __spreadArray([me], __read(args), false));
|
|
251
200
|
};
|
|
252
|
-
CustomMap.prototype.
|
|
201
|
+
CustomMap.prototype.createInstance = function () {
|
|
253
202
|
var me = this;
|
|
254
203
|
var value = new Map();
|
|
255
204
|
var newInstance = new CustomMap(value);
|
|
@@ -262,8 +211,9 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
262
211
|
return newInstance;
|
|
263
212
|
};
|
|
264
213
|
CustomMap.prototype.getType = function () {
|
|
214
|
+
var _a;
|
|
265
215
|
var me = this;
|
|
266
|
-
return me.value.get('classID') || 'map';
|
|
216
|
+
return ((_a = me.value.get('classID')) === null || _a === void 0 ? void 0 : _a.toString()) || 'map';
|
|
267
217
|
};
|
|
268
218
|
CustomMap.prototype.valueOf = function () {
|
|
269
219
|
var me = this;
|
package/dist/interpreter.js
CHANGED
|
@@ -99,7 +99,9 @@ var Interpreter = /** @class */ (function () {
|
|
|
99
99
|
topOperation = new (_b.apply(top_1.default, _c.concat([(_d.body = _e.sent(),
|
|
100
100
|
_d)])))();
|
|
101
101
|
mainContext.extend(me.api);
|
|
102
|
-
mainContext.
|
|
102
|
+
return [4 /*yield*/, mainContext.set(['params'], (0, typer_1.cast)(me.params))];
|
|
103
|
+
case 4:
|
|
104
|
+
_e.sent();
|
|
103
105
|
me.context = mainContext;
|
|
104
106
|
return [2 /*return*/, topOperation.run(mainContext)
|
|
105
107
|
.catch(function (err) {
|
package/dist/operations/top.js
CHANGED