greybel-interpreter 2.2.2 → 2.2.3
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.
|
@@ -3,6 +3,7 @@ import { OperationContext } from '../context';
|
|
|
3
3
|
import { CustomValue } from '../types/base';
|
|
4
4
|
import { CustomBoolean } from '../types/boolean';
|
|
5
5
|
import { CustomList } from '../types/list';
|
|
6
|
+
import { CustomNumber } from '../types/number';
|
|
6
7
|
import { CustomString } from '../types/string';
|
|
7
8
|
import { CPSVisit, Operation } from './operation';
|
|
8
9
|
export interface ProcessorHandlerFunction {
|
|
@@ -17,8 +18,8 @@ export declare const minusString: (a: CustomString, b: CustomValue) => CustomVal
|
|
|
17
18
|
export declare const multiplyString: (a: CustomString, b: CustomValue) => CustomValue;
|
|
18
19
|
export declare const divideString: (a: CustomString, b: CustomValue) => CustomValue;
|
|
19
20
|
export declare const StringProcessorHandler: ProcessorHandler;
|
|
20
|
-
export declare const multiplyList: (a: CustomList, b:
|
|
21
|
-
export declare const divideList: (a: CustomList, b:
|
|
21
|
+
export declare const multiplyList: (a: CustomList, b: CustomNumber) => CustomValue;
|
|
22
|
+
export declare const divideList: (a: CustomList, b: CustomNumber) => CustomValue;
|
|
22
23
|
export declare const ListProcessorHandler: ProcessorHandler;
|
|
23
24
|
export declare const MapProcessorHandler: ProcessorHandler;
|
|
24
25
|
export declare const InterfaceProcessorHandler: ProcessorHandler;
|
|
@@ -123,7 +123,7 @@ exports.ListProcessorHandler = {
|
|
|
123
123
|
if (right instanceof list_1.CustomList) {
|
|
124
124
|
return left.fork().extend(right);
|
|
125
125
|
}
|
|
126
|
-
return
|
|
126
|
+
return default_1.DefaultType.Void;
|
|
127
127
|
},
|
|
128
128
|
[greyscript_core_1.Operator.Equal]: (left, right) => {
|
|
129
129
|
if (right instanceof list_1.CustomList) {
|
|
@@ -137,15 +137,25 @@ exports.ListProcessorHandler = {
|
|
|
137
137
|
}
|
|
138
138
|
return default_1.DefaultType.Void;
|
|
139
139
|
},
|
|
140
|
-
[greyscript_core_1.Operator.Asterik]: (left, right) =>
|
|
141
|
-
|
|
140
|
+
[greyscript_core_1.Operator.Asterik]: (left, right) => {
|
|
141
|
+
if (right instanceof number_1.CustomNumber) {
|
|
142
|
+
return (0, exports.multiplyList)(left, right);
|
|
143
|
+
}
|
|
144
|
+
return default_1.DefaultType.Void;
|
|
145
|
+
},
|
|
146
|
+
[greyscript_core_1.Operator.Slash]: (left, right) => {
|
|
147
|
+
if (right instanceof number_1.CustomNumber) {
|
|
148
|
+
return (0, exports.divideList)(left, right);
|
|
149
|
+
}
|
|
150
|
+
return default_1.DefaultType.Void;
|
|
151
|
+
}
|
|
142
152
|
};
|
|
143
153
|
exports.MapProcessorHandler = {
|
|
144
154
|
[greyscript_core_1.Operator.Plus]: (left, right) => {
|
|
145
155
|
if (right instanceof map_1.CustomMap) {
|
|
146
156
|
return left.fork().extend(right);
|
|
147
157
|
}
|
|
148
|
-
return
|
|
158
|
+
return default_1.DefaultType.Void;
|
|
149
159
|
},
|
|
150
160
|
[greyscript_core_1.Operator.Equal]: (left, right) => {
|
|
151
161
|
if (right instanceof map_1.CustomMap) {
|
|
@@ -165,6 +175,12 @@ exports.InterfaceProcessorHandler = {
|
|
|
165
175
|
[greyscript_core_1.Operator.NotEqual]: (left, right) => new boolean_1.CustomBoolean(left.value !== right.value)
|
|
166
176
|
};
|
|
167
177
|
exports.NilProcessorHandler = {
|
|
178
|
+
[greyscript_core_1.Operator.Plus]: () => default_1.DefaultType.Void,
|
|
179
|
+
[greyscript_core_1.Operator.Minus]: () => default_1.DefaultType.Void,
|
|
180
|
+
[greyscript_core_1.Operator.Slash]: () => default_1.DefaultType.Void,
|
|
181
|
+
[greyscript_core_1.Operator.Asterik]: () => default_1.DefaultType.Void,
|
|
182
|
+
[greyscript_core_1.Operator.Power]: () => default_1.DefaultType.Void,
|
|
183
|
+
[greyscript_core_1.Operator.PercentSign]: () => default_1.DefaultType.Void,
|
|
168
184
|
[greyscript_core_1.Operator.Equal]: (_a, b) => new boolean_1.CustomBoolean(b instanceof nil_1.CustomNil),
|
|
169
185
|
[greyscript_core_1.Operator.NotEqual]: (_a, b) => new boolean_1.CustomBoolean(!(b instanceof nil_1.CustomNil))
|
|
170
186
|
};
|
|
@@ -173,9 +189,8 @@ exports.FunctionProcessorHandler = {
|
|
|
173
189
|
[greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.CustomBoolean(a !== b)
|
|
174
190
|
};
|
|
175
191
|
const handleNumber = (op, a, b) => {
|
|
176
|
-
if (b instanceof nil_1.CustomNil)
|
|
192
|
+
if (b instanceof nil_1.CustomNil)
|
|
177
193
|
b = new number_1.CustomNumber(0);
|
|
178
|
-
}
|
|
179
194
|
if (op in exports.NumberProcessorHandler && b instanceof number_1.CustomNumber) {
|
|
180
195
|
return exports.NumberProcessorHandler[op](a, b);
|
|
181
196
|
}
|
|
@@ -186,6 +201,10 @@ const handleNumber = (op, a, b) => {
|
|
|
186
201
|
};
|
|
187
202
|
exports.handleNumber = handleNumber;
|
|
188
203
|
const handleString = (op, a, b) => {
|
|
204
|
+
if (a instanceof nil_1.CustomNil)
|
|
205
|
+
a = new string_1.CustomString('');
|
|
206
|
+
if (b instanceof nil_1.CustomNil)
|
|
207
|
+
b = new string_1.CustomString('');
|
|
189
208
|
if (op in exports.StringProcessorHandler) {
|
|
190
209
|
return exports.StringProcessorHandler[op](a, b);
|
|
191
210
|
}
|
|
@@ -196,10 +215,8 @@ const handleString = (op, a, b) => {
|
|
|
196
215
|
};
|
|
197
216
|
exports.handleString = handleString;
|
|
198
217
|
const handleList = (op, a, b) => {
|
|
199
|
-
const left = a;
|
|
200
|
-
const right = b;
|
|
201
218
|
if (op in exports.ListProcessorHandler) {
|
|
202
|
-
return exports.ListProcessorHandler[op](
|
|
219
|
+
return exports.ListProcessorHandler[op](a, b);
|
|
203
220
|
}
|
|
204
221
|
else if (op in exports.GenericProcessorHandler) {
|
|
205
222
|
return exports.GenericProcessorHandler[op](a, b);
|
|
@@ -208,10 +225,8 @@ const handleList = (op, a, b) => {
|
|
|
208
225
|
};
|
|
209
226
|
exports.handleList = handleList;
|
|
210
227
|
const handleMap = (op, a, b) => {
|
|
211
|
-
const left = a;
|
|
212
|
-
const right = b;
|
|
213
228
|
if (op in exports.MapProcessorHandler) {
|
|
214
|
-
return exports.MapProcessorHandler[op](
|
|
229
|
+
return exports.MapProcessorHandler[op](a, b);
|
|
215
230
|
}
|
|
216
231
|
else if (op in exports.GenericProcessorHandler) {
|
|
217
232
|
return exports.GenericProcessorHandler[op](a, b);
|
|
@@ -220,10 +235,8 @@ const handleMap = (op, a, b) => {
|
|
|
220
235
|
};
|
|
221
236
|
exports.handleMap = handleMap;
|
|
222
237
|
const handleInterface = (op, a, b) => {
|
|
223
|
-
const left = a;
|
|
224
|
-
const right = b;
|
|
225
238
|
if (op in exports.InterfaceProcessorHandler) {
|
|
226
|
-
return exports.InterfaceProcessorHandler[op](
|
|
239
|
+
return exports.InterfaceProcessorHandler[op](a, b);
|
|
227
240
|
}
|
|
228
241
|
else if (op in exports.GenericProcessorHandler) {
|
|
229
242
|
return exports.GenericProcessorHandler[op](a, b);
|
|
@@ -267,7 +280,7 @@ const handle = (op, a, b) => {
|
|
|
267
280
|
}
|
|
268
281
|
if ((a instanceof string_1.CustomString || b instanceof string_1.CustomString) &&
|
|
269
282
|
op === greyscript_core_1.Operator.Plus) {
|
|
270
|
-
return exports.
|
|
283
|
+
return (0, exports.handleString)(op, a, b);
|
|
271
284
|
}
|
|
272
285
|
else if (a instanceof number_1.CustomNumber) {
|
|
273
286
|
return (0, exports.handleNumber)(op, a, b);
|
package/dist/types/nil.js
CHANGED