greybel-interpreter 3.5.0 → 4.0.0

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.
Files changed (116) hide show
  1. package/dist/byte-compiler/instruction.d.ts +129 -0
  2. package/dist/byte-compiler/instruction.js +60 -0
  3. package/dist/bytecode-generator.d.ts +61 -0
  4. package/dist/bytecode-generator.js +1165 -0
  5. package/dist/context.d.ts +20 -88
  6. package/dist/context.js +44 -273
  7. package/dist/index.d.ts +5 -29
  8. package/dist/index.js +14 -87
  9. package/dist/interpreter.d.ts +9 -11
  10. package/dist/interpreter.js +75 -87
  11. package/dist/types/function.d.ts +11 -25
  12. package/dist/types/function.js +41 -105
  13. package/dist/types/list.d.ts +4 -5
  14. package/dist/types/list.js +10 -52
  15. package/dist/types/map.d.ts +5 -6
  16. package/dist/types/map.js +15 -74
  17. package/dist/types/number.d.ts +4 -5
  18. package/dist/types/number.js +5 -12
  19. package/dist/types/string.d.ts +4 -5
  20. package/dist/types/string.js +6 -18
  21. package/dist/types/with-intrinsics.d.ts +4 -5
  22. package/dist/utils/error.d.ts +5 -5
  23. package/dist/utils/error.js +4 -5
  24. package/dist/utils/stack.d.ts +10 -0
  25. package/dist/utils/stack.js +30 -0
  26. package/dist/vm/evaluation.d.ts +26 -0
  27. package/dist/vm/evaluation.js +341 -0
  28. package/dist/vm.d.ts +66 -0
  29. package/dist/vm.js +662 -0
  30. package/package.json +1 -1
  31. package/dist/cps.d.ts +0 -16
  32. package/dist/cps.js +0 -202
  33. package/dist/operations/assign-globals.d.ts +0 -11
  34. package/dist/operations/assign-globals.js +0 -31
  35. package/dist/operations/assign-locals.d.ts +0 -11
  36. package/dist/operations/assign-locals.js +0 -31
  37. package/dist/operations/assign-outer.d.ts +0 -11
  38. package/dist/operations/assign-outer.js +0 -31
  39. package/dist/operations/assign-self.d.ts +0 -11
  40. package/dist/operations/assign-self.js +0 -41
  41. package/dist/operations/assign.d.ts +0 -13
  42. package/dist/operations/assign.js +0 -60
  43. package/dist/operations/block.d.ts +0 -13
  44. package/dist/operations/block.js +0 -48
  45. package/dist/operations/break.d.ts +0 -10
  46. package/dist/operations/break.js +0 -21
  47. package/dist/operations/call.d.ts +0 -13
  48. package/dist/operations/call.js +0 -64
  49. package/dist/operations/chunk.d.ts +0 -12
  50. package/dist/operations/chunk.js +0 -31
  51. package/dist/operations/continue.d.ts +0 -10
  52. package/dist/operations/continue.js +0 -21
  53. package/dist/operations/debugger-statement.d.ts +0 -10
  54. package/dist/operations/debugger-statement.js +0 -19
  55. package/dist/operations/envar.d.ts +0 -10
  56. package/dist/operations/envar.js +0 -21
  57. package/dist/operations/evaluate.d.ts +0 -45
  58. package/dist/operations/evaluate.js +0 -369
  59. package/dist/operations/for.d.ts +0 -14
  60. package/dist/operations/for.js +0 -87
  61. package/dist/operations/function-reference.d.ts +0 -12
  62. package/dist/operations/function-reference.js +0 -48
  63. package/dist/operations/function.d.ts +0 -19
  64. package/dist/operations/function.js +0 -84
  65. package/dist/operations/if-statement.d.ts +0 -19
  66. package/dist/operations/if-statement.js +0 -87
  67. package/dist/operations/import.d.ts +0 -20
  68. package/dist/operations/import.js +0 -56
  69. package/dist/operations/include.d.ts +0 -14
  70. package/dist/operations/include.js +0 -40
  71. package/dist/operations/list.d.ts +0 -11
  72. package/dist/operations/list.js +0 -40
  73. package/dist/operations/literal.d.ts +0 -11
  74. package/dist/operations/literal.js +0 -38
  75. package/dist/operations/map.d.ts +0 -11
  76. package/dist/operations/map.js +0 -42
  77. package/dist/operations/negated-binary.d.ts +0 -11
  78. package/dist/operations/negated-binary.js +0 -40
  79. package/dist/operations/new-instance.d.ts +0 -11
  80. package/dist/operations/new-instance.js +0 -37
  81. package/dist/operations/noop.d.ts +0 -7
  82. package/dist/operations/noop.js +0 -14
  83. package/dist/operations/not.d.ts +0 -11
  84. package/dist/operations/not.js +0 -33
  85. package/dist/operations/operation.d.ts +0 -15
  86. package/dist/operations/operation.js +0 -13
  87. package/dist/operations/reference-globals.d.ts +0 -7
  88. package/dist/operations/reference-globals.js +0 -13
  89. package/dist/operations/reference-locals.d.ts +0 -7
  90. package/dist/operations/reference-locals.js +0 -13
  91. package/dist/operations/reference-outer.d.ts +0 -7
  92. package/dist/operations/reference-outer.js +0 -13
  93. package/dist/operations/reference-self.d.ts +0 -7
  94. package/dist/operations/reference-self.js +0 -13
  95. package/dist/operations/reference.d.ts +0 -9
  96. package/dist/operations/reference.js +0 -17
  97. package/dist/operations/resolve-globals.d.ts +0 -5
  98. package/dist/operations/resolve-globals.js +0 -24
  99. package/dist/operations/resolve-locals.d.ts +0 -5
  100. package/dist/operations/resolve-locals.js +0 -24
  101. package/dist/operations/resolve-outer.d.ts +0 -5
  102. package/dist/operations/resolve-outer.js +0 -24
  103. package/dist/operations/resolve-self.d.ts +0 -5
  104. package/dist/operations/resolve-self.js +0 -24
  105. package/dist/operations/resolve.d.ts +0 -55
  106. package/dist/operations/resolve.js +0 -269
  107. package/dist/operations/return.d.ts +0 -11
  108. package/dist/operations/return.js +0 -43
  109. package/dist/operations/while.d.ts +0 -13
  110. package/dist/operations/while.js +0 -70
  111. package/dist/utils/create-assign.d.ts +0 -3
  112. package/dist/utils/create-assign.js +0 -25
  113. package/dist/utils/create-resolve.d.ts +0 -5
  114. package/dist/utils/create-resolve.js +0 -51
  115. package/dist/utils/path.d.ts +0 -10
  116. package/dist/utils/path.js +0 -33
