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 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;
@@ -8,4 +8,5 @@ export declare class Stack<T> {
8
8
  includes(value: T): boolean;
9
9
  values(): T[];
10
10
  get length(): number;
11
+ clear(): void;
11
12
  }
@@ -29,5 +29,9 @@ class Stack {
29
29
  get length() {
30
30
  return this.stack.length;
31
31
  }
32
+ clear() {
33
+ this.stack = [];
34
+ this.last = undefined;
35
+ }
32
36
  }
33
37
  exports.Stack = Stack;
package/dist/vm.d.ts CHANGED
@@ -50,7 +50,6 @@ export declare class VM {
50
50
  private readonly STACK_LIMIT;
51
51
  private sp;
52
52
  private stack;
53
- private iterators;
54
53
  private time;
55
54
  readonly target: string;
56
55
  readonly contextTypeIntrinsics: ContextTypeIntrinsics;
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
- this.iterators.push(iterator);
434
+ frame.iterators.push(iterator);
436
435
  break;
437
436
  }
438
437
  case instruction_1.OpCode.POP_ITERATOR: {
439
- this.iterators.pop();
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 = this.iterators.peek();
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "4.1.1",
3
+ "version": "4.1.2",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",