@magnusopera/fscript 0.78.1 → 0.79.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/dist/FScript.Language/TypeInfer.js +284 -63
- package/dist/FScript.Language/Types.js +78 -19
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Span_$reflection, Span, Position } from "./Span.js";
|
|
3
3
|
import { iterate as iterate_2, FSharpMap__Add, values, FSharpMap__get_Keys, keys, FSharpMap__TryFind, ofList, toList, FSharpMap__get_Item, FSharpMap__ContainsKey, FSharpMap__get_Count, exists as exists_1, add, fold as fold_1, remove, map as map_1, tryFind, isEmpty, empty } from "../fable_modules/fable-library-js.5.13.0/Map.js";
|
|
4
4
|
import { disposeSafe, getEnumerator, stringHash, compareArrays, equals, comparePrimitives } from "../fable_modules/fable-library-js.5.13.0/Util.js";
|
|
5
|
-
import { Types_generalize, Type_$reflection, Types_freshVar, Types_typeToString, Scheme, Type } from "./Types.js";
|
|
5
|
+
import { Types_generalize, Types_freshNumeric, Type_$reflection, Types_freshVar, Types_typeToString, Scheme, Type } from "./Types.js";
|
|
6
6
|
import { tryFind as tryFind_1, indexed, ofArray, collect, append, iterate, reverse, tryFindIndex, choose, tail as tail_2, cons, head as head_1, isEmpty as isEmpty_1, empty as empty_2, singleton, zip, length, exists, fold, map } from "../fable_modules/fable-library-js.5.13.0/List.js";
|
|
7
7
|
import { toList as toList_2, ofSeq, contains, add as add_1, empty as empty_1, FSharpSet__Add, FSharpSet__Contains } from "../fable_modules/fable-library-js.5.13.0/Set.js";
|
|
8
8
|
import { TypeException, TypeError$ } from "./Error.js";
|
|
@@ -32,30 +32,77 @@ function applyType(s, t) {
|
|
|
32
32
|
apply:
|
|
33
33
|
while (true) {
|
|
34
34
|
const current = current_mut;
|
|
35
|
+
let matchResult, v;
|
|
35
36
|
switch (current.tag) {
|
|
36
37
|
case 15: {
|
|
37
|
-
|
|
38
|
+
matchResult = 0;
|
|
39
|
+
v = current.fields[0];
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 16: {
|
|
43
|
+
matchResult = 0;
|
|
44
|
+
v = current.fields[0];
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 5: {
|
|
48
|
+
matchResult = 1;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case 6: {
|
|
52
|
+
matchResult = 2;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case 7: {
|
|
56
|
+
matchResult = 3;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case 8: {
|
|
60
|
+
matchResult = 4;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 9: {
|
|
64
|
+
matchResult = 5;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 10: {
|
|
68
|
+
matchResult = 6;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case 11: {
|
|
72
|
+
matchResult = 7;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
default:
|
|
76
|
+
matchResult = 8;
|
|
77
|
+
}
|
|
78
|
+
switch (matchResult) {
|
|
79
|
+
case 0: {
|
|
80
|
+
const matchValue = tryFind(v, s);
|
|
38
81
|
if (matchValue == null) {
|
|
39
82
|
return current;
|
|
40
83
|
}
|
|
41
|
-
else {
|
|
42
|
-
|
|
84
|
+
else if (!equals(matchValue, current)) {
|
|
85
|
+
const mapped_1 = matchValue;
|
|
86
|
+
current_mut = mapped_1;
|
|
43
87
|
continue apply;
|
|
44
88
|
}
|
|
89
|
+
else {
|
|
90
|
+
return current;
|
|
91
|
+
}
|
|
45
92
|
}
|
|
46
|
-
case
|
|
93
|
+
case 1:
|
|
47
94
|
return new Type(/* TList */ 5, [apply(current.fields[0])]);
|
|
48
|
-
case
|
|
95
|
+
case 2:
|
|
49
96
|
return new Type(/* TTask */ 6, [apply(current.fields[0])]);
|
|
50
|
-
case
|
|
97
|
+
case 3:
|
|
51
98
|
return new Type(/* TTuple */ 7, [map(apply, current.fields[0])]);
|
|
52
|
-
case
|
|
99
|
+
case 4:
|
|
53
100
|
return new Type(/* TRecord */ 8, [map_1((_arg, t1_2) => apply(t1_2), current.fields[0])]);
|
|
54
|
-
case
|
|
101
|
+
case 5:
|
|
55
102
|
return new Type(/* TMap */ 9, [apply(current.fields[0]), apply(current.fields[1])]);
|
|
56
|
-
case
|
|
103
|
+
case 6:
|
|
57
104
|
return new Type(/* TOption */ 10, [apply(current.fields[0])]);
|
|
58
|
-
case
|
|
105
|
+
case 7:
|
|
59
106
|
return new Type(/* TFun */ 11, [apply(current.fields[0]), apply(current.fields[1])]);
|
|
60
107
|
default:
|
|
61
108
|
return current;
|
|
@@ -104,7 +151,7 @@ function occurs(v, t) {
|
|
|
104
151
|
loop:
|
|
105
152
|
while (true) {
|
|
106
153
|
const current = current_mut;
|
|
107
|
-
let matchResult, item, keyType, valueType;
|
|
154
|
+
let matchResult, currentVar, item, keyType, valueType;
|
|
108
155
|
switch (current.tag) {
|
|
109
156
|
case 7: {
|
|
110
157
|
matchResult = 2;
|
|
@@ -125,6 +172,11 @@ function occurs(v, t) {
|
|
|
125
172
|
matchResult = 5;
|
|
126
173
|
break;
|
|
127
174
|
}
|
|
175
|
+
case 16: {
|
|
176
|
+
matchResult = 0;
|
|
177
|
+
currentVar = current.fields[0];
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
128
180
|
case 5: {
|
|
129
181
|
matchResult = 1;
|
|
130
182
|
item = current.fields[0];
|
|
@@ -152,12 +204,14 @@ function occurs(v, t) {
|
|
|
152
204
|
valueType = current.fields[1];
|
|
153
205
|
break;
|
|
154
206
|
}
|
|
155
|
-
default:
|
|
207
|
+
default: {
|
|
156
208
|
matchResult = 0;
|
|
209
|
+
currentVar = current.fields[0];
|
|
210
|
+
}
|
|
157
211
|
}
|
|
158
212
|
switch (matchResult) {
|
|
159
213
|
case 0:
|
|
160
|
-
return
|
|
214
|
+
return currentVar === v;
|
|
161
215
|
case 1: {
|
|
162
216
|
current_mut = item;
|
|
163
217
|
continue loop;
|
|
@@ -188,13 +242,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
188
242
|
uni:
|
|
189
243
|
while (true) {
|
|
190
244
|
const seen = seen_mut, a = a_mut, b = b_mut;
|
|
191
|
-
let arg, arg_1, arg_2, arg_3, arg_4, arg_5;
|
|
245
|
+
let arg, arg_1, arg_2, arg_3, arg_4, arg_5, arg_6;
|
|
192
246
|
if (FSharpSet__Contains(seen, [a, b]) ? true : FSharpSet__Contains(seen, [b, a])) {
|
|
193
247
|
return emptySubst;
|
|
194
248
|
}
|
|
195
249
|
else {
|
|
196
250
|
const seen$0027 = FSharpSet__Add(seen, [a, b]);
|
|
197
|
-
let matchResult, x_1, y_1, x_2, y_2, x_3, y_3, xs, ys, xf, yf, kx, ky, vx, vy, x_5, y_5, a1, a2, b1, b2, t, v, name_2, t_1, name_3, t_2;
|
|
251
|
+
let matchResult, x_1, y_1, x_2, y_2, x_3, y_3, xs, ys, xf, yf, kx, ky, vx, vy, x_5, y_5, a1, a2, b1, b2, t, v, name_2, t_1, name_3, t_2, v_1, w, concrete, v_2, other_4;
|
|
198
252
|
switch (a.tag) {
|
|
199
253
|
case 0: {
|
|
200
254
|
switch (b.tag) {
|
|
@@ -214,8 +268,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
214
268
|
t_2 = a;
|
|
215
269
|
break;
|
|
216
270
|
}
|
|
271
|
+
case 16: {
|
|
272
|
+
matchResult = 14;
|
|
273
|
+
other_4 = a;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
217
276
|
default:
|
|
218
|
-
matchResult =
|
|
277
|
+
matchResult = 15;
|
|
219
278
|
}
|
|
220
279
|
break;
|
|
221
280
|
}
|
|
@@ -237,8 +296,14 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
237
296
|
t_2 = a;
|
|
238
297
|
break;
|
|
239
298
|
}
|
|
299
|
+
case 16: {
|
|
300
|
+
matchResult = 13;
|
|
301
|
+
concrete = a;
|
|
302
|
+
v_2 = b.fields[0];
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
240
305
|
default:
|
|
241
|
-
matchResult =
|
|
306
|
+
matchResult = 15;
|
|
242
307
|
}
|
|
243
308
|
break;
|
|
244
309
|
}
|
|
@@ -260,8 +325,14 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
260
325
|
t_2 = a;
|
|
261
326
|
break;
|
|
262
327
|
}
|
|
328
|
+
case 16: {
|
|
329
|
+
matchResult = 13;
|
|
330
|
+
concrete = a;
|
|
331
|
+
v_2 = b.fields[0];
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
263
334
|
default:
|
|
264
|
-
matchResult =
|
|
335
|
+
matchResult = 15;
|
|
265
336
|
}
|
|
266
337
|
break;
|
|
267
338
|
}
|
|
@@ -283,8 +354,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
283
354
|
t_2 = a;
|
|
284
355
|
break;
|
|
285
356
|
}
|
|
357
|
+
case 16: {
|
|
358
|
+
matchResult = 14;
|
|
359
|
+
other_4 = a;
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
286
362
|
default:
|
|
287
|
-
matchResult =
|
|
363
|
+
matchResult = 15;
|
|
288
364
|
}
|
|
289
365
|
break;
|
|
290
366
|
}
|
|
@@ -306,8 +382,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
306
382
|
t_2 = a;
|
|
307
383
|
break;
|
|
308
384
|
}
|
|
385
|
+
case 16: {
|
|
386
|
+
matchResult = 14;
|
|
387
|
+
other_4 = a;
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
309
390
|
default:
|
|
310
|
-
matchResult =
|
|
391
|
+
matchResult = 15;
|
|
311
392
|
}
|
|
312
393
|
break;
|
|
313
394
|
}
|
|
@@ -329,8 +410,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
329
410
|
t_2 = a;
|
|
330
411
|
break;
|
|
331
412
|
}
|
|
413
|
+
case 16: {
|
|
414
|
+
matchResult = 14;
|
|
415
|
+
other_4 = a;
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
332
418
|
default:
|
|
333
|
-
matchResult =
|
|
419
|
+
matchResult = 15;
|
|
334
420
|
}
|
|
335
421
|
break;
|
|
336
422
|
}
|
|
@@ -355,6 +441,12 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
355
441
|
v = b.fields[0];
|
|
356
442
|
break;
|
|
357
443
|
}
|
|
444
|
+
case 16: {
|
|
445
|
+
matchResult = 10;
|
|
446
|
+
name_2 = a.fields[0];
|
|
447
|
+
t_1 = b;
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
358
450
|
default: {
|
|
359
451
|
matchResult = 10;
|
|
360
452
|
name_2 = a.fields[0];
|
|
@@ -383,8 +475,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
383
475
|
t_2 = a;
|
|
384
476
|
break;
|
|
385
477
|
}
|
|
478
|
+
case 16: {
|
|
479
|
+
matchResult = 14;
|
|
480
|
+
other_4 = a;
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
386
483
|
default:
|
|
387
|
-
matchResult =
|
|
484
|
+
matchResult = 15;
|
|
388
485
|
}
|
|
389
486
|
break;
|
|
390
487
|
}
|
|
@@ -408,8 +505,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
408
505
|
t_2 = a;
|
|
409
506
|
break;
|
|
410
507
|
}
|
|
508
|
+
case 16: {
|
|
509
|
+
matchResult = 14;
|
|
510
|
+
other_4 = a;
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
411
513
|
default:
|
|
412
|
-
matchResult =
|
|
514
|
+
matchResult = 15;
|
|
413
515
|
}
|
|
414
516
|
break;
|
|
415
517
|
}
|
|
@@ -433,8 +535,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
433
535
|
t_2 = a;
|
|
434
536
|
break;
|
|
435
537
|
}
|
|
538
|
+
case 16: {
|
|
539
|
+
matchResult = 14;
|
|
540
|
+
other_4 = a;
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
436
543
|
default:
|
|
437
|
-
matchResult =
|
|
544
|
+
matchResult = 15;
|
|
438
545
|
}
|
|
439
546
|
break;
|
|
440
547
|
}
|
|
@@ -458,8 +565,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
458
565
|
t_2 = a;
|
|
459
566
|
break;
|
|
460
567
|
}
|
|
568
|
+
case 16: {
|
|
569
|
+
matchResult = 14;
|
|
570
|
+
other_4 = a;
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
461
573
|
default:
|
|
462
|
-
matchResult =
|
|
574
|
+
matchResult = 15;
|
|
463
575
|
}
|
|
464
576
|
break;
|
|
465
577
|
}
|
|
@@ -485,8 +597,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
485
597
|
t_2 = a;
|
|
486
598
|
break;
|
|
487
599
|
}
|
|
600
|
+
case 16: {
|
|
601
|
+
matchResult = 14;
|
|
602
|
+
other_4 = a;
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
488
605
|
default:
|
|
489
|
-
matchResult =
|
|
606
|
+
matchResult = 15;
|
|
490
607
|
}
|
|
491
608
|
break;
|
|
492
609
|
}
|
|
@@ -510,8 +627,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
510
627
|
t_2 = a;
|
|
511
628
|
break;
|
|
512
629
|
}
|
|
630
|
+
case 16: {
|
|
631
|
+
matchResult = 14;
|
|
632
|
+
other_4 = a;
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
513
635
|
default:
|
|
514
|
-
matchResult =
|
|
636
|
+
matchResult = 15;
|
|
515
637
|
}
|
|
516
638
|
break;
|
|
517
639
|
}
|
|
@@ -537,8 +659,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
537
659
|
t_2 = a;
|
|
538
660
|
break;
|
|
539
661
|
}
|
|
662
|
+
case 16: {
|
|
663
|
+
matchResult = 14;
|
|
664
|
+
other_4 = a;
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
540
667
|
default:
|
|
541
|
-
matchResult =
|
|
668
|
+
matchResult = 15;
|
|
542
669
|
}
|
|
543
670
|
break;
|
|
544
671
|
}
|
|
@@ -548,6 +675,45 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
548
675
|
v = a.fields[0];
|
|
549
676
|
break;
|
|
550
677
|
}
|
|
678
|
+
case 16: {
|
|
679
|
+
switch (b.tag) {
|
|
680
|
+
case 15: {
|
|
681
|
+
matchResult = 9;
|
|
682
|
+
t = a;
|
|
683
|
+
v = b.fields[0];
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
case 12: {
|
|
687
|
+
matchResult = 11;
|
|
688
|
+
name_3 = b.fields[0];
|
|
689
|
+
t_2 = a;
|
|
690
|
+
break;
|
|
691
|
+
}
|
|
692
|
+
case 16: {
|
|
693
|
+
matchResult = 12;
|
|
694
|
+
v_1 = a.fields[0];
|
|
695
|
+
w = b.fields[0];
|
|
696
|
+
break;
|
|
697
|
+
}
|
|
698
|
+
case 1: {
|
|
699
|
+
matchResult = 13;
|
|
700
|
+
concrete = b;
|
|
701
|
+
v_2 = a.fields[0];
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
case 2: {
|
|
705
|
+
matchResult = 13;
|
|
706
|
+
concrete = b;
|
|
707
|
+
v_2 = a.fields[0];
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
default: {
|
|
711
|
+
matchResult = 14;
|
|
712
|
+
other_4 = b;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
551
717
|
default:
|
|
552
718
|
switch (b.tag) {
|
|
553
719
|
case 15: {
|
|
@@ -562,8 +728,13 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
562
728
|
t_2 = a;
|
|
563
729
|
break;
|
|
564
730
|
}
|
|
731
|
+
case 16: {
|
|
732
|
+
matchResult = 14;
|
|
733
|
+
other_4 = a;
|
|
734
|
+
break;
|
|
735
|
+
}
|
|
565
736
|
default:
|
|
566
|
-
matchResult =
|
|
737
|
+
matchResult = 15;
|
|
567
738
|
}
|
|
568
739
|
}
|
|
569
740
|
switch (matchResult) {
|
|
@@ -619,12 +790,17 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
619
790
|
if (equals(t, new Type(/* TVar */ 15, [v]))) {
|
|
620
791
|
return emptySubst;
|
|
621
792
|
}
|
|
793
|
+
else if (equals(t, new Type(/* TNumeric */ 16, [v]))) {
|
|
794
|
+
return ofList(singleton([v, t]), {
|
|
795
|
+
Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
|
|
796
|
+
});
|
|
797
|
+
}
|
|
622
798
|
else if (occurs(v, t)) {
|
|
623
799
|
throw new TypeException(new TypeError$("Occurs check failed", span));
|
|
624
800
|
}
|
|
625
801
|
else {
|
|
626
802
|
return ofList(singleton([v, t]), {
|
|
627
|
-
Compare: (
|
|
803
|
+
Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
|
|
628
804
|
});
|
|
629
805
|
}
|
|
630
806
|
case 10: {
|
|
@@ -717,15 +893,30 @@ function unify(typeDefs, t1, t2, span) {
|
|
|
717
893
|
}
|
|
718
894
|
}
|
|
719
895
|
}
|
|
896
|
+
case 12:
|
|
897
|
+
if (v_1 === w) {
|
|
898
|
+
return emptySubst;
|
|
899
|
+
}
|
|
900
|
+
else {
|
|
901
|
+
return ofList(singleton([v_1, new Type(/* TNumeric */ 16, [w])]), {
|
|
902
|
+
Compare: (x_8, y_8) => (comparePrimitives(x_8, y_8) | 0),
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
case 13:
|
|
906
|
+
return ofList(singleton([v_2, concrete]), {
|
|
907
|
+
Compare: (x_9, y_9) => (comparePrimitives(x_9, y_9) | 0),
|
|
908
|
+
});
|
|
909
|
+
case 14:
|
|
910
|
+
throw new TypeException(new TypeError$((arg_4 = Types_typeToString(other_4), toText(printf("Expected numeric type, got %s"))(arg_4)), span));
|
|
720
911
|
default:
|
|
721
|
-
throw new TypeException(new TypeError$((
|
|
912
|
+
throw new TypeException(new TypeError$((arg_5 = Types_typeToString(a), (arg_6 = Types_typeToString(b), toText(printf("Type mismatch: %s vs %s"))(arg_5)(arg_6))), span));
|
|
722
913
|
}
|
|
723
914
|
}
|
|
724
915
|
break;
|
|
725
916
|
}
|
|
726
917
|
};
|
|
727
918
|
return uni(empty_1({
|
|
728
|
-
Compare: (
|
|
919
|
+
Compare: (x_10, y_10) => (compareArrays(x_10, y_10) | 0),
|
|
729
920
|
}), t1, t2);
|
|
730
921
|
}
|
|
731
922
|
|
|
@@ -737,6 +928,28 @@ function instantiate(_arg) {
|
|
|
737
928
|
switch (t_1.tag) {
|
|
738
929
|
case 15:
|
|
739
930
|
return defaultArg(tryFind(t_1.fields[0], freshMap), t_1);
|
|
931
|
+
case 16: {
|
|
932
|
+
const matchValue = tryFind(t_1.fields[0], freshMap);
|
|
933
|
+
let matchResult, fresh;
|
|
934
|
+
if (matchValue != null) {
|
|
935
|
+
if (matchValue.tag === 15) {
|
|
936
|
+
matchResult = 0;
|
|
937
|
+
fresh = matchValue.fields[0];
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
matchResult = 1;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
else {
|
|
944
|
+
matchResult = 1;
|
|
945
|
+
}
|
|
946
|
+
switch (matchResult) {
|
|
947
|
+
case 0:
|
|
948
|
+
return new Type(/* TNumeric */ 16, [fresh]);
|
|
949
|
+
default:
|
|
950
|
+
return t_1;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
740
953
|
case 5:
|
|
741
954
|
return new Type(/* TList */ 5, [subst(t_1.fields[0])]);
|
|
742
955
|
case 6:
|
|
@@ -936,6 +1149,8 @@ function builtinType(name) {
|
|
|
936
1149
|
return Type.TInt;
|
|
937
1150
|
case "float":
|
|
938
1151
|
return Type.TFloat;
|
|
1152
|
+
case "numeric":
|
|
1153
|
+
return Types_freshNumeric();
|
|
939
1154
|
case "bool":
|
|
940
1155
|
return Type.TBool;
|
|
941
1156
|
case "string":
|
|
@@ -1084,6 +1299,8 @@ function annotationTypeFromRef(typeDefs, span, tref) {
|
|
|
1084
1299
|
return Type.TInt;
|
|
1085
1300
|
case "float":
|
|
1086
1301
|
return Type.TFloat;
|
|
1302
|
+
case "numeric":
|
|
1303
|
+
return Types_freshNumeric();
|
|
1087
1304
|
case "bool":
|
|
1088
1305
|
return Type.TBool;
|
|
1089
1306
|
case "string":
|
|
@@ -1346,15 +1563,17 @@ function inferPattern(telemetry, typeDefs, constructors, pat) {
|
|
|
1346
1563
|
}
|
|
1347
1564
|
}
|
|
1348
1565
|
|
|
1349
|
-
function
|
|
1566
|
+
function constrainNumeric(typeDefs, t, span) {
|
|
1350
1567
|
switch (t.tag) {
|
|
1351
1568
|
case 1:
|
|
1352
1569
|
case 2:
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1570
|
+
case 16:
|
|
1571
|
+
return [emptySubst, t];
|
|
1572
|
+
default: {
|
|
1573
|
+
const numeric = Types_freshNumeric();
|
|
1574
|
+
const subst = unify(typeDefs, t, numeric, span);
|
|
1575
|
+
return [subst, applyType(subst, numeric)];
|
|
1576
|
+
}
|
|
1358
1577
|
}
|
|
1359
1578
|
}
|
|
1360
1579
|
|
|
@@ -2249,69 +2468,71 @@ function inferExpr(telemetry, typeDefs, constructors, env, expr) {
|
|
|
2249
2468
|
const s2_14 = patternInput_50[0];
|
|
2250
2469
|
const s3_11 = unify(typeDefs, applyType(s2_14, patternInput_49[1]), t2_3, span_20);
|
|
2251
2470
|
const t_9 = applyType(s3_11, t2_3);
|
|
2252
|
-
let
|
|
2471
|
+
let patternInput_52;
|
|
2253
2472
|
switch (op) {
|
|
2254
2473
|
case "+":
|
|
2255
2474
|
case "-":
|
|
2256
2475
|
case "*":
|
|
2257
|
-
case "/":
|
|
2476
|
+
case "/": {
|
|
2477
|
+
patternInput_52 = constrainNumeric(typeDefs, t_9, span_20);
|
|
2478
|
+
break;
|
|
2479
|
+
}
|
|
2258
2480
|
case "%": {
|
|
2259
|
-
|
|
2481
|
+
patternInput_52 = [unify(typeDefs, t_9, Type.TInt, span_20), Type.TInt];
|
|
2260
2482
|
break;
|
|
2261
2483
|
}
|
|
2262
2484
|
case "=": {
|
|
2263
|
-
|
|
2485
|
+
patternInput_52 = [emptySubst, Type.TBool];
|
|
2264
2486
|
break;
|
|
2265
2487
|
}
|
|
2266
2488
|
case "<":
|
|
2267
2489
|
case ">":
|
|
2268
2490
|
case "<=":
|
|
2269
2491
|
case ">=": {
|
|
2270
|
-
|
|
2271
|
-
resultType = Type.TBool;
|
|
2492
|
+
patternInput_52 = [constrainNumeric(typeDefs, t_9, span_20)[0], Type.TBool];
|
|
2272
2493
|
break;
|
|
2273
2494
|
}
|
|
2274
2495
|
case "&&":
|
|
2275
2496
|
case "||": {
|
|
2276
|
-
unify(typeDefs, t_9, Type.TBool, span_20);
|
|
2277
|
-
resultType = Type.TBool;
|
|
2497
|
+
patternInput_52 = [unify(typeDefs, t_9, Type.TBool, span_20), Type.TBool];
|
|
2278
2498
|
break;
|
|
2279
2499
|
}
|
|
2280
2500
|
default:
|
|
2281
2501
|
throw new TypeException(new TypeError$(toText(printf("Unknown operator %s"))(op), span_20));
|
|
2282
2502
|
}
|
|
2283
|
-
|
|
2503
|
+
const resultType = patternInput_52[1];
|
|
2504
|
+
return [compose(patternInput_52[0], compose(s3_11, compose(s2_14, s1_23))), resultType, asTyped(expr, resultType)];
|
|
2284
2505
|
}
|
|
2285
2506
|
}
|
|
2286
2507
|
}
|
|
2287
2508
|
case 26: {
|
|
2288
|
-
const
|
|
2289
|
-
const t1_11 =
|
|
2290
|
-
return [
|
|
2509
|
+
const patternInput_53 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
|
|
2510
|
+
const t1_11 = patternInput_53[1];
|
|
2511
|
+
return [patternInput_53[0], new Type(/* TOption */ 10, [t1_11]), asTyped(expr, new Type(/* TOption */ 10, [t1_11]))];
|
|
2291
2512
|
}
|
|
2292
2513
|
case 27: {
|
|
2293
2514
|
const tv_9 = Types_freshVar();
|
|
2294
2515
|
return [emptySubst, new Type(/* TOption */ 10, [tv_9]), asTyped(expr, new Type(/* TOption */ 10, [tv_9]))];
|
|
2295
2516
|
}
|
|
2296
2517
|
case 23: {
|
|
2297
|
-
const
|
|
2298
|
-
const t1_12 =
|
|
2299
|
-
const s1_25 =
|
|
2300
|
-
const
|
|
2301
|
-
const s2_15 =
|
|
2302
|
-
const s_20 = compose(unify(typeDefs, applyType(s2_15,
|
|
2518
|
+
const patternInput_54 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
|
|
2519
|
+
const t1_12 = patternInput_54[1];
|
|
2520
|
+
const s1_25 = patternInput_54[0];
|
|
2521
|
+
const patternInput_55 = inferExpr(telemetry, typeDefs, constructors, applyEnv(s1_25, env), expr.fields[1]);
|
|
2522
|
+
const s2_15 = patternInput_55[0];
|
|
2523
|
+
const s_20 = compose(unify(typeDefs, applyType(s2_15, patternInput_55[1]), new Type(/* TList */ 5, [t1_12]), expr.fields[2]), compose(s2_15, s1_25));
|
|
2303
2524
|
const tRes_19 = applyType(s_20, new Type(/* TList */ 5, [t1_12]));
|
|
2304
2525
|
return [s_20, tRes_19, asTyped(expr, tRes_19)];
|
|
2305
2526
|
}
|
|
2306
2527
|
case 24: {
|
|
2307
2528
|
const span_22 = expr.fields[2];
|
|
2308
|
-
const
|
|
2309
|
-
const s1_26 =
|
|
2310
|
-
const
|
|
2311
|
-
const s2_16 =
|
|
2529
|
+
const patternInput_56 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
|
|
2530
|
+
const s1_26 = patternInput_56[0];
|
|
2531
|
+
const patternInput_57 = inferExpr(telemetry, typeDefs, constructors, applyEnv(s1_26, env), expr.fields[1]);
|
|
2532
|
+
const s2_16 = patternInput_57[0];
|
|
2312
2533
|
const tv_10 = Types_freshVar();
|
|
2313
|
-
const s3_13 = unify(typeDefs, applyType(s2_16,
|
|
2314
|
-
const s_21 = compose(unify(typeDefs, applyType(s3_13, applyType(s2_16,
|
|
2534
|
+
const s3_13 = unify(typeDefs, applyType(s2_16, patternInput_56[1]), new Type(/* TList */ 5, [tv_10]), span_22);
|
|
2535
|
+
const s_21 = compose(unify(typeDefs, applyType(s3_13, applyType(s2_16, patternInput_57[1])), new Type(/* TList */ 5, [applyType(s3_13, tv_10)]), span_22), compose(s3_13, compose(s2_16, s1_26)));
|
|
2315
2536
|
const tRes_20 = new Type(/* TList */ 5, [applyType(s_21, tv_10)]);
|
|
2316
2537
|
return [s_21, tRes_20, asTyped(expr, tRes_20)];
|
|
2317
2538
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
import { Union } from "../fable_modules/fable-library-js.5.13.0/Types.js";
|
|
3
3
|
import { union_type, int32_type, option_type, class_type, string_type, list_type } from "../fable_modules/fable-library-js.5.13.0/Reflection.js";
|
|
4
|
+
import { comparePrimitives, Exception } from "../fable_modules/fable-library-js.5.13.0/Util.js";
|
|
5
|
+
import { toList, isEmpty, ofList, difference, singleton, union, empty } from "../fable_modules/fable-library-js.5.13.0/Set.js";
|
|
4
6
|
import { empty as empty_1, fold, map } from "../fable_modules/fable-library-js.5.13.0/List.js";
|
|
5
|
-
import { toList, isEmpty, ofList, difference, singleton, empty, union } from "../fable_modules/fable-library-js.5.13.0/Set.js";
|
|
6
|
-
import { comparePrimitives } from "../fable_modules/fable-library-js.5.13.0/Util.js";
|
|
7
7
|
import { fold as fold_1, map as map_1 } from "../fable_modules/fable-library-js.5.13.0/Seq.js";
|
|
8
8
|
import { toList as toList_1, values } from "../fable_modules/fable-library-js.5.13.0/Map.js";
|
|
9
9
|
import { join, printf, toText } from "../fable_modules/fable-library-js.5.13.0/String.js";
|
|
@@ -15,7 +15,7 @@ export class Type extends Union {
|
|
|
15
15
|
this.fields = fields;
|
|
16
16
|
}
|
|
17
17
|
cases() {
|
|
18
|
-
return ["TUnit", "TInt", "TFloat", "TBool", "TString", "TList", "TTask", "TTuple", "TRecord", "TMap", "TOption", "TFun", "TNamed", "TUnion", "TTypeToken", "TVar"];
|
|
18
|
+
return ["TUnit", "TInt", "TFloat", "TBool", "TString", "TList", "TTask", "TTuple", "TRecord", "TMap", "TOption", "TFun", "TNamed", "TUnion", "TTypeToken", "TVar", "TNumeric"];
|
|
19
19
|
}
|
|
20
20
|
static TUnit = new Type(0, []);
|
|
21
21
|
static TInt = new Type(1, []);
|
|
@@ -26,7 +26,7 @@ export class Type extends Union {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function Type_$reflection() {
|
|
29
|
-
return union_type("FScript.Language.Type", [], Type, () => [[], [], [], [], [], [["Item", Type_$reflection()]], [["Item", Type_$reflection()]], [["Item", list_type(Type_$reflection())]], [["Item", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, Type_$reflection()])]], [["Item1", Type_$reflection()], ["Item2", Type_$reflection()]], [["Item", Type_$reflection()]], [["Item1", Type_$reflection()], ["Item2", Type_$reflection()]], [["Item", string_type]], [["Item1", string_type], ["Item2", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, option_type(Type_$reflection())])]], [], [["Item", int32_type]]]);
|
|
29
|
+
return union_type("FScript.Language.Type", [], Type, () => [[], [], [], [], [], [["Item", Type_$reflection()]], [["Item", Type_$reflection()]], [["Item", list_type(Type_$reflection())]], [["Item", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, Type_$reflection()])]], [["Item1", Type_$reflection()], ["Item2", Type_$reflection()]], [["Item", Type_$reflection()]], [["Item1", Type_$reflection()], ["Item2", Type_$reflection()]], [["Item", string_type]], [["Item1", string_type], ["Item2", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, option_type(Type_$reflection())])]], [], [["Item", int32_type]], [["Item", int32_type]]]);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export class Scheme extends Union {
|
|
@@ -52,52 +52,109 @@ export function Types_freshVar() {
|
|
|
52
52
|
return new Type(/* TVar */ 15, [id]);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
export function Types_freshNumeric() {
|
|
56
|
+
const matchValue = Types_freshVar();
|
|
57
|
+
if (matchValue.tag === 15) {
|
|
58
|
+
return new Type(/* TNumeric */ 16, [matchValue.fields[0]]);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw new Exception("Expected fresh type variable");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
55
65
|
export function Types_ftvType(t_mut) {
|
|
56
66
|
Types_ftvType:
|
|
57
67
|
while (true) {
|
|
58
68
|
const t = t_mut;
|
|
69
|
+
let matchResult, v;
|
|
59
70
|
switch (t.tag) {
|
|
60
71
|
case 5: {
|
|
72
|
+
matchResult = 1;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 6: {
|
|
76
|
+
matchResult = 2;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case 7: {
|
|
80
|
+
matchResult = 3;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case 8: {
|
|
84
|
+
matchResult = 4;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 9: {
|
|
88
|
+
matchResult = 5;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 10: {
|
|
92
|
+
matchResult = 6;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 11: {
|
|
96
|
+
matchResult = 7;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case 12:
|
|
100
|
+
case 13:
|
|
101
|
+
case 14: {
|
|
102
|
+
matchResult = 8;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case 15: {
|
|
106
|
+
matchResult = 9;
|
|
107
|
+
v = t.fields[0];
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case 16: {
|
|
111
|
+
matchResult = 9;
|
|
112
|
+
v = t.fields[0];
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
default:
|
|
116
|
+
matchResult = 0;
|
|
117
|
+
}
|
|
118
|
+
switch (matchResult) {
|
|
119
|
+
case 0:
|
|
120
|
+
return empty({
|
|
121
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
122
|
+
});
|
|
123
|
+
case 1: {
|
|
61
124
|
t_mut = t.fields[0];
|
|
62
125
|
continue Types_ftvType;
|
|
63
126
|
}
|
|
64
|
-
case
|
|
127
|
+
case 2: {
|
|
65
128
|
t_mut = t.fields[0];
|
|
66
129
|
continue Types_ftvType;
|
|
67
130
|
}
|
|
68
|
-
case
|
|
131
|
+
case 3: {
|
|
69
132
|
const list_1 = map(Types_ftvType, t.fields[0]);
|
|
70
133
|
return fold(union, empty({
|
|
71
134
|
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
72
135
|
}), list_1);
|
|
73
136
|
}
|
|
74
|
-
case
|
|
137
|
+
case 4: {
|
|
75
138
|
const source_1 = map_1(Types_ftvType, values(t.fields[0]));
|
|
76
139
|
return fold_1(union, empty({
|
|
77
140
|
Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
|
|
78
141
|
}), source_1);
|
|
79
142
|
}
|
|
80
|
-
case
|
|
143
|
+
case 5:
|
|
81
144
|
return union(Types_ftvType(t.fields[0]), Types_ftvType(t.fields[1]));
|
|
82
|
-
case
|
|
145
|
+
case 6: {
|
|
83
146
|
t_mut = t.fields[0];
|
|
84
147
|
continue Types_ftvType;
|
|
85
148
|
}
|
|
86
|
-
case
|
|
149
|
+
case 7:
|
|
87
150
|
return union(Types_ftvType(t.fields[0]), Types_ftvType(t.fields[1]));
|
|
88
|
-
case
|
|
89
|
-
case 13:
|
|
90
|
-
case 14:
|
|
151
|
+
case 8:
|
|
91
152
|
return empty({
|
|
92
153
|
Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
|
|
93
154
|
});
|
|
94
|
-
case 15:
|
|
95
|
-
return singleton(t.fields[0], {
|
|
96
|
-
Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
|
|
97
|
-
});
|
|
98
155
|
default:
|
|
99
|
-
return
|
|
100
|
-
Compare: (
|
|
156
|
+
return singleton(v, {
|
|
157
|
+
Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
|
|
101
158
|
});
|
|
102
159
|
}
|
|
103
160
|
break;
|
|
@@ -185,6 +242,8 @@ export function Types_typeToString(t) {
|
|
|
185
242
|
return t_1.fields[0];
|
|
186
243
|
case 14:
|
|
187
244
|
return "type";
|
|
245
|
+
case 16:
|
|
246
|
+
return "numeric";
|
|
188
247
|
case 15: {
|
|
189
248
|
const v = t_1.fields[0] | 0;
|
|
190
249
|
const letter = String.fromCharCode((~~"a".charCodeAt(0) + (v % 26)) & 0xFFFF);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magnusopera/fscript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.79.0",
|
|
4
4
|
"description": "Embeddable FScript language engine: parser, type inference, and evaluator.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/Library.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"interpreter"
|
|
22
22
|
],
|
|
23
23
|
"license": "MIT",
|
|
24
|
-
"homepage": "https://magnusopera.
|
|
24
|
+
"homepage": "https://fscript.magnusopera.io/manual/embedding/fable-javascript",
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/MagnusOpera/FScript/issues"
|
|
27
27
|
},
|