greybel-interpreter 4.1.0 → 4.1.2
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 +4 -0
- package/dist/context.js +2 -0
- package/dist/utils/stack.d.ts +2 -0
- package/dist/utils/stack.js +7 -0
- package/dist/vm.d.ts +0 -1
- package/dist/vm.js +7 -4
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ObjectValue } from './utils/object-value';
|
|
|
4
4
|
import { ContextTypeIntrinsics } from './context/types';
|
|
5
5
|
import { Instruction } from './byte-compiler/instruction';
|
|
6
6
|
import { CustomValueWithIntrinsicsResult } from './types/with-intrinsics';
|
|
7
|
+
import { Stack } from './utils/stack';
|
|
7
8
|
export declare enum ContextType {
|
|
8
9
|
Api = 0,
|
|
9
10
|
Global = 1,
|
|
@@ -35,6 +36,9 @@ export interface ContextForkOptions {
|
|
|
35
36
|
}
|
|
36
37
|
export declare class OperationContext {
|
|
37
38
|
previous: OperationContext;
|
|
39
|
+
iterators: Stack<Iterator<CustomValue> & {
|
|
40
|
+
index: number;
|
|
41
|
+
}>;
|
|
38
42
|
readonly type: ContextType;
|
|
39
43
|
readonly scope: Scope;
|
|
40
44
|
isProtected: boolean;
|
package/dist/context.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OperationContext = exports.Scope = exports.ContextType = void 0;
|
|
4
4
|
const map_1 = require("./types/map");
|
|
5
5
|
const string_1 = require("./types/string");
|
|
6
|
+
const stack_1 = require("./utils/stack");
|
|
6
7
|
var ContextType;
|
|
7
8
|
(function (ContextType) {
|
|
8
9
|
ContextType[ContextType["Api"] = 0] = "Api";
|
|
@@ -63,6 +64,7 @@ exports.Scope = Scope;
|
|
|
63
64
|
class OperationContext {
|
|
64
65
|
constructor(options) {
|
|
65
66
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
67
|
+
this.iterators = new stack_1.Stack();
|
|
66
68
|
this.code = options.code;
|
|
67
69
|
this.ip = 0;
|
|
68
70
|
this.previous = (_a = options.previous) !== null && _a !== void 0 ? _a : null;
|
package/dist/utils/stack.d.ts
CHANGED
package/dist/utils/stack.js
CHANGED
package/dist/vm.d.ts
CHANGED
package/dist/vm.js
CHANGED
|
@@ -102,7 +102,6 @@ class VM {
|
|
|
102
102
|
this.handler = options.handler;
|
|
103
103
|
this.debugger = options.debugger;
|
|
104
104
|
this.environmentVariables = (_b = options.environmentVariables) !== null && _b !== void 0 ? _b : new Map();
|
|
105
|
-
this.iterators = new stack_1.Stack();
|
|
106
105
|
this.imports = (_c = options.imports) !== null && _c !== void 0 ? _c : new Map();
|
|
107
106
|
this.externalFrames = (_d = options.externalFrames) !== null && _d !== void 0 ? _d : new stack_1.Stack();
|
|
108
107
|
}
|
|
@@ -163,6 +162,9 @@ class VM {
|
|
|
163
162
|
return ctx;
|
|
164
163
|
}
|
|
165
164
|
popFrame() {
|
|
165
|
+
if (this.frames.length === 1) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
166
168
|
const frame = this.frames.pop();
|
|
167
169
|
this.getFrame().ip++;
|
|
168
170
|
return frame;
|
|
@@ -429,17 +431,17 @@ class VM {
|
|
|
429
431
|
case instruction_1.OpCode.PUSH_ITERATOR: {
|
|
430
432
|
const value = this.popStack();
|
|
431
433
|
const iterator = value[Symbol.iterator]();
|
|
432
|
-
|
|
434
|
+
frame.iterators.push(iterator);
|
|
433
435
|
break;
|
|
434
436
|
}
|
|
435
437
|
case instruction_1.OpCode.POP_ITERATOR: {
|
|
436
|
-
|
|
438
|
+
frame.iterators.pop();
|
|
437
439
|
break;
|
|
438
440
|
}
|
|
439
441
|
case instruction_1.OpCode.NEXT: {
|
|
440
442
|
const nextInstruction = instruction;
|
|
441
443
|
let idx = frame.get(nextInstruction.idxVariable, this.contextTypeIntrinsics).toNumber();
|
|
442
|
-
const iterator =
|
|
444
|
+
const iterator = frame.iterators.peek();
|
|
443
445
|
iterator.index = ++idx;
|
|
444
446
|
const iteratorResult = iterator.next();
|
|
445
447
|
this.pushStack(new boolean_1.CustomBoolean(!iteratorResult.done));
|
|
@@ -684,6 +686,7 @@ class VM {
|
|
|
684
686
|
}
|
|
685
687
|
case instruction_1.OpCode.RETURN: {
|
|
686
688
|
const value = this.popStack();
|
|
689
|
+
frame.iterators.clear();
|
|
687
690
|
this.popFrame();
|
|
688
691
|
this.pushStack(value !== null && value !== void 0 ? value : default_1.DefaultType.Void);
|
|
689
692
|
break;
|