greybel-interpreter 1.4.4 → 1.4.6
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 +3 -2
- package/dist/context.js +113 -190
- package/dist/cps.js +135 -188
- package/dist/handler/error.js +6 -29
- package/dist/handler/output.js +15 -38
- package/dist/handler/resource.js +16 -39
- package/dist/handler-container.js +6 -8
- package/dist/index.d.ts +4 -3
- package/dist/index.js +10 -9
- package/dist/interpreter.d.ts +5 -4
- package/dist/interpreter.js +109 -203
- package/dist/operations/assign.d.ts +1 -1
- package/dist/operations/assign.js +28 -93
- package/dist/operations/block.d.ts +1 -1
- package/dist/operations/block.js +33 -89
- package/dist/operations/break.d.ts +1 -1
- package/dist/operations/break.js +11 -29
- package/dist/operations/call.d.ts +1 -1
- package/dist/operations/call.js +31 -106
- package/dist/operations/chunk.d.ts +1 -1
- package/dist/operations/chunk.js +15 -67
- package/dist/operations/continue.d.ts +1 -1
- package/dist/operations/continue.js +11 -29
- package/dist/operations/debugger-statement.d.ts +1 -1
- package/dist/operations/debugger-statement.js +11 -29
- package/dist/operations/evaluate.d.ts +1 -1
- package/dist/operations/evaluate.js +143 -247
- package/dist/operations/for.d.ts +1 -1
- package/dist/operations/for.js +62 -133
- package/dist/operations/function-reference.d.ts +1 -1
- package/dist/operations/function-reference.js +25 -84
- package/dist/operations/function.d.ts +1 -1
- package/dist/operations/function.js +49 -177
- package/dist/operations/if-statement.d.ts +1 -1
- package/dist/operations/if-statement.js +58 -154
- package/dist/operations/import.d.ts +1 -1
- package/dist/operations/import.js +35 -97
- package/dist/operations/include.d.ts +1 -1
- package/dist/operations/include.js +19 -73
- package/dist/operations/list.d.ts +1 -1
- package/dist/operations/list.js +24 -93
- package/dist/operations/literal.d.ts +1 -1
- package/dist/operations/literal.js +15 -33
- package/dist/operations/map.d.ts +1 -1
- package/dist/operations/map.js +26 -153
- package/dist/operations/negated-binary.d.ts +1 -1
- package/dist/operations/negated-binary.js +24 -91
- package/dist/operations/new-instance.d.ts +1 -1
- package/dist/operations/new-instance.js +21 -82
- package/dist/operations/noop.d.ts +1 -1
- package/dist/operations/noop.js +10 -27
- package/dist/operations/not.d.ts +1 -1
- package/dist/operations/not.js +17 -78
- package/dist/operations/operation.d.ts +2 -2
- package/dist/operations/operation.js +3 -5
- package/dist/operations/reference.d.ts +1 -1
- package/dist/operations/reference.js +10 -28
- package/dist/operations/resolve.d.ts +1 -1
- package/dist/operations/resolve.js +161 -281
- package/dist/operations/return.d.ts +1 -1
- package/dist/operations/return.js +27 -89
- package/dist/operations/while.d.ts +1 -1
- package/dist/operations/while.js +45 -116
- package/dist/types/base.d.ts +9 -0
- package/dist/types/base.js +5 -0
- package/dist/types/boolean.d.ts +3 -1
- package/dist/types/boolean.js +24 -36
- package/dist/types/default.d.ts +6 -9
- package/dist/types/default.js +11 -17
- package/dist/types/function.d.ts +1 -1
- package/dist/types/function.js +60 -130
- package/dist/types/interface.d.ts +2 -1
- package/dist/types/interface.js +44 -64
- package/dist/types/list.d.ts +4 -6
- package/dist/types/list.js +77 -128
- package/dist/types/map.d.ts +11 -15
- package/dist/types/map.js +101 -267
- package/dist/types/nil.d.ts +2 -1
- package/dist/types/nil.js +23 -36
- package/dist/types/number.d.ts +16 -2
- package/dist/types/number.js +60 -37
- package/dist/types/string.d.ts +4 -6
- package/dist/types/string.js +66 -90
- package/dist/types/{generics.d.ts → with-intrinsics.d.ts} +6 -9
- package/dist/types/with-intrinsics.js +19 -0
- package/dist/utils/deep-equal.js +9 -34
- package/dist/utils/object-value.d.ts +7 -0
- package/dist/utils/object-value.js +42 -0
- package/dist/utils/path.js +16 -43
- package/package.json +3 -3
- package/dist/intrinsics-container.d.ts +0 -7
- package/dist/intrinsics-container.js +0 -19
- package/dist/types/generics.js +0 -40
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23,216 +8,162 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
9
|
});
|
|
25
10
|
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
13
|
};
|
|
56
|
-
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
57
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
15
|
exports.handle = exports.handleFunction = exports.handleNil = exports.handleInterface = exports.handleMap = exports.handleList = exports.handleString = exports.handleNumber = exports.FunctionProcessorHandler = exports.NilProcessorHandler = exports.InterfaceProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.StringProcessorHandler = exports.multiplyString = exports.NumberProcessorHandler = exports.GenericProcessorHandler = void 0;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
exports.GenericProcessorHandler =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
exports.NumberProcessorHandler =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return new boolean_1.default(a.toNumber() >= b.toNumber());
|
|
97
|
-
},
|
|
98
|
-
_c[greyscript_core_1.Operator.Equal] = function (a, b) { return new boolean_1.default(a.toNumber() === b.toNumber()); },
|
|
99
|
-
_c[greyscript_core_1.Operator.LessThanOrEqual] = function (a, b) {
|
|
100
|
-
return new boolean_1.default(a.toNumber() <= b.toNumber());
|
|
101
|
-
},
|
|
102
|
-
_c[greyscript_core_1.Operator.NotEqual] = function (a, b) {
|
|
103
|
-
return new boolean_1.default(a.toNumber() !== b.toNumber());
|
|
104
|
-
},
|
|
105
|
-
_c);
|
|
106
|
-
var multiplyString = function (a, b) {
|
|
107
|
-
var multiStr = new Array(b.toNumber()).fill(a.toString()).join('');
|
|
16
|
+
const greyscript_core_1 = require("greyscript-core");
|
|
17
|
+
const boolean_1 = __importDefault(require("../types/boolean"));
|
|
18
|
+
const default_1 = __importDefault(require("../types/default"));
|
|
19
|
+
const function_1 = __importDefault(require("../types/function"));
|
|
20
|
+
const interface_1 = __importDefault(require("../types/interface"));
|
|
21
|
+
const list_1 = __importDefault(require("../types/list"));
|
|
22
|
+
const map_1 = __importDefault(require("../types/map"));
|
|
23
|
+
const nil_1 = __importDefault(require("../types/nil"));
|
|
24
|
+
const number_1 = __importDefault(require("../types/number"));
|
|
25
|
+
const string_1 = __importDefault(require("../types/string"));
|
|
26
|
+
const deep_equal_1 = __importDefault(require("../utils/deep-equal"));
|
|
27
|
+
const operation_1 = __importDefault(require("./operation"));
|
|
28
|
+
exports.GenericProcessorHandler = {
|
|
29
|
+
[greyscript_core_1.Operator.And]: (a, b) => new boolean_1.default(a.toTruthy() && b.toTruthy()),
|
|
30
|
+
[greyscript_core_1.Operator.Or]: (a, b) => new boolean_1.default(a.toTruthy() || b.toTruthy())
|
|
31
|
+
};
|
|
32
|
+
exports.NumberProcessorHandler = {
|
|
33
|
+
[greyscript_core_1.Operator.Plus]: (a, b) => new number_1.default(a.toNumber() + b.toNumber()),
|
|
34
|
+
[greyscript_core_1.Operator.Minus]: (a, b) => new number_1.default(a.toNumber() - b.toNumber()),
|
|
35
|
+
[greyscript_core_1.Operator.Slash]: (a, b) => new number_1.default(a.toNumber() / b.toNumber()),
|
|
36
|
+
[greyscript_core_1.Operator.Asterik]: (a, b) => new number_1.default(a.toNumber() * b.toNumber()),
|
|
37
|
+
[greyscript_core_1.Operator.Xor]: (a, b) => new number_1.default(a.toInt() ^ b.toInt()),
|
|
38
|
+
[greyscript_core_1.Operator.BitwiseOr]: (a, b) => new number_1.default(a.toInt() | b.toInt()),
|
|
39
|
+
[greyscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.default(a.toNumber() < b.toNumber()),
|
|
40
|
+
[greyscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.default(a.toNumber() > b.toNumber()),
|
|
41
|
+
[greyscript_core_1.Operator.LeftShift]: (a, b) => new number_1.default(a.toInt() << b.toInt()),
|
|
42
|
+
[greyscript_core_1.Operator.RightShift]: (a, b) => new number_1.default(a.toInt() >> b.toInt()),
|
|
43
|
+
[greyscript_core_1.Operator.UnsignedRightShift]: (a, b) => new number_1.default(a.toInt() >> b.toInt()),
|
|
44
|
+
[greyscript_core_1.Operator.BitwiseAnd]: (a, b) => new number_1.default(a.toInt() & b.toInt()),
|
|
45
|
+
[greyscript_core_1.Operator.PercentSign]: (a, b) => new number_1.default(a.toNumber() % b.toNumber()),
|
|
46
|
+
[greyscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.default(a.toNumber() >= b.toNumber()),
|
|
47
|
+
[greyscript_core_1.Operator.Equal]: (a, b) => new boolean_1.default(a.toNumber() === b.toNumber()),
|
|
48
|
+
[greyscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.default(a.toNumber() <= b.toNumber()),
|
|
49
|
+
[greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.default(a.toNumber() !== b.toNumber())
|
|
50
|
+
};
|
|
51
|
+
const multiplyString = (a, b) => {
|
|
52
|
+
const multiStr = new Array(b.toNumber()).fill(a.toString()).join('');
|
|
108
53
|
return new string_1.default(multiStr);
|
|
109
54
|
};
|
|
110
55
|
exports.multiplyString = multiplyString;
|
|
111
|
-
exports.StringProcessorHandler =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
_d[greyscript_core_1.Operator.Equal] = function (a, b) { return new boolean_1.default(a.toString() === b.toString()); },
|
|
124
|
-
_d[greyscript_core_1.Operator.LessThanOrEqual] = function (a, b) {
|
|
125
|
-
return new boolean_1.default(a.toString().length <= b.toString().length);
|
|
126
|
-
},
|
|
127
|
-
_d[greyscript_core_1.Operator.NotEqual] = function (a, b) {
|
|
128
|
-
return new boolean_1.default(a.toString() !== b.toString());
|
|
129
|
-
},
|
|
130
|
-
_d);
|
|
131
|
-
exports.ListProcessorHandler = (_e = {},
|
|
132
|
-
_e[greyscript_core_1.Operator.Plus] = function (left, right) {
|
|
56
|
+
exports.StringProcessorHandler = {
|
|
57
|
+
[greyscript_core_1.Operator.Plus]: (a, b) => new string_1.default(a.toString() + b.toString()),
|
|
58
|
+
[greyscript_core_1.Operator.Asterik]: (a, b) => (0, exports.multiplyString)(a, b),
|
|
59
|
+
[greyscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.default(a.toString().length < b.toString().length),
|
|
60
|
+
[greyscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.default(a.toString().length > b.toString().length),
|
|
61
|
+
[greyscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.default(a.toString().length >= b.toString().length),
|
|
62
|
+
[greyscript_core_1.Operator.Equal]: (a, b) => new boolean_1.default(a.toString() === b.toString()),
|
|
63
|
+
[greyscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.default(a.toString().length <= b.toString().length),
|
|
64
|
+
[greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.default(a.toString() !== b.toString())
|
|
65
|
+
};
|
|
66
|
+
exports.ListProcessorHandler = {
|
|
67
|
+
[greyscript_core_1.Operator.Plus]: (left, right) => {
|
|
133
68
|
if (right instanceof list_1.default) {
|
|
134
69
|
return left.fork().extend(right);
|
|
135
70
|
}
|
|
136
71
|
return left;
|
|
137
72
|
},
|
|
138
|
-
|
|
73
|
+
[greyscript_core_1.Operator.LessThan]: (left, right) => {
|
|
139
74
|
if (right instanceof list_1.default) {
|
|
140
75
|
return new boolean_1.default(left.value.length < right.value.length);
|
|
141
76
|
}
|
|
142
77
|
return default_1.default.Void;
|
|
143
78
|
},
|
|
144
|
-
|
|
79
|
+
[greyscript_core_1.Operator.GreaterThan]: (left, right) => {
|
|
145
80
|
if (right instanceof list_1.default) {
|
|
146
81
|
return new boolean_1.default(left.value.length > right.value.length);
|
|
147
82
|
}
|
|
148
83
|
return default_1.default.Void;
|
|
149
84
|
},
|
|
150
|
-
|
|
85
|
+
[greyscript_core_1.Operator.GreaterThanOrEqual]: (left, right) => {
|
|
151
86
|
if (right instanceof list_1.default) {
|
|
152
87
|
return new boolean_1.default(left.value.length >= right.value.length);
|
|
153
88
|
}
|
|
154
89
|
return default_1.default.Void;
|
|
155
90
|
},
|
|
156
|
-
|
|
91
|
+
[greyscript_core_1.Operator.Equal]: (left, right) => {
|
|
157
92
|
if (right instanceof list_1.default) {
|
|
158
93
|
return new boolean_1.default((0, deep_equal_1.default)(left, right));
|
|
159
94
|
}
|
|
160
95
|
return default_1.default.Void;
|
|
161
96
|
},
|
|
162
|
-
|
|
97
|
+
[greyscript_core_1.Operator.LessThanOrEqual]: (left, right) => {
|
|
163
98
|
if (right instanceof list_1.default) {
|
|
164
99
|
return new boolean_1.default(left.value.length <= right.value.length);
|
|
165
100
|
}
|
|
166
101
|
return default_1.default.Void;
|
|
167
102
|
},
|
|
168
|
-
|
|
103
|
+
[greyscript_core_1.Operator.NotEqual]: (left, right) => {
|
|
169
104
|
if (right instanceof list_1.default) {
|
|
170
105
|
return new boolean_1.default(!(0, deep_equal_1.default)(left, right));
|
|
171
106
|
}
|
|
172
107
|
return default_1.default.Void;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
exports.MapProcessorHandler =
|
|
176
|
-
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
exports.MapProcessorHandler = {
|
|
111
|
+
[greyscript_core_1.Operator.Plus]: (left, right) => {
|
|
177
112
|
if (right instanceof map_1.default) {
|
|
178
113
|
return left.fork().extend(right);
|
|
179
114
|
}
|
|
180
115
|
return left;
|
|
181
116
|
},
|
|
182
|
-
|
|
117
|
+
[greyscript_core_1.Operator.LessThan]: (left, right) => {
|
|
183
118
|
if (right instanceof map_1.default) {
|
|
184
119
|
return new boolean_1.default(left.value.size < right.value.size);
|
|
185
120
|
}
|
|
186
121
|
return default_1.default.Void;
|
|
187
122
|
},
|
|
188
|
-
|
|
123
|
+
[greyscript_core_1.Operator.GreaterThan]: (left, right) => {
|
|
189
124
|
if (right instanceof map_1.default) {
|
|
190
125
|
return new boolean_1.default(left.value.size > right.value.size);
|
|
191
126
|
}
|
|
192
127
|
return default_1.default.Void;
|
|
193
128
|
},
|
|
194
|
-
|
|
129
|
+
[greyscript_core_1.Operator.GreaterThanOrEqual]: (left, right) => {
|
|
195
130
|
if (right instanceof map_1.default) {
|
|
196
131
|
return new boolean_1.default(left.value.size >= right.value.size);
|
|
197
132
|
}
|
|
198
133
|
return default_1.default.Void;
|
|
199
134
|
},
|
|
200
|
-
|
|
135
|
+
[greyscript_core_1.Operator.Equal]: (left, right) => {
|
|
201
136
|
if (right instanceof map_1.default) {
|
|
202
137
|
return new boolean_1.default((0, deep_equal_1.default)(left, right));
|
|
203
138
|
}
|
|
204
139
|
return default_1.default.Void;
|
|
205
140
|
},
|
|
206
|
-
|
|
141
|
+
[greyscript_core_1.Operator.LessThanOrEqual]: (left, right) => {
|
|
207
142
|
if (right instanceof map_1.default) {
|
|
208
143
|
return new boolean_1.default(left.value.size <= right.value.size);
|
|
209
144
|
}
|
|
210
145
|
return default_1.default.Void;
|
|
211
146
|
},
|
|
212
|
-
|
|
147
|
+
[greyscript_core_1.Operator.NotEqual]: (left, right) => {
|
|
213
148
|
if (right instanceof map_1.default) {
|
|
214
149
|
return new boolean_1.default(!(0, deep_equal_1.default)(left, right));
|
|
215
150
|
}
|
|
216
151
|
return default_1.default.Void;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
exports.InterfaceProcessorHandler =
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
exports.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
_j[greyscript_core_1.Operator.Equal] = function (a, b) { return new boolean_1.default(a === b); },
|
|
233
|
-
_j[greyscript_core_1.Operator.NotEqual] = function (a, b) { return new boolean_1.default(a !== b); },
|
|
234
|
-
_j);
|
|
235
|
-
var handleNumber = function (op, a, b) {
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
exports.InterfaceProcessorHandler = {
|
|
155
|
+
[greyscript_core_1.Operator.Equal]: (left, right) => new boolean_1.default(left.value === right.value),
|
|
156
|
+
[greyscript_core_1.Operator.NotEqual]: (left, right) => new boolean_1.default(left.value !== right.value)
|
|
157
|
+
};
|
|
158
|
+
exports.NilProcessorHandler = {
|
|
159
|
+
[greyscript_core_1.Operator.Equal]: (_a, b) => new boolean_1.default(b instanceof nil_1.default),
|
|
160
|
+
[greyscript_core_1.Operator.NotEqual]: (_a, b) => new boolean_1.default(!(b instanceof nil_1.default))
|
|
161
|
+
};
|
|
162
|
+
exports.FunctionProcessorHandler = {
|
|
163
|
+
[greyscript_core_1.Operator.Equal]: (a, b) => new boolean_1.default(a === b),
|
|
164
|
+
[greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.default(a !== b)
|
|
165
|
+
};
|
|
166
|
+
const handleNumber = (op, a, b) => {
|
|
236
167
|
if (op in exports.NumberProcessorHandler) {
|
|
237
168
|
return exports.NumberProcessorHandler[op](a, b);
|
|
238
169
|
}
|
|
@@ -242,7 +173,7 @@ var handleNumber = function (op, a, b) {
|
|
|
242
173
|
return default_1.default.Void;
|
|
243
174
|
};
|
|
244
175
|
exports.handleNumber = handleNumber;
|
|
245
|
-
|
|
176
|
+
const handleString = (op, a, b) => {
|
|
246
177
|
if (op in exports.StringProcessorHandler) {
|
|
247
178
|
return exports.StringProcessorHandler[op](a, b);
|
|
248
179
|
}
|
|
@@ -252,9 +183,9 @@ var handleString = function (op, a, b) {
|
|
|
252
183
|
return default_1.default.Void;
|
|
253
184
|
};
|
|
254
185
|
exports.handleString = handleString;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
186
|
+
const handleList = (op, a, b) => {
|
|
187
|
+
const left = a;
|
|
188
|
+
const right = b;
|
|
258
189
|
if (op in exports.ListProcessorHandler) {
|
|
259
190
|
return exports.ListProcessorHandler[op](left, right);
|
|
260
191
|
}
|
|
@@ -264,9 +195,9 @@ var handleList = function (op, a, b) {
|
|
|
264
195
|
return default_1.default.Void;
|
|
265
196
|
};
|
|
266
197
|
exports.handleList = handleList;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
198
|
+
const handleMap = (op, a, b) => {
|
|
199
|
+
const left = a;
|
|
200
|
+
const right = b;
|
|
270
201
|
if (op in exports.MapProcessorHandler) {
|
|
271
202
|
return exports.MapProcessorHandler[op](left, right);
|
|
272
203
|
}
|
|
@@ -276,9 +207,9 @@ var handleMap = function (op, a, b) {
|
|
|
276
207
|
return default_1.default.Void;
|
|
277
208
|
};
|
|
278
209
|
exports.handleMap = handleMap;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
210
|
+
const handleInterface = (op, a, b) => {
|
|
211
|
+
const left = a;
|
|
212
|
+
const right = b;
|
|
282
213
|
if (op in exports.InterfaceProcessorHandler) {
|
|
283
214
|
return exports.InterfaceProcessorHandler[op](left, right);
|
|
284
215
|
}
|
|
@@ -288,7 +219,7 @@ var handleInterface = function (op, a, b) {
|
|
|
288
219
|
return default_1.default.Void;
|
|
289
220
|
};
|
|
290
221
|
exports.handleInterface = handleInterface;
|
|
291
|
-
|
|
222
|
+
const handleNil = (op, a, b) => {
|
|
292
223
|
if (op in exports.NilProcessorHandler) {
|
|
293
224
|
return exports.NilProcessorHandler[op](a, b);
|
|
294
225
|
}
|
|
@@ -298,7 +229,7 @@ var handleNil = function (op, a, b) {
|
|
|
298
229
|
return default_1.default.Void;
|
|
299
230
|
};
|
|
300
231
|
exports.handleNil = handleNil;
|
|
301
|
-
|
|
232
|
+
const handleFunction = (op, a, b) => {
|
|
302
233
|
if (op in exports.FunctionProcessorHandler) {
|
|
303
234
|
return exports.FunctionProcessorHandler[op](a, b);
|
|
304
235
|
}
|
|
@@ -308,7 +239,7 @@ var handleFunction = function (op, a, b) {
|
|
|
308
239
|
return default_1.default.Void;
|
|
309
240
|
};
|
|
310
241
|
exports.handleFunction = handleFunction;
|
|
311
|
-
|
|
242
|
+
const handle = (op, a, b) => {
|
|
312
243
|
if (a instanceof boolean_1.default) {
|
|
313
244
|
a = new number_1.default(a.toInt());
|
|
314
245
|
}
|
|
@@ -318,7 +249,8 @@ var handle = function (op, a, b) {
|
|
|
318
249
|
if (op === greyscript_core_1.Operator.Equal && a.getCustomType() !== b.getCustomType()) {
|
|
319
250
|
return default_1.default.False;
|
|
320
251
|
}
|
|
321
|
-
else if (op === greyscript_core_1.Operator.NotEqual &&
|
|
252
|
+
else if (op === greyscript_core_1.Operator.NotEqual &&
|
|
253
|
+
a.getCustomType() !== b.getCustomType()) {
|
|
322
254
|
return default_1.default.True;
|
|
323
255
|
}
|
|
324
256
|
if (a instanceof string_1.default || b instanceof string_1.default) {
|
|
@@ -345,94 +277,58 @@ var handle = function (op, a, b) {
|
|
|
345
277
|
return default_1.default.Void;
|
|
346
278
|
};
|
|
347
279
|
exports.handle = handle;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
case 0:
|
|
361
|
-
this.type = this.item.type;
|
|
362
|
-
this.op = this.item.operator;
|
|
363
|
-
_b = this;
|
|
364
|
-
return [4 /*yield*/, visit(this.item.left)];
|
|
365
|
-
case 1:
|
|
366
|
-
_b.left = _d.sent();
|
|
367
|
-
_c = this;
|
|
368
|
-
return [4 /*yield*/, visit(this.item.right)];
|
|
369
|
-
case 2:
|
|
370
|
-
_c.right = _d.sent();
|
|
371
|
-
return [2 /*return*/, this];
|
|
372
|
-
}
|
|
373
|
-
});
|
|
280
|
+
class Evaluate extends operation_1.default {
|
|
281
|
+
constructor(item, target) {
|
|
282
|
+
super(null, target);
|
|
283
|
+
this.item = item;
|
|
284
|
+
}
|
|
285
|
+
build(visit) {
|
|
286
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
+
this.type = this.item.type;
|
|
288
|
+
this.op = this.item.operator;
|
|
289
|
+
this.left = yield visit(this.item.left);
|
|
290
|
+
this.right = yield visit(this.item.right);
|
|
291
|
+
return this;
|
|
374
292
|
});
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
case 0: return [4 /*yield*/, this.resolve(ctx, expr.left)];
|
|
382
|
-
case 1:
|
|
383
|
-
left = _b.sent();
|
|
384
|
-
return [4 /*yield*/, this.resolve(ctx, expr.right)];
|
|
385
|
-
case 2:
|
|
386
|
-
right = _b.sent();
|
|
387
|
-
return [2 /*return*/, (0, exports.handle)(expr.op, left, right)];
|
|
388
|
-
}
|
|
389
|
-
});
|
|
293
|
+
}
|
|
294
|
+
resolveBinaryExpression(ctx, expr) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
296
|
+
const left = yield this.resolve(ctx, expr.left);
|
|
297
|
+
const right = yield this.resolve(ctx, expr.right);
|
|
298
|
+
return (0, exports.handle)(expr.op, left, right);
|
|
390
299
|
});
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
else if (expr.op === greyscript_core_1.Operator.Or && left.toTruthy()) {
|
|
404
|
-
return [2 /*return*/, new boolean_1.default(true)];
|
|
405
|
-
}
|
|
406
|
-
return [4 /*yield*/, this.resolve(ctx, expr.right)];
|
|
407
|
-
case 2:
|
|
408
|
-
right = _b.sent();
|
|
409
|
-
return [2 /*return*/, (0, exports.handle)(expr.op, left, right)];
|
|
410
|
-
}
|
|
411
|
-
});
|
|
300
|
+
}
|
|
301
|
+
resolveLogicalExpression(ctx, expr) {
|
|
302
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
const left = yield this.resolve(ctx, expr.left);
|
|
304
|
+
if (expr.op === greyscript_core_1.Operator.And && !left.toTruthy()) {
|
|
305
|
+
return new boolean_1.default(false);
|
|
306
|
+
}
|
|
307
|
+
else if (expr.op === greyscript_core_1.Operator.Or && left.toTruthy()) {
|
|
308
|
+
return new boolean_1.default(true);
|
|
309
|
+
}
|
|
310
|
+
const right = yield this.resolve(ctx, expr.right);
|
|
311
|
+
return (0, exports.handle)(expr.op, left, right);
|
|
412
312
|
});
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
default:
|
|
426
|
-
break;
|
|
427
|
-
}
|
|
313
|
+
}
|
|
314
|
+
resolve(ctx, op) {
|
|
315
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
316
|
+
if (op instanceof Evaluate) {
|
|
317
|
+
const expr = op;
|
|
318
|
+
switch (expr.type) {
|
|
319
|
+
case greyscript_core_1.ASTType.BinaryExpression:
|
|
320
|
+
return this.resolveBinaryExpression(ctx, expr);
|
|
321
|
+
case greyscript_core_1.ASTType.LogicalExpression:
|
|
322
|
+
return this.resolveLogicalExpression(ctx, expr);
|
|
323
|
+
default:
|
|
324
|
+
break;
|
|
428
325
|
}
|
|
429
|
-
|
|
430
|
-
|
|
326
|
+
}
|
|
327
|
+
return op.handle(ctx);
|
|
431
328
|
});
|
|
432
|
-
}
|
|
433
|
-
|
|
329
|
+
}
|
|
330
|
+
handle(ctx) {
|
|
434
331
|
return this.resolve(ctx, this);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
}(operation_1.default));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
438
334
|
exports.default = Evaluate;
|
package/dist/operations/for.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ASTForGenericStatement, ASTIdentifier } from 'greyscript-core';
|
|
2
2
|
import context from '../context';
|
|
3
|
-
import
|
|
3
|
+
import CustomValue from '../types/base';
|
|
4
4
|
import Block from './block';
|
|
5
5
|
import Operation, { CPSVisit } from './operation';
|
|
6
6
|
export default class For extends Operation {
|