greybel-interpreter 2.2.2 → 2.2.4
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/interpreter.js
CHANGED
|
@@ -17,6 +17,7 @@ const cps_1 = require("./cps");
|
|
|
17
17
|
const handler_container_1 = require("./handler-container");
|
|
18
18
|
const noop_1 = require("./operations/noop");
|
|
19
19
|
const default_1 = require("./types/default");
|
|
20
|
+
const function_1 = require("./types/function");
|
|
20
21
|
const list_1 = require("./types/list");
|
|
21
22
|
const map_1 = require("./types/map");
|
|
22
23
|
const number_1 = require("./types/number");
|
|
@@ -148,10 +149,12 @@ class Interpreter extends events_1.EventEmitter {
|
|
|
148
149
|
const numberIntrinsics = map_1.CustomMap.createWithInitialValue(number_1.CustomNumber.intrinsics);
|
|
149
150
|
const listIntrinsics = map_1.CustomMap.createWithInitialValue(list_1.CustomList.intrinsics);
|
|
150
151
|
const mapIntrinsics = map_1.CustomMap.createWithInitialValue(map_1.CustomMap.intrinsics);
|
|
152
|
+
const funcRefIntrinsics = map_1.CustomMap.createWithInitialValue(function_1.CustomFunction.intrinsics);
|
|
151
153
|
this.apiContext.set(new string_1.CustomString('string'), stringIntrinsics);
|
|
152
154
|
this.apiContext.set(new string_1.CustomString('number'), numberIntrinsics);
|
|
153
155
|
this.apiContext.set(new string_1.CustomString('list'), listIntrinsics);
|
|
154
156
|
this.apiContext.set(new string_1.CustomString('map'), mapIntrinsics);
|
|
157
|
+
this.apiContext.set(new string_1.CustomString('funcRef'), funcRefIntrinsics);
|
|
155
158
|
this.apiContext.extend(this.api);
|
|
156
159
|
const newParams = new list_1.CustomList(this.params.map((item) => new string_1.CustomString(item)));
|
|
157
160
|
this.globalContext.scope.set(exports.PARAMS_PROPERTY, newParams);
|
|
@@ -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/function.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OperationContext } from '../context';
|
|
2
2
|
import { Operation } from '../operations/operation';
|
|
3
|
+
import { ObjectValue } from '../utils/object-value';
|
|
3
4
|
import { CustomValue } from './base';
|
|
4
5
|
import { CustomMap } from './map';
|
|
5
6
|
export interface Callback {
|
|
@@ -15,6 +16,7 @@ export declare class Argument {
|
|
|
15
16
|
constructor(name: string, defaultValue?: Operation | CustomValue);
|
|
16
17
|
}
|
|
17
18
|
export declare class CustomFunction extends CustomValue {
|
|
19
|
+
static readonly intrinsics: ObjectValue;
|
|
18
20
|
readonly scope?: OperationContext;
|
|
19
21
|
readonly name: string;
|
|
20
22
|
readonly value: Callback;
|
package/dist/types/function.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.CustomFunction = exports.Argument = exports.SUPER_NAMESPACE = exports.SE
|
|
|
13
13
|
const context_1 = require("../context");
|
|
14
14
|
const operation_1 = require("../operations/operation");
|
|
15
15
|
const reference_1 = require("../operations/reference");
|
|
16
|
+
const object_value_1 = require("../utils/object-value");
|
|
16
17
|
const base_1 = require("./base");
|
|
17
18
|
const default_1 = require("./default");
|
|
18
19
|
const map_1 = require("./map");
|
|
@@ -82,7 +83,7 @@ class CustomFunction extends base_1.CustomValue {
|
|
|
82
83
|
return true;
|
|
83
84
|
}
|
|
84
85
|
instanceOf(v) {
|
|
85
|
-
return v
|
|
86
|
+
return v.value === CustomFunction.intrinsics;
|
|
86
87
|
}
|
|
87
88
|
run(self, args, callContext, next) {
|
|
88
89
|
var _a;
|
|
@@ -122,4 +123,5 @@ class CustomFunction extends base_1.CustomValue {
|
|
|
122
123
|
});
|
|
123
124
|
}
|
|
124
125
|
}
|
|
126
|
+
CustomFunction.intrinsics = new object_value_1.ObjectValue();
|
|
125
127
|
exports.CustomFunction = CustomFunction;
|
package/dist/types/nil.js
CHANGED