greybel-interpreter 0.6.1 → 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/custom-types/boolean.d.ts +1 -0
- package/dist/custom-types/boolean.js +3 -0
- package/dist/custom-types/list.d.ts +1 -0
- package/dist/custom-types/list.js +3 -0
- package/dist/custom-types/map.d.ts +1 -0
- package/dist/custom-types/map.js +3 -0
- package/dist/custom-types/nil.d.ts +1 -0
- package/dist/custom-types/nil.js +3 -0
- package/dist/custom-types/number.d.ts +1 -0
- package/dist/custom-types/number.js +3 -0
- package/dist/custom-types/string.d.ts +1 -0
- package/dist/custom-types/string.js +3 -0
- package/dist/expressions/logical-and-binary.js +4 -4
- package/dist/operations/function.d.ts +1 -0
- package/dist/operations/function.js +4 -1
- package/dist/operations/if-statement.js +55 -73
- package/dist/operations/not.js +1 -1
- package/dist/operations/while.js +2 -5
- package/dist/types/custom-type.d.ts +1 -0
- package/dist/types/custom-type.js +3 -0
- package/package.json +1 -1
|
@@ -38,6 +38,9 @@ var CustomBoolean = /** @class */ (function (_super) {
|
|
|
38
38
|
CustomBoolean.prototype.toTruthy = function () {
|
|
39
39
|
return this.value;
|
|
40
40
|
};
|
|
41
|
+
CustomBoolean.prototype.valueOf = function () {
|
|
42
|
+
return this.value;
|
|
43
|
+
};
|
|
41
44
|
CustomBoolean.intrinsics = new Map();
|
|
42
45
|
return CustomBoolean;
|
|
43
46
|
}(custom_type_1.CustomLiteralType));
|
|
@@ -224,6 +224,9 @@ var CustomList = /** @class */ (function (_super) {
|
|
|
224
224
|
CustomList.prototype.toTruthy = function () {
|
|
225
225
|
return this.value.length > 0;
|
|
226
226
|
};
|
|
227
|
+
CustomList.prototype.valueOf = function () {
|
|
228
|
+
return this.value;
|
|
229
|
+
};
|
|
227
230
|
CustomList.prototype.fork = function () {
|
|
228
231
|
return new CustomList(this.value);
|
|
229
232
|
};
|
package/dist/custom-types/map.js
CHANGED
|
@@ -232,6 +232,9 @@ var CustomMap = /** @class */ (function (_super) {
|
|
|
232
232
|
});
|
|
233
233
|
return "{".concat(body.join(','), "}");
|
|
234
234
|
};
|
|
235
|
+
CustomMap.prototype.valueOf = function () {
|
|
236
|
+
return this.value;
|
|
237
|
+
};
|
|
235
238
|
CustomMap.prototype.fork = function () {
|
|
236
239
|
return new CustomMap(this.value);
|
|
237
240
|
};
|
package/dist/custom-types/nil.js
CHANGED
|
@@ -35,6 +35,9 @@ var CustomNil = /** @class */ (function (_super) {
|
|
|
35
35
|
CustomNil.prototype.toString = function () {
|
|
36
36
|
return 'null';
|
|
37
37
|
};
|
|
38
|
+
CustomNil.prototype.valueOf = function () {
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
38
41
|
CustomNil.intrinsics = new Map();
|
|
39
42
|
return CustomNil;
|
|
40
43
|
}(custom_type_1.CustomLiteralType));
|
|
@@ -35,6 +35,9 @@ var CustomNumber = /** @class */ (function (_super) {
|
|
|
35
35
|
CustomNumber.prototype.toTruthy = function () {
|
|
36
36
|
return Number.isNaN(this.value) ? false : !!this.value;
|
|
37
37
|
};
|
|
38
|
+
CustomNumber.prototype.valueOf = function () {
|
|
39
|
+
return this.value;
|
|
40
|
+
};
|
|
38
41
|
CustomNumber.prototype.fork = function () {
|
|
39
42
|
return new CustomNumber(this.value);
|
|
40
43
|
};
|
|
@@ -160,6 +160,9 @@ var CustomString = /** @class */ (function (_super) {
|
|
|
160
160
|
CustomString.prototype.toTruthy = function () {
|
|
161
161
|
return this.value.length > 0;
|
|
162
162
|
};
|
|
163
|
+
CustomString.prototype.valueOf = function () {
|
|
164
|
+
return this.value;
|
|
165
|
+
};
|
|
163
166
|
CustomString.prototype.fork = function () {
|
|
164
167
|
return new CustomString(this.value);
|
|
165
168
|
};
|
|
@@ -98,10 +98,10 @@ exports.OPERATIONS = (_a = {},
|
|
|
98
98
|
_a[greybel_core_1.Operator.UnsignedRightShift] = function (a, b) { return a.toNumber() >>> b.toNumber(); },
|
|
99
99
|
_a[greybel_core_1.Operator.BitwiseAnd] = function (a, b) { return a.toNumber() & b.toNumber(); },
|
|
100
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.
|
|
102
|
-
_a[greybel_core_1.Operator.Equal] = function (a, b) { return a.
|
|
103
|
-
_a[greybel_core_1.Operator.LessThanOrEqual] = function (a, b) { return a.
|
|
104
|
-
_a[greybel_core_1.Operator.NotEqual] = function (a, b) { return a.
|
|
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
105
|
_a[greybel_core_1.Operator.And] = function (a, b) { return a.toTruthy() && b.toTruthy(); },
|
|
106
106
|
_a[greybel_core_1.Operator.Or] = function (a, b) { return a.toTruthy() || b.toTruthy(); },
|
|
107
107
|
_a);
|
|
@@ -89,7 +89,10 @@ var FunctionOperation = /** @class */ (function (_super) {
|
|
|
89
89
|
return true;
|
|
90
90
|
};
|
|
91
91
|
FunctionOperation.prototype.toNumber = function () {
|
|
92
|
-
return
|
|
92
|
+
return Number.NaN;
|
|
93
|
+
};
|
|
94
|
+
FunctionOperation.prototype.valueOf = function () {
|
|
95
|
+
return this;
|
|
93
96
|
};
|
|
94
97
|
FunctionOperation.prototype.run = function (operationContext) {
|
|
95
98
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -82,102 +82,84 @@ 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,
|
|
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) {
|
|
89
89
|
case 0:
|
|
90
90
|
me = this;
|
|
91
91
|
clauses = me.clauses;
|
|
92
|
-
_loop_1 = function (clause) {
|
|
93
|
-
var condition, resolveCondition_1;
|
|
94
|
-
return __generator(this, function (_c) {
|
|
95
|
-
switch (_c.label) {
|
|
96
|
-
case 0:
|
|
97
|
-
if (!(clause instanceof if_1.default || clause instanceof else_if_1.default)) return [3 /*break*/, 4];
|
|
98
|
-
condition = clause.condition;
|
|
99
|
-
resolveCondition_1 = function (item) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
-
var value, value;
|
|
102
|
-
return __generator(this, function (_a) {
|
|
103
|
-
switch (_a.label) {
|
|
104
|
-
case 0:
|
|
105
|
-
if (!(item instanceof expression_1.Expression)) return [3 /*break*/, 2];
|
|
106
|
-
return [4 /*yield*/, item.get(operationContext)];
|
|
107
|
-
case 1:
|
|
108
|
-
value = _a.sent();
|
|
109
|
-
return [2 /*return*/, resolveCondition_1(value)];
|
|
110
|
-
case 2:
|
|
111
|
-
if (!(item instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
112
|
-
return [4 /*yield*/, item.get(operationContext)];
|
|
113
|
-
case 3:
|
|
114
|
-
value = _a.sent();
|
|
115
|
-
return [2 /*return*/, resolveCondition_1(value)];
|
|
116
|
-
case 4:
|
|
117
|
-
if ((0, typer_1.isCustomValue)(item)) {
|
|
118
|
-
return [2 /*return*/, item.toTruthy()];
|
|
119
|
-
}
|
|
120
|
-
else if (typeof item === 'boolean') {
|
|
121
|
-
return [2 /*return*/, item];
|
|
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_1(condition)];
|
|
132
|
-
case 1:
|
|
133
|
-
if (!_c.sent()) return [3 /*break*/, 3];
|
|
134
|
-
return [4 /*yield*/, clause.body.run(operationContext)];
|
|
135
|
-
case 2:
|
|
136
|
-
_c.sent();
|
|
137
|
-
return [2 /*return*/, "break"];
|
|
138
|
-
case 3: return [3 /*break*/, 7];
|
|
139
|
-
case 4:
|
|
140
|
-
if (!(clause instanceof else_1.default)) return [3 /*break*/, 6];
|
|
141
|
-
return [4 /*yield*/, clause.body.run(operationContext)];
|
|
142
|
-
case 5:
|
|
143
|
-
_c.sent();
|
|
144
|
-
return [2 /*return*/, "break"];
|
|
145
|
-
case 6:
|
|
146
|
-
operationContext.debugger.raise('Invalid operation in if statement.', me, clause);
|
|
147
|
-
_c.label = 7;
|
|
148
|
-
case 7: return [2 /*return*/];
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
92
|
_b.label = 1;
|
|
153
93
|
case 1:
|
|
154
|
-
_b.trys.push([1,
|
|
94
|
+
_b.trys.push([1, 11, 12, 13]);
|
|
155
95
|
clauses_1 = __values(clauses), clauses_1_1 = clauses_1.next();
|
|
156
96
|
_b.label = 2;
|
|
157
97
|
case 2:
|
|
158
|
-
if (!!clauses_1_1.done) return [3 /*break*/,
|
|
98
|
+
if (!!clauses_1_1.done) return [3 /*break*/, 10];
|
|
159
99
|
clause = clauses_1_1.value;
|
|
160
|
-
return [
|
|
100
|
+
if (!(clause instanceof if_1.default || clause instanceof else_if_1.default)) return [3 /*break*/, 6];
|
|
101
|
+
condition = clause.condition;
|
|
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)];
|
|
161
132
|
case 3:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return [3 /*break*/, 5];
|
|
165
|
-
_b.label = 4;
|
|
133
|
+
if (!_b.sent()) return [3 /*break*/, 5];
|
|
134
|
+
return [4 /*yield*/, clause.body.run(operationContext)];
|
|
166
135
|
case 4:
|
|
136
|
+
_b.sent();
|
|
137
|
+
return [3 /*break*/, 10];
|
|
138
|
+
case 5: return [3 /*break*/, 9];
|
|
139
|
+
case 6:
|
|
140
|
+
if (!(clause instanceof else_1.default)) return [3 /*break*/, 8];
|
|
141
|
+
return [4 /*yield*/, clause.body.run(operationContext)];
|
|
142
|
+
case 7:
|
|
143
|
+
_b.sent();
|
|
144
|
+
return [3 /*break*/, 10];
|
|
145
|
+
case 8:
|
|
146
|
+
operationContext.debugger.raise('Invalid operation in if statement.', me, clause);
|
|
147
|
+
_b.label = 9;
|
|
148
|
+
case 9:
|
|
167
149
|
clauses_1_1 = clauses_1.next();
|
|
168
150
|
return [3 /*break*/, 2];
|
|
169
|
-
case
|
|
170
|
-
case
|
|
151
|
+
case 10: return [3 /*break*/, 13];
|
|
152
|
+
case 11:
|
|
171
153
|
e_1_1 = _b.sent();
|
|
172
154
|
e_1 = { error: e_1_1 };
|
|
173
|
-
return [3 /*break*/,
|
|
174
|
-
case
|
|
155
|
+
return [3 /*break*/, 13];
|
|
156
|
+
case 12:
|
|
175
157
|
try {
|
|
176
158
|
if (clauses_1_1 && !clauses_1_1.done && (_a = clauses_1.return)) _a.call(clauses_1);
|
|
177
159
|
}
|
|
178
160
|
finally { if (e_1) throw e_1.error; }
|
|
179
161
|
return [7 /*endfinally*/];
|
|
180
|
-
case
|
|
162
|
+
case 13: return [2 /*return*/];
|
|
181
163
|
}
|
|
182
164
|
});
|
|
183
165
|
});
|
package/dist/operations/not.js
CHANGED
|
@@ -85,7 +85,7 @@ var NotOperation = /** @class */ (function (_super) {
|
|
|
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
|
@@ -90,20 +90,17 @@ var WhileOperation = /** @class */ (function (_super) {
|
|
|
90
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
95
|
if (!(item instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
96
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
101
|
if ((0, typer_1.isCustomValue)(item)) {
|
|
102
102
|
return [2 /*return*/, item.toTruthy()];
|
|
103
103
|
}
|
|
104
|
-
else if (typeof item === 'boolean') {
|
|
105
|
-
return [2 /*return*/, item];
|
|
106
|
-
}
|
|
107
104
|
_a.label = 5;
|
|
108
105
|
case 5:
|
|
109
106
|
operationContext.debugger.raise('Unexpected condition', me, item);
|
|
@@ -31,6 +31,9 @@ var CustomType = /** @class */ (function () {
|
|
|
31
31
|
CustomType.prototype.toTruthy = function () {
|
|
32
32
|
throw new Error('Implentation of "toTruthy" missing');
|
|
33
33
|
};
|
|
34
|
+
CustomType.prototype.valueOf = function () {
|
|
35
|
+
throw new Error('Implentation of "valueOf" missing');
|
|
36
|
+
};
|
|
34
37
|
return CustomType;
|
|
35
38
|
}());
|
|
36
39
|
exports.CustomType = CustomType;
|