greybel-interpreter 4.1.1 → 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 +1 -0
- package/dist/utils/stack.js +4 -0
- package/dist/vm.d.ts +0 -1
- package/dist/vm.js +4 -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
|
}
|
|
@@ -432,17 +431,17 @@ class VM {
|
|
|
432
431
|
case instruction_1.OpCode.PUSH_ITERATOR: {
|
|
433
432
|
const value = this.popStack();
|
|
434
433
|
const iterator = value[Symbol.iterator]();
|
|
435
|
-
|
|
434
|
+
frame.iterators.push(iterator);
|
|
436
435
|
break;
|
|
437
436
|
}
|
|
438
437
|
case instruction_1.OpCode.POP_ITERATOR: {
|
|
439
|
-
|
|
438
|
+
frame.iterators.pop();
|
|
440
439
|
break;
|
|
441
440
|
}
|
|
442
441
|
case instruction_1.OpCode.NEXT: {
|
|
443
442
|
const nextInstruction = instruction;
|
|
444
443
|
let idx = frame.get(nextInstruction.idxVariable, this.contextTypeIntrinsics).toNumber();
|
|
445
|
-
const iterator =
|
|
444
|
+
const iterator = frame.iterators.peek();
|
|
446
445
|
iterator.index = ++idx;
|
|
447
446
|
const iteratorResult = iterator.next();
|
|
448
447
|
this.pushStack(new boolean_1.CustomBoolean(!iteratorResult.done));
|
|
@@ -687,6 +686,7 @@ class VM {
|
|
|
687
686
|
}
|
|
688
687
|
case instruction_1.OpCode.RETURN: {
|
|
689
688
|
const value = this.popStack();
|
|
689
|
+
frame.iterators.clear();
|
|
690
690
|
this.popFrame();
|
|
691
691
|
this.pushStack(value !== null && value !== void 0 ? value : default_1.DefaultType.Void);
|
|
692
692
|
break;
|