fez-lisp 1.5.60 → 1.5.63

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/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.60",
5
+ "version": "1.5.63",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -81,13 +81,11 @@ const formatType = (name, env) => {
81
81
  ? `${name} (${(stats[ARGUMENTS] ?? [])
82
82
  .map(
83
83
  (x) =>
84
- `${x[STATS][SIGNATURE]} ${x[STATS][TYPE_PROP].map(
85
- toTypeNames
84
+ `${x[STATS][SIGNATURE]} ${x[STATS][TYPE_PROP].map((x) =>
85
+ toTypeNames(x)
86
86
  ).join(' ')}${
87
- x[STATS][TYPE_PROP][0] === APPLY
88
- ? ` ${toTypeNames(
89
- x[STATS][RETURNS][1] ?? x[STATS][RETURNS][0]
90
- )}`
87
+ getSuffix(x[STATS][SIGNATURE]) === PREDICATE_SUFFIX
88
+ ? ' ' + toTypeNames(PREDICATE)
91
89
  : ''
92
90
  }`
93
91
  )
@@ -1261,9 +1259,12 @@ export const typeCheck = (ast) => {
1261
1259
  const isKnown = T[TYPE_PROP][0] !== UNKNOWN
1262
1260
  switch (first[VALUE]) {
1263
1261
  case 'xs':
1262
+ case 'arr':
1263
+ case 'matrix':
1264
+ case 'table':
1264
1265
  if (isKnown && T[TYPE_PROP][0] !== COLLECTION) {
1265
1266
  warningStack.add(
1266
- `A variable named xs must be of type (${
1267
+ `A variable named ${first[VALUE]} must be of type (${
1267
1268
  STATIC_TYPES.COLLECTION
1268
1269
  }) but got type (${toTypeNames(
1269
1270
  T[TYPE_PROP][0]
@@ -1648,6 +1649,16 @@ export const typeCheck = (ast) => {
1648
1649
  }
1649
1650
  for (let i = 0; i < params.length; ++i) {
1650
1651
  const param = params[i]
1652
+ // TODO move this somewhere else
1653
+ if (!isLeaf(param)) {
1654
+ warningStack.add(
1655
+ `Invalid body for (${
1656
+ first[VALUE]
1657
+ }) if it takes more than one expression it must be wrapped in a (${
1658
+ KEYWORDS.BLOCK
1659
+ }) (${stringifyArgs(exp)}) (check #666)`
1660
+ )
1661
+ }
1651
1662
  copy[param[VALUE]] = {
1652
1663
  [STATS]: {
1653
1664
  [SIGNATURE]: param[VALUE],
@@ -1959,7 +1970,7 @@ export const typeCheck = (ast) => {
1959
1970
  )}) (${stringifyArgs(exp)}) (check #3)`
1960
1971
  )
1961
1972
  } else if (
1962
- PRED_TYPE &&
1973
+ PRED_TYPE === PREDICATE &&
1963
1974
  env[CAR][STATS][RETURNS][1] !==
1964
1975
  PRED_TYPE &&
1965
1976
  !isCast
@@ -1999,6 +2010,21 @@ export const typeCheck = (ast) => {
1999
2010
  )}) (${stringifyArgs(exp)}) (check #2)`
2000
2011
  )
2001
2012
  }
2013
+ if (
2014
+ PRED_TYPE === PREDICATE &&
2015
+ rest[i][VALUE] !== TRUE &&
2016
+ rest[i][VALUE] !== FALSE
2017
+ ) {
2018
+ errorStack.add(
2019
+ `Incorrect type of argument (${i}) for special form (${
2020
+ first[VALUE]
2021
+ }). Expected (${toTypeNames(
2022
+ PRED_TYPE
2023
+ )}) but got (${toTypeNames(
2024
+ rest[i][VALUE]
2025
+ )}) (${stringifyArgs(exp)}) (check #5)`
2026
+ )
2027
+ }
2002
2028
  break
2003
2029
  }
2004
2030
  }
@@ -2016,16 +2042,45 @@ export const typeCheck = (ast) => {
2016
2042
  rest[i][TYPE] === WORD && env[rest[i][VALUE]]
2017
2043
  ? env[rest[i][VALUE]][STATS][TYPE_PROP][0]
2018
2044
  : rest[i][TYPE]
2019
- if (
2020
- (args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
2021
- T === ATOM &&
2022
- args[i][STATS][TYPE_PROP][0] !== ATOM) ||
2023
- (env[rest[i][VALUE]] &&
2024
- env[rest[i][VALUE]][STATS][TYPE_PROP][0] !==
2025
- UNKNOWN &&
2045
+ if (T === ATOM) {
2046
+ if (
2026
2047
  args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
2027
- env[rest[i][VALUE]][STATS][TYPE_PROP][0] !==
2028
- args[i][STATS][TYPE_PROP][0])
2048
+ args[i][STATS][TYPE_PROP][0] !== ATOM
2049
+ ) {
2050
+ errorStack.add(
2051
+ `Incorrect type of arguments ${i} for (${
2052
+ first[VALUE]
2053
+ }). Expected (${toTypeNames(
2054
+ args[i][STATS][TYPE_PROP][0]
2055
+ )}) but got (${toTypeNames(
2056
+ T
2057
+ )}) (${stringifyArgs(exp)}) (check #10)`
2058
+ )
2059
+ } else if (
2060
+ args[i][STATS][RETURNS][0] === ATOM &&
2061
+ args[i][STATS][RETURNS][1] === PREDICATE &&
2062
+ rest[i][VALUE] !== TRUE &&
2063
+ rest[i][VALUE] !== FALSE
2064
+ ) {
2065
+ errorStack.add(
2066
+ `Incorrect type of arguments ${i} for (${
2067
+ first[VALUE]
2068
+ }). Expected (${toTypeNames(
2069
+ args[i][STATS][RETURNS][1]
2070
+ )}) but got (${toTypeNames(
2071
+ T
2072
+ )}) (${stringifyArgs(exp)}) (check #13)`
2073
+ )
2074
+ }
2075
+ }
2076
+
2077
+ if (
2078
+ env[rest[i][VALUE]] &&
2079
+ env[rest[i][VALUE]][STATS][TYPE_PROP][0] !==
2080
+ UNKNOWN &&
2081
+ args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
2082
+ env[rest[i][VALUE]][STATS][TYPE_PROP][0] !==
2083
+ args[i][STATS][TYPE_PROP][0]
2029
2084
  ) {
2030
2085
  errorStack.add(
2031
2086
  `Incorrect type of arguments ${i} for (${