fez-lisp 1.5.155 → 1.5.157

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.155",
5
+ "version": "1.5.157",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -45,9 +45,7 @@ import {
45
45
  BOOLEAN,
46
46
  IS_ARGUMENT,
47
47
  NUMBER,
48
- SETTER,
49
- NUMBER_SUBTYPE,
50
- GENERIC
48
+ NUMBER_SUBTYPE
51
49
  } from './types.js'
52
50
  import {
53
51
  Brr,
@@ -462,14 +460,27 @@ const retryArgs = (stats, ctx, stack, cb) => {
462
460
  stagger(stack, 'prepend', ctx, cb)
463
461
  }
464
462
  }
465
- const IfApplyBranch = ({ leaf, branch, re, prop, ref, env }) => {
463
+ const IfApplyBranch = ({
464
+ leaf,
465
+ branch,
466
+ re,
467
+ prop,
468
+ ref,
469
+ env,
470
+ stack,
471
+ exp,
472
+ check
473
+ }) => {
466
474
  switch (leaf[VALUE]) {
467
475
  case KEYWORDS.IF:
468
476
  return ifExpression({
469
477
  re: re.slice(2),
470
478
  env,
471
479
  ref,
472
- prop
480
+ prop,
481
+ stack,
482
+ exp,
483
+ check
473
484
  })
474
485
  case KEYWORDS.CREATE_ARRAY:
475
486
  setPropToReturnRef(ref[STATS], prop, initArrayType({ rem: re, env }))
@@ -493,7 +504,9 @@ const IfApplyBranch = ({ leaf, branch, re, prop, ref, env }) => {
493
504
  env,
494
505
  prop,
495
506
  leaf: re.at(-1),
496
- re: re.at(-1).slice(2)
507
+ re: re.at(-1).slice(2),
508
+ stack,
509
+ exp
497
510
  })
498
511
  }
499
512
  break
@@ -501,7 +514,7 @@ const IfApplyBranch = ({ leaf, branch, re, prop, ref, env }) => {
501
514
  return setPropToReturnRef(ref[STATS], prop, branch[STATS])
502
515
  }
503
516
  }
504
- const ifExpression = ({ re, env, ref, prop }) => {
517
+ const ifExpression = ({ re, env, ref, prop, stack, exp, check }) => {
505
518
  if (re[0][TYPE] === ATOM || re[1][TYPE] === ATOM)
506
519
  return setPropToAtom(ref[STATS], prop)
507
520
  // TODO check that both brancehs are predicates if one is
@@ -510,6 +523,7 @@ const ifExpression = ({ re, env, ref, prop }) => {
510
523
  const alt = isLeaf(re[1]) ? re[1] : re[1][0]
511
524
  const concequent = env[conc[VALUE]]
512
525
  const alternative = env[alt[VALUE]]
526
+
513
527
  // TODO make this more simple - it's so many different things just because types are functions or not
514
528
  // WHY not consiter making return types for everything
515
529
  if (concequent)
@@ -527,7 +541,10 @@ const ifExpression = ({ re, env, ref, prop }) => {
527
541
  re: re[0],
528
542
  prop,
529
543
  env,
530
- ref
544
+ ref,
545
+ stack,
546
+ exp,
547
+ check
531
548
  })
532
549
  }
533
550
  if (alternative) {
@@ -545,13 +562,16 @@ const ifExpression = ({ re, env, ref, prop }) => {
545
562
  re: re[1],
546
563
  prop,
547
564
  env,
548
- ref
565
+ ref,
566
+ stack,
567
+ exp,
568
+ check
549
569
  })
550
570
  }
551
571
  }
552
572
  }
553
573
  }
