greybel-interpreter 0.5.8 → 0.6.2
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 +0 -1
- package/dist/context.js +0 -3
- package/dist/custom-types/boolean.d.ts +3 -1
- package/dist/custom-types/boolean.js +9 -3
- package/dist/custom-types/list.d.ts +4 -3
- package/dist/custom-types/list.js +19 -60
- package/dist/custom-types/map.d.ts +3 -2
- package/dist/custom-types/map.js +16 -30
- package/dist/custom-types/nil.d.ts +3 -1
- package/dist/custom-types/nil.js +8 -2
- package/dist/custom-types/number.d.ts +3 -1
- package/dist/custom-types/number.js +9 -3
- package/dist/custom-types/string.d.ts +7 -3
- package/dist/custom-types/string.js +99 -58
- package/dist/expressions/binary-negated-expression.d.ts +0 -1
- package/dist/expressions/binary-negated-expression.js +3 -7
- package/dist/expressions/call.js +22 -21
- package/dist/expressions/logical-and-binary.d.ts +0 -1
- package/dist/expressions/logical-and-binary.js +43 -46
- package/dist/expressions/path.js +27 -22
- package/dist/operations/function.d.ts +3 -0
- package/dist/operations/function.js +9 -0
- package/dist/operations/if-statement.js +49 -33
- package/dist/operations/not.js +3 -3
- package/dist/operations/while.js +11 -11
- package/dist/types/custom-type.d.ts +3 -1
- package/dist/types/custom-type.js +8 -2
- package/package.json +1 -1
package/dist/expressions/call.js
CHANGED
|
@@ -152,25 +152,27 @@ var CallExpression = /** @class */ (function (_super) {
|
|
|
152
152
|
var evaluate = function (node) {
|
|
153
153
|
return __awaiter(this, void 0, void 0, function () {
|
|
154
154
|
var args, pathExpr, callable_1, _a, callable, _b;
|
|
155
|
-
var _c, _d
|
|
156
|
-
return __generator(this, function (
|
|
157
|
-
switch (
|
|
155
|
+
var _c, _d;
|
|
156
|
+
return __generator(this, function (_e) {
|
|
157
|
+
switch (_e.label) {
|
|
158
158
|
case 0:
|
|
159
159
|
if (node instanceof expression_1.Expression) {
|
|
160
160
|
return [2 /*return*/, node.get(opc)];
|
|
161
161
|
}
|
|
162
162
|
return [4 /*yield*/, node.resolveArgs(operationContext)];
|
|
163
163
|
case 1:
|
|
164
|
-
args =
|
|
164
|
+
args = _e.sent();
|
|
165
165
|
return [4 /*yield*/, node.path.get(opc, me.expr)];
|
|
166
166
|
case 2:
|
|
167
|
-
pathExpr =
|
|
167
|
+
pathExpr = _e.sent();
|
|
168
168
|
operationContext.debugger.debug('Line', me.ast.start.line, 'CallExpression', 'pathExpr', pathExpr);
|
|
169
|
-
if (!pathExpr.handle) return [3 /*break*/,
|
|
170
|
-
if (!(0, typer_1.isCustomMap)(pathExpr.handle)
|
|
169
|
+
if (!pathExpr.handle) return [3 /*break*/, 7];
|
|
170
|
+
if (!((0, typer_1.isCustomMap)(pathExpr.handle) ||
|
|
171
|
+
(0, typer_1.isCustomList)(pathExpr.handle) ||
|
|
172
|
+
(0, typer_1.isCustomString)(pathExpr.handle))) return [3 /*break*/, 6];
|
|
171
173
|
return [4 /*yield*/, pathExpr.handle.getCallable(pathExpr.path)];
|
|
172
174
|
case 3:
|
|
173
|
-
callable_1 =
|
|
175
|
+
callable_1 = _e.sent();
|
|
174
176
|
if (!(callable_1.origin instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
175
177
|
opc.setMemory('args', args);
|
|
176
178
|
return [2 /*return*/, callable_1.origin.run(opc)];
|
|
@@ -178,23 +180,22 @@ var CallExpression = /** @class */ (function (_super) {
|
|
|
178
180
|
if (!(callable_1.origin instanceof Function)) return [3 /*break*/, 6];
|
|
179
181
|
_a = typer_1.cast;
|
|
180
182
|
return [4 /*yield*/, (_c = callable_1.origin).call.apply(_c, __spreadArray([pathExpr.handle], __read(args), false))];
|
|
181
|
-
case 5: return [2 /*return*/, _a.apply(void 0, [
|
|
183
|
+
case 5: return [2 /*return*/, _a.apply(void 0, [_e.sent()])];
|
|
182
184
|
case 6:
|
|
183
|
-
operationContext.debugger.raise('Unexpected handle call', me,
|
|
184
|
-
|
|
185
|
-
case 7: return [
|
|
186
|
-
case 8:
|
|
187
|
-
|
|
188
|
-
callable = _f.sent();
|
|
185
|
+
operationContext.debugger.raise('Unexpected handle call', me, pathExpr);
|
|
186
|
+
_e.label = 7;
|
|
187
|
+
case 7: return [4 /*yield*/, opc.getCallable(pathExpr.path)];
|
|
188
|
+
case 8:
|
|
189
|
+
callable = _e.sent();
|
|
189
190
|
opc.setMemory('args', args);
|
|
190
|
-
if (!(callable.origin instanceof operation_1.Operation)) return [3 /*break*/,
|
|
191
|
+
if (!(callable.origin instanceof operation_1.Operation)) return [3 /*break*/, 9];
|
|
191
192
|
return [2 /*return*/, callable.origin.run(opc)];
|
|
192
|
-
case
|
|
193
|
-
if (!(callable.origin instanceof Function)) return [3 /*break*/,
|
|
193
|
+
case 9:
|
|
194
|
+
if (!(callable.origin instanceof Function)) return [3 /*break*/, 11];
|
|
194
195
|
_b = typer_1.cast;
|
|
195
|
-
return [4 /*yield*/, (
|
|
196
|
-
case
|
|
197
|
-
case
|
|
196
|
+
return [4 /*yield*/, (_d = callable.origin).call.apply(_d, __spreadArray([callable.context], __read(args), false))];
|
|
197
|
+
case 10: return [2 /*return*/, _b.apply(void 0, [_e.sent()])];
|
|
198
|
+
case 11: return [2 /*return*/, (0, typer_1.cast)(callable.origin)];
|
|
198
199
|
}
|
|
199
200
|
});
|
|
200
201
|
});
|
|
@@ -2,7 +2,6 @@ import { ASTEvaluationExpression } from 'greybel-core';
|
|
|
2
2
|
import { Expression } from '../types/expression';
|
|
3
3
|
import { OperationContext } from '../context';
|
|
4
4
|
import { CustomType } from '../types/custom-type';
|
|
5
|
-
export declare const toPrimitive: (v: CustomType | any) => any;
|
|
6
5
|
export declare const multiplyString: (a: CustomType, b: CustomType) => string;
|
|
7
6
|
export declare type OperationMap = {
|
|
8
7
|
[key: string]: (a: CustomType, b: CustomType) => any;
|
|
@@ -52,18 +52,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
52
52
|
};
|
|
53
53
|
var _a;
|
|
54
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
-
exports.ExpressionSegment = exports.OPERATIONS = exports.multiplyString =
|
|
55
|
+
exports.ExpressionSegment = exports.OPERATIONS = exports.multiplyString = void 0;
|
|
56
56
|
var greybel_core_1 = require("greybel-core");
|
|
57
57
|
var greyscript_core_1 = require("greyscript-core");
|
|
58
58
|
var expression_1 = require("../types/expression");
|
|
59
59
|
var typer_1 = require("../typer");
|
|
60
|
-
var toPrimitive = function (v) {
|
|
61
|
-
return (0, typer_1.isCustomValue)(v) ? v.valueOf() : v;
|
|
62
|
-
};
|
|
63
|
-
exports.toPrimitive = toPrimitive;
|
|
64
60
|
var multiplyString = function (a, b) {
|
|
65
|
-
var aVal = a.
|
|
66
|
-
var bVal = b.
|
|
61
|
+
var aVal = a.toString();
|
|
62
|
+
var bVal = b.toNumber();
|
|
67
63
|
return new Array(bVal)
|
|
68
64
|
.fill(aVal)
|
|
69
65
|
.join('');
|
|
@@ -77,12 +73,13 @@ exports.OPERATIONS = (_a = {},
|
|
|
77
73
|
else if ((0, typer_1.isCustomList)(a) && (0, typer_1.isCustomList)(b)) {
|
|
78
74
|
return a.concat(b);
|
|
79
75
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
else if ((0, typer_1.isCustomString)(a) || (0, typer_1.isCustomString)(b)) {
|
|
77
|
+
return a.toString() + b.toString();
|
|
78
|
+
}
|
|
79
|
+
return a.toNumber() + b.toNumber();
|
|
83
80
|
},
|
|
84
|
-
_a[greybel_core_1.Operator.Minus] = function (a, b) { return
|
|
85
|
-
_a[greybel_core_1.Operator.Slash] = function (a, b) { return
|
|
81
|
+
_a[greybel_core_1.Operator.Minus] = function (a, b) { return a.toNumber() - b.toNumber(); },
|
|
82
|
+
_a[greybel_core_1.Operator.Slash] = function (a, b) { return a.toNumber() / b.toNumber(); },
|
|
86
83
|
_a[greybel_core_1.Operator.Asterik] = function (a, b) {
|
|
87
84
|
if ((0, typer_1.isCustomString)(a) && (0, typer_1.isCustomNumber)(b)) {
|
|
88
85
|
return (0, exports.multiplyString)(a, b);
|
|
@@ -90,25 +87,23 @@ exports.OPERATIONS = (_a = {},
|
|
|
90
87
|
else if ((0, typer_1.isCustomString)(b) && (0, typer_1.isCustomNumber)(a)) {
|
|
91
88
|
return (0, exports.multiplyString)(b, a);
|
|
92
89
|
}
|
|
93
|
-
|
|
94
|
-
var bVal = (0, exports.toPrimitive)(b);
|
|
95
|
-
return aVal * bVal;
|
|
90
|
+
return a.toNumber() * b.toNumber();
|
|
96
91
|
},
|
|
97
|
-
_a[greybel_core_1.Operator.Xor] = function (a, b) { return
|
|
98
|
-
_a[greybel_core_1.Operator.BitwiseOr] = function (a, b) { return
|
|
99
|
-
_a[greybel_core_1.Operator.LessThan] = function (a, b) { return
|
|
100
|
-
_a[greybel_core_1.Operator.GreaterThan] = function (a, b) { return
|
|
101
|
-
_a[greybel_core_1.Operator.LeftShift] = function (a, b) { return
|
|
102
|
-
_a[greybel_core_1.Operator.RightShift] = function (a, b) { return
|
|
103
|
-
_a[greybel_core_1.Operator.UnsignedRightShift] = function (a, b) { return
|
|
104
|
-
_a[greybel_core_1.Operator.BitwiseAnd] = function (a, b) { return
|
|
105
|
-
_a[greybel_core_1.Operator.PercentSign] = function (a, b) { return
|
|
106
|
-
_a[greybel_core_1.Operator.GreaterThanOrEqual] = function (a, b) { return
|
|
107
|
-
_a[greybel_core_1.Operator.Equal] = function (a, b) { return
|
|
108
|
-
_a[greybel_core_1.Operator.LessThanOrEqual] = function (a, b) { return
|
|
109
|
-
_a[greybel_core_1.Operator.NotEqual] = function (a, b) { return
|
|
110
|
-
_a[greybel_core_1.Operator.And] = function (a, b) { return
|
|
111
|
-
_a[greybel_core_1.Operator.Or] = function (a, b) { return
|
|
92
|
+
_a[greybel_core_1.Operator.Xor] = function (a, b) { return a.toNumber() ^ b.toNumber(); },
|
|
93
|
+
_a[greybel_core_1.Operator.BitwiseOr] = function (a, b) { return a.toNumber() | b.toNumber(); },
|
|
94
|
+
_a[greybel_core_1.Operator.LessThan] = function (a, b) { return a.toNumber() < b.toNumber(); },
|
|
95
|
+
_a[greybel_core_1.Operator.GreaterThan] = function (a, b) { return a.toNumber() > b.toNumber(); },
|
|
96
|
+
_a[greybel_core_1.Operator.LeftShift] = function (a, b) { return a.toNumber() << b.toNumber(); },
|
|
97
|
+
_a[greybel_core_1.Operator.RightShift] = function (a, b) { return a.toNumber() >> b.toNumber(); },
|
|
98
|
+
_a[greybel_core_1.Operator.UnsignedRightShift] = function (a, b) { return a.toNumber() >>> b.toNumber(); },
|
|
99
|
+
_a[greybel_core_1.Operator.BitwiseAnd] = function (a, b) { return a.toNumber() & b.toNumber(); },
|
|
100
|
+
_a[greybel_core_1.Operator.PercentSign] = function (a, b) { return a.toNumber() % b.toNumber(); },
|
|
101
|
+
_a[greybel_core_1.Operator.GreaterThanOrEqual] = function (a, b) { return a.valueOf() >= b.valueOf(); },
|
|
102
|
+
_a[greybel_core_1.Operator.Equal] = function (a, b) { return a.valueOf() == b.valueOf(); },
|
|
103
|
+
_a[greybel_core_1.Operator.LessThanOrEqual] = function (a, b) { return a.valueOf() <= b.valueOf(); },
|
|
104
|
+
_a[greybel_core_1.Operator.NotEqual] = function (a, b) { return a.valueOf() != b.valueOf(); },
|
|
105
|
+
_a[greybel_core_1.Operator.And] = function (a, b) { return a.toTruthy() && b.toTruthy(); },
|
|
106
|
+
_a[greybel_core_1.Operator.Or] = function (a, b) { return a.toTruthy() || b.toTruthy(); },
|
|
112
107
|
_a);
|
|
113
108
|
var ExpressionSegment = /** @class */ (function () {
|
|
114
109
|
function ExpressionSegment(type, operator, left, right) {
|
|
@@ -162,9 +157,9 @@ var LogicalAndBinaryExpression = /** @class */ (function (_super) {
|
|
|
162
157
|
case 0:
|
|
163
158
|
me = this;
|
|
164
159
|
evaluate = function (node) { return __awaiter(_this, void 0, void 0, function () {
|
|
165
|
-
var expr, _a, binaryResult, _b, _c, _d, logicalLeft, logicalResult,
|
|
166
|
-
return __generator(this, function (
|
|
167
|
-
switch (
|
|
160
|
+
var expr, _a, binaryResult, _b, _c, _d, _e, _f, logicalLeft, _g, logicalResult, _h, _j, _k, _l;
|
|
161
|
+
return __generator(this, function (_m) {
|
|
162
|
+
switch (_m.label) {
|
|
168
163
|
case 0:
|
|
169
164
|
if (!(0, typer_1.isCustomValue)(node)) return [3 /*break*/, 1];
|
|
170
165
|
return [2 /*return*/, node];
|
|
@@ -182,30 +177,32 @@ var LogicalAndBinaryExpression = /** @class */ (function (_super) {
|
|
|
182
177
|
return [3 /*break*/, 8];
|
|
183
178
|
case 2:
|
|
184
179
|
_c = (_b = exports.OPERATIONS)[expr.operator];
|
|
180
|
+
_d = typer_1.cast;
|
|
185
181
|
return [4 /*yield*/, evaluate(expr.left)];
|
|
186
182
|
case 3:
|
|
187
|
-
|
|
183
|
+
_e = [_d.apply(void 0, [_m.sent()])];
|
|
184
|
+
_f = typer_1.cast;
|
|
188
185
|
return [4 /*yield*/, evaluate(expr.right)];
|
|
189
186
|
case 4:
|
|
190
|
-
binaryResult = _c.apply(_b,
|
|
191
|
-
return [2 /*return*/,
|
|
192
|
-
case 5:
|
|
187
|
+
binaryResult = _c.apply(_b, _e.concat([_f.apply(void 0, [_m.sent()])]));
|
|
188
|
+
return [2 /*return*/, binaryResult];
|
|
189
|
+
case 5:
|
|
190
|
+
_g = typer_1.cast;
|
|
191
|
+
return [4 /*yield*/, evaluate(expr.left)];
|
|
193
192
|
case 6:
|
|
194
|
-
logicalLeft =
|
|
195
|
-
if (
|
|
196
|
-
logicalLeft = false;
|
|
197
|
-
}
|
|
198
|
-
if (expr.operator === greybel_core_1.Operator.And && !(0, exports.toPrimitive)(logicalLeft)) {
|
|
193
|
+
logicalLeft = _g.apply(void 0, [_m.sent()]);
|
|
194
|
+
if (expr.operator === greybel_core_1.Operator.And && !logicalLeft.toTruthy()) {
|
|
199
195
|
return [2 /*return*/, false];
|
|
200
196
|
}
|
|
201
|
-
else if (expr.operator === greybel_core_1.Operator.Or &&
|
|
197
|
+
else if (expr.operator === greybel_core_1.Operator.Or && logicalLeft.toTruthy()) {
|
|
202
198
|
return [2 /*return*/, true];
|
|
203
199
|
}
|
|
204
|
-
|
|
205
|
-
|
|
200
|
+
_j = (_h = exports.OPERATIONS)[expr.operator];
|
|
201
|
+
_k = [logicalLeft];
|
|
202
|
+
_l = typer_1.cast;
|
|
206
203
|
return [4 /*yield*/, evaluate(expr.right)];
|
|
207
204
|
case 7:
|
|
208
|
-
logicalResult =
|
|
205
|
+
logicalResult = _j.apply(_h, _k.concat([_l.apply(void 0, [_m.sent()])]));
|
|
209
206
|
return [2 /*return*/, logicalResult];
|
|
210
207
|
case 8: return [2 /*return*/, node.get(operationContext)];
|
|
211
208
|
}
|
package/dist/expressions/path.js
CHANGED
|
@@ -198,14 +198,14 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
198
198
|
me = this;
|
|
199
199
|
evaluate = function (node) {
|
|
200
200
|
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
-
var traverselPath, traversedPath, position, handle, current, functionContext, origin, value, origin, left, right;
|
|
202
|
-
return __generator(this, function (
|
|
203
|
-
switch (
|
|
201
|
+
var traverselPath, traversedPath, position, handle, current, functionContext, origin, _a, value, origin, left, right;
|
|
202
|
+
return __generator(this, function (_b) {
|
|
203
|
+
switch (_b.label) {
|
|
204
204
|
case 0:
|
|
205
205
|
traverselPath = [].concat(node.value);
|
|
206
206
|
traversedPath = [];
|
|
207
207
|
position = 0;
|
|
208
|
-
|
|
208
|
+
_b.label = 1;
|
|
209
209
|
case 1:
|
|
210
210
|
if (!(current = traverselPath.shift())) return [3 /*break*/, 30];
|
|
211
211
|
if (!(0, typer_1.isCustomValue)(current)) return [3 /*break*/, 2];
|
|
@@ -215,13 +215,13 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
215
215
|
if (!(current instanceof expression_1.Expression)) return [3 /*break*/, 4];
|
|
216
216
|
return [4 /*yield*/, current.get(operationContext, me.expr)];
|
|
217
217
|
case 3:
|
|
218
|
-
handle =
|
|
218
|
+
handle = _b.sent();
|
|
219
219
|
return [3 /*break*/, 29];
|
|
220
220
|
case 4:
|
|
221
221
|
if (!(current instanceof operation_1.Operation)) return [3 /*break*/, 6];
|
|
222
222
|
return [4 /*yield*/, current.get(operationContext)];
|
|
223
223
|
case 5:
|
|
224
|
-
handle =
|
|
224
|
+
handle = _b.sent();
|
|
225
225
|
return [3 /*break*/, 29];
|
|
226
226
|
case 6:
|
|
227
227
|
if (!(current instanceof PathSegment)) return [3 /*break*/, 12];
|
|
@@ -239,18 +239,19 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
239
239
|
if (!(traverselPath.length > 0)) return [3 /*break*/, 11];
|
|
240
240
|
return [4 /*yield*/, (handle || operationContext).get(traversedPath)];
|
|
241
241
|
case 8:
|
|
242
|
-
origin =
|
|
242
|
+
origin = _b.sent();
|
|
243
243
|
if (!(0, typer_1.isCustomValue)(origin)) return [3 /*break*/, 9];
|
|
244
244
|
handle = origin;
|
|
245
245
|
traversedPath = [];
|
|
246
246
|
return [3 /*break*/, 11];
|
|
247
247
|
case 9:
|
|
248
248
|
if (!(origin instanceof Function)) return [3 /*break*/, 11];
|
|
249
|
+
_a = typer_1.cast;
|
|
249
250
|
return [4 /*yield*/, origin.call(handle)];
|
|
250
251
|
case 10:
|
|
251
|
-
handle = _a.sent();
|
|
252
|
+
handle = _a.apply(void 0, [_b.sent()]);
|
|
252
253
|
traversedPath = [];
|
|
253
|
-
|
|
254
|
+
_b.label = 11;
|
|
254
255
|
case 11: return [3 /*break*/, 29];
|
|
255
256
|
case 12:
|
|
256
257
|
if (!(current instanceof IndexSegment)) return [3 /*break*/, 19];
|
|
@@ -262,31 +263,31 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
262
263
|
if (!(current instanceof expression_1.Expression)) return [3 /*break*/, 15];
|
|
263
264
|
return [4 /*yield*/, current.get(operationContext)];
|
|
264
265
|
case 14:
|
|
265
|
-
value =
|
|
266
|
+
value = _b.sent();
|
|
266
267
|
traversedPath.push(value.toString());
|
|
267
268
|
return [3 /*break*/, 16];
|
|
268
269
|
case 15:
|
|
269
270
|
operationContext.debugger.raise('Unexpected index', me, current);
|
|
270
|
-
|
|
271
|
+
_b.label = 16;
|
|
271
272
|
case 16:
|
|
272
273
|
if (!(handle && !parentExpr)) return [3 /*break*/, 18];
|
|
273
274
|
return [4 /*yield*/, handle.get(traversedPath, me.expr)];
|
|
274
275
|
case 17:
|
|
275
|
-
origin =
|
|
276
|
+
origin = _b.sent();
|
|
276
277
|
if (origin instanceof Function || origin instanceof function_1.default) {
|
|
277
278
|
handle = origin;
|
|
278
279
|
traversedPath = [];
|
|
279
280
|
}
|
|
280
|
-
|
|
281
|
+
_b.label = 18;
|
|
281
282
|
case 18: return [3 /*break*/, 29];
|
|
282
283
|
case 19:
|
|
283
284
|
if (!(current instanceof SliceSegment)) return [3 /*break*/, 28];
|
|
284
285
|
if (!!handle) return [3 /*break*/, 21];
|
|
285
286
|
return [4 /*yield*/, operationContext.get(traversedPath)];
|
|
286
287
|
case 20:
|
|
287
|
-
handle =
|
|
288
|
+
handle = _b.sent();
|
|
288
289
|
traversedPath = [];
|
|
289
|
-
|
|
290
|
+
_b.label = 21;
|
|
290
291
|
case 21:
|
|
291
292
|
if (!(0, typer_1.isCustomList)(handle) && !(0, typer_1.isCustomString)(handle)) {
|
|
292
293
|
operationContext.debugger.raise('Invalid type for slice', me, handle);
|
|
@@ -299,8 +300,8 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
299
300
|
if (!(left instanceof expression_1.Expression)) return [3 /*break*/, 24];
|
|
300
301
|
return [4 /*yield*/, left.get(operationContext)];
|
|
301
302
|
case 23:
|
|
302
|
-
left =
|
|
303
|
-
|
|
303
|
+
left = _b.sent();
|
|
304
|
+
_b.label = 24;
|
|
304
305
|
case 24:
|
|
305
306
|
right = current.right;
|
|
306
307
|
if (!(0, typer_1.isCustomValue)(right)) return [3 /*break*/, 25];
|
|
@@ -310,14 +311,14 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
310
311
|
if (!(right instanceof expression_1.Expression)) return [3 /*break*/, 27];
|
|
311
312
|
return [4 /*yield*/, right.get(operationContext)];
|
|
312
313
|
case 26:
|
|
313
|
-
right =
|
|
314
|
-
|
|
314
|
+
right = _b.sent();
|
|
315
|
+
_b.label = 27;
|
|
315
316
|
case 27:
|
|
316
317
|
handle = handle.slice(left, right);
|
|
317
318
|
return [3 /*break*/, 29];
|
|
318
319
|
case 28:
|
|
319
320
|
operationContext.debugger.raise('Unexpected handle', me, current);
|
|
320
|
-
|
|
321
|
+
_b.label = 29;
|
|
321
322
|
case 29:
|
|
322
323
|
position++;
|
|
323
324
|
return [3 /*break*/, 1];
|
|
@@ -338,7 +339,9 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
338
339
|
if (!(resultExpr.path.length === 0)) return [3 /*break*/, 2];
|
|
339
340
|
return [2 /*return*/, resultExpr.handle];
|
|
340
341
|
case 2:
|
|
341
|
-
if (!(0, typer_1.isCustomMap)(resultExpr.handle)
|
|
342
|
+
if (!((0, typer_1.isCustomMap)(resultExpr.handle) ||
|
|
343
|
+
(0, typer_1.isCustomList)(resultExpr.handle) ||
|
|
344
|
+
(0, typer_1.isCustomString)(resultExpr.handle))) return [3 /*break*/, 7];
|
|
342
345
|
context = resultExpr.handle;
|
|
343
346
|
return [4 /*yield*/, context.get(resultExpr.path)];
|
|
344
347
|
case 3:
|
|
@@ -351,7 +354,9 @@ var PathExpression = /** @class */ (function (_super) {
|
|
|
351
354
|
return [4 /*yield*/, value_1.call(context)];
|
|
352
355
|
case 5: return [2 /*return*/, _a.apply(void 0, [_c.sent()])];
|
|
353
356
|
case 6: return [2 /*return*/, value_1];
|
|
354
|
-
case 7:
|
|
357
|
+
case 7:
|
|
358
|
+
operationContext.debugger.raise('Unexpected handle get', me, resultExpr);
|
|
359
|
+
_c.label = 8;
|
|
355
360
|
case 8: return [4 /*yield*/, operationContext.get(resultExpr.path)];
|
|
356
361
|
case 9:
|
|
357
362
|
value = _c.sent();
|
|
@@ -17,5 +17,8 @@ export default class FunctionOperation extends FunctionOperationBase {
|
|
|
17
17
|
fork(context: any): FunctionOperation;
|
|
18
18
|
get(operationContext: OperationContext): FunctionOperation;
|
|
19
19
|
toString(): string;
|
|
20
|
+
toTruthy(): boolean;
|
|
21
|
+
toNumber(): number;
|
|
22
|
+
valueOf(): FunctionOperation;
|
|
20
23
|
run(operationContext: OperationContext): Promise<any>;
|
|
21
24
|
}
|
|
@@ -85,6 +85,15 @@ var FunctionOperation = /** @class */ (function (_super) {
|
|
|
85
85
|
FunctionOperation.prototype.toString = function () {
|
|
86
86
|
return 'Function';
|
|
87
87
|
};
|
|
88
|
+
FunctionOperation.prototype.toTruthy = function () {
|
|
89
|
+
return true;
|
|
90
|
+
};
|
|
91
|
+
FunctionOperation.prototype.toNumber = function () {
|
|
92
|
+
return Number.NaN;
|
|
93
|
+
};
|
|
94
|
+
FunctionOperation.prototype.valueOf = function () {
|
|
95
|
+
return this;
|
|
96
|
+
};
|
|
88
97
|
FunctionOperation.prototype.run = function (operationContext) {
|
|
89
98
|
return __awaiter(this, void 0, void 0, function () {
|
|
90
99
|
var me, opc, incArgs, args, argMap, functionContext, index, max;
|
|
@@ -82,7 +82,7 @@ var IfStatementOperation = /** @class */ (function (_super) {
|
|
|
82
82
|
}
|
|
83
83
|
IfStatementOperation.prototype.run = function (operationContext) {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
-
var me, clauses, clauses_1, clauses_1_1, clause, condition,
|
|
85
|
+
var me, clauses, clauses_1, clauses_1_1, clause, condition, resolveCondition, e_1_1;
|
|
86
86
|
var e_1, _a;
|
|
87
87
|
return __generator(this, function (_b) {
|
|
88
88
|
switch (_b.label) {
|
|
@@ -91,59 +91,75 @@ var IfStatementOperation = /** @class */ (function (_super) {
|
|
|
91
91
|
clauses = me.clauses;
|
|
92
92
|
_b.label = 1;
|
|
93
93
|
case 1:
|
|
94
|
-
_b.trys.push([1,
|
|
94
|
+
_b.trys.push([1, 11, 12, 13]);
|
|
95
95
|
clauses_1 = __values(clauses), clauses_1_1 = clauses_1.next();
|
|
96
96
|
_b.label = 2;
|
|
97
97
|
case 2:
|
|
98
|
-
if (!!clauses_1_1.done) return [3 /*break*/,
|
|
98
|
+
if (!!clauses_1_1.done) return [3 /*break*/, 10];
|
|
99
99
|
clause = clauses_1_1.value;
|
|
100
|
-
if (!(clause instanceof if_1.default || clause instanceof else_if_1.default)) return [3 /*break*/,
|
|
100
|
+
if (!(clause instanceof if_1.default || clause instanceof else_if_1.default)) return [3 /*break*/, 6];
|
|
101
101
|
condition = clause.condition;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
resolveCondition = function (item) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var value, value;
|
|
105
|
+
return __generator(this, function (_a) {
|
|
106
|
+
switch (_a.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
if (!(item instanceof expression_1.Expression)) return [3 /*break*/, 2];
|
|
109
|
+
return [4 /*yield*/, item.get(operationContext)];
|
|
110
|
+
case 1:
|
|
111
|
+
value = _a.sent();
|
|
112
|
+
return [2 /*return*/, value.toTruthy()];
|
|
113
|
+
case 2:
|
|
114
|
+
if (!(item instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
115
|
+
return [4 /*yield*/, item.get(operationContext)];
|
|
116
|
+
case 3:
|
|
117
|
+
value = _a.sent();
|
|
118
|
+
return [2 /*return*/, value.toTruthy()];
|
|
119
|
+
case 4:
|
|
120
|
+
if ((0, typer_1.isCustomValue)(item)) {
|
|
121
|
+
return [2 /*return*/, item.toTruthy()];
|
|
122
|
+
}
|
|
123
|
+
_a.label = 5;
|
|
124
|
+
case 5:
|
|
125
|
+
operationContext.debugger.raise('Unexpected condition', me, item);
|
|
126
|
+
return [2 /*return*/];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
return [4 /*yield*/, resolveCondition(condition)];
|
|
106
132
|
case 3:
|
|
107
|
-
if (!(
|
|
108
|
-
|
|
109
|
-
return [4 /*yield*/, condition.get(operationContext)];
|
|
133
|
+
if (!_b.sent()) return [3 /*break*/, 5];
|
|
134
|
+
return [4 /*yield*/, clause.body.run(operationContext)];
|
|
110
135
|
case 4:
|
|
111
|
-
|
|
112
|
-
return [3 /*break*/,
|
|
113
|
-
case 5:
|
|
114
|
-
operationContext.debugger.raise('Unexpected condition in clause', me, clause.condition);
|
|
115
|
-
_b.label = 6;
|
|
136
|
+
_b.sent();
|
|
137
|
+
return [3 /*break*/, 10];
|
|
138
|
+
case 5: return [3 /*break*/, 9];
|
|
116
139
|
case 6:
|
|
117
|
-
if (!
|
|
140
|
+
if (!(clause instanceof else_1.default)) return [3 /*break*/, 8];
|
|
118
141
|
return [4 /*yield*/, clause.body.run(operationContext)];
|
|
119
142
|
case 7:
|
|
120
143
|
_b.sent();
|
|
121
|
-
return [3 /*break*/,
|
|
122
|
-
case 8:
|
|
123
|
-
case 9:
|
|
124
|
-
if (!(clause instanceof else_1.default)) return [3 /*break*/, 11];
|
|
125
|
-
return [4 /*yield*/, clause.body.run(operationContext)];
|
|
126
|
-
case 10:
|
|
127
|
-
_b.sent();
|
|
128
|
-
return [3 /*break*/, 13];
|
|
129
|
-
case 11:
|
|
144
|
+
return [3 /*break*/, 10];
|
|
145
|
+
case 8:
|
|
130
146
|
operationContext.debugger.raise('Invalid operation in if statement.', me, clause);
|
|
131
|
-
_b.label =
|
|
132
|
-
case
|
|
147
|
+
_b.label = 9;
|
|
148
|
+
case 9:
|
|
133
149
|
clauses_1_1 = clauses_1.next();
|
|
134
150
|
return [3 /*break*/, 2];
|
|
135
|
-
case
|
|
136
|
-
case
|
|
151
|
+
case 10: return [3 /*break*/, 13];
|
|
152
|
+
case 11:
|
|
137
153
|
e_1_1 = _b.sent();
|
|
138
154
|
e_1 = { error: e_1_1 };
|
|
139
|
-
return [3 /*break*/,
|
|
140
|
-
case
|
|
155
|
+
return [3 /*break*/, 13];
|
|
156
|
+
case 12:
|
|
141
157
|
try {
|
|
142
158
|
if (clauses_1_1 && !clauses_1_1.done && (_a = clauses_1.return)) _a.call(clauses_1);
|
|
143
159
|
}
|
|
144
160
|
finally { if (e_1) throw e_1.error; }
|
|
145
161
|
return [7 /*endfinally*/];
|
|
146
|
-
case
|
|
162
|
+
case 13: return [2 /*return*/];
|
|
147
163
|
}
|
|
148
164
|
});
|
|
149
165
|
});
|
package/dist/operations/not.js
CHANGED
|
@@ -71,7 +71,7 @@ var NotOperation = /** @class */ (function (_super) {
|
|
|
71
71
|
case 0:
|
|
72
72
|
me = this;
|
|
73
73
|
if (!(0, typer_1.isCustomValue)(me.arg)) return [3 /*break*/, 1];
|
|
74
|
-
arg = me.arg.
|
|
74
|
+
arg = me.arg.toTruthy();
|
|
75
75
|
return [3 /*break*/, 4];
|
|
76
76
|
case 1:
|
|
77
77
|
if (!(me.arg instanceof expression_1.Expression)) return [3 /*break*/, 3];
|
|
@@ -79,13 +79,13 @@ var NotOperation = /** @class */ (function (_super) {
|
|
|
79
79
|
case 2:
|
|
80
80
|
arg = _a.sent();
|
|
81
81
|
if ((0, typer_1.isCustomValue)(arg)) {
|
|
82
|
-
arg = arg.
|
|
82
|
+
arg = arg.toTruthy();
|
|
83
83
|
}
|
|
84
84
|
return [3 /*break*/, 4];
|
|
85
85
|
case 3:
|
|
86
86
|
operationContext.debugger.raise('Unexpected not operation', me, me.arg);
|
|
87
87
|
_a.label = 4;
|
|
88
|
-
case 4: return [2 /*return*/, !arg];
|
|
88
|
+
case 4: return [2 /*return*/, (0, typer_1.cast)(!arg)];
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
91
|
});
|
package/dist/operations/while.js
CHANGED
|
@@ -80,30 +80,30 @@ var WhileOperation = /** @class */ (function (_super) {
|
|
|
80
80
|
isBreak: false,
|
|
81
81
|
isContinue: false
|
|
82
82
|
};
|
|
83
|
-
resolveCondition = function () {
|
|
83
|
+
resolveCondition = function (item) {
|
|
84
84
|
return __awaiter(this, void 0, void 0, function () {
|
|
85
85
|
var value, value;
|
|
86
86
|
return __generator(this, function (_a) {
|
|
87
87
|
switch (_a.label) {
|
|
88
88
|
case 0:
|
|
89
|
-
if (!(
|
|
90
|
-
return [4 /*yield*/,
|
|
89
|
+
if (!(item instanceof expression_1.Expression)) return [3 /*break*/, 2];
|
|
90
|
+
return [4 /*yield*/, item.get(opc)];
|
|
91
91
|
case 1:
|
|
92
92
|
value = _a.sent();
|
|
93
|
-
return [2 /*return*/,
|
|
93
|
+
return [2 /*return*/, value.toTruthy()];
|
|
94
94
|
case 2:
|
|
95
|
-
if (!(
|
|
96
|
-
return [4 /*yield*/,
|
|
95
|
+
if (!(item instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
96
|
+
return [4 /*yield*/, item.get(opc)];
|
|
97
97
|
case 3:
|
|
98
98
|
value = _a.sent();
|
|
99
|
-
return [2 /*return*/,
|
|
99
|
+
return [2 /*return*/, value.toTruthy()];
|
|
100
100
|
case 4:
|
|
101
|
-
if ((0, typer_1.isCustomValue)(
|
|
102
|
-
return [2 /*return*/,
|
|
101
|
+
if ((0, typer_1.isCustomValue)(item)) {
|
|
102
|
+
return [2 /*return*/, item.toTruthy()];
|
|
103
103
|
}
|
|
104
104
|
_a.label = 5;
|
|
105
105
|
case 5:
|
|
106
|
-
operationContext.debugger.raise('Unexpected condition', me,
|
|
106
|
+
operationContext.debugger.raise('Unexpected condition', me, item);
|
|
107
107
|
return [2 /*return*/];
|
|
108
108
|
}
|
|
109
109
|
});
|
|
@@ -111,7 +111,7 @@ var WhileOperation = /** @class */ (function (_super) {
|
|
|
111
111
|
};
|
|
112
112
|
opc.setMemory('loopContext', loopContext);
|
|
113
113
|
_a.label = 1;
|
|
114
|
-
case 1: return [4 /*yield*/, resolveCondition()];
|
|
114
|
+
case 1: return [4 /*yield*/, resolveCondition(me.condition)];
|
|
115
115
|
case 2:
|
|
116
116
|
if (!_a.sent()) return [3 /*break*/, 4];
|
|
117
117
|
loopContext.isContinue = false;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export declare abstract class CustomType {
|
|
2
2
|
static intrinsics: Map<string, Function>;
|
|
3
3
|
getType(): string;
|
|
4
|
-
|
|
4
|
+
toNumber(): number;
|
|
5
5
|
toString(): string;
|
|
6
|
+
toTruthy(): boolean;
|
|
7
|
+
valueOf(): any;
|
|
6
8
|
}
|
|
7
9
|
export declare abstract class CustomLiteralType extends CustomType {
|
|
8
10
|
value: any;
|