package/dist/context.d.ts CHANGED
@@ -1,109 +1,46 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { ASTBase } from 'miniscript-core';
4
- import { CPS } from './cps';
5
- import { HandlerContainer } from './handler-container';
6
- import { Operation } from './operations/operation';
7
1
  import { CustomValue } from './types/base';
8
2
  import { CustomMap } from './types/map';
9
3
  import { ObjectValue } from './utils/object-value';
10
- import { Path } from './utils/path';
11
4
  import { ContextTypeIntrinsics } from './context/types';
5
+ import { Instruction } from './byte-compiler/instruction';
12
6
  export declare enum ContextType {
13
7
  Api = 0,
14
8
  Global = 1,
15
9
  Function = 2,
16
- External = 3,
17
- Loop = 4,
18
- Map = 5,
19
- Call = 6
20
- }
21
- export declare enum ContextState {
22
- Temporary = 0,
23
- Default = 1
10
+ Injected = 3
24
11
  }
25
12
  export declare class Scope extends CustomMap {
26
13
  private readonly context;
27
14
  constructor(context: OperationContext);
28
- get(path: Path<CustomValue> | CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValue;
29
- }
30
- export declare class Debugger {
31
- private breakpoint;
32
- private nextStep;
33
- private lastContext;
34
- getLastContext(): OperationContext;
35
- debug(...segments: any[]): CustomValue;
36
- setBreakpoint(breakpoint: boolean): Debugger;
37
- getBreakpoint(_ctx: OperationContext): boolean;
38
- next(): Debugger;
39
- resume(): Promise<void>;
40
- interact(ctx: OperationContext, _ast: ASTBase, _op: Operation): void;
41
- }
42
- export interface ExitObserver {
43
- occured: () => boolean;
44
- close: () => void;
45
- }
46
- export declare class ProcessState extends EventEmitter {
47
- isPending: boolean;
48
- last: OperationContext;
49
- private observer;
50
- private observerWithExitOccurence;
51
- constructor();
52
- createExitObserver(): ExitObserver;
53
- }
54
- export declare class LoopState {
55
- isBreak: boolean;
56
- isContinue: boolean;
57
- }
58
- export declare class FunctionState {
59
- value: CustomValue;
60
- isReturn: boolean;
61
- context: CustomValue;
62
- super: CustomValue;
15
+ get(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValue;
63
16
  }
64
17
  export interface ContextOptions {
65
- target?: string;
66
- stackTrace?: Operation[];
18
+ code: Instruction[];
67
19
  previous?: OperationContext;
68
20
  type?: ContextType;
69
- state?: ContextState;
21
+ self?: CustomValue;
22
+ super?: CustomValue;
70
23
  isProtected?: boolean;
71
- injected?: boolean;
72
- debugger?: Debugger;
73
- handler?: HandlerContainer;
74
- cps?: CPS;
75
- processState?: ProcessState;
76
- environmentVariables?: Map<string, string>;
77
- ignoreOuter?: boolean;
78
- contextTypeIntrinsics?: ContextTypeIntrinsics;
79
- time?: number;
24
+ outer?: OperationContext;
80
25
  }
81
26
  export interface ContextForkOptions {
27
+ code: Instruction[];
82
28
  type: ContextType;
83
- state: ContextState;
29
+ self?: CustomValue;
30
+ super?: CustomValue;
84
31
  target?: string;
85
- injected?: boolean;
86
- ignoreOuter?: boolean;
87
- processState?: ProcessState;
32
+ outer?: OperationContext;
88
33
  }
89
34
  export declare class OperationContext {
90
- target: string;
91
- stackTrace: Operation[];
92
- debugger: Debugger;
93
- environmentVariables: Map<string, string>;
94
- handler: HandlerContainer;
95
- contextTypeIntrinsics: ContextTypeIntrinsics;
96
35
  previous: OperationContext;
97
36
  readonly type: ContextType;
98
- readonly state: ContextState;
99
37
  readonly scope: Scope;
100
- readonly cps: CPS;
101
- readonly time: number;
102
- readonly processState: ProcessState;
103
- loopState: LoopState;
104
- functionState: FunctionState;
105
38
  isProtected: boolean;
106
39
  injected: boolean;
40
+ ip: number;
41
+ code: Instruction[];
42
+ self: CustomValue | null;
43
+ super: CustomValue | null;
107
44
  readonly api: OperationContext;
108
45
  readonly locals: OperationContext;
109
46
  readonly outer: OperationContext;
@@ -111,15 +48,8 @@ export declare class OperationContext {
111
48
  private static readonly lookupApiType;
112
49
  private static readonly lookupGlobalsType;
113
50
  private static readonly lookupLocalsType;
114
- constructor(options?: ContextOptions);
115
- isIgnoredInDebugging(op: Operation): boolean;
116
- step(op: Operation): Promise<CustomValue>;
117
- setLastActive(ctx: OperationContext): OperationContext;
118
- getLastActive(): OperationContext;
119
- isPending(): boolean;
120
- setPending(pending: boolean): OperationContext;
51
+ constructor(options: ContextOptions);
121
52
  lookupAllOfType(validate: (type: ContextType) => boolean): OperationContext[];
122
- exit(): Promise<OperationContext>;
123
53
  lookupType(allowedTypes: Array<ContextType>): OperationContext;
124
54
  lookupAllScopes(): OperationContext[];
125
55
  lookupApi(): OperationContext;
@@ -127,7 +57,9 @@ export declare class OperationContext {
127
57
  lookupLocals(): OperationContext;
128
58
  lookupOuter(): OperationContext;
129
59
  extend(map: ObjectValue): OperationContext;
130
- set(path: Path<CustomValue> | CustomValue, value: CustomValue): void;
131
- get(path: Path<CustomValue> | CustomValue): CustomValue;
60
+ set(path: CustomValue, value: CustomValue): void;
61
+ get(path: CustomValue, contextTypeIntrinsics: ContextTypeIntrinsics): CustomValue;
62
+ injectContext(): void;
63
+ getCurrentInstruction(): Instruction;
132
64
  fork(options: ContextForkOptions): OperationContext;
133
65
  }
package/dist/context.js CHANGED
@@ -1,236 +1,57 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.OperationContext = exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
13
- const events_1 = require("events");
14
- const handler_container_1 = require("./handler-container");
15
- const noop_1 = require("./operations/noop");
16
- const operation_1 = require("./operations/operation");
17
- const base_1 = require("./types/base");
18
- const default_1 = require("./types/default");
3
+ exports.OperationContext = exports.Scope = exports.ContextType = void 0;
19
4
  const map_1 = require("./types/map");
20
- const path_1 = require("./utils/path");
21
- const set_immediate_1 = require("./utils/set-immediate");
22
- const uuid_1 = require("./utils/uuid");
5
+ const string_1 = require("./types/string");
23
6
  var ContextType;
24
7
  (function (ContextType) {
25
8
  ContextType[ContextType["Api"] = 0] = "Api";
26
9
  ContextType[ContextType["Global"] = 1] = "Global";
27
10
  ContextType[ContextType["Function"] = 2] = "Function";
28
- ContextType[ContextType["External"] = 3] = "External";
29
- ContextType[ContextType["Loop"] = 4] = "Loop";
30
- ContextType[ContextType["Map"] = 5] = "Map";
31
- ContextType[ContextType["Call"] = 6] = "Call";
11
+ ContextType[ContextType["Injected"] = 3] = "Injected";
32
12
  })(ContextType = exports.ContextType || (exports.ContextType = {}));
33
- var ContextState;
34
- (function (ContextState) {
35
- ContextState[ContextState["Temporary"] = 0] = "Temporary";
36
- ContextState[ContextState["Default"] = 1] = "Default";
37
- })(ContextState = exports.ContextState || (exports.ContextState = {}));
38
13
  class Scope extends map_1.CustomMap {
39
14
  constructor(context) {
40
15
  super();
41
16
  this.context = context;
42
17
  }
43
- get(path, typeIntrinsics) {
18
+ get(current, typeIntrinsics) {
44
19
  var _a, _b, _c, _d;
45
- if (path instanceof base_1.CustomValue) {
46
- return this.get(new path_1.Path([path]), typeIntrinsics);
20
+ if (this.has(current)) {
21
+ return super.get(current, typeIntrinsics);
47
22
  }
48
- if (path.count() === 0) {
49
- return this;
50
- }
51
- const traversalPath = path.clone();
52
- const current = traversalPath.next();
53
- if (this.has(path)) {
54
- return super.get(path, typeIntrinsics);
23
+ else if ((_a = this.context.outer) === null || _a === void 0 ? void 0 : _a.scope.has(current)) {
24
+ return this.context.outer.scope.get(current, typeIntrinsics);
55
25
  }
56
- else if ((_a = this.context.outer) === null || _a === void 0 ? void 0 : _a.scope.has(path)) {
57
- return this.context.outer.scope.get(path, typeIntrinsics);
26
+ else if ((_b = this.context.globals) === null || _b === void 0 ? void 0 : _b.scope.has(current)) {
27
+ return this.context.globals.scope.get(current, typeIntrinsics);
58
28
  }
59
- else if ((_b = this.context.globals) === null || _b === void 0 ? void 0 : _b.scope.has(path)) {
60
- return this.context.globals.scope.get(path, typeIntrinsics);
61
- }
62
- else if ((_c = this.context.api) === null || _c === void 0 ? void 0 : _c.scope.has(path)) {
63
- return this.context.api.scope.get(path, typeIntrinsics);
29
+ else if ((_c = this.context.api) === null || _c === void 0 ? void 0 : _c.scope.has(current)) {
30
+ return this.context.api.scope.get(current, typeIntrinsics);
64
31
  }
65
32
  const intrinsics = (_d = typeIntrinsics.map) !== null && _d !== void 0 ? _d : map_1.CustomMap.getIntrinsics();
66
- if (traversalPath.count() === 0 && intrinsics.has(current)) {
33
+ if (intrinsics.has(current)) {
67
34
  return intrinsics.get(current);
68
35
  }
69
- throw new Error(`Unknown path ${path.toString()}.`);
36
+ throw new Error(`Unknown path ${current.toString()}.`);
70
37
  }
71
38
  }
72
39
  exports.Scope = Scope;
73
- class Debugger {
74
- constructor() {
75
- this.breakpoint = false;
76
- this.nextStep = false;
77
- /* eslint-disable no-use-before-define */
78
- this.lastContext = null;
79
- }
80
- getLastContext() {
81
- return this.lastContext;
82
- }
83
- debug(...segments) {
84
- console.debug(...segments);
85
- return default_1.DefaultType.Void;
86
- }
87
- setBreakpoint(breakpoint) {
88
- this.breakpoint = breakpoint;
89
- return this;
90
- }
91
- getBreakpoint(_ctx) {
92
- return this.breakpoint;
93
- }
94
- next() {
95
- this.nextStep = true;
96
- return this;
97
- }
98
- resume() {
99
- if (!this.breakpoint) {
100
- return Promise.resolve();
101
- }
102
- return new Promise((resolve) => {
103
- const check = () => {
104
- if (!this.breakpoint) {
105
- resolve();
106
- }
107
- else if (this.nextStep) {
108
- this.nextStep = false;
109
- resolve();
110
- }
111
- else {
112
- (0, set_immediate_1.setImmediate)(check);
113
- }
114
- };
115
- check();
116
- });
117
- }
118
- interact(ctx, _ast, _op) {
119
- const me = this;
120
- console.warn('Debugger is not setup.');
121
- console.info(ctx);
122
- me.breakpoint = false;
123
- }
124
- }
125
- exports.Debugger = Debugger;
126
- class ProcessState extends events_1.EventEmitter {
127
- constructor() {
128
- super();
129
- this.isPending = false;
130
- /* eslint-disable no-use-before-define */
131
- this.last = null;
132
- this.observer = new Set();
133
- this.observerWithExitOccurence = new Set();
134
- this.once('exit', () => {
135
- this.observerWithExitOccurence = new Set(this.observer);
136
- });
137
- }
138
- createExitObserver() {
139
- const id = (0, uuid_1.uuid)();
140
- this.observer.add(id);
141
- return {
142
- occured: () => this.observerWithExitOccurence.has(id),
143
- close: () => this.observer.delete(id)
144
- };
145
- }
146
- }
147
- exports.ProcessState = ProcessState;
148
- class LoopState {
149
- constructor() {
150
- this.isBreak = false;
151
- this.isContinue = false;
152
- }
153
- }
154
- exports.LoopState = LoopState;
155
- class FunctionState {
156
- constructor() {
157
- this.value = default_1.DefaultType.Void;
158
- this.isReturn = false;
159
- this.context = null;
160
- this.super = null;
161
- }
162
- }
163
- exports.FunctionState = FunctionState;
164
40
  class OperationContext {
165
- constructor(options = {}) {
166
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
167
- this.target = (_a = options.target) !== null && _a !== void 0 ? _a : 'unknown';
168
- this.stackTrace = (_b = options.stackTrace) !== null && _b !== void 0 ? _b : [];
169
- this.time = (_c = options.time) !== null && _c !== void 0 ? _c : Date.now();
170
- this.previous = (_d = options.previous) !== null && _d !== void 0 ? _d : null;
171
- this.type = (_e = options.type) !== null && _e !== void 0 ? _e : ContextType.Api;
172
- this.state = (_f = options.state) !== null && _f !== void 0 ? _f : ContextState.Default;
173
- this.scope = new Scope(this);
174
- this.isProtected = (_g = options.isProtected) !== null && _g !== void 0 ? _g : false;
175
- this.injected = (_h = options.injected) !== null && _h !== void 0 ? _h : false;
176
- this.debugger = (_j = options.debugger) !== null && _j !== void 0 ? _j : new Debugger();
177
- this.handler = (_k = options.handler) !== null && _k !== void 0 ? _k : new handler_container_1.HandlerContainer();
178
- this.contextTypeIntrinsics = (_l = options.contextTypeIntrinsics) !== null && _l !== void 0 ? _l : {
179
- string: null,
180
- number: null,
181
- list: null,
182
- map: null,
183
- function: null
184
- };
185
- this.cps = (_m = options.cps) !== null && _m !== void 0 ? _m : null;
186
- this.processState = (_o = options.processState) !== null && _o !== void 0 ? _o : new ProcessState();
187
- this.environmentVariables = (_p = options.environmentVariables) !== null && _p !== void 0 ? _p : new Map();
188
- this.functionState = new FunctionState();
189
- this.loopState = new LoopState();
41
+ constructor(options) {
42
+ var _a, _b, _c, _d, _e, _f, _g;
43
+ this.code = options.code;
44
+ this.ip = 0;
45
+ this.previous = (_a = options.previous) !== null && _a !== void 0 ? _a : null;
46
+ this.type = (_b = options.type) !== null && _b !== void 0 ? _b : ContextType.Api;
47
+ this.scope = this.type === ContextType.Injected ? options.previous.scope : new Scope(this);
48
+ this.self = (_c = options.self) !== null && _c !== void 0 ? _c : null;
49
+ this.super = (_d = options.super) !== null && _d !== void 0 ? _d : null;
50
+ this.isProtected = (_e = options.isProtected) !== null && _e !== void 0 ? _e : false;
190
51
  this.api = this.lookupApi();
191
52
  this.globals = this.lookupGlobals();
192
- this.locals = (_q = this.lookupLocals()) !== null && _q !== void 0 ? _q : this;
193
- this.outer = (_r = (options.ignoreOuter ? null : this.lookupOuter())) !== null && _r !== void 0 ? _r : this.globals;
194
- }
195
- isIgnoredInDebugging(op) {
196
- return op instanceof operation_1.OperationBlock || op instanceof noop_1.Noop;
197
- }
198
- step(op) {
199
- var _a;
200
- return __awaiter(this, void 0, void 0, function* () {
201
- if (this.isIgnoredInDebugging(op)) {
202
- return op.handle(this);
203
- }
204
- this.stackTrace.unshift(op);
205
- if (!this.injected) {
206
- this.target = (_a = op.target) !== null && _a !== void 0 ? _a : this.target;
207
- this.setLastActive(this);
208
- if (this.debugger.getBreakpoint(this)) {
209
- this.processState.emit('breakpoint');
210
- this.debugger.interact(this, op.item, op);
211
- yield this.debugger.resume();
212
- }
213
- }
214
- const result = yield op.handle(this);
215
- this.stackTrace.shift();
216
- return result;
217
- });
218
- }
219
- setLastActive(ctx) {
220
- if (!ctx.injected) {
221
- this.processState.last = ctx;
222
- }
223
- return this;
224
- }
225
- getLastActive() {
226
- return this.processState.last;
227
- }
228
- isPending() {
229
- return this.processState.isPending;
230
- }
231
- setPending(pending) {
232
- this.processState.isPending = pending;
233
- return this;
53
+ this.locals = (_f = this.lookupLocals()) !== null && _f !== void 0 ? _f : this;
54
+ this.outer = (_g = options.outer) !== null && _g !== void 0 ? _g : this.lookupOuter();
234
55
  }
235
56
  lookupAllOfType(validate) {
236
57
  const me = this;
@@ -247,23 +68,6 @@ class OperationContext {
247
68
  }
248
69
  return result;
249
70
  }
250
- exit() {
251
- if (this.processState.isPending) {
252
- this.processState.emit('exit');
253
- return new Promise((resolve) => {
254
- const check = () => {
255
- if (!this.processState.isPending) {
256
- resolve(this);
257
- }
258
- else {
259
- (0, set_immediate_1.setImmediate)(check);
260
- }
261
- };
262
- check();
263
- });
264
- }
265
- return Promise.reject(new Error('No running process found.'));
266
- }
267
71
  lookupType(allowedTypes) {
268
72
  if (allowedTypes.includes(this.type)) {
269
73
  return this;
@@ -294,67 +98,34 @@ class OperationContext {
294
98
  return (_b = (_a = this.locals.previous) === null || _a === void 0 ? void 0 : _a.lookupLocals()) !== null && _b !== void 0 ? _b : null;
295
99
  }
296
100
  extend(map) {
297
- var _a;
298
- if (this.state === ContextState.Temporary) {
299
- (_a = this.previous) === null || _a === void 0 ? void 0 : _a.extend(map);
300
- }
301
- else {
302
- this.scope.extend(map);
303
- }
101
+ this.scope.extend(map);
304
102
  return this;
305
103
  }
306
104
  set(path, value) {
307
- var _a;
308
- if (path instanceof base_1.CustomValue) {
309
- this.set(new path_1.Path([path]), value);
310
- return;
311
- }
312
- if (this.state === ContextState.Temporary) {
313
- (_a = this.previous) === null || _a === void 0 ? void 0 : _a.set(path, value);
314
- }
315
- else {
316
- this.locals.scope.set(path, value);
317
- }
105
+ this.locals.scope.set(path, value);
318
106
  }
319
- get(path) {
320
- var _a;
321
- if (path instanceof base_1.CustomValue) {
322
- return this.get(new path_1.Path([path]));
323
- }
324
- if (path.count() === 0) {
325
- return this.scope;
326
- }
327
- if (this.state === ContextState.Temporary) {
328
- return (_a = this.previous) === null || _a === void 0 ? void 0 : _a.get(path);
329
- }
330
- return this.locals.scope.get(path, this.contextTypeIntrinsics);
107
+ get(path, contextTypeIntrinsics) {
108
+ return this.locals.scope.get(path, contextTypeIntrinsics);
109
+ }
110
+ injectContext() {
111
+ if (this.self)
112
+ this.set(new string_1.CustomString('self'), this.self);
113
+ if (this.super)
114
+ this.set(new string_1.CustomString('super'), this.super);
115
+ }
116
+ getCurrentInstruction() {
117
+ return this.code[this.ip - 1];
331
118
  }
332
119
  fork(options) {
333
- var _a, _b;
334
- const newContext = new OperationContext({
335
- target: (_a = options.target) !== null && _a !== void 0 ? _a : this.target,
336
- stackTrace: this.stackTrace,
120
+ return new OperationContext({
337
121
  previous: this,
338
122
  type: options.type,
339
- state: options.state,
340
- ignoreOuter: options.ignoreOuter,
341
123
  isProtected: false,
342
- injected: this.injected,
343
- debugger: this.debugger,
344
- handler: this.handler,
345
- cps: this.cps,
346
- processState: (_b = options.processState) !== null && _b !== void 0 ? _b : this.processState,
347
- environmentVariables: this.environmentVariables,
348
- contextTypeIntrinsics: this.contextTypeIntrinsics,
349
- time: this.time
124
+ code: options.code,
125
+ self: options.self,
126
+ super: options.super,
127
+ outer: options.outer
350
128
  });
351
- if (options.type !== ContextType.Function) {
352
- if (options.type !== ContextType.Loop) {
353
- newContext.loopState = this.loopState;
354
- }
355
- newContext.functionState = this.functionState;
356
- }
357
- return newContext;
358
129
  }
359
130
  }
360
131
  OperationContext.lookupApiType = [ContextType.Api];
package/dist/index.d.ts CHANGED
@@ -1,39 +1,13 @@
1
- export { ContextForkOptions, ContextOptions, ContextState, ContextType, Debugger, FunctionState, LoopState, OperationContext, ProcessState, Scope } from './context';
2
- export { CPS, CPSContext, CPSVisitCallback, defaultCPSVisit } from './cps';
1
+ export { ContextForkOptions, ContextOptions, ContextType, OperationContext, Scope } from './context';
3
2
  export { DefaultErrorHandler, ErrorHandler } from './handler/error';
4
3
  export { DefaultOutputHandler, KeyEvent, OutputHandler, PrintOptions } from './handler/output';
5
4
  export { DefaultResourceHandler, ResourceHandler } from './handler/resource';
6
5
  export { HandlerContainer } from './handler-container';
7
6
  export { Interpreter, InterpreterOptions } from './interpreter';
8
- export { Assign } from './operations/assign';
9
- export { Block, IsEOL } from './operations/block';
10
- export { Break } from './operations/break';
11
- export { Call } from './operations/call';
12
- export { Chunk } from './operations/chunk';
13
- export { Continue } from './operations/continue';
14
- export { DebuggerStatement } from './operations/debugger-statement';
15
- export { Evaluate, GenericProcessorHandler, handle, handleList, handleMap, handleNumber, handleString, ListProcessorHandler, MapProcessorHandler, NumberProcessorHandler, ProcessorHandler, ProcessorHandlerFunction, StringProcessorHandler } from './operations/evaluate';
16
- export { For } from './operations/for';
17
- export { FunctionOperation } from './operations/function';
18
- export { Clause, IfStatement } from './operations/if-statement';
19
- export { Import } from './operations/import';
20
- export { Include } from './operations/include';
21
- export { List } from './operations/list';
22
- export { Literal } from './operations/literal';
23
- export { MapOperation } from './operations/map';
24
- export { NegatedBinary } from './operations/negated-binary';
25
- export { NewInstance } from './operations/new-instance';
26
- export { Noop } from './operations/noop';
27
- export { Not } from './operations/not';
28
- export { CPSVisit, Operation } from './operations/operation';
29
- export { Reference } from './operations/reference';
30
- export { IdentifierSegment, IndexSegment, OperationSegment, Resolve, ResolveResult, Segment } from './operations/resolve';
31
- export { Return } from './operations/return';
32
- export { While } from './operations/while';
33
7
  export { CustomValue } from './types/base';
34
8
  export { CustomBoolean } from './types/boolean';
35
9
  export { DefaultType } from './types/default';
36
- export { Argument, Callback, CustomFunction } from './types/function';
10
+ export { CustomFunctionCallback, CustomFunction } from './types/function';
37
11
  export { CustomList, CustomListIterator } from './types/list';
38
12
  export { CustomMap, CustomMapIterator } from './types/map';
39
13
  export { CustomNil } from './types/nil';
@@ -42,6 +16,8 @@ export { CustomString, CustomStringIterator } from './types/string';
42
16
  export { CustomObject, CustomValueWithIntrinsics } from './types/with-intrinsics';
43
17
  export { PrepareError, RuntimeError } from './utils/error';
44
18
  export { ObjectValue } from './utils/object-value';
45
- export { Path } from './utils/path';
46
19
  export { deepEqual } from './utils/deep-equal';
47
20
  export { deepHash } from './utils/deep-hash';
21
+ export { Debugger, VM, VMOptions } from './vm';
22
+ export { Instruction } from './byte-compiler/instruction';
23
+ export { BytecodeGenerator, BytecodeCompileResult, BytecodeConverterOptions, BytecodeGeneratorContext } from './bytecode-generator';