greybel-interpreter 3.1.0 → 3.2.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.
- package/dist/interpreter.d.ts +2 -0
- package/dist/interpreter.js +10 -4
- package/dist/operations/evaluate.js +6 -5
- package/package.json +2 -2
package/dist/interpreter.d.ts
CHANGED
|
@@ -36,9 +36,11 @@ export declare class Interpreter extends EventEmitter {
|
|
|
36
36
|
setDebugger(dbgr: Debugger): Interpreter;
|
|
37
37
|
setApi(newApi: ObjectValue): Interpreter;
|
|
38
38
|
setHandler(handler: HandlerContainer): Interpreter;
|
|
39
|
+
parse(code: string): import("miniscript-core").ASTBase | import("greybel-core").ASTChunkAdvanced;
|
|
39
40
|
prepare(code: string): Promise<Operation>;
|
|
40
41
|
inject(code: string, context?: OperationContext): Promise<Interpreter>;
|
|
41
42
|
injectInLastContext(code: string): Promise<Interpreter>;
|
|
43
|
+
createCPS(): CPS;
|
|
42
44
|
private initScopes;
|
|
43
45
|
private start;
|
|
44
46
|
run({ customCode, ctxOptions }?: InterpreterRunOptions): Promise<Interpreter>;
|
package/dist/interpreter.js
CHANGED
|
@@ -68,10 +68,13 @@ class Interpreter extends events_1.EventEmitter {
|
|
|
68
68
|
this.handler = handler;
|
|
69
69
|
return this;
|
|
70
70
|
}
|
|
71
|
+
parse(code) {
|
|
72
|
+
const parser = new greybel_core_1.Parser(code);
|
|
73
|
+
return parser.parseChunk();
|
|
74
|
+
}
|
|
71
75
|
prepare(code) {
|
|
72
76
|
try {
|
|
73
|
-
const
|
|
74
|
-
const chunk = parser.parseChunk();
|
|
77
|
+
const chunk = this.parse(code);
|
|
75
78
|
return this.cps.visit(chunk);
|
|
76
79
|
}
|
|
77
80
|
catch (err) {
|
|
@@ -118,9 +121,12 @@ class Interpreter extends events_1.EventEmitter {
|
|
|
118
121
|
throw new Error('Unable to inject into last context.');
|
|
119
122
|
});
|
|
120
123
|
}
|
|
121
|
-
|
|
124
|
+
createCPS() {
|
|
122
125
|
const cpsCtx = new cps_1.CPSContext(this.target, this.handler);
|
|
123
|
-
|
|
126
|
+
return new cps_1.CPS(cpsCtx);
|
|
127
|
+
}
|
|
128
|
+
initScopes(ctxOptions) {
|
|
129
|
+
this.cps = this.createCPS();
|
|
124
130
|
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
131
|
string: string_1.CustomString.getIntrinsics().fork(),
|
|
126
132
|
number: number_1.CustomNumber.getIntrinsics().fork(),
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Evaluate = exports.handle = exports.handleFunction = exports.handleNil = exports.handleMap = exports.handleList = exports.handleString = exports.handleNumber = exports.FunctionProcessorHandler = exports.NilProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.divideList = exports.multiplyList = exports.StringProcessorHandler = exports.divideString = exports.multiplyString = exports.minusString = exports.NumberProcessorHandler = exports.GenericProcessorHandler = void 0;
|
|
13
13
|
const miniscript_core_1 = require("miniscript-core");
|
|
14
|
+
const operators_1 = require("greybel-core/dist/types/operators");
|
|
14
15
|
const boolean_1 = require("../types/boolean");
|
|
15
16
|
const default_1 = require("../types/default");
|
|
16
17
|
const function_1 = require("../types/function");
|
|
@@ -31,13 +32,13 @@ exports.NumberProcessorHandler = {
|
|
|
31
32
|
[miniscript_core_1.Operator.Slash]: (a, b) => new number_1.CustomNumber(a.toNumber() / b.toNumber()),
|
|
32
33
|
[miniscript_core_1.Operator.Asterik]: (a, b) => new number_1.CustomNumber(a.toNumber() * b.toNumber()),
|
|
33
34
|
[miniscript_core_1.Operator.Power]: (a, b) => new number_1.CustomNumber(Math.pow(a.toNumber(), b.toNumber())),
|
|
34
|
-
[
|
|
35
|
+
[operators_1.Operator.BitwiseOr]: (a, b) => new number_1.CustomNumber(a.toInt() | b.toInt()),
|
|
35
36
|
[miniscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() < b.toNumber()),
|
|
36
37
|
[miniscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() > b.toNumber()),
|
|
37
|
-
[
|
|
38
|
-
[
|
|
39
|
-
[
|
|
40
|
-
[
|
|
38
|
+
[operators_1.Operator.LeftShift]: (a, b) => new number_1.CustomNumber(a.toInt() << b.toInt()),
|
|
39
|
+
[operators_1.Operator.RightShift]: (a, b) => new number_1.CustomNumber(a.toInt() >> b.toInt()),
|
|
40
|
+
[operators_1.Operator.UnsignedRightShift]: (a, b) => new number_1.CustomNumber(a.toInt() >> b.toInt()),
|
|
41
|
+
[operators_1.Operator.BitwiseAnd]: (a, b) => new number_1.CustomNumber(a.toInt() & b.toInt()),
|
|
41
42
|
[miniscript_core_1.Operator.PercentSign]: (a, b) => new number_1.CustomNumber(a.toNumber() % b.toNumber()),
|
|
42
43
|
[miniscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() >= b.toNumber()),
|
|
43
44
|
[miniscript_core_1.Operator.Equal]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() === b.toNumber()),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "greybel-interpreter",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Interpreter",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"lru-cache": "^10.0.1",
|
|
52
|
-
"greybel-core": "^1.
|
|
52
|
+
"greybel-core": "^1.2.0"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
55
55
|
"miniscript"
|