greybel-interpreter 4.0.8 → 4.0.10
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 +2 -0
- package/dist/context.js +23 -0
- package/dist/vm.d.ts +2 -1
- package/dist/vm.js +10 -5
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { CustomMap } from './types/map';
|
|
|
3
3
|
import { ObjectValue } from './utils/object-value';
|
|
4
4
|
import { ContextTypeIntrinsics } from './context/types';
|
|
5
5
|
import { Instruction } from './byte-compiler/instruction';
|
|
6
|
+
import { CustomValueWithIntrinsicsResult } from './types/with-intrinsics';
|
|
6
7
|
export declare enum ContextType {
|
|
7
8
|
Api = 0,
|
|
8
9
|
Global = 1,
|
|
@@ -13,6 +14,7 @@ export declare class Scope extends CustomMap {
|
|
|
13
14
|
private readonly context;
|
|
14
15
|
constructor(context: OperationContext);
|
|
15
16
|
get(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValue;
|
|
17
|
+
getWithOrigin(current: CustomValue, typeIntrinsics: ContextTypeIntrinsics): CustomValueWithIntrinsicsResult;
|
|
16
18
|
}
|
|
17
19
|
export interface ContextOptions {
|
|
18
20
|
code: Instruction[];
|
package/dist/context.js
CHANGED
|
@@ -35,6 +35,29 @@ class Scope extends map_1.CustomMap {
|
|
|
35
35
|
}
|
|
36
36
|
throw new Error(`Unknown path ${current.toString()}.`);
|
|
37
37
|
}
|
|
38
|
+
getWithOrigin(current, typeIntrinsics) {
|
|
39
|
+
var _a, _b, _c, _d;
|
|
40
|
+
if (this.has(current)) {
|
|
41
|
+
return super.getWithOrigin(current, typeIntrinsics);
|
|
42
|
+
}
|
|
43
|
+
else if ((_a = this.context.outer) === null || _a === void 0 ? void 0 : _a.scope.has(current)) {
|
|
44
|
+
return this.context.outer.scope.getWithOrigin(current, typeIntrinsics);
|
|
45
|
+
}
|
|
46
|
+
else if ((_b = this.context.globals) === null || _b === void 0 ? void 0 : _b.scope.has(current)) {
|
|
47
|
+
return this.context.globals.scope.getWithOrigin(current, typeIntrinsics);
|
|
48
|
+
}
|
|
49
|
+
else if ((_c = this.context.api) === null || _c === void 0 ? void 0 : _c.scope.has(current)) {
|
|
50
|
+
return this.context.api.scope.getWithOrigin(current, typeIntrinsics);
|
|
51
|
+
}
|
|
52
|
+
const intrinsics = (_d = typeIntrinsics.map) !== null && _d !== void 0 ? _d : map_1.CustomMap.getIntrinsics();
|
|
53
|
+
if (intrinsics.has(current)) {
|
|
54
|
+
return {
|
|
55
|
+
value: intrinsics.get(current),
|
|
56
|
+
origin: null
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`Unknown path ${current.toString()}.`);
|
|
60
|
+
}
|
|
38
61
|
}
|
|
39
62
|
exports.Scope = Scope;
|
|
40
63
|
class OperationContext {
|
package/dist/vm.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface VMOptions {
|
|
|
36
36
|
debugger: Debugger;
|
|
37
37
|
environmentVariables?: Map<string, string>;
|
|
38
38
|
imports?: Map<string, Instruction[]>;
|
|
39
|
-
|
|
39
|
+
externalFrames?: Stack<OperationContext>;
|
|
40
40
|
}
|
|
41
41
|
export declare class VM {
|
|
42
42
|
private readonly ACTIONS_PER_LOOP;
|
|
@@ -55,6 +55,7 @@ export declare class VM {
|
|
|
55
55
|
readonly handler: HandlerContainer;
|
|
56
56
|
readonly debugger: Debugger;
|
|
57
57
|
readonly imports: Map<string, Instruction[]>;
|
|
58
|
+
readonly externalFrames: Stack<OperationContext>;
|
|
58
59
|
constructor(options: VMOptions);
|
|
59
60
|
getTime(): number;
|
|
60
61
|
isPending(): boolean;
|
package/dist/vm.js
CHANGED
|
@@ -96,13 +96,14 @@ class VM {
|
|
|
96
96
|
this.sp = 0;
|
|
97
97
|
this.time = -1;
|
|
98
98
|
this.target = options.target;
|
|
99
|
-
this.frames =
|
|
99
|
+
this.frames = new stack_1.Stack(options.globals);
|
|
100
100
|
this.contextTypeIntrinsics = options.contextTypeIntrinsics;
|
|
101
101
|
this.handler = options.handler;
|
|
102
102
|
this.debugger = options.debugger;
|
|
103
|
-
this.environmentVariables = (
|
|
103
|
+
this.environmentVariables = (_a = options.environmentVariables) !== null && _a !== void 0 ? _a : new Map();
|
|
104
104
|
this.iterators = new stack_1.Stack();
|
|
105
|
-
this.imports = (
|
|
105
|
+
this.imports = (_b = options.imports) !== null && _b !== void 0 ? _b : new Map();
|
|
106
|
+
this.externalFrames = (_c = options.externalFrames) !== null && _c !== void 0 ? _c : new stack_1.Stack();
|
|
106
107
|
}
|
|
107
108
|
getTime() {
|
|
108
109
|
return this.time;
|
|
@@ -111,10 +112,14 @@ class VM {
|
|
|
111
112
|
return this.state === VMState.PENDING;
|
|
112
113
|
}
|
|
113
114
|
getStacktrace() {
|
|
115
|
+
const externalFrames = this.externalFrames.values();
|
|
114
116
|
const frames = this.frames.values();
|
|
115
117
|
const stacktrace = [];
|
|
116
|
-
for (let index =
|
|
117
|
-
stacktrace.push(
|
|
118
|
+
for (let index = 0; index < externalFrames.length; index++) {
|
|
119
|
+
stacktrace.push(externalFrames[index].getCurrentInstruction());
|
|
120
|
+
}
|
|
121
|
+
for (let index = 0; index < frames.length; index++) {
|
|
122
|
+
stacktrace.unshift(frames[index].getCurrentInstruction());
|
|
118
123
|
}
|
|
119
124
|
return stacktrace;
|
|
120
125
|
}
|