fez-lisp 1.5.90 → 1.5.91

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/check.js +126 -44
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "fez-lisp",
3
3
  "description": "Lisp interpreted & compiled to JavaScript",
4
4
  "author": "AT290690",
5
- "version": "1.5.90",
5
+ "version": "1.5.91",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -763,11 +763,24 @@ export const typeCheck = (ast) => {
763
763
  } else if (!isKnown && !isCast && env[CAR]) {
764
764
  if (
765
765
  env[CAR][STATS][TYPE_PROP][0] === APPLY &&
766
- root[first[VALUE]][STATS][RETURNS][0] !== UNKNOWN &&
767
766
  env[CAR][STATS][RETURNS][0] !== UNKNOWN
768
- )
769
- env[CAR][STATS][RETURNS][0] =
770
- root[first[VALUE]][STATS][RETURNS][0]
767
+ ) {
768
+ switch (first[VALUE]) {
769
+ case KEYWORDS.IF:
770
+ break
771
+ case KEYWORDS.CALL_FUNCTION:
772
+ break
773
+ default:
774
+ // console.log(stringifyArgs(exp))
775
+ // TODO fix this assigment
776
+ // It turns out it's not possible to determine return type of function here
777
+ // what if it's a global function used elsewhere where the return type mwould be different/
778
+ // env[CAR][STATS][RETURNS][0] =
779
+ // root[first[VALUE]][STATS][RETURNS][0]
780
+ break
781
+ }
782
+ }
783
+
771
784
  // TODO also handle casting
772
785
  }
773
786
  } else {
@@ -866,6 +879,79 @@ export const typeCheck = (ast) => {
866
879
  env[rest[i][VALUE]][STATS][ARG_COUNT]
867
880
  } (${stringifyArgs(exp)}) (check #778)`
868
881
  )
882
+ } else {
883
+ // DEFINED LAMBDAS TYPE CHECKING
884
+ // TODO delete this maybe
885
+ // It will not be possilbe to know return type
886
+ // const match1 = () => {
887
+ // const actual = env[rest[i][VALUE]]
888
+ // const expected = args[i]
889
+ // if (
890
+ // expected[STATS][RETURNS][0] !== UNKNOWN &&
891
+ // actual[STATS][RETURNS][0] !== UNKNOWN &&
892
+ // expected[STATS][RETURNS][0] !==
893
+ // actual[STATS][RETURNS][0]
894
+ // ) {
895
+ // errorStack.add(
896
+ // `Incorrect return type for (${
897
+ // expected[STATS][SIGNATURE]
898
+ // }) the (lambda) argument of (${
899
+ // first[VALUE]
900
+ // }) at position (${i}). Expected (${toTypeNames(
901
+ // expected[STATS][RETURNS][0]
902
+ // )}) but got (${toTypeNames(
903
+ // actual[STATS][RETURNS][0]
904
+ // )}) (${stringifyArgs(exp)}) (check #782)`
905
+ // )
906
+ // } else if (
907
+ // actual[STATS].retried < MAX_RETRY_DEFINITION
908
+ // ) {
909
+ // actual[STATS].retried += 1
910
+ // stack.unshift(() => match1())
911
+ // }
912
+ // }
913
+ // match1()
914
+ for (
915
+ let j = 0;
916
+ j < args[i][STATS][ARGUMENTS].length;
917
+ ++j
918
+ ) {
919
+ const match2 = () => {
920
+ const actual =
921
+ env[rest[i][VALUE]][STATS][ARGUMENTS][j]
922
+ const expected = args[i][STATS][ARGUMENTS][j]
923
+ if (
924
+ actual[STATS][TYPE_PROP][0] !== UNKNOWN &&
925
+ expected[STATS][TYPE_PROP][0] !== UNKNOWN &&
926
+ actual[STATS][TYPE_PROP][0] !==
927
+ expected[STATS][TYPE_PROP][0]
928
+ )
929
+ errorStack.add(
930
+ `Incorrect type for (lambda) (${
931
+ args[i][STATS][SIGNATURE]
932
+ }) argument at position (${j}) named as (${
933
+ env[rest[i][VALUE]][STATS][ARGUMENTS][j][
934
+ STATS
935
+ ][SIGNATURE]
936
+ }). Expected (${toTypeNames(
937
+ args[i][STATS][ARGUMENTS][j][STATS][
938
+ TYPE_PROP
939
+ ][0]
940
+ )}) but got (${toTypeNames(
941
+ env[rest[i][VALUE]][STATS][ARGUMENTS][j][
942
+ STATS
943
+ ][TYPE_PROP][0]
944
+ )}) (${stringifyArgs(exp)}) (check #781)`
945
+ )
946
+ else if (
947
+ actual[STATS].retried < MAX_RETRY_DEFINITION
948
+ ) {
949
+ actual[STATS].retried += 1
950
+ stack.unshift(() => match2())
951
+ }
952
+ }
953
+ match2()
954
+ }
869
955
  }
