greybel-interpreter 2.6.11 → 2.6.13
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 -2
- package/dist/context.js +13 -6
- package/dist/operations/assign.js +3 -1
- package/dist/operations/block.js +3 -1
- package/dist/operations/call.js +3 -1
- package/dist/operations/for.js +5 -1
- package/dist/operations/function-reference.js +3 -1
- package/dist/operations/resolve.js +7 -2
- package/dist/operations/while.js +5 -1
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -39,10 +39,14 @@ export declare class Debugger {
|
|
|
39
39
|
resume(): Promise<void>;
|
|
40
40
|
interact(ctx: OperationContext, _ast: ASTBase, _op: Operation): void;
|
|
41
41
|
}
|
|
42
|
+
export interface ExitObserver {
|
|
43
|
+
occured: () => boolean;
|
|
44
|
+
close: () => void;
|
|
45
|
+
}
|
|
42
46
|
export declare class ProcessState extends EventEmitter {
|
|
43
|
-
isExit: boolean;
|
|
44
47
|
isPending: boolean;
|
|
45
48
|
last: OperationContext;
|
|
49
|
+
createExitObserver(): ExitObserver;
|
|
46
50
|
}
|
|
47
51
|
export declare class LoopState {
|
|
48
52
|
isBreak: boolean;
|
|
@@ -104,7 +108,6 @@ export declare class OperationContext {
|
|
|
104
108
|
step(op: Operation): Promise<CustomValue>;
|
|
105
109
|
setLastActive(ctx: OperationContext): OperationContext;
|
|
106
110
|
getLastActive(): OperationContext;
|
|
107
|
-
isExit(): boolean;
|
|
108
111
|
isPending(): boolean;
|
|
109
112
|
setPending(pending: boolean): OperationContext;
|
|
110
113
|
lookupAllOfType(validate: (type: ContextType) => boolean): OperationContext[];
|
package/dist/context.js
CHANGED
|
@@ -124,11 +124,23 @@ exports.Debugger = Debugger;
|
|
|
124
124
|
class ProcessState extends events_1.EventEmitter {
|
|
125
125
|
constructor() {
|
|
126
126
|
super(...arguments);
|
|
127
|
-
this.isExit = false;
|
|
128
127
|
this.isPending = false;
|
|
129
128
|
/* eslint-disable no-use-before-define */
|
|
130
129
|
this.last = null;
|
|
131
130
|
}
|
|
131
|
+
createExitObserver() {
|
|
132
|
+
let isExit = false;
|
|
133
|
+
const listener = () => {
|
|
134
|
+
isExit = true;
|
|
135
|
+
};
|
|
136
|
+
this.once('exit', listener);
|
|
137
|
+
return {
|
|
138
|
+
occured: () => isExit,
|
|
139
|
+
close: () => {
|
|
140
|
+
this.off('exit', listener);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
132
144
|
}
|
|
133
145
|
exports.ProcessState = ProcessState;
|
|
134
146
|
class LoopState {
|
|
@@ -203,9 +215,6 @@ class OperationContext {
|
|
|
203
215
|
getLastActive() {
|
|
204
216
|
return this.processState.last;
|
|
205
217
|
}
|
|
206
|
-
isExit() {
|
|
207
|
-
return this.processState.isExit;
|
|
208
|
-
}
|
|
209
218
|
isPending() {
|
|
210
219
|
return this.processState.isPending;
|
|
211
220
|
}
|
|
@@ -230,12 +239,10 @@ class OperationContext {
|
|
|
230
239
|
}
|
|
231
240
|
exit() {
|
|
232
241
|
if (this.processState.isPending) {
|
|
233
|
-
this.processState.isExit = true;
|
|
234
242
|
this.processState.emit('exit');
|
|
235
243
|
return new Promise((resolve) => {
|
|
236
244
|
const check = () => {
|
|
237
245
|
if (!this.processState.isPending) {
|
|
238
|
-
this.processState.isExit = false;
|
|
239
246
|
resolve(this);
|
|
240
247
|
}
|
|
241
248
|
else {
|
|
@@ -30,8 +30,10 @@ class Assign extends operation_1.Operation {
|
|
|
30
30
|
}
|
|
31
31
|
handle(ctx) {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const exitObserver = ctx.processState.createExitObserver();
|
|
33
34
|
const resolveResult = yield this.left.getResult(ctx);
|
|
34
|
-
|
|
35
|
+
exitObserver.close();
|
|
36
|
+
if (exitObserver.occured()) {
|
|
35
37
|
return default_1.DefaultType.Void;
|
|
36
38
|
}
|
|
37
39
|
if (resolveResult.path.count() === 0) {
|
package/dist/operations/block.js
CHANGED
|
@@ -32,13 +32,15 @@ class Block extends operation_1.Operation {
|
|
|
32
32
|
else if (ctx.type === context_1.ContextType.Function) {
|
|
33
33
|
isEOL = () => ctx.functionState.isReturn;
|
|
34
34
|
}
|
|
35
|
+
const exitObserver = ctx.processState.createExitObserver();
|
|
35
36
|
for (let index = 0; index < this.stack.length; index++) {
|
|
36
|
-
if (isEOL() ||
|
|
37
|
+
if (isEOL() || exitObserver.occured()) {
|
|
37
38
|
break;
|
|
38
39
|
}
|
|
39
40
|
const op = this.stack[index];
|
|
40
41
|
yield ctx.step(op);
|
|
41
42
|
}
|
|
43
|
+
exitObserver.close();
|
|
42
44
|
return default_1.DefaultType.Void;
|
|
43
45
|
});
|
|
44
46
|
}
|
package/dist/operations/call.js
CHANGED
|
@@ -31,8 +31,10 @@ class Call extends operation_1.Operation {
|
|
|
31
31
|
}
|
|
32
32
|
handle(ctx) {
|
|
33
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const exitObserver = ctx.processState.createExitObserver();
|
|
34
35
|
const resolveResult = yield this.fnRef.getResult(ctx);
|
|
35
|
-
|
|
36
|
+
exitObserver.close();
|
|
37
|
+
if (exitObserver.occured()) {
|
|
36
38
|
return default_1.DefaultType.Void;
|
|
37
39
|
}
|
|
38
40
|
const valueRef = yield this.fnRef.handle(ctx, resolveResult, false);
|
package/dist/operations/for.js
CHANGED
|
@@ -43,6 +43,7 @@ class For extends operation_1.OperationBlock {
|
|
|
43
43
|
return Promise.resolve(default_1.DefaultType.Void);
|
|
44
44
|
}
|
|
45
45
|
const loopState = new context_1.LoopState();
|
|
46
|
+
const exitObserver = ctx.processState.createExitObserver();
|
|
46
47
|
forCtx.loopState = loopState;
|
|
47
48
|
return new Promise((resolve, reject) => {
|
|
48
49
|
const iterator = iteratorValue[Symbol.iterator]();
|
|
@@ -52,6 +53,7 @@ class For extends operation_1.OperationBlock {
|
|
|
52
53
|
const iteration = () => __awaiter(this, void 0, void 0, function* () {
|
|
53
54
|
try {
|
|
54
55
|
if (iteratorResult.done) {
|
|
56
|
+
exitObserver.close();
|
|
55
57
|
resolve(default_1.DefaultType.Void);
|
|
56
58
|
return;
|
|
57
59
|
}
|
|
@@ -62,7 +64,8 @@ class For extends operation_1.OperationBlock {
|
|
|
62
64
|
yield this.block.handle(forCtx);
|
|
63
65
|
if (loopState.isBreak ||
|
|
64
66
|
forCtx.functionState.isReturn ||
|
|
65
|
-
|
|
67
|
+
exitObserver.occured()) {
|
|
68
|
+
exitObserver.close();
|
|
66
69
|
resolve(default_1.DefaultType.Void);
|
|
67
70
|
return;
|
|
68
71
|
}
|
|
@@ -72,6 +75,7 @@ class For extends operation_1.OperationBlock {
|
|
|
72
75
|
(0, set_immediate_1.setImmediate)(iteration);
|
|
73
76
|
}
|
|
74
77
|
catch (err) {
|
|
78
|
+
exitObserver.close();
|
|
75
79
|
reject(err);
|
|
76
80
|
}
|
|
77
81
|
});
|
|
@@ -28,8 +28,10 @@ class FunctionReference extends operation_1.Operation {
|
|
|
28
28
|
}
|
|
29
29
|
handle(ctx) {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const exitObserver = ctx.processState.createExitObserver();
|
|
31
32
|
const refResult = yield this.ref.getResult(ctx);
|
|
32
|
-
|
|
33
|
+
exitObserver.close();
|
|
34
|
+
if (exitObserver.occured()) {
|
|
33
35
|
return default_1.DefaultType.Void;
|
|
34
36
|
}
|
|
35
37
|
if (!(refResult.handle instanceof resolve_1.ResolveNil)) {
|
|
@@ -157,10 +157,12 @@ class Resolve extends operation_1.Operation {
|
|
|
157
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
158
|
let traversedPath = new path_1.Path();
|
|
159
159
|
let index = 0;
|
|
160
|
+
const exitObserver = ctx.processState.createExitObserver();
|
|
160
161
|
const maxIndex = this.path.count();
|
|
161
162
|
const lastIndex = maxIndex - 1;
|
|
162
163
|
for (; index < maxIndex; index++) {
|
|
163
|
-
if (
|
|
164
|
+
if (exitObserver.occured()) {
|
|
165
|
+
exitObserver.close();
|
|
164
166
|
return new ResolveResult(null, new ResolveNil());
|
|
165
167
|
}
|
|
166
168
|
const current = this.path.at(index);
|
|
@@ -211,6 +213,7 @@ class Resolve extends operation_1.Operation {
|
|
|
211
213
|
}
|
|
212
214
|
}
|
|
213
215
|
}
|
|
216
|
+
exitObserver.close();
|
|
214
217
|
return new ResolveResult(traversedPath, handle);
|
|
215
218
|
});
|
|
216
219
|
}
|
|
@@ -218,8 +221,10 @@ class Resolve extends operation_1.Operation {
|
|
|
218
221
|
var _a;
|
|
219
222
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
223
|
if (result === null) {
|
|
224
|
+
const exitObserver = ctx.processState.createExitObserver();
|
|
221
225
|
result = yield this.getResult(ctx);
|
|
222
|
-
|
|
226
|
+
exitObserver.close();
|
|
227
|
+
if (exitObserver.occured()) {
|
|
223
228
|
return default_1.DefaultType.Void;
|
|
224
229
|
}
|
|
225
230
|
}
|
package/dist/operations/while.js
CHANGED
|
@@ -35,12 +35,14 @@ class While extends operation_1.OperationBlock {
|
|
|
35
35
|
state: context_1.ContextState.Temporary
|
|
36
36
|
});
|
|
37
37
|
const loopState = new context_1.LoopState();
|
|
38
|
+
const exitObserver = ctx.processState.createExitObserver();
|
|
38
39
|
whileCtx.loopState = loopState;
|
|
39
40
|
return new Promise((resolve, reject) => {
|
|
40
41
|
const iteration = () => __awaiter(this, void 0, void 0, function* () {
|
|
41
42
|
try {
|
|
42
43
|
const conditionResult = yield whileCtx.step(this.condition);
|
|
43
44
|
if (!conditionResult.toTruthy()) {
|
|
45
|
+
exitObserver.close();
|
|
44
46
|
resolve(default_1.DefaultType.Void);
|
|
45
47
|
return;
|
|
46
48
|
}
|
|
@@ -48,13 +50,15 @@ class While extends operation_1.OperationBlock {
|
|
|
48
50
|
yield this.block.handle(whileCtx);
|
|
49
51
|
if (loopState.isBreak ||
|
|
50
52
|
whileCtx.functionState.isReturn ||
|
|
51
|
-
|
|
53
|
+
exitObserver.occured()) {
|
|
54
|
+
exitObserver.close();
|
|
52
55
|
resolve(default_1.DefaultType.Void);
|
|
53
56
|
return;
|
|
54
57
|
}
|
|
55
58
|
(0, set_immediate_1.setImmediate)(iteration);
|
|
56
59
|
}
|
|
57
60
|
catch (err) {
|
|
61
|
+
exitObserver.close();
|
|
58
62
|
reject(err);
|
|
59
63
|
}
|
|
60
64
|
});
|