fez-lisp 1.5.73 → 1.5.75
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/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/check.js +352 -401
- package/src/macros.js +83 -92
- package/src/types.js +2 -1
package/src/check.js
CHANGED
@@ -32,6 +32,7 @@ import {
|
|
32
32
|
PREDICATE,
|
33
33
|
COLLECTION,
|
34
34
|
MAX_RETRY_DEFINITION,
|
35
|
+
MAX_ARGUMENT_RETRY,
|
35
36
|
ORDER,
|
36
37
|
VARIABLE_ORDER_INDEX
|
37
38
|
} from './types.js'
|
@@ -390,6 +391,7 @@ export const typeCheck = (ast) => {
|
|
390
391
|
[STATS]: {
|
391
392
|
[TYPE_PROP]: [APPLY],
|
392
393
|
retried: 0,
|
394
|
+
counter: 0,
|
393
395
|
[VARIABLE_ORDER_INDEX]: env[ORDER],
|
394
396
|
[ARGS_COUNT]: n - 2,
|
395
397
|
[ARGUMENTS]: [],
|
@@ -422,7 +424,9 @@ export const typeCheck = (ast) => {
|
|
422
424
|
)
|
423
425
|
}
|
424
426
|
// FULL REFF ASSIGMENT
|
425
|
-
env[name] =
|
427
|
+
env[name] = SPECIAL_FORMS_SET.has(rest[1][VALUE])
|
428
|
+
? structuredClone(env[rest[1][VALUE]])
|
429
|
+
: env[rest[1][VALUE]]
|
426
430
|
|
427
431
|
if (
|
428
432
|
getSuffix(rest[1][VALUE]) === PREDICATE_SUFFIX &&
|
@@ -451,6 +455,7 @@ export const typeCheck = (ast) => {
|
|
451
455
|
env[name] = {
|
452
456
|
[STATS]: {
|
453
457
|
retried: 0,
|
458
|
+
counter: 0,
|
454
459
|
[VARIABLE_ORDER_INDEX]: env[ORDER],
|
455
460
|
[TYPE_PROP]: [ATOM],
|
456
461
|
[RETURNS]: [ATOM]
|
@@ -485,6 +490,7 @@ export const typeCheck = (ast) => {
|
|
485
490
|
env[name] = {
|
486
491
|
[STATS]: {
|
487
492
|
retried: 0,
|
493
|
+
counter: 0,
|
488
494
|
[VARIABLE_ORDER_INDEX]: env[ORDER],
|
489
495
|
[TYPE_PROP]: [
|
490
496
|
isL
|
@@ -597,7 +603,8 @@ export const typeCheck = (ast) => {
|
|
597
603
|
[TYPE_PROP]: [UNKNOWN],
|
598
604
|
[RETURNS]: [UNKNOWN],
|
599
605
|
[ARGUMENTS]: [],
|
600
|
-
retried: 0
|
606
|
+
retried: 0,
|
607
|
+
counter: 0
|
601
608
|
}
|
602
609
|
}
|
603
610
|
const ref = env[copy[SCOPE_NAME]]
|
@@ -678,459 +685,403 @@ export const typeCheck = (ast) => {
|
|
678
685
|
errorStack.add(
|
679
686
|
`Trying to call undefined (lambda) ${first[VALUE]} (check #9)`
|
680
687
|
)
|
681
|
-
else
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
)
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
// TODO recursively take return type of applicaion
|
706
|
-
if (env[first[VALUE]][STATS][RETURNS][0] === APPLY) {
|
707
|
-
env[first[VALUE]][STATS][RETURNS] = [UNKNOWN]
|
708
|
-
}
|
709
|
-
// FN ASSIGMENT
|
710
|
-
env[first[VALUE]][STATS][TYPE_PROP] = [APPLY]
|
711
|
-
env[first[VALUE]][STATS][ARGS_COUNT] = rest.length
|
688
|
+
else if (
|
689
|
+
env[first[VALUE]][STATS][TYPE_PROP][0] === APPLY &&
|
690
|
+
env[first[VALUE]][STATS][ARGS_COUNT] !== VARIADIC &&
|
691
|
+
env[first[VALUE]][STATS][ARGS_COUNT] !== rest.length
|
692
|
+
) {
|
693
|
+
errorStack.add(
|
694
|
+
`Incorrect number of arguments for (${
|
695
|
+
first[VALUE]
|
696
|
+
}). Expected (= ${
|
697
|
+
env[first[VALUE]][STATS][ARGS_COUNT]
|
698
|
+
}) but got ${rest.length} (${stringifyArgs(exp)}) (check #15)`
|
699
|
+
)
|
700
|
+
} else {
|
701
|
+
if (first[TYPE] === APPLY && !isSpecial) {
|
702
|
+
if (env[first[VALUE]][STATS][TYPE_PROP][0] === ATOM) {
|
703
|
+
errorStack.add(
|
704
|
+
`(${first[VALUE]}) is not a (lambda) (${stringifyArgs(
|
705
|
+
exp
|
706
|
+
)}) (check #12)`
|
707
|
+
)
|
708
|
+
} else if (!env[first[VALUE]][STATS][ARGS_COUNT]) {
|
709
|
+
// TODO recursively take return type of applicaion
|
710
|
+
if (env[first[VALUE]][STATS][RETURNS][0] === APPLY) {
|
711
|
+
env[first[VALUE]][STATS][RETURNS] = [UNKNOWN]
|
712
712
|
}
|
713
|
+
// FN ASSIGMENT
|
714
|
+
env[first[VALUE]][STATS][TYPE_PROP] = [APPLY]
|
715
|
+
env[first[VALUE]][STATS][ARGS_COUNT] = rest.length
|
713
716
|
}
|
717
|
+
}
|
714
718
|
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
)}) (${stringifyArgs(exp)}) (check #27)`
|
768
|
-
)
|
769
|
-
}
|
770
|
-
if (
|
771
|
-
PRED_TYPE &&
|
772
|
-
PRED_TYPE === PREDICATE &&
|
773
|
-
returns[VALUE] !== TRUE &&
|
774
|
-
returns[VALUE] !== FALSE
|
775
|
-
) {
|
776
|
-
errorStack.add(
|
777
|
-
`Incorrect type of argument ${i} for (${
|
778
|
-
first[VALUE]
|
779
|
-
}). Expected (${toTypeNames(
|
780
|
-
PRED_TYPE
|
781
|
-
)}) but got an (${toTypeNames(
|
782
|
-
ATOM
|
783
|
-
)}) which is neither ${TRUE} or ${FALSE} (${stringifyArgs(
|
784
|
-
exp
|
785
|
-
)}) (check #27)`
|
786
|
-
)
|
787
|
-
}
|
788
|
-
} else if (env[returns[VALUE]]) {
|
789
|
-
if (
|
790
|
-
MAIN_TYPE !==
|
791
|
-
env[returns[VALUE]][STATS][RETURNS][0]
|
792
|
-
) {
|
793
|
-
errorStack.add(
|
794
|
-
`Incorrect type of argument ${i} for (${
|
795
|
-
first[VALUE]
|
796
|
-
}). Expected (${toTypeNames(
|
797
|
-
MAIN_TYPE
|
798
|
-
)}) but got (${toTypeNames(
|
799
|
-
env[returns[VALUE]][STATS][TYPE_PROP]
|
800
|
-
)}) (${stringifyArgs(exp)}) (check #29)`
|
801
|
-
)
|
802
|
-
}
|
803
|
-
// Never happens because there is only 1 sub type at the moment
|
804
|
-
// if (
|
805
|
-
// PRED_TYPE &&
|
806
|
-
// PRED_TYPE !==
|
807
|
-
// env[returns[VALUE]][STATS][RETURNS][1]
|
808
|
-
// ) {
|
809
|
-
// }
|
810
|
-
}
|
719
|
+
// also type of arg
|
720
|
+
const args = env[first[VALUE]][STATS][ARGUMENTS] ?? []
|
721
|
+
for (let i = 0; i < args.length; ++i) {
|
722
|
+
// type check
|
723
|
+
const PRED_TYPE = args[i][STATS][TYPE_PROP][1]
|
724
|
+
const MAIN_TYPE = args[i][STATS][TYPE_PROP][0]
|
725
|
+
if (PRED_TYPE != undefined && !isLeaf(rest[i])) {
|
726
|
+
const current = rest[i][0]
|
727
|
+
if (current[TYPE] === APPLY) {
|
728
|
+
if (current[VALUE] == KEYWORDS.CALL_FUNCTION) {
|
729
|
+
if (isLeaf(rest[i].at(-1))) {
|
730
|
+
const fnName = rest[i].at(-1)[VALUE]
|
731
|
+
const fn = env[fnName]
|
732
|
+
if (fn && fn[STATS][RETURNS][0] !== MAIN_TYPE) {
|
733
|
+
errorStack.add(
|
734
|
+
`Incorrect type of argument (${i}) for (${
|
735
|
+
first[VALUE]
|
736
|
+
}). Expected (${toTypeNames(
|
737
|
+
MAIN_TYPE
|
738
|
+
)}) but got an (${toTypeNames(
|
739
|
+
fn[STATS][RETURNS][0]
|
740
|
+
)}) (${stringifyArgs(exp)}) (check #26)`
|
741
|
+
)
|
742
|
+
}
|
743
|
+
if (fn && fn[STATS][RETURNS][1] !== PRED_TYPE) {
|
744
|
+
errorStack.add(
|
745
|
+
`Incorrect type of argument (${i}) for (${
|
746
|
+
first[VALUE]
|
747
|
+
}). Expected (${toTypeNames(
|
748
|
+
PRED_TYPE
|
749
|
+
)}) but got an (${toTypeNames(
|
750
|
+
fn[STATS][RETURNS][1] ?? fn[STATS][RETURNS][0]
|
751
|
+
)}) which is neither ${TRUE} or ${FALSE} (${stringifyArgs(
|
752
|
+
exp
|
753
|
+
)}) (check #27)`
|
754
|
+
)
|
755
|
+
}
|
756
|
+
} else {
|
757
|
+
const body = rest[i].at(-1).at(-1)
|
758
|
+
const rem = hasBlock(body) ? body.at(-1) : body
|
759
|
+
const returns = isLeaf(rem) ? rem : rem[0]
|
760
|
+
if (returns[TYPE] === ATOM) {
|
761
|
+
if (MAIN_TYPE !== ATOM) {
|
762
|
+
errorStack.add(
|
763
|
+
`Incorrect type of argument ${i} for (${
|
764
|
+
first[VALUE]
|
765
|
+
}). Expected (${toTypeNames(
|
766
|
+
MAIN_TYPE
|
767
|
+
)}) but got an (${toTypeNames(
|
768
|
+
ATOM
|
769
|
+
)}) (${stringifyArgs(exp)}) (check #27)`
|
770
|
+
)
|
811
771
|
}
|
812
|
-
} else if (
|
813
|
-
PRED_TYPE &&
|
814
|
-
env[current[VALUE]] &&
|
815
|
-
env[current[VALUE]][STATS][RETURNS][1] !== PRED_TYPE
|
816
|
-
) {
|
817
772
|
if (
|
818
|
-
|
773
|
+
PRED_TYPE &&
|
774
|
+
PRED_TYPE === PREDICATE &&
|
775
|
+
returns[VALUE] !== TRUE &&
|
776
|
+
returns[VALUE] !== FALSE
|
819
777
|
) {
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
778
|
+
errorStack.add(
|
779
|
+
`Incorrect type of argument ${i} for (${
|
780
|
+
first[VALUE]
|
781
|
+
}). Expected (${toTypeNames(
|
782
|
+
PRED_TYPE
|
783
|
+
)}) but got an (${toTypeNames(
|
784
|
+
ATOM
|
785
|
+
)}) which is neither ${TRUE} or ${FALSE} (${stringifyArgs(
|
786
|
+
exp
|
787
|
+
)}) (check #27)`
|
788
|
+
)
|
789
|
+
}
|
790
|
+
} else if (env[returns[VALUE]]) {
|
791
|
+
if (
|
792
|
+
MAIN_TYPE !==
|
793
|
+
env[returns[VALUE]][STATS][RETURNS][0]
|
794
|
+
) {
|
795
|
+
errorStack.add(
|
796
|
+
`Incorrect type of argument ${i} for (${
|
797
|
+
first[VALUE]
|
798
|
+
}). Expected (${toTypeNames(
|
799
|
+
MAIN_TYPE
|
800
|
+
)}) but got (${toTypeNames(
|
801
|
+
env[returns[VALUE]][STATS][TYPE_PROP]
|
802
|
+
)}) (${stringifyArgs(exp)}) (check #29)`
|
803
|
+
)
|
841
804
|
}
|
805
|
+
// Never happens because there is only 1 sub type at the moment
|
806
|
+
// if (
|
807
|
+
// PRED_TYPE &&
|
808
|
+
// PRED_TYPE !==
|
809
|
+
// env[returns[VALUE]][STATS][RETURNS][1]
|
810
|
+
// ) {
|
811
|
+
// }
|
842
812
|
}
|
843
813
|
}
|
844
|
-
}
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
// // else if (rest[i][TYPE] === ATOM) {
|
860
|
-
// // if (
|
861
|
-
// // PRED_TYPE === PREDICATE &&
|
862
|
-
// // rest[i][VALUE] !== TRUE &&
|
863
|
-
// // rest[i][VALUE] !== FALSE
|
864
|
-
// // ) {
|
865
|
-
// // }
|
866
|
-
// // }
|
867
|
-
// } else {
|
868
|
-
// // above code used to be ere
|
869
|
-
// }
|
870
|
-
// }
|
871
|
-
|
872
|
-
if (first[TYPE] === APPLY && isSpecial) {
|
873
|
-
const isCast = STATIC_TYPES_SET.has(first[VALUE])
|
874
|
-
const expectedArgs = env[first[VALUE]][STATS][ARGUMENTS]
|
875
|
-
for (let i = 0; i < rest.length; ++i) {
|
876
|
-
const PRED_TYPE = args[i][STATS][TYPE_PROP][1]
|
877
|
-
const MAIN_TYPE = expectedArgs[i][STATS][TYPE_PROP][0]
|
878
|
-
if (MAIN_TYPE === UNKNOWN && !isCast) continue
|
879
|
-
if (!isLeaf(rest[i])) {
|
880
|
-
const CAR = rest[i][0][VALUE]
|
881
|
-
const isKnown =
|
882
|
-
env[CAR] &&
|
883
|
-
env[CAR][STATS][RETURNS][0] !== UNKNOWN
|
884
|
-
if (isKnown && !isCast) {
|
885
|
-
if (env[CAR][STATS][RETURNS][0] !== MAIN_TYPE) {
|
886
|
-
errorStack.add(
|
887
|
-
`Incorrect type of argument (${i}) for special form (${
|
888
|
-
first[VALUE]
|
889
|
-
}). Expected (${toTypeNames(
|
890
|
-
MAIN_TYPE
|
891
|
-
)}) but got (${toTypeNames(
|
892
|
-
env[CAR][STATS][RETURNS][0]
|
893
|
-
)}) (${stringifyArgs(exp)}) (check #1)`
|
894
|
-
)
|
895
|
-
}
|
896
|
-
// never reached because there is only 1 subtype at the moment
|
897
|
-
// else if (
|
898
|
-
// PRED_TYPE &&
|
899
|
-
// env[CAR][STATS][RETURNS][1] !== PRED_TYPE
|
900
|
-
// ) {
|
901
|
-
// }
|
902
|
-
}
|
814
|
+
} else if (
|
815
|
+
PRED_TYPE &&
|
816
|
+
env[current[VALUE]] &&
|
817
|
+
env[current[VALUE]][STATS][RETURNS][1] !== PRED_TYPE
|
818
|
+
) {
|
819
|
+
if (current[VALUE] === KEYWORDS.ANONYMOUS_FUNCTION) {
|
820
|
+
const body = rest[i].at(-1)
|
821
|
+
const rem = hasBlock(body) ? body.at(-1) : body
|
822
|
+
const returns = isLeaf(rem) ? rem : rem[0]
|
823
|
+
if (
|
824
|
+
env[returns[VALUE]] &&
|
825
|
+
root[returns[VALUE]][STATS][RETURNS][1] ===
|
826
|
+
PREDICATE
|
827
|
+
) {
|
828
|
+
// TODO invert this logic
|
903
829
|
} else {
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
830
|
+
errorStack.add(
|
831
|
+
`Incorrect type of arguments (${i}) for (${
|
832
|
+
first[VALUE]
|
833
|
+
}). Expected (${toTypeNames(
|
834
|
+
PRED_TYPE
|
835
|
+
)}) but got (${toTypeNames(
|
836
|
+
env[current[VALUE]][STATS][RETURNS][1] ??
|
837
|
+
env[current[VALUE]][STATS][RETURNS][0]
|
838
|
+
)}) (${stringifyArgs(exp)}) (check #21)`
|
839
|
+
)
|
840
|
+
}
|
841
|
+
}
|
842
|
+
}
|
843
|
+
}
|
844
|
+
}
|
845
|
+
if (first[TYPE] === APPLY && isSpecial) {
|
846
|
+
const isCast = STATIC_TYPES_SET.has(first[VALUE])
|
847
|
+
const expectedArgs = env[first[VALUE]][STATS][ARGUMENTS]
|
848
|
+
for (let i = 0; i < rest.length; ++i) {
|
849
|
+
const PRED_TYPE = args[i][STATS][TYPE_PROP][1]
|
850
|
+
const MAIN_TYPE = expectedArgs[i][STATS][TYPE_PROP][0]
|
851
|
+
if (MAIN_TYPE === UNKNOWN && !isCast) continue
|
852
|
+
if (!isLeaf(rest[i])) {
|
853
|
+
const CAR = rest[i][0][VALUE]
|
854
|
+
const isKnown =
|
855
|
+
env[CAR] && env[CAR][STATS][RETURNS][0] !== UNKNOWN
|
856
|
+
if (isKnown && !isCast) {
|
857
|
+
if (env[CAR][STATS][RETURNS][0] !== MAIN_TYPE) {
|
858
|
+
errorStack.add(
|
859
|
+
`Incorrect type of argument (${i}) for special form (${
|
860
|
+
first[VALUE]
|
861
|
+
}). Expected (${toTypeNames(
|
862
|
+
MAIN_TYPE
|
863
|
+
)}) but got (${toTypeNames(
|
864
|
+
env[CAR][STATS][RETURNS][0]
|
865
|
+
)}) (${stringifyArgs(exp)}) (check #1)`
|
866
|
+
)
|
867
|
+
}
|
868
|
+
// never reached because there is only 1 subtype at the moment
|
869
|
+
// else if (
|
870
|
+
// PRED_TYPE &&
|
871
|
+
// env[CAR][STATS][RETURNS][1] !== PRED_TYPE
|
872
|
+
// ) {
|
873
|
+
// }
|
874
|
+
}
|
875
|
+
} else {
|
876
|
+
switch (rest[i][TYPE]) {
|
877
|
+
case WORD:
|
878
|
+
{
|
879
|
+
const CAR = rest[i][VALUE]
|
880
|
+
const isKnown =
|
881
|
+
env[CAR] &&
|
882
|
+
env[CAR][STATS][TYPE_PROP][0] !== UNKNOWN
|
883
|
+
if (isKnown && !isCast) {
|
884
|
+
if (
|
885
|
+
MAIN_TYPE !== env[CAR][STATS][TYPE_PROP][0]
|
886
|
+
) {
|
958
887
|
errorStack.add(
|
959
888
|
`Incorrect type of argument (${i}) for special form (${
|
960
889
|
first[VALUE]
|
961
890
|
}). Expected (${toTypeNames(
|
962
891
|
MAIN_TYPE
|
963
892
|
)}) but got (${toTypeNames(
|
964
|
-
|
965
|
-
)}) (${stringifyArgs(exp)}) (check #
|
893
|
+
env[CAR][STATS][TYPE_PROP][0]
|
894
|
+
)}) (${stringifyArgs(exp)}) (check #3)`
|
966
895
|
)
|
967
|
-
}
|
968
|
-
if (
|
896
|
+
} else if (
|
969
897
|
PRED_TYPE === PREDICATE &&
|
970
|
-
|
971
|
-
|
972
|
-
)
|
898
|
+
env[CAR][STATS][RETURNS][1] !== PRED_TYPE &&
|
899
|
+
!isCast
|
900
|
+
)
|
973
901
|
errorStack.add(
|
974
902
|
`Incorrect type of argument (${i}) for special form (${
|
975
903
|
first[VALUE]
|
976
904
|
}). Expected (${toTypeNames(
|
977
905
|
PRED_TYPE
|
978
906
|
)}) but got (${toTypeNames(
|
979
|
-
|
980
|
-
|
907
|
+
env[CAR][STATS][RETURNS][1] ??
|
908
|
+
env[CAR][STATS][TYPE_PROP][0]
|
909
|
+
)}) (${stringifyArgs(exp)}) (check #6)`
|
981
910
|
)
|
911
|
+
} else if (env[rest[i][VALUE]]) {
|
912
|
+
if (isCast) {
|
913
|
+
// CAST assigment
|
914
|
+
env[rest[i][VALUE]][STATS][TYPE_PROP] =
|
915
|
+
root[first[VALUE]][STATS][RETURNS]
|
916
|
+
root[first[VALUE]][STATS][RETURNS] =
|
917
|
+
root[first[VALUE]][STATS][RETURNS]
|
918
|
+
} else {
|
919
|
+
// VALUE assigment
|
920
|
+
env[rest[i][VALUE]][STATS][TYPE_PROP][0] =
|
921
|
+
MAIN_TYPE
|
982
922
|
}
|
983
|
-
|
984
|
-
break
|
985
923
|
}
|
986
924
|
}
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
// type checking
|
991
|
-
else if (
|
992
|
-
rest[i] &&
|
993
|
-
args[i][STATS] &&
|
994
|
-
rest[i][TYPE] !== args[i][STATS][TYPE_PROP][0]
|
995
|
-
) {
|
996
|
-
if (isLeaf(rest[i])) {
|
997
|
-
const T =
|
998
|
-
rest[i][TYPE] === WORD && env[rest[i][VALUE]]
|
999
|
-
? env[rest[i][VALUE]][STATS][TYPE_PROP][0]
|
1000
|
-
: rest[i][TYPE]
|
1001
|
-
if (T === ATOM) {
|
1002
|
-
if (
|
1003
|
-
args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
|
1004
|
-
args[i][STATS][TYPE_PROP][0] !== ATOM
|
1005
|
-
) {
|
925
|
+
break
|
926
|
+
case ATOM: {
|
927
|
+
if (rest[i][TYPE] !== MAIN_TYPE) {
|
1006
928
|
errorStack.add(
|
1007
|
-
`Incorrect type of
|
929
|
+
`Incorrect type of argument (${i}) for special form (${
|
1008
930
|
first[VALUE]
|
1009
931
|
}). Expected (${toTypeNames(
|
1010
|
-
|
932
|
+
MAIN_TYPE
|
1011
933
|
)}) but got (${toTypeNames(
|
1012
|
-
|
1013
|
-
)}) (${stringifyArgs(exp)}) (check #
|
934
|
+
rest[i][TYPE]
|
935
|
+
)}) (${stringifyArgs(exp)}) (check #2)`
|
1014
936
|
)
|
1015
|
-
}
|
1016
|
-
|
1017
|
-
|
937
|
+
}
|
938
|
+
if (
|
939
|
+
PRED_TYPE === PREDICATE &&
|
1018
940
|
rest[i][VALUE] !== TRUE &&
|
1019
941
|
rest[i][VALUE] !== FALSE
|
1020
942
|
) {
|
1021
943
|
errorStack.add(
|
1022
|
-
`Incorrect type of
|
944
|
+
`Incorrect type of argument (${i}) for special form (${
|
1023
945
|
first[VALUE]
|
1024
946
|
}). Expected (${toTypeNames(
|
1025
|
-
|
947
|
+
PRED_TYPE
|
1026
948
|
)}) but got (${toTypeNames(
|
1027
|
-
|
1028
|
-
)}) (${stringifyArgs(exp)}) (check #
|
949
|
+
rest[i][VALUE]
|
950
|
+
)}) (${stringifyArgs(exp)}) (check #5)`
|
1029
951
|
)
|
1030
952
|
}
|
1031
|
-
}
|
1032
953
|
|
1033
|
-
|
1034
|
-
env[rest[i][VALUE]] &&
|
1035
|
-
env[rest[i][VALUE]][STATS][TYPE_PROP][0] !==
|
1036
|
-
UNKNOWN &&
|
1037
|
-
args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
|
1038
|
-
env[rest[i][VALUE]][STATS][TYPE_PROP][0] !==
|
1039
|
-
args[i][STATS][TYPE_PROP][0]
|
1040
|
-
) {
|
1041
|
-
errorStack.add(
|
1042
|
-
`Incorrect type of arguments ${i} for (${
|
1043
|
-
first[VALUE]
|
1044
|
-
}). Expected (${toTypeNames(
|
1045
|
-
args[i][STATS][TYPE_PROP][0]
|
1046
|
-
)}) but got (${toTypeNames(T)}) (${stringifyArgs(
|
1047
|
-
exp
|
1048
|
-
)}) (check #30)`
|
1049
|
-
)
|
1050
|
-
} else {
|
1051
|
-
// const retry = env[rest[i][VALUE]]
|
1052
|
-
// if (
|
1053
|
-
// retry &&
|
1054
|
-
// retry[STATS].retried < RETRY_COUNT &&
|
1055
|
-
// args[i][STATS][TYPE_PROP][0] === UNKNOWN
|
1056
|
-
// ) {
|
1057
|
-
// retry[STATS].retried += 1
|
1058
|
-
// stack.unshift(() => check(exp, env, scope))
|
1059
|
-
// } else
|
1060
|
-
if (
|
1061
|
-
args[i][STATS][TYPE_PROP][0] === UNKNOWN &&
|
1062
|
-
args[i][STATS].retried < MAX_RETRY_DEFINITION
|
1063
|
-
) {
|
1064
|
-
args[i][STATS].retried += 1
|
1065
|
-
stack.unshift(() => check(exp, env, scope))
|
1066
|
-
} else {
|
1067
|
-
if (
|
1068
|
-
env[rest[i][VALUE]] &&
|
1069
|
-
args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
|
1070
|
-
env[rest[i][VALUE]][STATS][TYPE_PROP][0] ===
|
1071
|
-
UNKNOWN &&
|
1072
|
-
args[i][STATS][TYPE_PROP][0] !== APPLY
|
1073
|
-
) {
|
1074
|
-
// REFF ASSIGMENT
|
1075
|
-
env[rest[i][VALUE]][STATS][TYPE_PROP] =
|
1076
|
-
args[i][STATS][TYPE_PROP]
|
1077
|
-
env[rest[i][VALUE]][STATS][RETURNS] =
|
1078
|
-
args[i][STATS][RETURNS]
|
1079
|
-
}
|
1080
|
-
}
|
1081
|
-
}
|
1082
|
-
} else if (rest[i].length) {
|
1083
|
-
// TODO figure out what cann we do in this else ?
|
1084
|
-
// Check arg types (check 4)
|
1085
|
-
// )
|
1086
|
-
// TODO figure out if we need this
|
1087
|
-
|
1088
|
-
if (
|
1089
|
-
rest[i][0][TYPE] === APPLY &&
|
1090
|
-
env[rest[i][0][VALUE]]
|
1091
|
-
) {
|
1092
|
-
const actual =
|
1093
|
-
env[rest[i][0][VALUE]][STATS][RETURNS]
|
1094
|
-
const expected = args[i][STATS][TYPE_PROP]
|
1095
|
-
if (
|
1096
|
-
expected[0] !== UNKNOWN &&
|
1097
|
-
actual[0] !== UNKNOWN
|
1098
|
-
) {
|
1099
|
-
if (expected[0] !== actual[0])
|
1100
|
-
errorStack.add(
|
1101
|
-
`Incorrect type of arguments ${i} for (${
|
1102
|
-
first[VALUE]
|
1103
|
-
}). Expected (${toTypeNames(
|
1104
|
-
expected[0]
|
1105
|
-
)}) but got (${toTypeNames(
|
1106
|
-
actual[0]
|
1107
|
-
)}) (${stringifyArgs(exp)}) (check #16)`
|
1108
|
-
)
|
1109
|
-
} else {
|
1110
|
-
if (
|
1111
|
-
args[i][STATS].retried < MAX_RETRY_DEFINITION
|
1112
|
-
) {
|
1113
|
-
args[i][STATS].retried += 1
|
1114
|
-
stack.unshift(() => check(exp, env, scope))
|
1115
|
-
}
|
1116
|
-
}
|
954
|
+
break
|
1117
955
|
}
|
1118
956
|
}
|
1119
957
|
}
|
1120
958
|
}
|
1121
959
|
}
|
960
|
+
// type checking
|
961
|
+
else if (isLeaf(rest[i])) {
|
962
|
+
const T =
|
963
|
+
rest[i][TYPE] === WORD && env[rest[i][VALUE]]
|
964
|
+
? env[rest[i][VALUE]][STATS][TYPE_PROP][0]
|
965
|
+
: rest[i][TYPE]
|
966
|
+
if (
|
967
|
+
T === ATOM &&
|
968
|
+
args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
|
969
|
+
args[i][STATS][TYPE_PROP][0] !== ATOM
|
970
|
+
) {
|
971
|
+
errorStack.add(
|
972
|
+
`Incorrect type of arguments ${i} for (${
|
973
|
+
first[VALUE]
|
974
|
+
}). Expected (${toTypeNames(
|
975
|
+
args[i][STATS][TYPE_PROP][0]
|
976
|
+
)}) but got (${toTypeNames(T)}) (${stringifyArgs(
|
977
|
+
exp
|
978
|
+
)}) (check #10)`
|
979
|
+
)
|
980
|
+
} else if (
|
981
|
+
T === ATOM &&
|
982
|
+
args[i][STATS][RETURNS][0] === ATOM &&
|
983
|
+
args[i][STATS][RETURNS][1] === PREDICATE &&
|
984
|
+
rest[i][VALUE] !== TRUE &&
|
985
|
+
rest[i][VALUE] !== FALSE
|
986
|
+
) {
|
987
|
+
errorStack.add(
|
988
|
+
`Incorrect type of arguments ${i} for (${
|
989
|
+
first[VALUE]
|
990
|
+
}). Expected (${toTypeNames(
|
991
|
+
args[i][STATS][RETURNS][1]
|
992
|
+
)}) but got (${toTypeNames(T)}) (${stringifyArgs(
|
993
|
+
exp
|
994
|
+
)}) (check #13)`
|
995
|
+
)
|
996
|
+
}
|
997
|
+
|
998
|
+
if (
|
999
|
+
env[rest[i][VALUE]] &&
|
1000
|
+
env[rest[i][VALUE]][STATS][TYPE_PROP][0] !== UNKNOWN &&
|
1001
|
+
args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
|
1002
|
+
env[rest[i][VALUE]][STATS][TYPE_PROP][0] !==
|
1003
|
+
args[i][STATS][TYPE_PROP][0]
|
1004
|
+
) {
|
1005
|
+
errorStack.add(
|
1006
|
+
`Incorrect type of arguments ${i} for (${
|
1007
|
+
first[VALUE]
|
1008
|
+
}). Expected (${toTypeNames(
|
1009
|
+
args[i][STATS][TYPE_PROP][0]
|
1010
|
+
)}) but got (${toTypeNames(T)}) (${stringifyArgs(
|
1011
|
+
exp
|
1012
|
+
)}) (check #30)`
|
1013
|
+
)
|
1014
|
+
} else if (
|
1015
|
+
args[i][STATS][TYPE_PROP][0] === UNKNOWN &&
|
1016
|
+
args[i][STATS].retried < MAX_RETRY_DEFINITION
|
1017
|
+
) {
|
1018
|
+
args[i][STATS].retried += 1
|
1019
|
+
stack.unshift(() => check(exp, env, scope))
|
1020
|
+
} else {
|
1021
|
+
if (
|
1022
|
+
env[rest[i][VALUE]] &&
|
1023
|
+
args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
|
1024
|
+
env[rest[i][VALUE]][STATS][TYPE_PROP][0] === UNKNOWN &&
|
1025
|
+
args[i][STATS][TYPE_PROP][0] !== APPLY
|
1026
|
+
) {
|
1027
|
+
// REFF ASSIGMENT
|
1028
|
+
env[rest[i][VALUE]][STATS][TYPE_PROP] =
|
1029
|
+
args[i][STATS][TYPE_PROP]
|
1030
|
+
env[rest[i][VALUE]][STATS][RETURNS] =
|
1031
|
+
args[i][STATS][RETURNS]
|
1032
|
+
}
|
1033
|
+
}
|
1034
|
+
} else if (
|
1035
|
+
rest[i].length &&
|
1036
|
+
rest[i][0][TYPE] === APPLY &&
|
1037
|
+
env[rest[i][0][VALUE]]
|
1038
|
+
) {
|
1039
|
+
const match = () => {
|
1040
|
+
const actual = env[rest[i][0][VALUE]][STATS][RETURNS]
|
1041
|
+
const expected = args[i][STATS][TYPE_PROP]
|
1042
|
+
if (args[i][STATS].counter < MAX_ARGUMENT_RETRY) {
|
1043
|
+
args[i][STATS].counter++
|
1044
|
+
stack.unshift(() => match())
|
1045
|
+
}
|
1046
|
+
if (expected[0] !== UNKNOWN && actual[0] !== UNKNOWN) {
|
1047
|
+
if (expected[0] !== actual[0])
|
1048
|
+
errorStack.add(
|
1049
|
+
`Incorrect type of arguments ${i} for (${
|
1050
|
+
first[VALUE]
|
1051
|
+
}). Expected (${toTypeNames(
|
1052
|
+
expected[0]
|
1053
|
+
)}) but got (${toTypeNames(
|
1054
|
+
actual[0]
|
1055
|
+
)}) (${stringifyArgs(exp)}) (check #16)`
|
1056
|
+
)
|
1057
|
+
} else if (
|
1058
|
+
expected[0] === UNKNOWN &&
|
1059
|
+
args[i][STATS].retried < MAX_RETRY_DEFINITION
|
1060
|
+
) {
|
1061
|
+
args[i][STATS].retried += 1
|
1062
|
+
stack.unshift(() => match())
|
1063
|
+
}
|
1064
|
+
}
|
1065
|
+
|
1066
|
+
match()
|
1067
|
+
}
|
1122
1068
|
}
|
1123
1069
|
}
|
1124
1070
|
})
|
1125
1071
|
for (let i = 0; i < rest.length; ++i) {
|
1126
1072
|
const r = rest[i]
|
1127
|
-
if (isLeaf(r) && r[TYPE] !== ATOM
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1073
|
+
if (isLeaf(r) && r[TYPE] !== ATOM) {
|
1074
|
+
if (env[r[VALUE]] == undefined) {
|
1075
|
+
errorStack.add(
|
1076
|
+
`(${
|
1077
|
+
first[VALUE]
|
1078
|
+
}) is trying to access undefined variable (${
|
1079
|
+
r[VALUE]
|
1080
|
+
}) at argument (${i}) (${stringifyArgs(exp)}) (check #20)`
|
1081
|
+
)
|
1082
|
+
}
|
1133
1083
|
}
|
1084
|
+
|
1134
1085
|
check(r, env, scope)
|
1135
1086
|
}
|
1136
1087
|
break
|