fez-lisp 1.5.118 → 1.5.119

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.118",
5
+ "version": "1.5.119",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -3,12 +3,8 @@ import {
3
3
  ATOM,
4
4
  FALSE,
5
5
  KEYWORDS,
6
- MULTI_DIMENTIONAL_SETTERS,
7
- MUTATION_SUFFIX,
8
- MUTATORS_SET,
9
6
  PLACEHOLDER,
10
7
  PREDICATE_SUFFIX,
11
- PREDICATES_INPUT_SET,
12
8
  PREDICATES_OUTPUT_SET,
13
9
  SPECIAL_FORMS_SET,
14
10
  STATIC_TYPES,
@@ -51,7 +47,6 @@ import {
51
47
  getSuffix,
52
48
  hasApplyLambdaBlock,
53
49
  hasBlock,
54
- logExp,
55
50
  stringifyArgs
56
51
  } from './utils.js'
57
52
  Set.prototype.union = function (B) {
@@ -61,7 +56,6 @@ Set.prototype.union = function (B) {
61
56
  B.forEach((element) => out.add(element))
62
57
  return out
63
58
  }
64
-
65
59
  Set.prototype.xor = function (B) {
66
60
  const A = this
67
61
  const out = new Set()
@@ -69,14 +63,12 @@ Set.prototype.xor = function (B) {
69
63
  A.forEach((element) => !B.has(element) && out.add(element))
70
64
  return out
71
65
  }
72
-
73
66
  Set.prototype.intersection = function (B) {
74
67
  const A = this
75
68
  const out = new Set()
76
69
  B.forEach((element) => A.has(element) && out.add(element))
77
70
  return out
78
71
  }
79
-
80
72
  Set.prototype.difference = function (B) {
81
73
  const A = this
82
74
  const out = new Set()
@@ -537,7 +529,7 @@ const checkReturnType = ({ exp, stack, name, env }) => {
537
529
  stack
538
530
  })
539
531
  }
540
- export const typeCheck = (ast, error = true) => {
532
+ export const typeCheck = (ast) => {
541
533
  let scopeIndex = 0
542
534
  const root = structuredClone(SPECIAL_FORM_TYPES)
543
535
  const Types = new Map()
@@ -546,7 +538,7 @@ export const typeCheck = (ast, error = true) => {
546
538
  const [first, ...rest] = isLeaf(exp) ? [exp] : exp
547
539
  if (first === undefined)
548
540
  throw new TypeError(
549
- `(lambda) invocation with missing (Abstraction) name () Provide an (Abstraction) name as the (1) argument.`
541
+ `(${KEYWORDS.ANONYMOUS_FUNCTION}) invocation with missing (Abstraction) name () Provide an (Abstraction) name as the (1) argument.`
550
542
  )
551
543
  const isSpecial =
552
544
  SPECIAL_FORMS_SET.has(first[VALUE]) || STATIC_TYPES_SET.has(first[VALUE])
@@ -663,7 +655,6 @@ export const typeCheck = (ast, error = true) => {
663
655
  : env[right[VALUE]][STATS][RETURNS][0]
664
656
  if (type !== UNKNOWN)
665
657
  setTypeToReturn(env[name][STATS], env[right[VALUE]][STATS])
666
-
667
658
  const body = rightHand
668
659
  const rem = hasBlock(body) ? body.at(-1) : body
669
660
  const returns = isLeaf(rem) ? rem : rem[0]
@@ -713,7 +704,6 @@ export const typeCheck = (ast, error = true) => {
713
704
  const ref = env[copy[SCOPE_NAME]]
714
705
  if (!ref) continue
715
706
  ref[STATS][ARGUMENTS][i] = copy[param[VALUE]]
716
-
717
707
  // TODO overwrite return type check here
718
708
  }
719
709
  const returns = deepLambdaReturn(
@@ -781,7 +771,7 @@ export const typeCheck = (ast, error = true) => {
781
771
  stack.append(() => {
782
772
  if (!isSpecial && env[first[VALUE]] === undefined)
783
773
  throw new TypeError(
784
- `Trying to call undefined (lambda) ${first[VALUE]} (check #9)`
774
+ `Trying to call undefined (${KEYWORDS.ANONYMOUS_FUNCTION}) ${first[VALUE]} (check #9)`
785
775
  )
786
776
  else if (
787
777
  env[first[VALUE]][STATS][TYPE_PROP][0] === APPLY &&
@@ -799,9 +789,9 @@ export const typeCheck = (ast, error = true) => {
799
789
  if (first[TYPE] === APPLY && !isSpecial) {
800
790
  if (getType(env[first[VALUE]][STATS]) === ATOM)
801
791
  throw new TypeError(
802
- `(${first[VALUE]}) is not a (lambda) (${stringifyArgs(
803
- exp
804
- )}) (check #12)`
792
+ `(${first[VALUE]}) is not a (${
793
+ KEYWORDS.ANONYMOUS_FUNCTION
794
+ }) (${stringifyArgs(exp)}) (check #12)`
805
795
  )
806
796
  else if (!env[first[VALUE]][STATS][ARG_COUNT]) {
807
797
  // TODO recursively take return type of applicaion
@@ -1065,7 +1055,9 @@ export const typeCheck = (ast, error = true) => {
1065
1055
  throw new TypeError(
1066
1056
  `Incorrect number of arguments for (${
1067
1057
  args[i][STATS][SIGNATURE]
1068
- }) the (lambda) argument of (${
1058
+ }) the (${
1059
+ KEYWORDS.ANONYMOUS_FUNCTION
1060
+ }) argument of (${
1069
1061
  first[VALUE]
1070
1062
  }) at position (${i}). Expected (= ${
1071
1063
  args[i][STATS][ARG_COUNT]
@@ -1089,7 +1081,9 @@ export const typeCheck = (ast, error = true) => {
1089
1081
  throw new TypeError(
1090
1082
  `Incorrect return type for (${
1091
1083
  expected[STATS][SIGNATURE]
1092
- }) the (lambda) argument of (${
1084
+ }) the (${
1085
+ KEYWORDS.ANONYMOUS_FUNCTION
1086
+ }) argument of (${
1093
1087
  first[VALUE]
1094
1088
  }) at position (${i}). Expected (${toTypeNames(
1095
1089
  getReturn(expected[STATS])
@@ -1115,7 +1109,9 @@ export const typeCheck = (ast, error = true) => {
1115
1109
  !compareTypes(actual[STATS], expected[STATS])
1116
1110
  )
1117
1111
  throw new TypeError(
1118
- `Incorrect type for (lambda) (${
1112
+ `Incorrect type for (${
1113
+ KEYWORDS.ANONYMOUS_FUNCTION
1114
+ }) (${
1119
1115
  args[i][STATS][SIGNATURE]
1120
1116
  }) argument at position (${j}) named as (${
1121
1117
  actual[STATS][SIGNATURE]
@@ -1202,7 +1198,9 @@ export const typeCheck = (ast, error = true) => {
1202
1198
  throw new TypeError(
1203
1199
  `Incorrect number of arguments for (${
1204
1200
  args[i][STATS][SIGNATURE]
1205
- }) the (lambda) argument of (${
1201
+ }) the (${
1202
+ KEYWORDS.ANONYMOUS_FUNCTION
1203
+ }) argument of (${
1206
1204
  first[VALUE]
1207
1205
  }) at position (${i}). Expected (= ${
1208
1206
  args[i][STATS][ARG_COUNT]
@@ -1240,7 +1238,9 @@ export const typeCheck = (ast, error = true) => {
1240
1238
  throw new TypeError(
1241
1239
  `Incorrect return type for (${
1242
1240
  expected[STATS][SIGNATURE]
1243
- }) the (lambda) argument of (${
1241
+ }) the (${
1242
+ KEYWORDS.ANONYMOUS_FUNCTION
1243
+ }) argument of (${
1244
1244
  first[VALUE]
1245
1245
  }) at position (${i}). Expected (${toTypeNames(
1246
1246
  getReturn(expected[STATS])
@@ -1275,7 +1275,9 @@ export const typeCheck = (ast, error = true) => {
1275
1275
  )
1276
1276
  )
1277
1277
  throw new TypeError(
1278
- `Incorrect type for (lambda) (${
1278
+ `Incorrect type for (${
1279
+ KEYWORDS.ANONYMOUS_FUNCTION
1280
+ }) (${
1279
1281
  args[i][STATS][SIGNATURE]
1280
1282
  }) argument at position (${j}) named as (${
1281
1283
  local[lambdaName][STATS][
@@ -1312,7 +1314,6 @@ export const typeCheck = (ast, error = true) => {
1312
1314
  }
1313
1315
  match()
1314
1316
  }
1315
-
1316
1317
  // handly typehints for arrays
1317
1318
  // if (
1318
1319
  // first[TYPE] === APPLY &&
package/src/macros.js CHANGED
@@ -70,6 +70,19 @@ export const deSuggarAst = (ast, scope) => {
70
70
  case APPLY:
71
71
  {
72
72
  switch (first[VALUE]) {
73
+ // ; Idea for pattern matching
74
+ // ; (let f (lambda xs
75
+ // ; (|= xs
76
+ // ; [] 10
77
+ // ; [1] (array:tail xs)
78
+ // ; (*) -1)))
79
+
80
+ // (let f (lambda xs
81
+ // (apply xs (lambda xs (cond
82
+ // (= (length xs) 0) 10
83
+ // (= (get xs 0) 1) (array:tail xs)
84
+ // (*) -1)))))
85
+
73
86
  // case KEYWORDS.CALL_FUNCTION: {
74
87
  // if (prev === undefined && scope[0][VALUE] === KEYWORDS.CALL_FUNCTION) {
75
88
  // exp[0][VALUE] = KEYWORDS.BLOCK
@@ -274,9 +287,7 @@ export const deSuggarAst = (ast, scope) => {
274
287
  if (i < rest.length - 1) {
275
288
  temp.push([APPLY, KEYWORDS.ADDITION], rest[i], [])
276
289
  temp = temp.at(-1)
277
- } else {
278
- temp.push(...rest[i])
279
- }
290
+ } else temp.push(...rest[i])
280
291
  }
281
292
  deSuggarAst(exp, scope)
282
293
  }
@@ -289,9 +300,7 @@ export const deSuggarAst = (ast, scope) => {
289
300
  if (i < rest.length - 1) {
290
301
  temp.push([APPLY, KEYWORDS.SUBTRACTION], rest[i], [])
291
302
  temp = temp.at(-1)
292
- } else {
293
- temp.push(...rest[i])
294
- }
303
+ } else temp.push(...rest[i])
295
304
  }
296
305
  deSuggarAst(exp, scope)
297
306
  } else {
@@ -325,9 +334,7 @@ export const deSuggarAst = (ast, scope) => {
325
334
  if (i < rest.length - 1) {
326
335
  temp.push([APPLY, KEYWORDS.DIVISION], rest[i], [])
327
336
  temp = temp.at(-1)
328
- } else {
329
- temp.push(...rest[i])
330
- }
337
+ } else temp.push(...rest[i])
331
338
  }
332
339
  deSuggarAst(exp, scope)
333
340
  }
@@ -343,9 +350,7 @@ export const deSuggarAst = (ast, scope) => {
343
350
  if (i < rest.length - 1) {
344
351
  temp.push([APPLY, KEYWORDS.AND], rest[i], [])
345
352
  temp = temp.at(-1)
346
- } else {
347
- temp.push(...rest[i])
348
- }
353
+ } else temp.push(...rest[i])
349
354
  }
350
355
  deSuggarAst(exp, scope)
351
356
  }
@@ -361,9 +366,7 @@ export const deSuggarAst = (ast, scope) => {
361
366
  if (i < rest.length - 1) {
362
367
  temp.push([APPLY, KEYWORDS.OR], rest[i], [])
363
368
  temp = temp.at(-1)
364
- } else {
365
- temp.push(...rest[i])
366
- }
369
+ } else temp.push(...rest[i])
367
370
  }
368
371
  deSuggarAst(exp, scope)
369
372
  }
package/src/types.js CHANGED
@@ -1189,19 +1189,21 @@ export const formatSubType = (T) => {
1189
1189
  T[1] instanceof Set
1190
1190
  ? [...T[1]]
1191
1191
  .map((x) =>
1192
- x === COLLECTION ? formatSubType([x]) : toTypeNames(x)
1192
+ x === COLLECTION
1193
+ ? formatSubType([x])
1194
+ : toTypeNamesAnyToUknown(x)
1193
1195
  )
1194
1196
  .join(' ')
1195
- : toTypeNames(ANY)
1197
+ : toTypeNamesAnyToUknown(ANY)
1196
1198
  }]`
1197
1199
  case ATOM:
1198
1200
  return `${
1199
1201
  T[1] instanceof Set
1200
- ? [...T[1]].map((x) => toTypeNames(x)).join(' ')
1201
- : toTypeNames(NUMBER)
1202
+ ? [...T[1]].map((x) => toTypeNamesAnyToUknown(x)).join(' ')
1203
+ : toTypeNamesAnyToUknown(NUMBER)
1202
1204
  }`
1203
1205
  default:
1204
- return toTypeNames(T[0])
1206
+ return toTypeNamesAnyToUknown(T[0])
1205
1207
  }
1206
1208
  }
1207
1209
  export const formatType = (name, env) => {