greybel-interpreter 2.2.20 → 3.0.1
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 +1 -1
- package/dist/cps.d.ts +1 -1
- package/dist/cps.js +39 -69
- package/dist/operations/assign.d.ts +1 -1
- package/dist/operations/block.d.ts +1 -1
- package/dist/operations/break.d.ts +1 -1
- package/dist/operations/call.d.ts +1 -1
- package/dist/operations/chunk.d.ts +1 -1
- package/dist/operations/continue.d.ts +1 -1
- package/dist/operations/debugger-statement.d.ts +1 -1
- package/dist/operations/evaluate.d.ts +1 -1
- package/dist/operations/evaluate.js +56 -56
- package/dist/operations/for.d.ts +1 -1
- package/dist/operations/function-reference.d.ts +1 -1
- package/dist/operations/function.d.ts +1 -1
- package/dist/operations/function.js +3 -3
- package/dist/operations/if-statement.d.ts +1 -1
- package/dist/operations/if-statement.js +7 -7
- package/dist/operations/import.d.ts +1 -1
- package/dist/operations/include.d.ts +1 -1
- package/dist/operations/list.d.ts +1 -1
- package/dist/operations/literal.d.ts +1 -1
- package/dist/operations/literal.js +5 -5
- package/dist/operations/map.d.ts +1 -1
- package/dist/operations/negated-binary.d.ts +1 -1
- package/dist/operations/negated-binary.js +3 -3
- package/dist/operations/new-instance.d.ts +1 -1
- package/dist/operations/not.d.ts +1 -1
- package/dist/operations/operation.d.ts +1 -1
- package/dist/operations/resolve.d.ts +1 -1
- package/dist/operations/resolve.js +5 -5
- package/dist/operations/return.d.ts +1 -1
- package/dist/operations/while.d.ts +1 -1
- package/dist/utils/error.d.ts +1 -1
- package/package.json +3 -5
package/dist/context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import { ASTBase } from '
|
|
3
|
+
import { ASTBase } from 'miniscript-core';
|
|
4
4
|
import { CPS } from './cps';
|
|
5
5
|
import { HandlerContainer } from './handler-container';
|
|
6
6
|
import { Operation } from './operations/operation';
|
package/dist/cps.d.ts
CHANGED
package/dist/cps.js
CHANGED
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CPS = exports.CPSContext = void 0;
|
|
13
13
|
const greybel_core_1 = require("greybel-core");
|
|
14
|
-
const
|
|
14
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
15
15
|
const assign_1 = require("./operations/assign");
|
|
16
16
|
const break_1 = require("./operations/break");
|
|
17
17
|
const call_1 = require("./operations/call");
|
|
@@ -48,37 +48,37 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
|
|
|
48
48
|
const currentTarget = stack[stack.length - 1];
|
|
49
49
|
const defaultVisit = visit.bind(null, context, stack);
|
|
50
50
|
switch (item.type) {
|
|
51
|
-
case
|
|
51
|
+
case miniscript_core_1.ASTType.MapConstructorExpression:
|
|
52
52
|
return new map_1.MapOperation(item, currentTarget).build(defaultVisit);
|
|
53
|
-
case
|
|
53
|
+
case miniscript_core_1.ASTType.ListConstructorExpression:
|
|
54
54
|
return new list_1.List(item, currentTarget).build(defaultVisit);
|
|
55
|
-
case
|
|
55
|
+
case miniscript_core_1.ASTType.AssignmentStatement:
|
|
56
56
|
return new assign_1.Assign(item, currentTarget).build(defaultVisit);
|
|
57
|
-
case
|
|
58
|
-
case
|
|
59
|
-
case
|
|
60
|
-
case
|
|
57
|
+
case miniscript_core_1.ASTType.MemberExpression:
|
|
58
|
+
case miniscript_core_1.ASTType.Identifier:
|
|
59
|
+
case miniscript_core_1.ASTType.IndexExpression:
|
|
60
|
+
case miniscript_core_1.ASTType.SliceExpression:
|
|
61
61
|
return new resolve_1.Resolve(item, currentTarget).build(defaultVisit);
|
|
62
|
-
case
|
|
62
|
+
case miniscript_core_1.ASTType.FunctionDeclaration:
|
|
63
63
|
return new function_1.FunctionOperation(item, currentTarget).build(defaultVisit);
|
|
64
|
-
case
|
|
64
|
+
case miniscript_core_1.ASTType.InvalidCodeExpression:
|
|
65
65
|
return new noop_1.Noop(item, currentTarget).build(defaultVisit);
|
|
66
|
-
case
|
|
66
|
+
case miniscript_core_1.ASTType.WhileStatement:
|
|
67
67
|
return new while_1.While(item, currentTarget).build(defaultVisit);
|
|
68
|
-
case
|
|
68
|
+
case miniscript_core_1.ASTType.ForGenericStatement:
|
|
69
69
|
return new for_1.For(item, currentTarget).build(defaultVisit);
|
|
70
|
-
case
|
|
71
|
-
case
|
|
70
|
+
case miniscript_core_1.ASTType.IfStatement:
|
|
71
|
+
case miniscript_core_1.ASTType.IfShortcutStatement:
|
|
72
72
|
return new if_statement_1.IfStatement(item, currentTarget).build(defaultVisit);
|
|
73
|
-
case
|
|
73
|
+
case miniscript_core_1.ASTType.ReturnStatement:
|
|
74
74
|
return new return_1.Return(item, currentTarget).build(defaultVisit);
|
|
75
|
-
case
|
|
75
|
+
case miniscript_core_1.ASTType.BreakStatement:
|
|
76
76
|
return new break_1.Break(item, currentTarget).build(defaultVisit);
|
|
77
|
-
case
|
|
77
|
+
case miniscript_core_1.ASTType.ContinueStatement:
|
|
78
78
|
return new continue_1.Continue(item, currentTarget).build(defaultVisit);
|
|
79
|
-
case
|
|
79
|
+
case miniscript_core_1.ASTType.CallExpression:
|
|
80
80
|
return new call_1.Call(item, currentTarget).build(defaultVisit);
|
|
81
|
-
case
|
|
81
|
+
case miniscript_core_1.ASTType.CallStatement:
|
|
82
82
|
return defaultVisit(item.expression);
|
|
83
83
|
case greybel_core_1.ASTType.FeatureImportExpression: {
|
|
84
84
|
const importExpr = item;
|
|
@@ -89,7 +89,7 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
|
|
|
89
89
|
}
|
|
90
90
|
const code = yield context.handler.resourceHandler.get(target);
|
|
91
91
|
if (code == null) {
|
|
92
|
-
const range = new
|
|
92
|
+
const range = new miniscript_core_1.ASTRange(item.start, item.end);
|
|
93
93
|
throw new error_1.PrepareError(`Cannot find import "${currentTarget}"`, {
|
|
94
94
|
target: currentTarget,
|
|
95
95
|
range
|
|
@@ -106,7 +106,7 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
|
|
|
106
106
|
}
|
|
107
107
|
throw new error_1.PrepareError(err.message, {
|
|
108
108
|
target,
|
|
109
|
-
range: new
|
|
109
|
+
range: new miniscript_core_1.ASTRange(item.start, item.end)
|
|
110
110
|
}, err);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -119,7 +119,7 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
|
|
|
119
119
|
}
|
|
120
120
|
const code = yield context.handler.resourceHandler.get(target);
|
|
121
121
|
if (code == null) {
|
|
122
|
-
const range = new
|
|
122
|
+
const range = new miniscript_core_1.ASTRange(item.start, item.end);
|
|
123
123
|
throw new error_1.PrepareError(`Cannot find include "${currentTarget}"`, {
|
|
124
124
|
target: currentTarget,
|
|
125
125
|
range
|
|
@@ -136,37 +136,7 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
|
|
|
136
136
|
}
|
|
137
137
|
throw new error_1.PrepareError(err.message, {
|
|
138
138
|
target,
|
|
139
|
-
range: new
|
|
140
|
-
}, err);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
case greyscript_core_1.ASTType.ImportCodeExpression: {
|
|
144
|
-
const importExpr = item;
|
|
145
|
-
const target = yield context.handler.resourceHandler.getTargetRelativeTo(currentTarget, importExpr.directory);
|
|
146
|
-
if (stack.includes(target)) {
|
|
147
|
-
console.warn(`Found circular dependency between "${currentTarget}" and "${target}" at line ${item.start.line}. Using noop instead to prevent overflow.`);
|
|
148
|
-
return new noop_1.Noop(item, target);
|
|
149
|
-
}
|
|
150
|
-
const code = yield context.handler.resourceHandler.get(target);
|
|
151
|
-
if (code == null) {
|
|
152
|
-
const range = new greyscript_core_1.ASTRange(item.start, item.end);
|
|
153
|
-
throw new error_1.PrepareError(`Cannot find native import "${currentTarget}"`, {
|
|
154
|
-
target: currentTarget,
|
|
155
|
-
range
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
try {
|
|
159
|
-
const subVisit = visit.bind(null, context, [...stack, target]);
|
|
160
|
-
const importStatement = yield new include_1.Include(importExpr, currentTarget, target, code).build(subVisit);
|
|
161
|
-
return importStatement;
|
|
162
|
-
}
|
|
163
|
-
catch (err) {
|
|
164
|
-
if (err instanceof error_1.PrepareError) {
|
|
165
|
-
throw err;
|
|
166
|
-
}
|
|
167
|
-
throw new error_1.PrepareError(err.message, {
|
|
168
|
-
target,
|
|
169
|
-
range: new greyscript_core_1.ASTRange(item.start, item.end)
|
|
139
|
+
range: new miniscript_core_1.ASTRange(item.start, item.end)
|
|
170
140
|
}, err);
|
|
171
141
|
}
|
|
172
142
|
}
|
|
@@ -174,22 +144,22 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
|
|
|
174
144
|
return new debugger_statement_1.DebuggerStatement(item, currentTarget);
|
|
175
145
|
case greybel_core_1.ASTType.FeatureEnvarExpression:
|
|
176
146
|
return new envar_1.EnvarExpression(item, currentTarget);
|
|
177
|
-
case
|
|
178
|
-
case
|
|
179
|
-
case
|
|
180
|
-
case
|
|
147
|
+
case miniscript_core_1.ASTType.BooleanLiteral:
|
|
148
|
+
case miniscript_core_1.ASTType.StringLiteral:
|
|
149
|
+
case miniscript_core_1.ASTType.NumericLiteral:
|
|
150
|
+
case miniscript_core_1.ASTType.NilLiteral:
|
|
181
151
|
return new literal_1.Literal(item, currentTarget).build(defaultVisit);
|
|
182
|
-
case
|
|
152
|
+
case miniscript_core_1.ASTType.EmptyExpression:
|
|
183
153
|
return new noop_1.Noop(item, currentTarget).build(defaultVisit);
|
|
184
|
-
case
|
|
185
|
-
case
|
|
186
|
-
case
|
|
154
|
+
case miniscript_core_1.ASTType.IsaExpression:
|
|
155
|
+
case miniscript_core_1.ASTType.BinaryExpression:
|
|
156
|
+
case miniscript_core_1.ASTType.LogicalExpression:
|
|
187
157
|
return new evaluate_1.Evaluate(item, currentTarget).build(defaultVisit);
|
|
188
|
-
case
|
|
158
|
+
case miniscript_core_1.ASTType.NegationExpression:
|
|
189
159
|
return new not_1.Not(item, currentTarget).build(defaultVisit);
|
|
190
|
-
case
|
|
160
|
+
case miniscript_core_1.ASTType.BinaryNegatedExpression:
|
|
191
161
|
return new negated_binary_1.NegatedBinary(item, currentTarget).build(defaultVisit);
|
|
192
|
-
case
|
|
162
|
+
case miniscript_core_1.ASTType.UnaryExpression: {
|
|
193
163
|
const unaryExpr = item;
|
|
194
164
|
if (unaryExpr.operator === 'new') {
|
|
195
165
|
return new new_instance_1.NewInstance(unaryExpr).build(defaultVisit);
|
|
@@ -197,20 +167,20 @@ const visit = (context, stack, item) => __awaiter(void 0, void 0, void 0, functi
|
|
|
197
167
|
else if (unaryExpr.operator === '@') {
|
|
198
168
|
return new function_reference_1.FunctionReference(unaryExpr).build(defaultVisit);
|
|
199
169
|
}
|
|
200
|
-
const range = new
|
|
170
|
+
const range = new miniscript_core_1.ASTRange(item.start, item.end);
|
|
201
171
|
throw new error_1.PrepareError(`Unknown unary expression`, {
|
|
202
172
|
target: currentTarget,
|
|
203
173
|
range
|
|
204
174
|
});
|
|
205
175
|
}
|
|
206
|
-
case
|
|
176
|
+
case miniscript_core_1.ASTType.Chunk:
|
|
207
177
|
return new chunk_1.Chunk(item, currentTarget).build(defaultVisit);
|
|
208
|
-
case
|
|
178
|
+
case miniscript_core_1.ASTType.Comment:
|
|
209
179
|
return new noop_1.Noop(item, currentTarget);
|
|
210
|
-
case
|
|
180
|
+
case miniscript_core_1.ASTType.ParenthesisExpression:
|
|
211
181
|
return defaultVisit(item.expression);
|
|
212
182
|
default: {
|
|
213
|
-
const range = new
|
|
183
|
+
const range = new miniscript_core_1.ASTRange(item.start, item.end);
|
|
214
184
|
throw new error_1.PrepareError(`Unexpected AST type ${item.type}`, {
|
|
215
185
|
target: currentTarget,
|
|
216
186
|
range
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
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
|
-
const
|
|
13
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
14
14
|
const boolean_1 = require("../types/boolean");
|
|
15
15
|
const default_1 = require("../types/default");
|
|
16
16
|
const function_1 = require("../types/function");
|
|
@@ -22,27 +22,27 @@ const string_1 = require("../types/string");
|
|
|
22
22
|
const deep_equal_1 = require("../utils/deep-equal");
|
|
23
23
|
const operation_1 = require("./operation");
|
|
24
24
|
exports.GenericProcessorHandler = {
|
|
25
|
-
[
|
|
26
|
-
[
|
|
25
|
+
[miniscript_core_1.Operator.And]: (a, b) => new boolean_1.CustomBoolean(a.toTruthy() && b.toTruthy()),
|
|
26
|
+
[miniscript_core_1.Operator.Or]: (a, b) => new boolean_1.CustomBoolean(a.toTruthy() || b.toTruthy())
|
|
27
27
|
};
|
|
28
28
|
exports.NumberProcessorHandler = {
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
[
|
|
37
|
-
[
|
|
38
|
-
[
|
|
39
|
-
[
|
|
40
|
-
[
|
|
41
|
-
[
|
|
42
|
-
[
|
|
43
|
-
[
|
|
44
|
-
[
|
|
45
|
-
[
|
|
29
|
+
[miniscript_core_1.Operator.Plus]: (a, b) => new number_1.CustomNumber(a.toNumber() + b.toNumber()),
|
|
30
|
+
[miniscript_core_1.Operator.Minus]: (a, b) => new number_1.CustomNumber(a.toNumber() - b.toNumber()),
|
|
31
|
+
[miniscript_core_1.Operator.Slash]: (a, b) => new number_1.CustomNumber(a.toNumber() / b.toNumber()),
|
|
32
|
+
[miniscript_core_1.Operator.Asterik]: (a, b) => new number_1.CustomNumber(a.toNumber() * b.toNumber()),
|
|
33
|
+
[miniscript_core_1.Operator.Power]: (a, b) => new number_1.CustomNumber(Math.pow(a.toNumber(), b.toNumber())),
|
|
34
|
+
[miniscript_core_1.Operator.BitwiseOr]: (a, b) => new number_1.CustomNumber(a.toInt() | b.toInt()),
|
|
35
|
+
[miniscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() < b.toNumber()),
|
|
36
|
+
[miniscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() > b.toNumber()),
|
|
37
|
+
[miniscript_core_1.Operator.LeftShift]: (a, b) => new number_1.CustomNumber(a.toInt() << b.toInt()),
|
|
38
|
+
[miniscript_core_1.Operator.RightShift]: (a, b) => new number_1.CustomNumber(a.toInt() >> b.toInt()),
|
|
39
|
+
[miniscript_core_1.Operator.UnsignedRightShift]: (a, b) => new number_1.CustomNumber(a.toInt() >> b.toInt()),
|
|
40
|
+
[miniscript_core_1.Operator.BitwiseAnd]: (a, b) => new number_1.CustomNumber(a.toInt() & b.toInt()),
|
|
41
|
+
[miniscript_core_1.Operator.PercentSign]: (a, b) => new number_1.CustomNumber(a.toNumber() % b.toNumber()),
|
|
42
|
+
[miniscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() >= b.toNumber()),
|
|
43
|
+
[miniscript_core_1.Operator.Equal]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() === b.toNumber()),
|
|
44
|
+
[miniscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() <= b.toNumber()),
|
|
45
|
+
[miniscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.CustomBoolean(a.toNumber() !== b.toNumber())
|
|
46
46
|
};
|
|
47
47
|
const minusString = (a, b) => {
|
|
48
48
|
const origin = a.toString();
|
|
@@ -80,16 +80,16 @@ const divideString = (a, b) => {
|
|
|
80
80
|
};
|
|
81
81
|
exports.divideString = divideString;
|
|
82
82
|
exports.StringProcessorHandler = {
|
|
83
|
-
[
|
|
84
|
-
[
|
|
85
|
-
[
|
|
86
|
-
[
|
|
87
|
-
[
|
|
88
|
-
[
|
|
89
|
-
[
|
|
90
|
-
[
|
|
91
|
-
[
|
|
92
|
-
[
|
|
83
|
+
[miniscript_core_1.Operator.Plus]: (a, b) => new string_1.CustomString(a.toString() + b.toString()),
|
|
84
|
+
[miniscript_core_1.Operator.Minus]: (a, b) => (0, exports.minusString)(a, b),
|
|
85
|
+
[miniscript_core_1.Operator.Asterik]: (a, b) => (0, exports.multiplyString)(a, b),
|
|
86
|
+
[miniscript_core_1.Operator.Slash]: (a, b) => (0, exports.divideString)(a, b),
|
|
87
|
+
[miniscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.CustomBoolean(a.toString() < b.toString()),
|
|
88
|
+
[miniscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.CustomBoolean(a.toString() > b.toString()),
|
|
89
|
+
[miniscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString() >= b.toString()),
|
|
90
|
+
[miniscript_core_1.Operator.Equal]: (a, b) => new boolean_1.CustomBoolean(a.toString() === b.toString()),
|
|
91
|
+
[miniscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString() <= b.toString()),
|
|
92
|
+
[miniscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString() !== b.toString())
|
|
93
93
|
};
|
|
94
94
|
const multiplyList = (a, b) => {
|
|
95
95
|
const factor = b.toNumber();
|
|
@@ -118,31 +118,31 @@ const divideList = (a, b) => {
|
|
|
118
118
|
};
|
|
119
119
|
exports.divideList = divideList;
|
|
120
120
|
exports.ListProcessorHandler = {
|
|
121
|
-
[
|
|
121
|
+
[miniscript_core_1.Operator.Plus]: (left, right) => {
|
|
122
122
|
if (right instanceof list_1.CustomList) {
|
|
123
123
|
return left.fork().extend(right);
|
|
124
124
|
}
|
|
125
125
|
return default_1.DefaultType.Void;
|
|
126
126
|
},
|
|
127
|
-
[
|
|
127
|
+
[miniscript_core_1.Operator.Equal]: (left, right) => {
|
|
128
128
|
if (right instanceof list_1.CustomList) {
|
|
129
129
|
return new boolean_1.CustomBoolean((0, deep_equal_1.deepEqual)(left, right));
|
|
130
130
|
}
|
|
131
131
|
return default_1.DefaultType.Void;
|
|
132
132
|
},
|
|
133
|
-
[
|
|
133
|
+
[miniscript_core_1.Operator.NotEqual]: (left, right) => {
|
|
134
134
|
if (right instanceof list_1.CustomList) {
|
|
135
135
|
return new boolean_1.CustomBoolean(!(0, deep_equal_1.deepEqual)(left, right));
|
|
136
136
|
}
|
|
137
137
|
return default_1.DefaultType.Void;
|
|
138
138
|
},
|
|
139
|
-
[
|
|
139
|
+
[miniscript_core_1.Operator.Asterik]: (left, right) => {
|
|
140
140
|
if (right instanceof number_1.CustomNumber) {
|
|
141
141
|
return (0, exports.multiplyList)(left, right);
|
|
142
142
|
}
|
|
143
143
|
return default_1.DefaultType.Void;
|
|
144
144
|
},
|
|
145
|
-
[
|
|
145
|
+
[miniscript_core_1.Operator.Slash]: (left, right) => {
|
|
146
146
|
if (right instanceof number_1.CustomNumber) {
|
|
147
147
|
return (0, exports.divideList)(left, right);
|
|
148
148
|
}
|
|
@@ -150,19 +150,19 @@ exports.ListProcessorHandler = {
|
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
152
|
exports.MapProcessorHandler = {
|
|
153
|
-
[
|
|
153
|
+
[miniscript_core_1.Operator.Plus]: (left, right) => {
|
|
154
154
|
if (right instanceof map_1.CustomMap) {
|
|
155
155
|
return left.fork().extend(right);
|
|
156
156
|
}
|
|
157
157
|
return default_1.DefaultType.Void;
|
|
158
158
|
},
|
|
159
|
-
[
|
|
159
|
+
[miniscript_core_1.Operator.Equal]: (left, right) => {
|
|
160
160
|
if (right instanceof map_1.CustomMap) {
|
|
161
161
|
return new boolean_1.CustomBoolean((0, deep_equal_1.deepEqual)(left, right));
|
|
162
162
|
}
|
|
163
163
|
return default_1.DefaultType.Void;
|
|
164
164
|
},
|
|
165
|
-
[
|
|
165
|
+
[miniscript_core_1.Operator.NotEqual]: (left, right) => {
|
|
166
166
|
if (right instanceof map_1.CustomMap) {
|
|
167
167
|
return new boolean_1.CustomBoolean(!(0, deep_equal_1.deepEqual)(left, right));
|
|
168
168
|
}
|
|
@@ -170,18 +170,18 @@ exports.MapProcessorHandler = {
|
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
172
|
exports.NilProcessorHandler = {
|
|
173
|
-
[
|
|
174
|
-
[
|
|
175
|
-
[
|
|
176
|
-
[
|
|
177
|
-
[
|
|
178
|
-
[
|
|
179
|
-
[
|
|
180
|
-
[
|
|
173
|
+
[miniscript_core_1.Operator.Plus]: () => default_1.DefaultType.Void,
|
|
174
|
+
[miniscript_core_1.Operator.Minus]: () => default_1.DefaultType.Void,
|
|
175
|
+
[miniscript_core_1.Operator.Slash]: () => default_1.DefaultType.Void,
|
|
176
|
+
[miniscript_core_1.Operator.Asterik]: () => default_1.DefaultType.Void,
|
|
177
|
+
[miniscript_core_1.Operator.Power]: () => default_1.DefaultType.Void,
|
|
178
|
+
[miniscript_core_1.Operator.PercentSign]: () => default_1.DefaultType.Void,
|
|
179
|
+
[miniscript_core_1.Operator.Equal]: (_a, b) => new boolean_1.CustomBoolean(b instanceof nil_1.CustomNil),
|
|
180
|
+
[miniscript_core_1.Operator.NotEqual]: (_a, b) => new boolean_1.CustomBoolean(!(b instanceof nil_1.CustomNil))
|
|
181
181
|
};
|
|
182
182
|
exports.FunctionProcessorHandler = {
|
|
183
|
-
[
|
|
184
|
-
[
|
|
183
|
+
[miniscript_core_1.Operator.Equal]: (a, b) => new boolean_1.CustomBoolean(a === b),
|
|
184
|
+
[miniscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.CustomBoolean(a !== b)
|
|
185
185
|
};
|
|
186
186
|
const handleNumber = (op, a, b) => {
|
|
187
187
|
if (b instanceof nil_1.CustomNil)
|
|
@@ -256,15 +256,15 @@ const handle = (op, a, b) => {
|
|
|
256
256
|
if (b instanceof boolean_1.CustomBoolean) {
|
|
257
257
|
b = new number_1.CustomNumber(b.toInt());
|
|
258
258
|
}
|
|
259
|
-
if (op ===
|
|
259
|
+
if (op === miniscript_core_1.Operator.Equal && a.getCustomType() !== b.getCustomType()) {
|
|
260
260
|
return default_1.DefaultType.False;
|
|
261
261
|
}
|
|
262
|
-
else if (op ===
|
|
262
|
+
else if (op === miniscript_core_1.Operator.NotEqual &&
|
|
263
263
|
a.getCustomType() !== b.getCustomType()) {
|
|
264
264
|
return default_1.DefaultType.True;
|
|
265
265
|
}
|
|
266
266
|
if ((a instanceof string_1.CustomString || b instanceof string_1.CustomString) &&
|
|
267
|
-
op ===
|
|
267
|
+
op === miniscript_core_1.Operator.Plus) {
|
|
268
268
|
return (0, exports.handleString)(op, a, b);
|
|
269
269
|
}
|
|
270
270
|
else if (a instanceof number_1.CustomNumber) {
|
|
@@ -312,10 +312,10 @@ class Evaluate extends operation_1.Operation {
|
|
|
312
312
|
resolveLogicalExpression(ctx, expr) {
|
|
313
313
|
return __awaiter(this, void 0, void 0, function* () {
|
|
314
314
|
const left = yield this.resolve(ctx, expr.left);
|
|
315
|
-
if (expr.op ===
|
|
315
|
+
if (expr.op === miniscript_core_1.Operator.And && !left.toTruthy()) {
|
|
316
316
|
return new boolean_1.CustomBoolean(false);
|
|
317
317
|
}
|
|
318
|
-
else if (expr.op ===
|
|
318
|
+
else if (expr.op === miniscript_core_1.Operator.Or && left.toTruthy()) {
|
|
319
319
|
return new boolean_1.CustomBoolean(true);
|
|
320
320
|
}
|
|
321
321
|
const right = yield this.resolve(ctx, expr.right);
|
|
@@ -327,14 +327,14 @@ class Evaluate extends operation_1.Operation {
|
|
|
327
327
|
if (op instanceof Evaluate) {
|
|
328
328
|
const expr = op;
|
|
329
329
|
switch (expr.type) {
|
|
330
|
-
case
|
|
330
|
+
case miniscript_core_1.ASTType.IsaExpression: {
|
|
331
331
|
const left = yield this.resolve(ctx, expr.left);
|
|
332
332
|
const right = yield this.resolve(ctx, expr.right);
|
|
333
333
|
return new boolean_1.CustomBoolean(left.instanceOf(right));
|
|
334
334
|
}
|
|
335
|
-
case
|
|
335
|
+
case miniscript_core_1.ASTType.BinaryExpression:
|
|
336
336
|
return this.resolveBinaryExpression(ctx, expr);
|
|
337
|
-
case
|
|
337
|
+
case miniscript_core_1.ASTType.LogicalExpression:
|
|
338
338
|
return this.resolveLogicalExpression(ctx, expr);
|
|
339
339
|
default:
|
|
340
340
|
break;
|
package/dist/operations/for.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASTForGenericStatement, ASTIdentifier } from '
|
|
1
|
+
import { ASTForGenericStatement, ASTIdentifier } from 'miniscript-core';
|
|
2
2
|
import { OperationContext } from '../context';
|
|
3
3
|
import { CustomValue } from '../types/base';
|
|
4
4
|
import { Block } from './block';
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.FunctionOperation = exports.SUPER_PROPERTY = exports.SELF_PROPERTY = void 0;
|
|
13
|
-
const
|
|
13
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
14
14
|
const context_1 = require("../context");
|
|
15
15
|
const default_1 = require("../types/default");
|
|
16
16
|
const function_1 = require("../types/function");
|
|
@@ -31,7 +31,7 @@ class FunctionOperation extends operation_1.Operation {
|
|
|
31
31
|
this.block = new block_1.Block(this.item, stack);
|
|
32
32
|
this.args = yield Promise.all(this.item.parameters.map((child) => __awaiter(this, void 0, void 0, function* () {
|
|
33
33
|
switch (child.type) {
|
|
34
|
-
case
|
|
34
|
+
case miniscript_core_1.ASTType.AssignmentStatement: {
|
|
35
35
|
const assignStatement = child;
|
|
36
36
|
const assignKey = assignStatement.variable;
|
|
37
37
|
return {
|
|
@@ -39,7 +39,7 @@ class FunctionOperation extends operation_1.Operation {
|
|
|
39
39
|
op: yield visit(assignStatement.init)
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
case
|
|
42
|
+
case miniscript_core_1.ASTType.Identifier: {
|
|
43
43
|
const identifierKey = child;
|
|
44
44
|
return {
|
|
45
45
|
name: identifierKey.name,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASTElseClause, ASTIfClause, ASTIfStatement } from '
|
|
1
|
+
import { ASTElseClause, ASTIfClause, ASTIfStatement } from 'miniscript-core';
|
|
2
2
|
import { OperationContext } from '../context';
|
|
3
3
|
import { CustomValue } from '../types/base';
|
|
4
4
|
import { Block } from './block';
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.IfStatement = exports.Clause = void 0;
|
|
13
|
-
const
|
|
13
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
14
14
|
const boolean_1 = require("../types/boolean");
|
|
15
15
|
const default_1 = require("../types/default");
|
|
16
16
|
const block_1 = require("./block");
|
|
@@ -50,14 +50,14 @@ class IfStatement extends operation_1.OperationBlock {
|
|
|
50
50
|
for (let index = 0; index < this.item.clauses.length; index++) {
|
|
51
51
|
const child = this.item.clauses[index];
|
|
52
52
|
switch (child.type) {
|
|
53
|
-
case
|
|
54
|
-
case
|
|
55
|
-
case
|
|
56
|
-
case
|
|
53
|
+
case miniscript_core_1.ASTType.IfClause:
|
|
54
|
+
case miniscript_core_1.ASTType.IfShortcutClause:
|
|
55
|
+
case miniscript_core_1.ASTType.ElseifClause:
|
|
56
|
+
case miniscript_core_1.ASTType.ElseifShortcutClause:
|
|
57
57
|
yield this.buildIfClause(child, visit);
|
|
58
58
|
break;
|
|
59
|
-
case
|
|
60
|
-
case
|
|
59
|
+
case miniscript_core_1.ASTType.ElseClause:
|
|
60
|
+
case miniscript_core_1.ASTType.ElseShortcutClause:
|
|
61
61
|
yield this.buildElseClause(child, visit);
|
|
62
62
|
break;
|
|
63
63
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ASTFeatureImportExpression } from 'greybel-core';
|
|
2
|
-
import { ASTBase } from '
|
|
2
|
+
import { ASTBase } from 'miniscript-core';
|
|
3
3
|
import { OperationContext } from '../context';
|
|
4
4
|
import { CustomValue } from '../types/base';
|
|
5
5
|
import { CustomString } from '../types/string';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASTListConstructorExpression } from '
|
|
1
|
+
import { ASTListConstructorExpression } from 'miniscript-core';
|
|
2
2
|
import { OperationContext } from '../context';
|
|
3
3
|
import { CustomValue } from '../types/base';
|
|
4
4
|
import { CPSVisit, Operation } from './operation';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Literal = void 0;
|
|
4
|
-
const
|
|
4
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
5
5
|
const boolean_1 = require("../types/boolean");
|
|
6
6
|
const default_1 = require("../types/default");
|
|
7
7
|
const number_1 = require("../types/number");
|
|
@@ -14,16 +14,16 @@ class Literal extends operation_1.Operation {
|
|
|
14
14
|
}
|
|
15
15
|
build(_visit) {
|
|
16
16
|
switch (this.item.type) {
|
|
17
|
-
case
|
|
17
|
+
case miniscript_core_1.ASTType.BooleanLiteral:
|
|
18
18
|
this.value = new boolean_1.CustomBoolean(this.item.value);
|
|
19
19
|
break;
|
|
20
|
-
case
|
|
20
|
+
case miniscript_core_1.ASTType.StringLiteral:
|
|
21
21
|
this.value = new string_1.CustomString(this.item.value);
|
|
22
22
|
break;
|
|
23
|
-
case
|
|
23
|
+
case miniscript_core_1.ASTType.NumericLiteral:
|
|
24
24
|
this.value = new number_1.CustomNumber(this.item.value);
|
|
25
25
|
break;
|
|
26
|
-
case
|
|
26
|
+
case miniscript_core_1.ASTType.NilLiteral:
|
|
27
27
|
this.value = default_1.DefaultType.Void;
|
|
28
28
|
break;
|
|
29
29
|
default:
|
package/dist/operations/map.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASTMapConstructorExpression } from '
|
|
1
|
+
import { ASTMapConstructorExpression } from 'miniscript-core';
|
|
2
2
|
import { OperationContext } from '../context';
|
|
3
3
|
import { CustomValue } from '../types/base';
|
|
4
4
|
import { CPSVisit, Operation } from './operation';
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.NegatedBinary = void 0;
|
|
13
|
-
const
|
|
13
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
14
14
|
const number_1 = require("../types/number");
|
|
15
15
|
const operation_1 = require("./operation");
|
|
16
16
|
class NegatedBinary extends operation_1.Operation {
|
|
@@ -27,9 +27,9 @@ class NegatedBinary extends operation_1.Operation {
|
|
|
27
27
|
handle(ctx) {
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
29
|
switch (this.item.operator) {
|
|
30
|
-
case
|
|
30
|
+
case miniscript_core_1.Operator.Minus:
|
|
31
31
|
return new number_1.CustomNumber(-(yield this.arg.handle(ctx)).toNumber());
|
|
32
|
-
case
|
|
32
|
+
case miniscript_core_1.Operator.Plus:
|
|
33
33
|
return new number_1.CustomNumber(+(yield this.arg.handle(ctx)).toNumber());
|
|
34
34
|
default:
|
|
35
35
|
throw new Error('Unexpected negation operator.');
|
package/dist/operations/not.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Resolve = exports.ResolveResult = exports.ResolveNil = exports.SegmentContainer = exports.OperationSegment = exports.IndexSegment = exports.IdentifierSegment = exports.PathSegment = exports.SliceSegment = void 0;
|
|
13
|
-
const
|
|
13
|
+
const miniscript_core_1 = require("miniscript-core");
|
|
14
14
|
const default_1 = require("../types/default");
|
|
15
15
|
const function_1 = require("../types/function");
|
|
16
16
|
const list_1 = require("../types/list");
|
|
@@ -105,20 +105,20 @@ class Resolve extends operation_1.Operation {
|
|
|
105
105
|
buildProcessor(node, visit) {
|
|
106
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
107
|
switch (node.type) {
|
|
108
|
-
case
|
|
108
|
+
case miniscript_core_1.ASTType.MemberExpression: {
|
|
109
109
|
const memberExpr = node;
|
|
110
110
|
yield this.buildProcessor(memberExpr.base, visit);
|
|
111
111
|
yield this.buildProcessor(memberExpr.identifier, visit);
|
|
112
112
|
break;
|
|
113
113
|
}
|
|
114
|
-
case
|
|
114
|
+
case miniscript_core_1.ASTType.IndexExpression: {
|
|
115
115
|
const indexExpr = node;
|
|
116
116
|
yield this.buildProcessor(indexExpr.base, visit);
|
|
117
117
|
const indexSegment = new IndexSegment(yield visit(indexExpr.index));
|
|
118
118
|
this.path.push(indexSegment);
|
|
119
119
|
break;
|
|
120
120
|
}
|
|
121
|
-
case
|
|
121
|
+
case miniscript_core_1.ASTType.SliceExpression: {
|
|
122
122
|
const sliceExpr = node;
|
|
123
123
|
yield this.buildProcessor(sliceExpr.base, visit);
|
|
124
124
|
const left = yield visit(sliceExpr.left);
|
|
@@ -127,7 +127,7 @@ class Resolve extends operation_1.Operation {
|
|
|
127
127
|
this.path.push(sliceSegment);
|
|
128
128
|
break;
|
|
129
129
|
}
|
|
130
|
-
case
|
|
130
|
+
case miniscript_core_1.ASTType.Identifier: {
|
|
131
131
|
const identifier = node;
|
|
132
132
|
const identifierSegment = new IdentifierSegment(identifier.name);
|
|
133
133
|
this.path.push(identifierSegment);
|
package/dist/utils/error.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "greybel-interpreter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Interpreter",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index",
|
|
@@ -48,11 +48,9 @@
|
|
|
48
48
|
"typescript": "^5.0.4"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"greybel-core": "^0.
|
|
52
|
-
"greyscript-core": "^0.9.12"
|
|
51
|
+
"greybel-core": "^1.0.2"
|
|
53
52
|
},
|
|
54
53
|
"keywords": [
|
|
55
|
-
"
|
|
56
|
-
"greyhack"
|
|
54
|
+
"miniscript"
|
|
57
55
|
]
|
|
58
56
|
}
|