fez-lisp 1.5.78 → 1.5.80

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.78",
5
+ "version": "1.5.80",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -85,18 +85,16 @@ export const formatType = (name, env) => {
85
85
  const stats = env[name][STATS]
86
86
  return stats
87
87
  ? stats[TYPE_PROP][0] === APPLY
88
- ? `${name} (${
88
+ ? `${typeof name !== 'number' ? `${name} ` : ''}(${
89
89
  stats[ARG_COUNT] === VARIADIC
90
90
  ? '... ' + STATIC_TYPES.UNKNOWN
91
91
  : (stats[ARGUMENTS] ?? [])
92
92
  .map(
93
- (x) =>
94
- `${x[STATS][SIGNATURE]} ${x[STATS][TYPE_PROP].map((x) =>
95
- toTypeNames(x)
96
- ).join(' ')}${
97
- getSuffix(x[STATS][SIGNATURE]) === PREDICATE_SUFFIX
98
- ? ' ' + toTypeNames(PREDICATE)
99
- : ''
93
+ (x, i) =>
94
+ `${
95
+ x[STATS][TYPE_PROP][0] === APPLY
96
+ ? `${formatType(i, stats[ARGUMENTS])}`
97
+ : `${x[STATS][TYPE_PROP].map(toTypeNames).join(' ')}`
100
98
  }`
101
99
  )
102
100
  .join(' ')
@@ -407,6 +405,7 @@ export const typeCheck = (ast) => {
407
405
  env[name] = {
408
406
  [STATS]: {
409
407
  [TYPE_PROP]: [APPLY],
408
+ [SIGNATURE]: name,
410
409
  retried: 0,
411
410
  counter: 0,
412
411
  [VARIABLE_ORDER_INDEX]: env[ORDER],
@@ -471,6 +470,7 @@ export const typeCheck = (ast) => {
471
470
  // DECLARATION of ATOM
472
471
  env[name] = {
473
472
  [STATS]: {
473
+ [SIGNATURE]: name,
474
474
  retried: 0,
475
475
  counter: 0,
476
476
  [VARIABLE_ORDER_INDEX]: env[ORDER],
@@ -508,6 +508,7 @@ export const typeCheck = (ast) => {
508
508
  [STATS]: {
509
509
  retried: 0,
510
510
  counter: 0,
511
+ [SIGNATURE]: name,
511
512
  [VARIABLE_ORDER_INDEX]: env[ORDER],
512
513
  [TYPE_PROP]: [
513
514
  isL
@@ -1036,8 +1037,30 @@ export const typeCheck = (ast) => {
1036
1037
  exp
1037
1038
  )}) (check #13)`
1038
1039
  )
1040
+ } else if (
1041
+ T === APPLY &&
1042
+ args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
1043
+ env[rest[i][VALUE]][STATS][TYPE_PROP][0] !== UNKNOWN &&
1044
+ env[rest[i][VALUE]][STATS][ARG_COUNT] !== VARIADIC
1045
+ ) {
1046
+ // Handles words that are Lambdas
1047
+ if (
1048
+ env[rest[i][VALUE]][STATS][ARG_COUNT] !==
1049
+ args[i][STATS][ARG_COUNT]
1050
+ ) {
1051
+ errorStack.add(
1052
+ `Incorrect number of arguments for (${
1053
+ args[i][STATS][SIGNATURE]
1054
+ }) the (lambda) argument of (${
1055
+ first[VALUE]
1056
+ }) at position (${i}). Expected (= ${
1057
+ args[i][STATS][ARG_COUNT]
1058
+ }) but got ${
1059
+ env[rest[i][VALUE]][STATS][ARG_COUNT]
1060
+ } (${stringifyArgs(exp)}) (check #778)`
1061
+ )
1062
+ }
1039
1063
  }
1040
-
1041
1064
  if (
1042
1065
  env[rest[i][VALUE]] &&
1043
1066
  env[rest[i][VALUE]][STATS][TYPE_PROP][0] !== UNKNOWN &&
@@ -1074,11 +1097,7 @@ export const typeCheck = (ast) => {
1074
1097
  args[i][STATS][RETURNS]
1075
1098
  }
1076
1099
  }
1077
- } else if (
1078
- rest[i].length &&
1079
- rest[i][0][TYPE] === APPLY &&
1080
- env[rest[i][0][VALUE]]
1081
- ) {
1100
+ } else if (env[rest[i][0][VALUE]]) {
1082
1101
  const match = () => {
1083
1102
  const actual = env[rest[i][0][VALUE]][STATS][RETURNS]
1084
1103
  const expected = args[i][STATS][TYPE_PROP]
@@ -1099,6 +1118,7 @@ export const typeCheck = (ast) => {
1099
1118
  )
1100
1119
  else {
1101
1120
  switch (expected[0]) {
1121
+ // almost exclusively for anonymous lambdas
1102
1122
  case APPLY:
1103
1123
  {
1104
1124
  const argsN = rest[i].length - 2
@@ -1109,17 +1129,24 @@ export const typeCheck = (ast) => {
1109
1129
  if (argsN !== args[i][STATS][ARG_COUNT]) {
1110
1130
  errorStack.add(
1111
1131
  `Incorrect number of arguments for (${
1132
+ args[i][STATS][SIGNATURE]
1133
+ }) the (lambda) argument of (${
1112
1134
  first[VALUE]
1113
- }). Expected (= ${
1114
- env[first[VALUE]][STATS][ARG_COUNT]
1115
- }) but got ${
1116
- rest.length
1117
- } (${stringifyArgs(exp)}) (check #777)`
1135
+ }) at position (${i}). Expected (= ${
1136
+ args[i][STATS][ARG_COUNT]
1137
+ }) but got ${argsN} (${stringifyArgs(
1138
+ exp
1139
+ )}) (check #777)`
1118
1140
  )
1119
1141
  }
1142
+ } else {
1143
+ // TODO fix curry: lambdas enter here as undefined
1120
1144
  }
1121
1145
  }
1122
1146
  break
1147
+ // case ATOM:
1148
+ // case COLLECTION:
1149
+ // break
1123
1150
  }
1124
1151
  }
1125
1152
  } else if (
@@ -1130,7 +1157,6 @@ export const typeCheck = (ast) => {
1130
1157
  stack.unshift(() => match())
1131
1158
  }
1132
1159
  }
1133
-
1134
1160
  match()
1135
1161
  }
1136
1162
  }
@@ -1149,7 +1175,6 @@ export const typeCheck = (ast) => {
1149
1175
  )
1150
1176
  }
1151
1177
  }
1152
-
1153
1178
  check(r, env, scope)
1154
1179
  }
1155
1180
  break