affinirum 1.3.1 → 1.4.0
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/README.md +156 -126
- package/dst/Affinirum.d.ts +1 -1
- package/dst/Affinirum.js +43 -47
- package/dst/ParserState.js +2 -2
- package/dst/atom/ArrayAtom.d.ts +3 -3
- package/dst/atom/ArrayAtom.js +14 -13
- package/dst/atom/FunctionAtom.d.ts +1 -1
- package/dst/atom/FunctionAtom.js +10 -8
- package/dst/atom/ObjectAtom.d.ts +3 -3
- package/dst/atom/ObjectAtom.js +14 -18
- package/dst/atom/PrimitiveAtom.js +3 -3
- package/dst/cjs/Affinirum.js +43 -47
- package/dst/cjs/ParserState.js +2 -2
- package/dst/cjs/atom/ArrayAtom.js +14 -13
- package/dst/cjs/atom/FunctionAtom.js +10 -8
- package/dst/cjs/atom/ObjectAtom.js +14 -18
- package/dst/cjs/atom/PrimitiveAtom.js +3 -3
- package/dst/cjs/node/ArrayNode.js +7 -3
- package/dst/cjs/node/{FunctionNode.js → CallNode.js} +5 -4
- package/dst/cjs/node/ObjectNode.js +4 -2
- package/dst/node/ArrayNode.d.ts +2 -1
- package/dst/node/ArrayNode.js +7 -3
- package/dst/node/{FunctionNode.d.ts → CallNode.d.ts} +1 -1
- package/dst/node/{FunctionNode.js → CallNode.js} +3 -2
- package/dst/node/ObjectNode.d.ts +1 -1
- package/dst/node/ObjectNode.js +4 -2
- package/package.json +1 -1
package/dst/cjs/Affinirum.js
CHANGED
|
@@ -15,8 +15,8 @@ const Constants_js_1 = require("./Constants.js");
|
|
|
15
15
|
const Functions_js_1 = require("./Functions.js");
|
|
16
16
|
const ArrayNode_js_1 = require("./node/ArrayNode.js");
|
|
17
17
|
const BlockNode_js_1 = require("./node/BlockNode.js");
|
|
18
|
+
const CallNode_js_1 = require("./node/CallNode.js");
|
|
18
19
|
const ConstantNode_js_1 = require("./node/ConstantNode.js");
|
|
19
|
-
const FunctionNode_js_1 = require("./node/FunctionNode.js");
|
|
20
20
|
const JumpNode_js_1 = require("./node/JumpNode.js");
|
|
21
21
|
const LoopNode_js_1 = require("./node/LoopNode.js");
|
|
22
22
|
const ObjectNode_js_1 = require("./node/ObjectNode.js");
|
|
@@ -30,7 +30,7 @@ class Affinirum {
|
|
|
30
30
|
_script;
|
|
31
31
|
_strict;
|
|
32
32
|
_root;
|
|
33
|
-
|
|
33
|
+
_varframes = new Map();
|
|
34
34
|
_variables = new Map();
|
|
35
35
|
_constants = new Map(Constants_js_1.Constants);
|
|
36
36
|
_functions = new Map(Functions_js_1.Functions);
|
|
@@ -97,12 +97,12 @@ class Affinirum {
|
|
|
97
97
|
const variables = this._scope.variables();
|
|
98
98
|
for (const name in variables) {
|
|
99
99
|
if (!Object.prototype.hasOwnProperty.call(values, name)) {
|
|
100
|
-
this.
|
|
100
|
+
this._varframes.get(name)?.throwError(`undefined variable ${name}:\n`);
|
|
101
101
|
}
|
|
102
102
|
const variable = variables[name];
|
|
103
103
|
const value = values?.[name] ?? undefined;
|
|
104
104
|
if (!variable.type.match(Type_js_1.Type.of(value))) {
|
|
105
|
-
this.
|
|
105
|
+
this._varframes.get(name)?.throwError(`unexpected type ${Type_js_1.Type.of(value)} for variable ${name} of type ${variable.type}:\n`);
|
|
106
106
|
}
|
|
107
107
|
variable.value = value;
|
|
108
108
|
}
|
|
@@ -151,7 +151,7 @@ class Affinirum {
|
|
|
151
151
|
let node = this._disjunction(state, scope);
|
|
152
152
|
while (state.operator === Unknown_js_1.funcCoalesce) {
|
|
153
153
|
const fnode = new ConstantNode_js_1.ConstantNode(state, state.operator);
|
|
154
|
-
node = new
|
|
154
|
+
node = new CallNode_js_1.CallNode(state, fnode, [node, this._disjunction(state.next(), scope)]);
|
|
155
155
|
}
|
|
156
156
|
return node;
|
|
157
157
|
}
|
|
@@ -159,7 +159,7 @@ class Affinirum {
|
|
|
159
159
|
let node = this._conjunction(state, scope);
|
|
160
160
|
while (state.operator === Boolean_js_1.funcOr) {
|
|
161
161
|
const fnode = new ConstantNode_js_1.ConstantNode(state, state.operator);
|
|
162
|
-
node = new
|
|
162
|
+
node = new CallNode_js_1.CallNode(state, fnode, [node, this._conjunction(state.next(), scope)]);
|
|
163
163
|
}
|
|
164
164
|
return node;
|
|
165
165
|
}
|
|
@@ -167,7 +167,7 @@ class Affinirum {
|
|
|
167
167
|
let node = this._negation(state, scope);
|
|
168
168
|
while (state.operator === Boolean_js_1.funcAnd) {
|
|
169
169
|
const fnode = new ConstantNode_js_1.ConstantNode(state, state.operator);
|
|
170
|
-
node = new
|
|
170
|
+
node = new CallNode_js_1.CallNode(state, fnode, [node, this._negation(state.next(), scope)]);
|
|
171
171
|
}
|
|
172
172
|
return node;
|
|
173
173
|
}
|
|
@@ -182,7 +182,7 @@ class Affinirum {
|
|
|
182
182
|
let node = this._comparison(state, scope);
|
|
183
183
|
if (negate) {
|
|
184
184
|
const fnode = new ConstantNode_js_1.ConstantNode(frame, Boolean_js_1.funcNot);
|
|
185
|
-
node = new
|
|
185
|
+
node = new CallNode_js_1.CallNode(frame, fnode, [node]);
|
|
186
186
|
}
|
|
187
187
|
return node;
|
|
188
188
|
}
|
|
@@ -192,7 +192,7 @@ class Affinirum {
|
|
|
192
192
|
|| state.operator === Number_js_1.funcGreaterOrEqual || state.operator === Number_js_1.funcLessOrEqual
|
|
193
193
|
|| state.operator === Unknown_js_1.funcEqual || state.operator === Unknown_js_1.funcNotEqual) {
|
|
194
194
|
const fnode = new ConstantNode_js_1.ConstantNode(state, state.operator);
|
|
195
|
-
node = new
|
|
195
|
+
node = new CallNode_js_1.CallNode(state, fnode, [node, this._aggregate(state.next(), scope)]);
|
|
196
196
|
}
|
|
197
197
|
return node;
|
|
198
198
|
}
|
|
@@ -200,7 +200,7 @@ class Affinirum {
|
|
|
200
200
|
let node = this._product(state, scope);
|
|
201
201
|
while (state.operator === Aggregable_js_1.funcAdd || state.operator === Number_js_1.funcSubtract) {
|
|
202
202
|
const fnode = new ConstantNode_js_1.ConstantNode(state, state.operator);
|
|
203
|
-
node = new
|
|
203
|
+
node = new CallNode_js_1.CallNode(state, fnode, [node, this._product(state.next(), scope)]);
|
|
204
204
|
}
|
|
205
205
|
return node;
|
|
206
206
|
}
|
|
@@ -208,7 +208,7 @@ class Affinirum {
|
|
|
208
208
|
let node = this._signum(state, scope);
|
|
209
209
|
while (state.operator === Number_js_1.funcMultiply || state.operator === Number_js_1.funcDivide || state.operator === Number_js_1.funcRemainder) {
|
|
210
210
|
const fnode = new ConstantNode_js_1.ConstantNode(state, state.operator);
|
|
211
|
-
node = new
|
|
211
|
+
node = new CallNode_js_1.CallNode(state, fnode, [node, this._signum(state.next(), scope)]);
|
|
212
212
|
}
|
|
213
213
|
return node;
|
|
214
214
|
}
|
|
@@ -225,7 +225,7 @@ class Affinirum {
|
|
|
225
225
|
let node = this._factor(state, scope);
|
|
226
226
|
if (negate) {
|
|
227
227
|
const fnode = new ConstantNode_js_1.ConstantNode(frame, Number_js_1.funcNegate);
|
|
228
|
-
node = new
|
|
228
|
+
node = new CallNode_js_1.CallNode(frame, fnode, [node]);
|
|
229
229
|
}
|
|
230
230
|
return node;
|
|
231
231
|
}
|
|
@@ -233,7 +233,7 @@ class Affinirum {
|
|
|
233
233
|
let node = this._accessor(state, scope);
|
|
234
234
|
while (state.operator === Number_js_1.funcPower) {
|
|
235
235
|
const fnode = new ConstantNode_js_1.ConstantNode(state, state.operator);
|
|
236
|
-
node = new
|
|
236
|
+
node = new CallNode_js_1.CallNode(state, fnode, [node, this._accessor(state.next(), scope)]);
|
|
237
237
|
}
|
|
238
238
|
return node;
|
|
239
239
|
}
|
|
@@ -241,11 +241,11 @@ class Affinirum {
|
|
|
241
241
|
let node = this._term(state, scope);
|
|
242
242
|
while (state.isDot || state.isQuestion || state.isParenthesesOpen || state.isBracketsOpen) {
|
|
243
243
|
const frame = state.starts();
|
|
244
|
-
if (state.isDot || state.isQuestion) {
|
|
244
|
+
if (state.isDot || state.isQuestion) { // property access or property existance operator
|
|
245
245
|
const operator = state.isDot ? Iterable_js_1.funcAt : Iterable_js_1.funcHas;
|
|
246
246
|
if (state.next().isLiteral && (typeof state.literal.value === "string" || typeof state.literal.value === "bigint")) {
|
|
247
247
|
const fnode = new ConstantNode_js_1.ConstantNode(frame.ends(state), operator);
|
|
248
|
-
node = new
|
|
248
|
+
node = new CallNode_js_1.CallNode(frame, fnode, [node, new ConstantNode_js_1.ConstantNode(state, new Constant_js_1.Constant(state.literal.value))]);
|
|
249
249
|
state.next();
|
|
250
250
|
}
|
|
251
251
|
else if (state.isToken) {
|
|
@@ -260,17 +260,17 @@ class Affinirum {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
const fnode = new ConstantNode_js_1.ConstantNode(frame.ends(state), func);
|
|
263
|
-
node = new
|
|
263
|
+
node = new CallNode_js_1.CallNode(frame, fnode, subnodes);
|
|
264
264
|
state.closeParentheses().next();
|
|
265
265
|
}
|
|
266
266
|
else {
|
|
267
267
|
const fnode = new ConstantNode_js_1.ConstantNode(frame.ends(state), func);
|
|
268
|
-
node = new
|
|
268
|
+
node = new CallNode_js_1.CallNode(frame, fnode, [node]);
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
else {
|
|
272
272
|
const fnode = new ConstantNode_js_1.ConstantNode(frame.ends(), operator);
|
|
273
|
-
node = new
|
|
273
|
+
node = new CallNode_js_1.CallNode(frame, fnode, [node, new ConstantNode_js_1.ConstantNode(state, new Constant_js_1.Constant(state.token))]);
|
|
274
274
|
state.next();
|
|
275
275
|
}
|
|
276
276
|
}
|
|
@@ -278,7 +278,7 @@ class Affinirum {
|
|
|
278
278
|
state.throwError("missing array index or object key");
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
else if (state.isParenthesesOpen) {
|
|
281
|
+
else if (state.isParenthesesOpen) { // function call
|
|
282
282
|
const subnodes = [];
|
|
283
283
|
while (!state.next().isParenthesesClose) {
|
|
284
284
|
subnodes.push(this._unit(state, scope));
|
|
@@ -286,25 +286,25 @@ class Affinirum {
|
|
|
286
286
|
break;
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
node = new
|
|
289
|
+
node = new CallNode_js_1.CallNode(frame.ends(state), node, subnodes);
|
|
290
290
|
state.closeParentheses().next();
|
|
291
291
|
}
|
|
292
|
-
else if (state.isBracketsOpen) {
|
|
292
|
+
else if (state.isBracketsOpen) { // index access operator
|
|
293
293
|
const fnode = new ConstantNode_js_1.ConstantNode(frame, Iterable_js_1.funcAt);
|
|
294
|
-
node = new
|
|
294
|
+
node = new CallNode_js_1.CallNode(frame, fnode, [node, this._unit(state.next(), scope)]);
|
|
295
295
|
state.closeBrackets().next();
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
return node;
|
|
299
299
|
}
|
|
300
300
|
_term(state, scope) {
|
|
301
|
-
if (state.isLiteral) {
|
|
301
|
+
if (state.isLiteral) { // literal constant
|
|
302
302
|
const frame = state.starts();
|
|
303
303
|
const constant = new Constant_js_1.Constant(state.literal.value);
|
|
304
304
|
state.next();
|
|
305
305
|
return new ConstantNode_js_1.ConstantNode(frame, constant);
|
|
306
306
|
}
|
|
307
|
-
else if (state.isToken) {
|
|
307
|
+
else if (state.isToken) { // variable
|
|
308
308
|
const frame = state.starts();
|
|
309
309
|
const constants = this._constants.get(state.token);
|
|
310
310
|
if (constants != null) {
|
|
@@ -334,8 +334,8 @@ class Affinirum {
|
|
|
334
334
|
}
|
|
335
335
|
scope.global(state.token, variable);
|
|
336
336
|
}
|
|
337
|
-
if (!this.
|
|
338
|
-
this.
|
|
337
|
+
if (!this._varframes.has(state.token)) {
|
|
338
|
+
this._varframes.set(state.token, state.starts());
|
|
339
339
|
}
|
|
340
340
|
if (state.next().isAssignment) {
|
|
341
341
|
if (!variable.assignable) {
|
|
@@ -344,7 +344,7 @@ class Affinirum {
|
|
|
344
344
|
if (state.assignment.operator) {
|
|
345
345
|
const operator = state.assignment.operator;
|
|
346
346
|
const fnode = new ConstantNode_js_1.ConstantNode(frame, operator);
|
|
347
|
-
const subnode = new
|
|
347
|
+
const subnode = new CallNode_js_1.CallNode(frame, fnode, [new VariableNode_js_1.VariableNode(frame, variable), this._unit(state.next(), scope)]);
|
|
348
348
|
return new VariableNode_js_1.VariableNode(frame, variable, subnode);
|
|
349
349
|
}
|
|
350
350
|
else {
|
|
@@ -354,7 +354,7 @@ class Affinirum {
|
|
|
354
354
|
}
|
|
355
355
|
return new VariableNode_js_1.VariableNode(frame, variable);
|
|
356
356
|
}
|
|
357
|
-
else if (state.isBracesOpen) {
|
|
357
|
+
else if (state.isBracesOpen) { // code block
|
|
358
358
|
const frame = state.starts();
|
|
359
359
|
const subnodes = [];
|
|
360
360
|
while (!state.next().isBracesClose) {
|
|
@@ -370,7 +370,7 @@ class Affinirum {
|
|
|
370
370
|
else if (state.isBracesClose) {
|
|
371
371
|
state.throwError("unexpected closing braces");
|
|
372
372
|
}
|
|
373
|
-
else if (state.isParenthesesOpen) {
|
|
373
|
+
else if (state.isParenthesesOpen) { // unit grouping
|
|
374
374
|
const node = this._unit(state.next(), scope);
|
|
375
375
|
state.closeParentheses().next();
|
|
376
376
|
return node;
|
|
@@ -378,7 +378,7 @@ class Affinirum {
|
|
|
378
378
|
else if (state.isParenthesesClose) {
|
|
379
379
|
state.throwError("unexpected closing parentheses");
|
|
380
380
|
}
|
|
381
|
-
else if (state.isBracketsOpen) {
|
|
381
|
+
else if (state.isBracketsOpen) { // array or object
|
|
382
382
|
const frame = state.starts();
|
|
383
383
|
const subnodes = [];
|
|
384
384
|
let index = 0, colon = false;
|
|
@@ -410,7 +410,7 @@ class Affinirum {
|
|
|
410
410
|
else if (state.isBracketsClose) {
|
|
411
411
|
state.throwError("unexpected closing brackets");
|
|
412
412
|
}
|
|
413
|
-
else if (state.isVar || state.isVal) {
|
|
413
|
+
else if (state.isVar || state.isVal) { // variable declaration
|
|
414
414
|
const assignable = state.isVar;
|
|
415
415
|
if (!state.next().isToken) {
|
|
416
416
|
state.throwError("missing variable name");
|
|
@@ -465,12 +465,8 @@ class Affinirum {
|
|
|
465
465
|
state.throwError("unexpected expression token");
|
|
466
466
|
}
|
|
467
467
|
_function(state, scope) {
|
|
468
|
+
state.next().openParentheses();
|
|
468
469
|
const frame = state.starts();
|
|
469
|
-
let retType = Type_js_1.Type.Unknown;
|
|
470
|
-
if (!state.next().isParenthesesOpen) {
|
|
471
|
-
retType = this._type(state, scope);
|
|
472
|
-
state.openParentheses();
|
|
473
|
-
}
|
|
474
470
|
let variadic = false;
|
|
475
471
|
const variables = new Map();
|
|
476
472
|
while (!state.next().isParenthesesClose) {
|
|
@@ -502,10 +498,11 @@ class Affinirum {
|
|
|
502
498
|
break;
|
|
503
499
|
}
|
|
504
500
|
}
|
|
505
|
-
state.closeParentheses();
|
|
501
|
+
state.closeParentheses().next();
|
|
502
|
+
const retType = state.isColon ? this._type(state.next(), scope) : Type_js_1.Type.Unknown;
|
|
506
503
|
frame.ends(state);
|
|
507
504
|
const args = Array.from(variables.values());
|
|
508
|
-
const subnode = this._unit(state
|
|
505
|
+
const subnode = this._unit(state, scope.subscope(variables));
|
|
509
506
|
const func = (...values) => {
|
|
510
507
|
args.forEach((arg, ix) => arg.value = values[ix]);
|
|
511
508
|
return subnode.evaluate();
|
|
@@ -530,7 +527,7 @@ class Affinirum {
|
|
|
530
527
|
return new SwitchNode_js_1.SwitchNode(frame, cnode, [cthen, celse]);
|
|
531
528
|
}
|
|
532
529
|
_type(state, scope) {
|
|
533
|
-
if (state.isType) {
|
|
530
|
+
if (state.isType) { // literal type
|
|
534
531
|
let type = state.type;
|
|
535
532
|
if (state.next().isQuestion) {
|
|
536
533
|
type = type.toOptional();
|
|
@@ -564,11 +561,7 @@ class Affinirum {
|
|
|
564
561
|
: Type_js_1.Type.arrayType(itemKeyTypes.map(([, v]) => v));
|
|
565
562
|
}
|
|
566
563
|
else if (state.isTilda) { // function type
|
|
567
|
-
|
|
568
|
-
if (!state.next().isParenthesesOpen) {
|
|
569
|
-
retType = this._type(state, scope);
|
|
570
|
-
state.openParentheses();
|
|
571
|
-
}
|
|
564
|
+
state.next().openParentheses();
|
|
572
565
|
let variadic = false;
|
|
573
566
|
const argTypes = [];
|
|
574
567
|
while (!state.next().isParenthesesClose) {
|
|
@@ -591,11 +584,14 @@ class Affinirum {
|
|
|
591
584
|
}
|
|
592
585
|
}
|
|
593
586
|
state.closeParentheses().next();
|
|
594
|
-
|
|
595
|
-
retType = Type_js_1.Type.Unknown;
|
|
596
|
-
}
|
|
587
|
+
const retType = state.isColon ? this._type(state.next(), scope) : Type_js_1.Type.Unknown;
|
|
597
588
|
return Type_js_1.Type.functionType(retType, argTypes, variadic);
|
|
598
589
|
}
|
|
590
|
+
else if (state.isParenthesesOpen) { // type grouping
|
|
591
|
+
const type = this._type(state.next(), scope);
|
|
592
|
+
state.closeParentheses().next();
|
|
593
|
+
return type;
|
|
594
|
+
}
|
|
599
595
|
else {
|
|
600
596
|
state.throwError("missing type name");
|
|
601
597
|
}
|
package/dst/cjs/ParserState.js
CHANGED
|
@@ -384,7 +384,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
384
384
|
this._fragment = funcDivideAssignment;
|
|
385
385
|
break;
|
|
386
386
|
case "/":
|
|
387
|
-
if (this._expr.charAt(++this._end) ===
|
|
387
|
+
if (this._expr.charAt(++this._end) === "/") {
|
|
388
388
|
++this._end;
|
|
389
389
|
while (this._expr.charAt(this._end) !== ""
|
|
390
390
|
&& (this._expr.charAt(this._end) !== c
|
|
@@ -394,7 +394,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
|
394
394
|
}
|
|
395
395
|
if (this._end >= this._expr.length) {
|
|
396
396
|
this._start = this._expr.length;
|
|
397
|
-
throw new Error(
|
|
397
|
+
throw new Error("missing closing comment mark");
|
|
398
398
|
}
|
|
399
399
|
++this._end;
|
|
400
400
|
}
|
|
@@ -2,29 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArrayAtom = void 0;
|
|
4
4
|
class ArrayAtom {
|
|
5
|
-
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
5
|
+
_valTypes;
|
|
6
|
+
constructor(_valTypes = []) {
|
|
7
|
+
this._valTypes = _valTypes;
|
|
8
8
|
}
|
|
9
9
|
get _undefined() {
|
|
10
|
-
return this.
|
|
10
|
+
return this._valTypes.length === 0;
|
|
11
11
|
}
|
|
12
12
|
subtypes() {
|
|
13
|
-
return this.
|
|
13
|
+
return this._valTypes;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
return this.
|
|
15
|
+
valueType(index) {
|
|
16
|
+
return this._valTypes[index];
|
|
17
17
|
}
|
|
18
18
|
match(atom) {
|
|
19
19
|
if (atom instanceof ArrayAtom) {
|
|
20
20
|
if (this._undefined || atom._undefined) {
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < this._itemTypes.length; ++i) {
|
|
27
|
-
if (!this._itemTypes[i].match(atom._itemTypes[i])) {
|
|
23
|
+
for (let i = 0; i < this._valTypes.length; ++i) {
|
|
24
|
+
const vtype = atom.valueType(i);
|
|
25
|
+
if (!vtype || !this._valTypes[i].match(vtype)) {
|
|
28
26
|
return false;
|
|
29
27
|
}
|
|
30
28
|
}
|
|
@@ -36,7 +34,10 @@ class ArrayAtom {
|
|
|
36
34
|
return 0x10000 + this.subtypes().reduce((acc, i) => acc + i.weight(), 0);
|
|
37
35
|
}
|
|
38
36
|
toString() {
|
|
39
|
-
|
|
37
|
+
if (this._undefined) {
|
|
38
|
+
return "array";
|
|
39
|
+
}
|
|
40
|
+
return `[${this._valTypes.join(",")}]`;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
exports.ArrayAtom = ArrayAtom;
|
|
@@ -44,7 +44,7 @@ class FunctionAtom {
|
|
|
44
44
|
return this._argTypes.length;
|
|
45
45
|
}
|
|
46
46
|
argType(index) {
|
|
47
|
-
return this._argTypes[index] ?? this._argTypes[this._argTypes.length - 1]
|
|
47
|
+
return this._argTypes[index] ?? (this._isVariadic ? this._argTypes[this._argTypes.length - 1] : undefined);
|
|
48
48
|
}
|
|
49
49
|
match(atom) {
|
|
50
50
|
if (atom instanceof FunctionAtom) {
|
|
@@ -54,8 +54,10 @@ class FunctionAtom {
|
|
|
54
54
|
if (!this._retType.match(atom._retType) || this.minArity > atom.maxArity || this.maxArity < atom.minArity) {
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
const argc = Math.max(this.minArity, atom.minArity);
|
|
58
|
+
for (let i = 0; i < argc; ++i) {
|
|
59
|
+
const atype = atom.argType(i);
|
|
60
|
+
if (!atype || !this.argType(i)?.match(atype)) {
|
|
59
61
|
return false;
|
|
60
62
|
}
|
|
61
63
|
}
|
|
@@ -67,11 +69,11 @@ class FunctionAtom {
|
|
|
67
69
|
return 0x1000000000000 + (this._retType ? [this._retType, ...this._argTypes] : []).reduce((acc, i) => acc + i.weight(), 0);
|
|
68
70
|
}
|
|
69
71
|
toString() {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}).join(",");
|
|
74
|
-
return
|
|
72
|
+
if (this._undefined) {
|
|
73
|
+
return "function";
|
|
74
|
+
}
|
|
75
|
+
const argTypes = this._argTypes.map((i, ix) => ix === this._argTypes.length - 1 && this.isVariadic ? `...${i.toString()}` : i.toString()).join(",");
|
|
76
|
+
return `~(${argTypes}):${this._retType.toString()}`;
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
exports.FunctionAtom = FunctionAtom;
|
|
@@ -2,34 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectAtom = void 0;
|
|
4
4
|
class ObjectAtom {
|
|
5
|
-
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
5
|
+
_valTypes;
|
|
6
|
+
constructor(_valTypes = {}) {
|
|
7
|
+
this._valTypes = _valTypes;
|
|
8
8
|
}
|
|
9
9
|
get _undefined() {
|
|
10
|
-
return Object.keys(this.
|
|
10
|
+
return Object.keys(this._valTypes).length === 0;
|
|
11
11
|
}
|
|
12
12
|
subtypes() {
|
|
13
|
-
return Object.values(this.
|
|
13
|
+
return Object.values(this._valTypes);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
return this.
|
|
15
|
+
valueType(key) {
|
|
16
|
+
return this._valTypes[key];
|
|
17
17
|
}
|
|
18
18
|
match(atom) {
|
|
19
19
|
if (atom instanceof ObjectAtom) {
|
|
20
20
|
if (this._undefined || atom._undefined) {
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
|
-
for (const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
if (!this._propTypes[prop].match(atom._propTypes[prop])) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
for (const prop in atom._propTypes) {
|
|
32
|
-
if (!this.propType(prop)) {
|
|
23
|
+
for (const key in this._valTypes) {
|
|
24
|
+
const vtype = atom.valueType(key);
|
|
25
|
+
if (!vtype || !this._valTypes[key].match(vtype)) {
|
|
33
26
|
return false;
|
|
34
27
|
}
|
|
35
28
|
}
|
|
@@ -41,7 +34,10 @@ class ObjectAtom {
|
|
|
41
34
|
return 0x100000000 + this.subtypes().reduce((acc, i) => acc + i.weight(), 0);
|
|
42
35
|
}
|
|
43
36
|
toString() {
|
|
44
|
-
|
|
37
|
+
if (this._undefined) {
|
|
38
|
+
return "object";
|
|
39
|
+
}
|
|
40
|
+
return `[${Object.entries(this._valTypes).map(([k, v]) => `"${k}":${v}`).join(",")}]`;
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
43
|
exports.ObjectAtom = ObjectAtom;
|
|
@@ -17,13 +17,13 @@ class PrimitiveAtom {
|
|
|
17
17
|
}
|
|
18
18
|
weight() {
|
|
19
19
|
switch (this._primitive) {
|
|
20
|
-
case "void": return
|
|
20
|
+
case "void": return 0x1;
|
|
21
21
|
case "boolean": return 0x2;
|
|
22
|
-
case "timestamp": return
|
|
22
|
+
case "timestamp": return 0x4;
|
|
23
23
|
case "float": return 0x8;
|
|
24
24
|
case "integer": return 0x10;
|
|
25
25
|
case "buffer": return 0x20;
|
|
26
|
-
case "string": return
|
|
26
|
+
case "string": return 0x40;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
toString() {
|
|
@@ -7,15 +7,19 @@ const ConstantNode_js_1 = require("./ConstantNode.js");
|
|
|
7
7
|
const Type_js_1 = require("../Type.js");
|
|
8
8
|
class ArrayNode extends Node_js_1.Node {
|
|
9
9
|
_subnodes;
|
|
10
|
-
|
|
10
|
+
_type;
|
|
11
|
+
constructor(frame, _subnodes, generic = false) {
|
|
11
12
|
super(frame);
|
|
12
13
|
this._subnodes = _subnodes;
|
|
14
|
+
this._type = generic
|
|
15
|
+
? Type_js_1.Type.Array
|
|
16
|
+
: Type_js_1.Type.arrayType(_subnodes.map((i) => i.type));
|
|
13
17
|
}
|
|
14
18
|
get type() {
|
|
15
|
-
return
|
|
19
|
+
return this._type;
|
|
16
20
|
}
|
|
17
21
|
compile(type) {
|
|
18
|
-
this.reduceType(type);
|
|
22
|
+
this._type = this.reduceType(type);
|
|
19
23
|
let constant = true;
|
|
20
24
|
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
21
25
|
this._subnodes[i] = this._subnodes[i].compile(Type_js_1.Type.Unknown);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CallNode = void 0;
|
|
4
4
|
const Node_js_1 = require("../Node.js");
|
|
5
5
|
const Constant_js_1 = require("../Constant.js");
|
|
6
6
|
const ConstantNode_js_1 = require("./ConstantNode.js");
|
|
7
7
|
const ArrayNode_js_1 = require("./ArrayNode.js");
|
|
8
8
|
const Type_js_1 = require("../Type.js");
|
|
9
9
|
const JumpException_js_1 = require("../JumpException.js");
|
|
10
|
-
class
|
|
10
|
+
class CallNode extends Node_js_1.Node {
|
|
11
11
|
_fnode;
|
|
12
12
|
_subnodes;
|
|
13
13
|
_type;
|
|
@@ -34,7 +34,8 @@ class FunctionNode extends Node_js_1.Node {
|
|
|
34
34
|
if (this._fnode.constant) {
|
|
35
35
|
let constant = true;
|
|
36
36
|
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
37
|
-
const
|
|
37
|
+
const argTypes = functionAtoms.map((a) => a.argType(i));
|
|
38
|
+
const argType = Type_js_1.Type.union(...argTypes.filter((t) => t != null));
|
|
38
39
|
this._subnodes[i] = this._subnodes[i].compile(argType);
|
|
39
40
|
constant &&= this._subnodes[i].constant;
|
|
40
41
|
}
|
|
@@ -77,4 +78,4 @@ class FunctionNode extends Node_js_1.Node {
|
|
|
77
78
|
+ `${super.toString(ident)} call node subnodes:\n${subnodes}`;
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
|
-
exports.
|
|
81
|
+
exports.CallNode = CallNode;
|
|
@@ -8,10 +8,12 @@ const Type_js_1 = require("../Type.js");
|
|
|
8
8
|
class ObjectNode extends Node_js_1.Node {
|
|
9
9
|
_subnodes;
|
|
10
10
|
_type;
|
|
11
|
-
constructor(frame, _subnodes) {
|
|
11
|
+
constructor(frame, _subnodes, generic = false) {
|
|
12
12
|
super(frame);
|
|
13
13
|
this._subnodes = _subnodes;
|
|
14
|
-
this._type =
|
|
14
|
+
this._type = generic
|
|
15
|
+
? Type_js_1.Type.Object
|
|
16
|
+
: Type_js_1.Type.objectType(Object.fromEntries(_subnodes.filter(([i]) => i instanceof ConstantNode_js_1.ConstantNode && i.constant).map(([k, v]) => [k.evaluate(), v.type])));
|
|
15
17
|
}
|
|
16
18
|
get type() {
|
|
17
19
|
return this._type;
|
package/dst/node/ArrayNode.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { Value } from "../Value.js";
|
|
|
4
4
|
import { Type } from "../Type.js";
|
|
5
5
|
export declare class ArrayNode extends Node {
|
|
6
6
|
protected _subnodes: Node[];
|
|
7
|
-
|
|
7
|
+
protected _type: Type;
|
|
8
|
+
constructor(frame: ParserFrame, _subnodes: Node[], generic?: boolean);
|
|
8
9
|
get type(): Type;
|
|
9
10
|
compile(type: Type): Node;
|
|
10
11
|
evaluate(): Value;
|
package/dst/node/ArrayNode.js
CHANGED
|
@@ -4,15 +4,19 @@ import { ConstantNode } from "./ConstantNode.js";
|
|
|
4
4
|
import { Type } from "../Type.js";
|
|
5
5
|
export class ArrayNode extends Node {
|
|
6
6
|
_subnodes;
|
|
7
|
-
|
|
7
|
+
_type;
|
|
8
|
+
constructor(frame, _subnodes, generic = false) {
|
|
8
9
|
super(frame);
|
|
9
10
|
this._subnodes = _subnodes;
|
|
11
|
+
this._type = generic
|
|
12
|
+
? Type.Array
|
|
13
|
+
: Type.arrayType(_subnodes.map((i) => i.type));
|
|
10
14
|
}
|
|
11
15
|
get type() {
|
|
12
|
-
return
|
|
16
|
+
return this._type;
|
|
13
17
|
}
|
|
14
18
|
compile(type) {
|
|
15
|
-
this.reduceType(type);
|
|
19
|
+
this._type = this.reduceType(type);
|
|
16
20
|
let constant = true;
|
|
17
21
|
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
18
22
|
this._subnodes[i] = this._subnodes[i].compile(Type.Unknown);
|
|
@@ -2,7 +2,7 @@ import { Node } from "../Node.js";
|
|
|
2
2
|
import { ParserFrame } from "../ParserFrame.js";
|
|
3
3
|
import { Value } from "../Value.js";
|
|
4
4
|
import { Type } from "../Type.js";
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class CallNode extends Node {
|
|
6
6
|
protected _fnode: Node;
|
|
7
7
|
protected _subnodes: Node[];
|
|
8
8
|
protected _type: Type;
|
|
@@ -4,7 +4,7 @@ import { ConstantNode } from "./ConstantNode.js";
|
|
|
4
4
|
import { ArrayNode } from "./ArrayNode.js";
|
|
5
5
|
import { Type } from "../Type.js";
|
|
6
6
|
import { JumpException } from "../JumpException.js";
|
|
7
|
-
export class
|
|
7
|
+
export class CallNode extends Node {
|
|
8
8
|
_fnode;
|
|
9
9
|
_subnodes;
|
|
10
10
|
_type;
|
|
@@ -31,7 +31,8 @@ export class FunctionNode extends Node {
|
|
|
31
31
|
if (this._fnode.constant) {
|
|
32
32
|
let constant = true;
|
|
33
33
|
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
34
|
-
const
|
|
34
|
+
const argTypes = functionAtoms.map((a) => a.argType(i));
|
|
35
|
+
const argType = Type.union(...argTypes.filter((t) => t != null));
|
|
35
36
|
this._subnodes[i] = this._subnodes[i].compile(argType);
|
|
36
37
|
constant &&= this._subnodes[i].constant;
|
|
37
38
|
}
|
package/dst/node/ObjectNode.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Type } from "../Type.js";
|
|
|
5
5
|
export declare class ObjectNode extends Node {
|
|
6
6
|
protected _subnodes: [Node, Node][];
|
|
7
7
|
protected _type: Type;
|
|
8
|
-
constructor(frame: ParserFrame, _subnodes: [Node, Node][]);
|
|
8
|
+
constructor(frame: ParserFrame, _subnodes: [Node, Node][], generic?: boolean);
|
|
9
9
|
get type(): Type;
|
|
10
10
|
compile(type: Type): Node;
|
|
11
11
|
evaluate(): Value;
|
package/dst/node/ObjectNode.js
CHANGED
|
@@ -5,10 +5,12 @@ import { Type } from "../Type.js";
|
|
|
5
5
|
export class ObjectNode extends Node {
|
|
6
6
|
_subnodes;
|
|
7
7
|
_type;
|
|
8
|
-
constructor(frame, _subnodes) {
|
|
8
|
+
constructor(frame, _subnodes, generic = false) {
|
|
9
9
|
super(frame);
|
|
10
10
|
this._subnodes = _subnodes;
|
|
11
|
-
this._type =
|
|
11
|
+
this._type = generic
|
|
12
|
+
? Type.Object
|
|
13
|
+
: Type.objectType(Object.fromEntries(_subnodes.filter(([i]) => i instanceof ConstantNode && i.constant).map(([k, v]) => [k.evaluate(), v.type])));
|
|
12
14
|
}
|
|
13
15
|
get type() {
|
|
14
16
|
return this._type;
|