554
- const resolveCondition = ({ rem, name, env, exp, prop }) => {
574
+ const resolveCondition = ({ rem, name, env, exp, prop, stack, check }) => {
555
575
  const ret = rem[0]
556
576
  const re = rem.slice(2)
557
577
  const ref = env[name]
@@ -559,7 +579,7 @@ const resolveCondition = ({ rem, name, env, exp, prop }) => {
559
579
  checkPredicateName(exp, [[WORD, name], isLeaf(re[1]) ? re[1] : re[1][0]])
560
580
  switch (ret[VALUE]) {
561
581
  case KEYWORDS.IF:
562
- ifExpression({ re, env, ref, prop })
582
+ ifExpression({ re, env, ref, prop, exp, stack, check })
563
583
  break
564
584
  default:
565
585
  if (env[ret[VALUE]]) setPropRef(ref[STATS], prop, env[ret[VALUE]][STATS])
@@ -622,7 +642,7 @@ const resolveSetter = (first, rest, env, stack) => {
622
642
  getSubType(env[right[VALUE]][STATS])
623
643
  )
624
644
  } else
625
- retry(env[right[VALUE]][STATS], [first[VALUE], rest], stack, () =>
645
+ once(env[right[VALUE]][STATS], [first[VALUE], rest], stack, () =>
626
646
  resolveSetter(first, rest, env, stack)
627
647
  )
628
648
  }
@@ -659,19 +679,20 @@ const resolveSetter = (first, rest, env, stack) => {
659
679
  current[STATS][TYPE_PROP][1] = new Set([
660
680
  ...getSubReturn(env[right[VALUE]][STATS])
661
681
  ])
662
- } else
663
- retry(env[right[VALUE]][STATS], [first[VALUE], rest], stack, () =>
664
- resolveSetter(first, rest, env, stack)
665
- )
682
+ }
683
+ // else
684
+ // retry(env[right[VALUE]][STATS], [first[VALUE], rest], stack, () =>
685
+ // resolveSetter(first, rest, env, stack)
686
+ // )
666
687
  }
667
688
  break
668
689
  }
669
690
  setTypeToCollection(current[STATS])
670
- // Retry setting the sub-type if infered it out later
671
- if (!hasSubType(current[STATS]) || getSubType(current[STATS]).has(UNKNOWN))
672
- retry(current[STATS], [first[VALUE], rest], stack, () =>
673
- resolveSetter(first, rest, env, stack)
674
- )
691
+ // // Retry setting the sub-type if infered it out later
692
+ // if (!hasSubType(current[STATS]) || getSubType(current[STATS]).has(UNKNOWN))
693
+ // retry(current[STATS], [first[VALUE], rest], stack, () =>
694
+ // resolveSetter(first, rest, env, stack)
695
+ // )
675
696
  }
676
697
  }
