greybel-interpreter 4.0.16 → 4.0.17
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/vm.d.ts +3 -1
- package/dist/vm.js +45 -19
- package/package.json +1 -1
- package/dist/utils/next-tick.d.ts +0 -1
- package/dist/utils/next-tick.js +0 -10
package/dist/vm.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ export interface FrameOptions {
|
|
|
26
26
|
export declare enum VMState {
|
|
27
27
|
PREPARATION = 0,
|
|
28
28
|
PENDING = 1,
|
|
29
|
-
FINISHED = 2
|
|
29
|
+
FINISHED = 2,
|
|
30
|
+
STOPPED = 3
|
|
30
31
|
}
|
|
31
32
|
export interface VMOptions {
|
|
32
33
|
target: string;
|
|
@@ -73,4 +74,5 @@ export declare class VM {
|
|
|
73
74
|
private createFrame;
|
|
74
75
|
private popFrame;
|
|
75
76
|
exec(): Promise<void>;
|
|
77
|
+
private resume;
|
|
76
78
|
}
|
package/dist/vm.js
CHANGED
|
@@ -25,7 +25,7 @@ const evaluation_1 = require("./vm/evaluation");
|
|
|
25
25
|
const number_1 = require("./types/number");
|
|
26
26
|
const map_1 = require("./types/map");
|
|
27
27
|
const list_1 = require("./types/list");
|
|
28
|
-
const
|
|
28
|
+
const set_immediate_1 = require("./utils/set-immediate");
|
|
29
29
|
const string_1 = require("./types/string");
|
|
30
30
|
const events_1 = __importDefault(require("events"));
|
|
31
31
|
const object_value_1 = require("./utils/object-value");
|
|
@@ -63,7 +63,7 @@ class Debugger {
|
|
|
63
63
|
resolve();
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
|
-
setImmediate(check);
|
|
66
|
+
(0, set_immediate_1.setImmediate)(check);
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
check();
|
|
@@ -82,11 +82,12 @@ var VMState;
|
|
|
82
82
|
VMState[VMState["PREPARATION"] = 0] = "PREPARATION";
|
|
83
83
|
VMState[VMState["PENDING"] = 1] = "PENDING";
|
|
84
84
|
VMState[VMState["FINISHED"] = 2] = "FINISHED";
|
|
85
|
+
VMState[VMState["STOPPED"] = 3] = "STOPPED";
|
|
85
86
|
})(VMState = exports.VMState || (exports.VMState = {}));
|
|
86
87
|
class VM {
|
|
87
88
|
constructor(options) {
|
|
88
89
|
var _a, _b, _c, _d;
|
|
89
|
-
this.ACTIONS_PER_LOOP =
|
|
90
|
+
this.ACTIONS_PER_LOOP = 80000;
|
|
90
91
|
this.STACK_LIMIT = 512;
|
|
91
92
|
this.stack = new Array(this.STACK_LIMIT);
|
|
92
93
|
this.signal = new events_1.default();
|
|
@@ -134,6 +135,7 @@ class VM {
|
|
|
134
135
|
return this.signal;
|
|
135
136
|
}
|
|
136
137
|
exit() {
|
|
138
|
+
this.state = VMState.STOPPED;
|
|
137
139
|
this.signal.emit('exit');
|
|
138
140
|
}
|
|
139
141
|
getFrame() {
|
|
@@ -166,16 +168,28 @@ class VM {
|
|
|
166
168
|
return frame;
|
|
167
169
|
}
|
|
168
170
|
exec() {
|
|
169
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
170
171
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
172
|
+
return new Promise((resolve, reject) => {
|
|
173
|
+
this.state = VMState.PENDING;
|
|
174
|
+
this.time = Date.now();
|
|
175
|
+
this.resume((err) => {
|
|
176
|
+
if (err) {
|
|
177
|
+
reject(err);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
resolve();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
resume(done) {
|
|
186
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
187
|
+
try {
|
|
188
|
+
while (true) {
|
|
189
|
+
if (!this.isPending()) {
|
|
190
|
+
done();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
179
193
|
const frame = this.getFrame();
|
|
180
194
|
if (frame.code.length === frame.ip) {
|
|
181
195
|
this.popFrame();
|
|
@@ -504,8 +518,11 @@ class VM {
|
|
|
504
518
|
const value = frame.scope.value.get(arg.name);
|
|
505
519
|
args.set(arg.name.toString(), value);
|
|
506
520
|
}
|
|
507
|
-
|
|
508
|
-
|
|
521
|
+
callback(this, frame.self, args).then((result) => {
|
|
522
|
+
this.pushStack(result);
|
|
523
|
+
this.resume(done);
|
|
524
|
+
}).catch(done);
|
|
525
|
+
return;
|
|
509
526
|
}
|
|
510
527
|
case instruction_1.OpCode.SLICE: {
|
|
511
528
|
const b = this.popStack();
|
|
@@ -674,9 +691,11 @@ class VM {
|
|
|
674
691
|
case instruction_1.OpCode.BREAKPOINT: {
|
|
675
692
|
if (this.debugger.getBreakpoint(this)) {
|
|
676
693
|
this.debugger.interact(this, instruction.source);
|
|
677
|
-
|
|
694
|
+
this.debugger.resume().then(() => {
|
|
695
|
+
this.resume(done);
|
|
696
|
+
}).catch(done);
|
|
678
697
|
}
|
|
679
|
-
|
|
698
|
+
return;
|
|
680
699
|
}
|
|
681
700
|
case instruction_1.OpCode.BREAKPOINT_ENABLE: {
|
|
682
701
|
this.debugger.setBreakpoint(true);
|
|
@@ -684,16 +703,23 @@ class VM {
|
|
|
684
703
|
}
|
|
685
704
|
case instruction_1.OpCode.HALT: {
|
|
686
705
|
this.state = VMState.FINISHED;
|
|
687
|
-
this.signal.
|
|
706
|
+
this.signal.emit('done');
|
|
707
|
+
done();
|
|
688
708
|
return;
|
|
689
709
|
}
|
|
690
710
|
}
|
|
691
711
|
if (this.actionCount++ === this.maxActionsPerLoop) {
|
|
692
712
|
this.actionCount = 0;
|
|
693
|
-
|
|
713
|
+
(0, set_immediate_1.setImmediate)(() => {
|
|
714
|
+
this.resume(done);
|
|
715
|
+
});
|
|
716
|
+
return;
|
|
694
717
|
}
|
|
695
718
|
}
|
|
696
|
-
}
|
|
719
|
+
}
|
|
720
|
+
catch (err) {
|
|
721
|
+
done(err);
|
|
722
|
+
}
|
|
697
723
|
}
|
|
698
724
|
}
|
|
699
725
|
exports.VM = VM;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const nextTick: () => Promise<void>;
|
package/dist/utils/next-tick.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nextTick = void 0;
|
|
4
|
-
const set_immediate_1 = require("./set-immediate");
|
|
5
|
-
const nextTick = () => {
|
|
6
|
-
return new Promise((resolve) => {
|
|
7
|
-
(0, set_immediate_1.setImmediate)(resolve);
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
exports.nextTick = nextTick;
|