greybel-interpreter 0.1.5 → 0.1.9
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 +5 -0
- package/dist/context.js +5 -1
- package/dist/custom-types/list.js +2 -2
- package/dist/custom-types/map.js +2 -2
- package/dist/custom-types/string.js +1 -1
- package/dist/expressions/call.js +30 -28
- package/dist/expressions/path.js +12 -11
- package/dist/interpreter.d.ts +3 -1
- package/dist/interpreter.js +9 -0
- package/dist/operations/body.js +1 -1
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -39,6 +39,9 @@ export declare class Debugger {
|
|
|
39
39
|
interact(operationContext: OperationContext, item: Operation | Expression): void;
|
|
40
40
|
run(code: string): Promise<void>;
|
|
41
41
|
}
|
|
42
|
+
export interface OperationContextProcessState {
|
|
43
|
+
exit: boolean;
|
|
44
|
+
}
|
|
42
45
|
export interface OperationContextOptions {
|
|
43
46
|
isProtected?: boolean;
|
|
44
47
|
type?: string;
|
|
@@ -46,6 +49,7 @@ export interface OperationContextOptions {
|
|
|
46
49
|
previous?: OperationContext;
|
|
47
50
|
debugger?: Debugger;
|
|
48
51
|
cps?: CPS;
|
|
52
|
+
processState?: OperationContextProcessState;
|
|
49
53
|
}
|
|
50
54
|
export declare class OperationContext {
|
|
51
55
|
debugger: Debugger;
|
|
@@ -56,6 +60,7 @@ export declare class OperationContext {
|
|
|
56
60
|
isProtected: boolean;
|
|
57
61
|
memory: Map<string, any>;
|
|
58
62
|
cps: CPS | null;
|
|
63
|
+
processState: OperationContextProcessState;
|
|
59
64
|
constructor(options: OperationContextOptions);
|
|
60
65
|
valueOf(): Map<string, any>;
|
|
61
66
|
extend(map: Map<string, any>): OperationContext;
|
package/dist/context.js
CHANGED
|
@@ -312,6 +312,9 @@ var OperationContext = /** @class */ (function () {
|
|
|
312
312
|
me.memory = new Map();
|
|
313
313
|
me.debugger = options.debugger || new Debugger();
|
|
314
314
|
me.cps = options.cps;
|
|
315
|
+
me.processState = options.processState || {
|
|
316
|
+
exit: false
|
|
317
|
+
};
|
|
315
318
|
}
|
|
316
319
|
OperationContext.prototype.valueOf = function () {
|
|
317
320
|
return this.scope.valueOf();
|
|
@@ -381,7 +384,8 @@ var OperationContext = /** @class */ (function () {
|
|
|
381
384
|
type: type,
|
|
382
385
|
state: state,
|
|
383
386
|
debugger: me.debugger,
|
|
384
|
-
cps: me.cps
|
|
387
|
+
cps: me.cps,
|
|
388
|
+
processState: me.processState
|
|
385
389
|
});
|
|
386
390
|
if (me.type === ContextType.FUNCTION || me.type === ContextType.GLOBAL) {
|
|
387
391
|
opc.scope.refs.set('locals', opc.scope);
|
|
@@ -195,7 +195,7 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
else if (path.length === 1 && CustomList.intrinsics.has(currentValue)) {
|
|
198
|
-
return [2 /*return*/, CustomList.intrinsics.get(currentValue)];
|
|
198
|
+
return [2 /*return*/, CustomList.intrinsics.get(currentValue).bind(null, me)];
|
|
199
199
|
}
|
|
200
200
|
else {
|
|
201
201
|
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
@@ -228,7 +228,7 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
228
228
|
}
|
|
229
229
|
else if (path.length === 1 && CustomList.intrinsics.has(current)) {
|
|
230
230
|
return [2 /*return*/, {
|
|
231
|
-
origin: CustomList.intrinsics.get(current),
|
|
231
|
+
origin: CustomList.intrinsics.get(current).bind(null, me),
|
|
232
232
|
context: me
|
|
233
233
|
}];
|
|
234
234
|
}
|
package/dist/custom-types/map.js
CHANGED
|
@@ -180,7 +180,7 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
else if (path.length === 1 && CustomMap.intrinsics.has(currentValue)) {
|
|
183
|
-
return [2 /*return*/, CustomMap.intrinsics.get(currentValue)];
|
|
183
|
+
return [2 /*return*/, CustomMap.intrinsics.get(currentValue).bind(null, me)];
|
|
184
184
|
}
|
|
185
185
|
else {
|
|
186
186
|
throw new Error("Cannot get path ".concat(path.join('.')));
|
|
@@ -212,7 +212,7 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
212
212
|
}
|
|
213
213
|
else if (path.length === 1 && CustomMap.intrinsics.has(current)) {
|
|
214
214
|
return [2 /*return*/, {
|
|
215
|
-
origin: CustomMap.intrinsics.get(current),
|
|
215
|
+
origin: CustomMap.intrinsics.get(current).bind(null, me),
|
|
216
216
|
context: me
|
|
217
217
|
}];
|
|
218
218
|
}
|
|
@@ -120,7 +120,7 @@ var CustomString = /** @class */ (function (_super) {
|
|
|
120
120
|
return me.value.length === 0 ? null : me.value;
|
|
121
121
|
};
|
|
122
122
|
CustomString.prototype.toString = function () {
|
|
123
|
-
return
|
|
123
|
+
return this.value;
|
|
124
124
|
};
|
|
125
125
|
CustomString.prototype.fork = function () {
|
|
126
126
|
return new CustomString(this.value);
|
package/dist/expressions/call.js
CHANGED
|
@@ -123,48 +123,50 @@ var CallExpression = /** @class */ (function (_super) {
|
|
|
123
123
|
var opc = operationContext.fork(context_1.ContextType.CALL, context_1.ContextState.TEMPORARY);
|
|
124
124
|
var evaluate = function (node) {
|
|
125
125
|
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
-
var args, pathExpr, callable_1, callable,
|
|
127
|
-
var
|
|
128
|
-
return __generator(this, function (
|
|
129
|
-
switch (
|
|
126
|
+
var args, pathExpr, callable_1, _a, callable, _b;
|
|
127
|
+
var _c, _d, _e;
|
|
128
|
+
return __generator(this, function (_f) {
|
|
129
|
+
switch (_f.label) {
|
|
130
130
|
case 0:
|
|
131
131
|
if (node instanceof expression_1.Expression) {
|
|
132
132
|
return [2 /*return*/, node.get(opc)];
|
|
133
133
|
}
|
|
134
134
|
return [4 /*yield*/, node.resolveArgs(operationContext)];
|
|
135
135
|
case 1:
|
|
136
|
-
args =
|
|
136
|
+
args = _f.sent();
|
|
137
137
|
return [4 /*yield*/, node.path.get(opc, me.expr)];
|
|
138
138
|
case 2:
|
|
139
|
-
pathExpr =
|
|
139
|
+
pathExpr = _f.sent();
|
|
140
140
|
operationContext.debugger.debug('CallExpression', 'pathExpr', pathExpr);
|
|
141
|
-
if (!pathExpr.handle) return [3 /*break*/,
|
|
142
|
-
if (!(0, typer_1.isCustomMap)(pathExpr.handle)) return [3 /*break*/,
|
|
141
|
+
if (!pathExpr.handle) return [3 /*break*/, 8];
|
|
142
|
+
if (!(0, typer_1.isCustomMap)(pathExpr.handle)) return [3 /*break*/, 7];
|
|
143
143
|
return [4 /*yield*/, pathExpr.handle.getCallable(pathExpr.path)];
|
|
144
144
|
case 3:
|
|
145
|
-
callable_1 =
|
|
146
|
-
if (callable_1.origin instanceof operation_1.Operation)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
_e.label = 4;
|
|
155
|
-
case 4: return [2 /*return*/, (0, typer_1.cast)((_c = pathExpr.handle).callMethod.apply(_c, __spreadArray([pathExpr.path], __read(args), false)))];
|
|
156
|
-
case 5: return [4 /*yield*/, opc.getCallable(pathExpr.path)];
|
|
145
|
+
callable_1 = _f.sent();
|
|
146
|
+
if (!(callable_1.origin instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
147
|
+
opc.setMemory('args', args);
|
|
148
|
+
return [2 /*return*/, callable_1.origin.run(opc)];
|
|
149
|
+
case 4:
|
|
150
|
+
if (!(callable_1.origin instanceof Function)) return [3 /*break*/, 6];
|
|
151
|
+
_a = typer_1.cast;
|
|
152
|
+
return [4 /*yield*/, (_c = callable_1.origin).call.apply(_c, __spreadArray([pathExpr.handle], __read(args), false))];
|
|
153
|
+
case 5: return [2 /*return*/, _a.apply(void 0, [_f.sent()])];
|
|
157
154
|
case 6:
|
|
158
|
-
|
|
155
|
+
operationContext.debugger.raise('Unexpected handle call', me, callable_1);
|
|
156
|
+
_f.label = 7;
|
|
157
|
+
case 7: return [2 /*return*/, (0, typer_1.cast)((_d = pathExpr.handle).callMethod.apply(_d, __spreadArray([pathExpr.path], __read(args), false)))];
|
|
158
|
+
case 8: return [4 /*yield*/, opc.getCallable(pathExpr.path)];
|
|
159
|
+
case 9:
|
|
160
|
+
callable = _f.sent();
|
|
159
161
|
opc.setMemory('args', args);
|
|
160
|
-
if (!(callable.origin instanceof operation_1.Operation)) return [3 /*break*/,
|
|
162
|
+
if (!(callable.origin instanceof operation_1.Operation)) return [3 /*break*/, 10];
|
|
161
163
|
return [2 /*return*/, callable.origin.run(opc)];
|
|
162
|
-
case
|
|
163
|
-
if (!(callable.origin instanceof Function)) return [3 /*break*/,
|
|
164
|
-
|
|
165
|
-
return [4 /*yield*/, (
|
|
166
|
-
case
|
|
167
|
-
case
|
|
164
|
+
case 10:
|
|
165
|
+
if (!(callable.origin instanceof Function)) return [3 /*break*/, 12];
|
|
166
|
+
_b = typer_1.cast;
|
|
167
|
+
return [4 /*yield*/, (_e = callable.origin).call.apply(_e, __spreadArray([callable.context], __read(args), false))];
|
|
168
|
+
case 11: return [2 /*return*/, _b.apply(void 0, [_f.sent()])];
|
|
169
|
+
case 12: return [2 /*return*/, (0, typer_1.cast)(callable.origin)];
|
|
168
170
|
}
|
|
169
171
|
});
|
|
170
172
|
});
|
package/dist/expressions/path.js
CHANGED
|
@@ -134,9 +134,9 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
134
134
|
}
|
|
135
135
|
PathExpression.prototype.get = function (operationContext, parentExpr) {
|
|
136
136
|
return __awaiter(this, void 0, void 0, function () {
|
|
137
|
-
var me, evaluate, resultExpr, context, value_1, value, callable,
|
|
138
|
-
return __generator(this, function (
|
|
139
|
-
switch (
|
|
137
|
+
var me, evaluate, resultExpr, context, value_1, _a, value, callable, _b;
|
|
138
|
+
return __generator(this, function (_c) {
|
|
139
|
+
switch (_c.label) {
|
|
140
140
|
case 0:
|
|
141
141
|
me = this;
|
|
142
142
|
evaluate = function (node) {
|
|
@@ -265,7 +265,7 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
265
265
|
operationContext.debugger.debug('PathExpression', 'get', 'expr', me.expr);
|
|
266
266
|
return [4 /*yield*/, evaluate(me.expr)];
|
|
267
267
|
case 1:
|
|
268
|
-
resultExpr =
|
|
268
|
+
resultExpr = _c.sent();
|
|
269
269
|
if (!!parentExpr) return [3 /*break*/, 14];
|
|
270
270
|
if (!resultExpr.handle) return [3 /*break*/, 8];
|
|
271
271
|
if (!(resultExpr.path.length === 0)) return [3 /*break*/, 2];
|
|
@@ -275,30 +275,31 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
275
275
|
context = resultExpr.handle;
|
|
276
276
|
return [4 /*yield*/, context.get(resultExpr.path)];
|
|
277
277
|
case 3:
|
|
278
|
-
value_1 =
|
|
278
|
+
value_1 = _c.sent();
|
|
279
279
|
if (!(value_1 instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
280
280
|
return [2 /*return*/, value_1.run(operationContext)];
|
|
281
281
|
case 4:
|
|
282
282
|
if (!(value_1 instanceof Function)) return [3 /*break*/, 6];
|
|
283
|
+
_a = typer_1.cast;
|
|
283
284
|
return [4 /*yield*/, value_1.call(context)];
|
|
284
|
-
case 5: return [2 /*return*/,
|
|
285
|
+
case 5: return [2 /*return*/, _a.apply(void 0, [_c.sent()])];
|
|
285
286
|
case 6: return [2 /*return*/, value_1];
|
|
286
287
|
case 7: return [2 /*return*/, (0, typer_1.cast)(resultExpr.handle.callMethod(resultExpr.path))];
|
|
287
288
|
case 8: return [4 /*yield*/, operationContext.get(resultExpr.path)];
|
|
288
289
|
case 9:
|
|
289
|
-
value =
|
|
290
|
+
value = _c.sent();
|
|
290
291
|
if (!(value instanceof Function)) return [3 /*break*/, 12];
|
|
291
292
|
return [4 /*yield*/, operationContext.getCallable(resultExpr.path)];
|
|
292
293
|
case 10:
|
|
293
|
-
callable =
|
|
294
|
-
|
|
294
|
+
callable = _c.sent();
|
|
295
|
+
_b = typer_1.cast;
|
|
295
296
|
return [4 /*yield*/, callable.origin.call(callable.context)];
|
|
296
|
-
case 11: return [2 /*return*/,
|
|
297
|
+
case 11: return [2 /*return*/, _b.apply(void 0, [_c.sent()])];
|
|
297
298
|
case 12:
|
|
298
299
|
if (value instanceof operation_1.Operation) {
|
|
299
300
|
return [2 /*return*/, value.run(operationContext)];
|
|
300
301
|
}
|
|
301
|
-
|
|
302
|
+
_c.label = 13;
|
|
302
303
|
case 13: return [2 /*return*/, value];
|
|
303
304
|
case 14: return [2 /*return*/, resultExpr];
|
|
304
305
|
}
|
package/dist/interpreter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Debugger } from './context';
|
|
1
|
+
import { OperationContext, Debugger } from './context';
|
|
2
2
|
import { ResourceHandler } from './resource';
|
|
3
3
|
export interface InterpreterOptions {
|
|
4
4
|
target?: string;
|
|
@@ -15,6 +15,8 @@ export default class Interpreter {
|
|
|
15
15
|
params: any[];
|
|
16
16
|
resourceHandler: ResourceHandler;
|
|
17
17
|
debugger: Debugger;
|
|
18
|
+
context: OperationContext | null;
|
|
18
19
|
constructor(options: InterpreterOptions);
|
|
19
20
|
digest(): Promise<any>;
|
|
21
|
+
exit(): void;
|
|
20
22
|
}
|
package/dist/interpreter.js
CHANGED
|
@@ -17,6 +17,7 @@ var Interpreter = /** @class */ (function () {
|
|
|
17
17
|
me.debugger = options.debugger || new context_1.Debugger();
|
|
18
18
|
me.api = options.api || new Map();
|
|
19
19
|
me.params = options.params || [];
|
|
20
|
+
me.context = null;
|
|
20
21
|
if (options.target) {
|
|
21
22
|
me.target = options.target;
|
|
22
23
|
me.code = me.resourceHandler.get(options.target);
|
|
@@ -44,12 +45,20 @@ var Interpreter = /** @class */ (function () {
|
|
|
44
45
|
});
|
|
45
46
|
mainContext.extend(me.api);
|
|
46
47
|
mainContext.scope.refs.set('params', (0, typer_1.cast)(me.params));
|
|
48
|
+
me.context = mainContext;
|
|
47
49
|
return topOperation.run(mainContext)
|
|
48
50
|
.catch(function (err) {
|
|
49
51
|
console.error(err);
|
|
50
52
|
throw err;
|
|
51
53
|
});
|
|
52
54
|
};
|
|
55
|
+
Interpreter.prototype.exit = function () {
|
|
56
|
+
var me = this;
|
|
57
|
+
if (me.context == null) {
|
|
58
|
+
throw new Error('Unexpected exit signal.');
|
|
59
|
+
}
|
|
60
|
+
me.context.processState.exit = true;
|
|
61
|
+
};
|
|
53
62
|
return Interpreter;
|
|
54
63
|
}());
|
|
55
64
|
exports.default = Interpreter;
|
package/dist/operations/body.js
CHANGED