677
698
  const resolveGetter = ({ rem, prop, name, env }) => {
@@ -758,7 +779,7 @@ const resolveReturnType = ({
758
779
  setPropToSubReturn(env[name][STATS], prop, initArrayType({ rem, env }))
759
780
  break
760
781
  case KEYWORDS.IF:
761
- resolveCondition({ rem, name, env, exp, prop })
782
+ resolveCondition({ rem, name, env, exp, prop, stack, check })
762
783
  break
763
784
  default:
764
785
  {
@@ -766,7 +787,7 @@ const resolveReturnType = ({
766
787
  GETTERS_SET.has(returns[VALUE]) &&
767
788
  !resolveGetter({ rem, prop, name, env })
768
789
  )
769
- return retry(env[name][STATS], [returns, env], stack, () => {
790
+ return once(env[name][STATS], [returns, env], stack, () => {
770
791
  resolveReturnType({
771
792
  returns,
772
793
  rem,
@@ -795,7 +816,6 @@ const resolveReturnType = ({
795
816
  // ALWAYS APPLY
796
817
  // rest.at(-1)[0][TYPE] === APPLY
797
818
  // Here is upon application to store the result in the variable
798
-
799
819
  if (isUnknownType(env[name][STATS]))
800
820
  stagger(stack, 'prepend', exp, () => {
801
821
  if (isGenericReturn(env[returns[VALUE]][STATS])) {
@@ -1004,7 +1024,7 @@ export const typeCheck = (ast) => {
1004
1024
  )}) (${stringifyArgs(exp)}) (check #783)`
1005
1025
  )
1006
1026
  else
1007
- retry(
1027
+ once(
1008
1028
  actual[STATS],
1009
1029
  [[WORD, lambdaName], local],
1010
1030
  stack,
@@ -1013,52 +1033,45 @@ export const typeCheck = (ast) => {
1013
1033
  }
1014
1034
  match1()
1015
1035
  for (let j = 0; j < args[i][STATS][ARGUMENTS].length; ++j) {
1016
- const match2 = () => {
1017
- const actual = local[lambdaName][STATS][ARGUMENTS][j]
1018
- const expected = args[i][STATS][ARGUMENTS][j]
1019
- if (
1020
- !isUnknownType(actual[STATS]) &&
1021
- !isUnknownType(expected[STATS]) &&
1022
- !equalTypes(actual[STATS], expected[STATS])
1036
+ const actual = local[lambdaName][STATS][ARGUMENTS][j]
1037
+ const expected = args[i][STATS][ARGUMENTS][j]
1038
+ if (
1039
+ !isUnknownType(actual[STATS]) &&
1040
+ !isUnknownType(expected[STATS]) &&
1041
+ !equalTypes(actual[STATS], expected[STATS])
1042
+ )
1043
+ throw new TypeError(
1044
+ `Incorrect type for (${KEYWORDS.ANONYMOUS_FUNCTION}) (${
1045
+ args[i][STATS][SIGNATURE]
1046
+ }) argument at position (${j}) named as (${
1047
+ local[lambdaName][STATS][ARGUMENTS][j][STATS][
1048
+ SIGNATURE
1049
+ ]
1050
+ }). Expected (${toTypeNames(
1051
+ getType(expected[STATS])
1052
+ )}) but got (${toTypeNames(
1053
+ getType(actual[STATS])
1054
+ )}) (${stringifyArgs(exp)}) (check #780)`
1023
1055
  )
1024
- throw new TypeError(
1025
- `Incorrect type for (${
1026
- KEYWORDS.ANONYMOUS_FUNCTION
1027
- }) (${
1028
- args[i][STATS][SIGNATURE]
1029
- }) argument at position (${j}) named as (${
1030
- local[lambdaName][STATS][ARGUMENTS][j][STATS][
1031
- SIGNATURE
1032
- ]
1033
- }). Expected (${toTypeNames(
1034
- getType(expected[STATS])
1035
- )}) but got (${toTypeNames(
1036
- getType(actual[STATS])
1037
- )}) (${stringifyArgs(exp)}) (check #780)`
1038
- )
1039
- else if (!eualSubReturn(expected[STATS], actual[STATS]))
1040
- throw new TypeError(
1041
- `Incorrect return type for (${
1042
- expected[STATS][SIGNATURE]
1043
- }) the (${
1044
- KEYWORDS.ANONYMOUS_FUNCTION
1045
- }) argument of (${
1046
- first[VALUE]
1047
- }) at position (${i}). Expected (${toTypeNames(
1048
- getReturn(expected[STATS])
1049
- )}) but got (${toTypeNames(
1050
- getReturn(actual[STATS])
1051
- )}) (${stringifyArgs(exp)}) (check #784)`
1052
- )
1053
- else
1054
- retry(
1055
- actual[STATS],
1056
- [[WORD, lambdaName], local],
1057
- stack,
1058
- match2
1059
- )
1060
- }
1061
- match2()
1056
+ else if (!eualSubReturn(expected[STATS], actual[STATS]))
1057
+ throw new TypeError(
1058
+ `Incorrect return type for (${
1059
+ expected[STATS][SIGNATURE]
1060
+ }) the (${KEYWORDS.ANONYMOUS_FUNCTION}) argument of (${
1061
+ first[VALUE]
1062
+ }) at position (${i}). Expected (${toTypeNames(
1063
+ getReturn(expected[STATS])
1064
+ )}) but got (${toTypeNames(
1065
+ getReturn(actual[STATS])
1066
+ )}) (${stringifyArgs(exp)}) (check #784)`
1067
+ )
1068
+ // else
1069
+ // retry(
1070
+ // actual[STATS],
1071
+ // [[WORD, lambdaName], local],
1072
+ // stack,
1073
+ // match2
1074
+ // )
1062
1075
  }
1063
1076
  }
1064
1077
  } else {
@@ -1250,11 +1263,11 @@ export const typeCheck = (ast) => {
1250
1263
  [TYPE_PROP]: [UNKNOWN],
1251
1264
  [RETURNS]: [UNKNOWN],
1252
1265
  [ARGUMENTS]: [],
1266
+ argIndex: i,
1253
1267
  retried: 0,
1254
1268
  counter: 0
1255
1269
  }
1256
1270
  }
1257
-
1258
1271
  const ref = env[copy[SCOPE_NAME]]
1259
1272
  if (!ref) continue
1260
1273
  ref[STATS][ARGUMENTS][i] = copy[param[VALUE]]
@@ -1289,7 +1302,8 @@ export const typeCheck = (ast) => {
1289
1302
  env: copy,
1290
1303
  exp,
1291
1304
  stack,
1292
- prop: RETURNS
1305
+ prop: RETURNS,
1306
+ check
1293
1307
  })
1294
1308
  break
1295
1309
  default:
@@ -1553,76 +1567,6 @@ export const typeCheck = (ast) => {
1553
1567
  )
1554
1568
  }
1555
1569
  }
1556
- // DEFINED LAMBDAS TYPE CHECKING
1557
- // #C1
1558
- // TODO delete this maybe
1559
- // It will not be possilbe to know return type
1560
- const match1 = () => {
1561
- const actual = env[name]
1562
- const expected = args[i]
1563
- if (
1564
- !isUnknownReturn(expected[STATS]) &&
1565
- !isUnknownReturn(actual[STATS]) &&
1566
- !equalReturns(expected[STATS], actual[STATS])
1567
- ) {
1568
- throw new TypeError(
1569
- `Incorrect return type for (${
1570
- expected[STATS][SIGNATURE]
1571
- }) the (${
1572
- KEYWORDS.ANONYMOUS_FUNCTION
1573
- }) argument of (${
1574
- first[VALUE]
1575
- }) at position (${i}). Expected (${toTypeNames(
1576
- getReturn(expected[STATS])
1577
- )}) but got (${toTypeNames(
1578
- getReturn(actual[STATS])
1579
- )}) (${stringifyArgs(exp)}) (check #782)`
1580
- )
1581
- } else
1582
- retry(
1583
- actual[STATS],
1584
- [first, env],
1585
- stack,
1586
- match1
1587
- )
1588
- }
1589
- match1()
1590
- for (
1591
- let j = 0;
1592
- j < args[i][STATS][ARGUMENTS].length;
1593
- ++j
1594
- ) {
1595
- const match2 = () => {
1596
- const actual = env[name][STATS][ARGUMENTS][j]
1597
- const expected = args[i][STATS][ARGUMENTS][j]
1598
- if (
1599
- !isUnknownType(actual[STATS]) &&
1600
- !isUnknownType(expected[STATS]) &&
1601
- !equalTypes(actual[STATS], expected[STATS])
1602
- )
1603
- throw new TypeError(
1604
- `Incorrect type for (${
1605
- KEYWORDS.ANONYMOUS_FUNCTION
1606
- }) (${
1607
- args[i][STATS][SIGNATURE]
1608
- }) argument at position (${j}) named as (${
1609
- actual[STATS][SIGNATURE]
1610
- }). Expected (${toTypeNames(
1611
- getType(expected[STATS])
1612
- )}) but got (${toTypeNames(
1613
- getType(actual[STATS])
1614
- )}) (${stringifyArgs(exp)}) (check #781)`
1615
- )
1616
- else
1617
- retry(
1618
- actual[STATS],
1619
- [first, env],
1620
- stack,
1621
- match2
1622
- )
1623
- }
1624
- match2()
1625
- }
1626
1570
  }
1627
1571
  break
1628
1572
  }
package/src/types.js CHANGED
@@ -24,7 +24,7 @@ export const NUMBER = 6
24
24
  export const ANY = 4
25
25
  export const GENERIC = 7
26
26
  export const ANONYMOUS_FUNCTION_TYPE_PREFIX = 'lambda::annonymous::'
27
- export const MAX_ARGUMENT_RETRY = 1
27
+ export const MAX_ARGUMENT_RETRY = 3
28
28
  export const MAX_RETRY_DEFINITION = 50
29
29
  export const IS_ARGUMENT = 'is_arg'
30
30
  export const NIL = 'nil'