870
956
  }
871
957
  if (
@@ -962,38 +1048,40 @@ export const typeCheck = (ast) => {
962
1048
  local,
963
1049
  scope
964
1050
  )
965
- const match1 = () => {
966
- const actual = local[lambdaName]
967
- const expected = args[i]
968
- if (
969
- expected[STATS][RETURNS][0] !==
970
- UNKNOWN &&
971
- actual[STATS][RETURNS][0] !== UNKNOWN &&
972
- expected[STATS][RETURNS][0] !==
973
- actual[STATS][RETURNS][0]
974
- ) {
975
- errorStack.add(
976
- `Incorrect return type for (${
977
- expected[STATS][SIGNATURE]
978
- }) the (lambda) argument of (${
979
- first[VALUE]
980
- }) at position (${i}). Expected (${toTypeNames(
981
- expected[STATS][RETURNS][0]
982
- )}) but got (${toTypeNames(
983
- actual[STATS][RETURNS][0]
984
- )}) (${stringifyArgs(
985
- exp
986
- )}) (check #779)`
987
- )
988
- } else if (
989
- actual[STATS].retried <
990
- MAX_RETRY_DEFINITION
991
- ) {
992
- actual[STATS].retried += 1
993
- stack.unshift(() => match1())
994
- }
995
- }
996
- match1()
1051
+ // TODO delete this maybe
1052
+ // It will not be possilbe to know return type
1053
+ // const match1 = () => {
1054
+ // const actual = local[lambdaName]
1055
+ // const expected = args[i]
1056
+ // if (
1057
+ // expected[STATS][RETURNS][0] !==
1058
+ // UNKNOWN &&
1059
+ // actual[STATS][RETURNS][0] !== UNKNOWN &&
1060
+ // expected[STATS][RETURNS][0] !==
1061
+ // actual[STATS][RETURNS][0]
1062
+ // ) {
1063
+ // errorStack.add(
1064
+ // `Incorrect return type for (${
1065
+ // expected[STATS][SIGNATURE]
1066
+ // }) the (lambda) argument of (${
1067
+ // first[VALUE]
1068
+ // }) at position (${i}). Expected (${toTypeNames(
1069
+ // expected[STATS][RETURNS][0]
1070
+ // )}) but got (${toTypeNames(
1071
+ // actual[STATS][RETURNS][0]
1072
+ // )}) (${stringifyArgs(
1073
+ // exp
1074
+ // )}) (check #779)`
1075
+ // )
1076
+ // } else if (
1077
+ // actual[STATS].retried <
1078
+ // MAX_RETRY_DEFINITION
1079
+ // ) {
1080
+ // actual[STATS].retried += 1
1081
+ // stack.unshift(() => match1())
1082
+ // }
1083
+ // }
1084
+ // match1()
997
1085
  for (
998
1086
  let j = 0;
999
1087
  j < args[i][STATS][ARGUMENTS].length;
@@ -1011,7 +1099,7 @@ export const typeCheck = (ast) => {
1011
1099
  UNKNOWN &&
1012
1100
  actual[STATS][TYPE_PROP][0] !==
1013
1101
  expected[STATS][TYPE_PROP][0]
1014
- )
1102
+ ) {
1015
1103
  errorStack.add(
1016
1104
  `Incorrect type for (lambda) (${
1017
1105
  args[i][STATS][SIGNATURE]
@@ -1031,7 +1119,7 @@ export const typeCheck = (ast) => {
1031
1119
  exp
1032
1120
  )}) (check #780)`
1033
1121
  )
1034
- else if (
1122
+ } else if (
1035
1123
  actual[STATS].retried <
1036
1124
  MAX_RETRY_DEFINITION
1037
1125
  ) {
@@ -1041,12 +1129,6 @@ export const typeCheck = (ast) => {
1041
1129
  }
1042
1130
  match2()
1043
1131
  }
1044
- // console.log(
1045
- // env[first[VALUE]][STATS][ARGUMENTS][i][
1046
- // STATS
1047
- // ],
1048
- // args[i][STATS]
1049
- // )
1050
1132
  }
1051
1133
  } else {
1052
1134
  // TODO fix curry: lambdas enter here as undefined