greybel-interpreter 2.8.2 → 2.8.3
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/interpreter.d.ts +6 -2
- package/dist/interpreter.js +15 -21
- package/dist/operations/function.js +1 -1
- package/dist/types/function.d.ts +1 -1
- package/dist/types/function.js +4 -4
- package/dist/utils/object-value.d.ts +1 -0
- package/dist/utils/object-value.js +7 -0
- package/package.json +1 -1
package/dist/interpreter.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import { Debugger, OperationContext } from './context';
|
|
3
|
+
import { ContextOptions, Debugger, OperationContext } from './context';
|
|
4
4
|
import { CPS } from './cps';
|
|
5
5
|
import { HandlerContainer } from './handler-container';
|
|
6
6
|
import { Operation } from './operations/operation';
|
|
@@ -17,6 +17,10 @@ export interface InterpreterOptions {
|
|
|
17
17
|
debugger?: Debugger;
|
|
18
18
|
environmentVariables?: Map<string, string>;
|
|
19
19
|
}
|
|
20
|
+
export interface InterpreterRunOptions {
|
|
21
|
+
customCode?: string;
|
|
22
|
+
ctxOptions?: ContextOptions;
|
|
23
|
+
}
|
|
20
24
|
export declare class Interpreter extends EventEmitter {
|
|
21
25
|
target: string;
|
|
22
26
|
api: ObjectValue;
|
|
@@ -37,7 +41,7 @@ export declare class Interpreter extends EventEmitter {
|
|
|
37
41
|
injectInLastContext(code: string): Promise<Interpreter>;
|
|
38
42
|
private initScopes;
|
|
39
43
|
private start;
|
|
40
|
-
run(customCode?:
|
|
44
|
+
run({ customCode, ctxOptions }?: InterpreterRunOptions): Promise<Interpreter>;
|
|
41
45
|
resume(): Interpreter;
|
|
42
46
|
pause(): Interpreter;
|
|
43
47
|
exit(): Promise<OperationContext>;
|
package/dist/interpreter.js
CHANGED
|
@@ -118,27 +118,21 @@ class Interpreter extends events_1.EventEmitter {
|
|
|
118
118
|
throw new Error('Unable to inject into last context.');
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
-
initScopes() {
|
|
121
|
+
initScopes(ctxOptions) {
|
|
122
122
|
const cpsCtx = new cps_1.CPSContext(this.target, this.handler);
|
|
123
123
|
this.cps = new cps_1.CPS(cpsCtx);
|
|
124
|
-
const apiContext = new context_1.OperationContext({
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
const funcRefIntrinsics = new map_1.CustomMap(function_1.CustomFunction.intrinsics);
|
|
137
|
-
apiContext.contextTypeIntrinsics.string = stringIntrinsics.value;
|
|
138
|
-
apiContext.contextTypeIntrinsics.number = numberIntrinsics.value;
|
|
139
|
-
apiContext.contextTypeIntrinsics.list = listIntrinsics.value;
|
|
140
|
-
apiContext.contextTypeIntrinsics.map = mapIntrinsics.value;
|
|
141
|
-
apiContext.contextTypeIntrinsics.function = funcRefIntrinsics.value;
|
|
124
|
+
const apiContext = new context_1.OperationContext(Object.assign({ target: this.target, isProtected: true, debugger: this.debugger, handler: this.handler, cps: this.cps, environmentVariables: this.environmentVariables, contextTypeIntrinsics: {
|
|
125
|
+
string: string_1.CustomString.getIntrinsics().fork(),
|
|
126
|
+
number: number_1.CustomNumber.getIntrinsics().fork(),
|
|
127
|
+
list: list_1.CustomList.getIntrinsics().fork(),
|
|
128
|
+
map: map_1.CustomMap.getIntrinsics().fork(),
|
|
129
|
+
function: function_1.CustomFunction.intrinsics.fork()
|
|
130
|
+
} }, ctxOptions));
|
|
131
|
+
const stringIntrinsics = map_1.CustomMap.createWithInitialValue(apiContext.contextTypeIntrinsics.string);
|
|
132
|
+
const numberIntrinsics = map_1.CustomMap.createWithInitialValue(apiContext.contextTypeIntrinsics.number);
|
|
133
|
+
const listIntrinsics = map_1.CustomMap.createWithInitialValue(apiContext.contextTypeIntrinsics.list);
|
|
134
|
+
const mapIntrinsics = map_1.CustomMap.createWithInitialValue(apiContext.contextTypeIntrinsics.map);
|
|
135
|
+
const funcRefIntrinsics = map_1.CustomMap.createWithInitialValue(apiContext.contextTypeIntrinsics.function);
|
|
142
136
|
apiContext.scope.set(new string_1.CustomString('string'), stringIntrinsics);
|
|
143
137
|
apiContext.scope.set(new string_1.CustomString('number'), numberIntrinsics);
|
|
144
138
|
apiContext.scope.set(new string_1.CustomString('list'), listIntrinsics);
|
|
@@ -178,12 +172,12 @@ class Interpreter extends events_1.EventEmitter {
|
|
|
178
172
|
return this;
|
|
179
173
|
});
|
|
180
174
|
}
|
|
181
|
-
run(customCode) {
|
|
175
|
+
run({ customCode, ctxOptions } = {}) {
|
|
182
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
177
|
if (this.apiContext !== null && this.apiContext.isPending()) {
|
|
184
178
|
throw new Error('Process already running.');
|
|
185
179
|
}
|
|
186
|
-
this.initScopes();
|
|
180
|
+
this.initScopes(ctxOptions);
|
|
187
181
|
const code = customCode !== null && customCode !== void 0 ? customCode : (yield this.handler.resourceHandler.get(this.target));
|
|
188
182
|
const top = yield this.prepare(code);
|
|
189
183
|
return this.start(top);
|
|
@@ -74,7 +74,7 @@ class FunctionOperation extends operation_1.Operation {
|
|
|
74
74
|
fnCtx.functionState = functionState;
|
|
75
75
|
yield this.block.handle(fnCtx);
|
|
76
76
|
return functionState.value;
|
|
77
|
-
}), assignOuter);
|
|
77
|
+
}), [], assignOuter);
|
|
78
78
|
for (const item of this.args) {
|
|
79
79
|
func.addArgument(item.name, item.op);
|
|
80
80
|
}
|
package/dist/types/function.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare class CustomFunction extends CustomValue {
|
|
|
26
26
|
static createExternalAnonymous(callback: Callback): CustomFunction;
|
|
27
27
|
static createExternal(name: string, callback: Callback): CustomFunction;
|
|
28
28
|
static createExternalWithSelf(name: string, callback: Callback): CustomFunction;
|
|
29
|
-
constructor(scope: OperationContext, name: string, callback: Callback, assignOuter?: boolean);
|
|
29
|
+
constructor(scope: OperationContext, name: string, callback: Callback, argumentDefs?: Array<Argument>, assignOuter?: boolean);
|
|
30
30
|
addArgument(name: string, defaultValue?: Operation | CustomValue): CustomFunction;
|
|
31
31
|
fork(): CustomFunction;
|
|
32
32
|
forkAs(name: string): CustomFunction;
|
package/dist/types/function.js
CHANGED
|
@@ -51,12 +51,12 @@ class CustomFunction extends base_1.CustomValue {
|
|
|
51
51
|
static createExternalWithSelf(name, callback) {
|
|
52
52
|
return new CustomFunction(null, name, callback).addArgument(exports.SELF_NAMESPACE);
|
|
53
53
|
}
|
|
54
|
-
constructor(scope, name, callback, assignOuter = false) {
|
|
54
|
+
constructor(scope, name, callback, argumentDefs = [], assignOuter = false) {
|
|
55
55
|
super();
|
|
56
56
|
this.scope = scope;
|
|
57
57
|
this.name = name;
|
|
58
58
|
this.value = callback;
|
|
59
|
-
this.argumentDefs =
|
|
59
|
+
this.argumentDefs = argumentDefs;
|
|
60
60
|
this.assignOuter = assignOuter;
|
|
61
61
|
this._nextContext = null;
|
|
62
62
|
}
|
|
@@ -65,10 +65,10 @@ class CustomFunction extends base_1.CustomValue {
|
|
|
65
65
|
return this;
|
|
66
66
|
}
|
|
67
67
|
fork() {
|
|
68
|
-
return new CustomFunction(this.scope, this.name, this.value);
|
|
68
|
+
return new CustomFunction(this.scope, this.name, this.value, this.argumentDefs);
|
|
69
69
|
}
|
|
70
70
|
forkAs(name) {
|
|
71
|
-
return new CustomFunction(this.scope, name, this.value);
|
|
71
|
+
return new CustomFunction(this.scope, name, this.value, this.argumentDefs);
|
|
72
72
|
}
|
|
73
73
|
getCustomType() {
|
|
74
74
|
return 'function';
|
|
@@ -12,6 +12,7 @@ export declare class ObjectValue {
|
|
|
12
12
|
entries(): ObjectValueKeyPair[];
|
|
13
13
|
get size(): number;
|
|
14
14
|
forEach(callback: (value: CustomValue, key: CustomValue, map: ObjectValue) => any): void;
|
|
15
|
+
fork(): ObjectValue;
|
|
15
16
|
extend(objVal: ObjectValue): this;
|
|
16
17
|
clear(): void;
|
|
17
18
|
}
|
|
@@ -56,6 +56,13 @@ class ObjectValue {
|
|
|
56
56
|
callback(value, key, this);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
fork() {
|
|
60
|
+
const newObject = new ObjectValue();
|
|
61
|
+
for (const [key, value] of this.entries()) {
|
|
62
|
+
newObject.set(key.fork(), value.fork());
|
|
63
|
+
}
|
|
64
|
+
return newObject;
|
|
65
|
+
}
|
|
59
66
|
extend(objVal) {
|
|
60
67
|
for (const [key, value] of objVal.entries()) {
|
|
61
68
|
this.set(key, value);
|