fez-lisp 1.5.89 → 1.5.90

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 +134 -14
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.89",
5
+ "version": "1.5.90",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -197,6 +197,8 @@ export const typeCheck = (ast) => {
197
197
  root[ORDER] = 0
198
198
  const errorStack = new Set()
199
199
  const warningStack = new Set()
200
+ // TODO delete this
201
+ const tempStack = new Set()
200
202
  const Types = new Map()
201
203
  const stack = []
202
204
  const check = (exp, env, scope) => {
@@ -619,16 +621,18 @@ export const typeCheck = (ast) => {
619
621
  )
620
622
  } else if (!env[first[VALUE]][STATS][ARG_COUNT]) {
621
623
  // TODO recursively take return type of applicaion
622
- if (env[first[VALUE]][STATS][RETURNS][0] === APPLY) {
623
- env[first[VALUE]][STATS][RETURNS] = [UNKNOWN]
624
- }
624
+ // if (env[first[VALUE]][STATS][RETURNS][0] === APPLY) {
625
+ // env[first[VALUE]][STATS][RETURNS] = [UNKNOWN]
626
+ // }
625
627
  // FN ASSIGMENT
628
+
629
+ // ASSIGMENT of paramaters of lambda that are a lambda
630
+ // minus one to remove the body
626
631
  env[first[VALUE]][STATS][TYPE_PROP] = [APPLY]
627
632
  env[first[VALUE]][STATS][ARG_COUNT] = rest.length
628
633
  env[first[VALUE]][STATS][ARGUMENTS] = fillUknownArgs(
629
634
  rest.length
630
635
  )
631
- // ASSIGMENT of paramaters of lambda that are a lambda
632
636
  for (let i = 0; i < rest.length; ++i) {
633
637
  const arg = env[first[VALUE]][STATS][ARGUMENTS]
634
638
  arg[i] = {
@@ -641,13 +645,23 @@ export const typeCheck = (ast) => {
641
645
  [ARG_COUNT]: 0
642
646
  }
643
647
  }
644
- switch (rest[i][TYPE]) {
645
- case ATOM:
646
- arg[i][STATS][TYPE_PROP][0] = ATOM
648
+ const ARG = isLeaf(rest[i]) ? rest[i] : rest[i][0]
649
+ if (!env[ARG[VALUE]]) continue
650
+ // console.log(stringifyArgs(exp), ARG)
651
+ switch (ARG[TYPE]) {
652
+ // THERE ARE NO ATOM ARGUMENTS
653
+ // case ATOM:
654
+ // break
655
+ case APPLY:
656
+ // passing arg asA APPLICATION
657
+ if (arg[i][STATS][TYPE_PROP][0] === UNKNOWN)
658
+ arg[i][STATS][TYPE_PROP] =
659
+ env[ARG[VALUE]][STATS][RETURNS]
647
660
  break
648
661
  case WORD:
649
- case APPLY:
650
- arg[i][STATS] = env[rest[i][VALUE]][STATS]
662
+ // if param is a word we assosiate them by referanc
663
+ if (arg[i][STATS][TYPE_PROP][0] === UNKNOWN)
664
+ arg[i][STATS] = env[ARG[VALUE]][STATS]
651
665
  break
652
666
  }
653
667
  }
@@ -661,16 +675,12 @@ export const typeCheck = (ast) => {
661
675
  // TODO get rof pred type
662
676
  // const PRED_TYPE = args[i][STATS][TYPE_PROP][1]
663
677
  const MAIN_TYPE = args[i][STATS][TYPE_PROP][0]
678
+
664
679
  if (first[TYPE] === APPLY && isSpecial) {
665
680
  if (
666
681
  MAIN_TYPE === ATOM &&
667
682
  PREDICATES_INPUT_SET.has(first[VALUE])
668
683
  ) {
669
- // if (isRestILeaf && rest[i][TYPE] === ATOM && rest[i][VALUE] !== TRUE && rest[i][TYPE] !== FALSE) throw some rror
670
- // else if (
671
- // isRestILeaf && est[i][TYPE] === ATOM && (rest[i][VALUE] === TRUE || rest[i][VALUE] === FALSE)
672
- // ) continue
673
- // else
674
684
  if (
675
685
  !isRestILeaf &&
676
686
  rest[i][0][TYPE] === APPLY &&
@@ -750,6 +760,15 @@ export const typeCheck = (ast) => {
750
760
  // env[CAR][STATS][RETURNS][1] !== PRED_TYPE
751
761
  // ) {
752
762
  // }
763
+ } else if (!isKnown && !isCast && env[CAR]) {
764
+ if (
765
+ env[CAR][STATS][TYPE_PROP][0] === APPLY &&
766
+ root[first[VALUE]][STATS][RETURNS][0] !== UNKNOWN &&
767
+ env[CAR][STATS][RETURNS][0] !== UNKNOWN
768
+ )
769
+ env[CAR][STATS][RETURNS][0] =
770
+ root[first[VALUE]][STATS][RETURNS][0]
771
+ // TODO also handle casting
753
772
  }
754
773
  } else {
755
774
  switch (rest[i][TYPE]) {
@@ -927,6 +946,107 @@ export const typeCheck = (ast) => {
927
946
  exp
928
947
  )}) (check #777)`
929
948
  )
949
+ } else {
950
+ // ANONYMOUS LAMBDAS TYPE CHECKING
951
+ const local = Object.create(env)
952
+ const lambdaName = `lambda::annonymous::${i}::${performance
953
+ .now()
954
+ .toString()
955
+ .replace('.', 0)}*`
956
+ check(
957
+ [
958
+ [APPLY, KEYWORDS.DEFINE_VARIABLE],
959
+ [WORD, lambdaName],
960
+ rest[i]
961
+ ],
962
+ local,
963
+ scope
964
+ )
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()
997
+ for (
998
+ let j = 0;
999
+ j < args[i][STATS][ARGUMENTS].length;
1000
+ ++j
1001
+ ) {
1002
+ const match2 = () => {
1003
+ const actual =
1004
+ local[lambdaName][STATS][ARGUMENTS][j]
1005
+ const expected =
1006
+ args[i][STATS][ARGUMENTS][j]
1007
+ if (
1008
+ actual[STATS][TYPE_PROP][0] !==
1009
+ UNKNOWN &&
1010
+ expected[STATS][TYPE_PROP][0] !==
1011
+ UNKNOWN &&
1012
+ actual[STATS][TYPE_PROP][0] !==
1013
+ expected[STATS][TYPE_PROP][0]
1014
+ )
1015
+ errorStack.add(
1016
+ `Incorrect type for (lambda) (${
1017
+ args[i][STATS][SIGNATURE]
1018
+ }) argument at position (${j}) named as (${
1019
+ local[lambdaName][STATS][
1020
+ ARGUMENTS
1021
+ ][j][STATS][SIGNATURE]
1022
+ }). Expected (${toTypeNames(
1023
+ args[i][STATS][ARGUMENTS][j][
1024
+ STATS
1025
+ ][TYPE_PROP][0]
1026
+ )}) but got (${toTypeNames(
1027
+ local[lambdaName][STATS][
1028
+ ARGUMENTS
1029
+ ][j][STATS][TYPE_PROP][0]
1030
+ )}) (${stringifyArgs(
1031
+ exp
1032
+ )}) (check #780)`
1033
+ )
1034
+ else if (
1035
+ actual[STATS].retried <
1036
+ MAX_RETRY_DEFINITION
1037
+ ) {
1038
+ actual[STATS].retried += 1
1039
+ stack.unshift(() => match2())
1040
+ }
1041
+ }
1042
+ match2()
1043
+ }
1044
+ // console.log(
1045
+ // env[first[VALUE]][STATS][ARGUMENTS][i][
1046
+ // STATS
1047
+ // ],
1048
+ // args[i][STATS]
1049
+ // )
930
1050
  }
931
1051
  } else {
932
1052
  // TODO fix curry: lambdas enter here as undefined