fez-lisp 1.5.154 → 1.5.156

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.154",
5
+ "version": "1.5.156",
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,
@@ -327,17 +325,6 @@ const IsPredicate = (leaf) =>
327
325
  (PREDICATES_OUTPUT_SET.has(leaf[VALUE]) ||
328
326
  getSuffix(leaf[VALUE]) === PREDICATE_SUFFIX))
329
327
 
330
- // THese should also check if sub type is Uknown array and pass as ok
331
- const notABooleanType = (a, b) => {
332
- return (
333
- hasSubType(a) &&
334
- getSubType(a).has(BOOLEAN) &&
335
- !isUnknownType(b) &&
336
- !isAnyType(b) &&
337
- ((!hasSubType(b) && getType(b) !== COLLECTION) ||
338
- (hasSubType(b) && getSubType(a).difference(getSubType(b)).size !== 0))
339
- )
340
- }
341
328
  const equalSubTypes = (a, b) => {
342
329
  return (
343
330
  !hasSubType(a) ||
@@ -371,24 +358,6 @@ const equalSubTypesWithSubReturn = (a, b) => {
371
358
  getSubType(a).difference(getSubReturn(b)).size === 0
372
359
  )
373
360
  }
374
- const notABooleanTypeWithReturn = (a, b) => {
375
- return (
376
- hasSubType(a) &&
377
- getSubType(a).has(BOOLEAN) &&
378
- !isUnknownReturn(b) &&
379
- !isAnyReturn(b) &&
380
- (!hasSubReturn(b) || getSubType(a).difference(getSubReturn(b)).size !== 0)
381
- )
382
- }
383
- const notABooleanReturn = (a, b) => {
384
- return (
385
- hasSubReturn(a) &&
386
- getSubReturn(a).has(BOOLEAN) &&
387
- !isUnknownReturn(b) &&
388
- !isAnyReturn(b) &&
389
- (!hasSubReturn(b) || getSubReturn(a).difference(getSubReturn(b)).size !== 0)
390
- )
391
- }
392
361
  const isAtomABoolean = (atom) => atom === TRUE || atom === FALSE
393
362
  const checkPredicateName = (exp, rest) => {
394
363
  if (getSuffix(rest[0][VALUE]) === PREDICATE_SUFFIX) {
@@ -491,14 +460,27 @@ const retryArgs = (stats, ctx, stack, cb) => {
491
460
  stagger(stack, 'prepend', ctx, cb)
492
461
  }
493
462
  }
494
- 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
+ }) => {
495
474
  switch (leaf[VALUE]) {
496
475
  case KEYWORDS.IF:
497
476
  return ifExpression({
498
477
  re: re.slice(2),
499
478
  env,
500
479
  ref,
501
- prop
480
+ prop,
481
+ stack,
482
+ exp,
483
+ check
502
484
  })
503
485
  case KEYWORDS.CREATE_ARRAY:
504
486
  setPropToReturnRef(ref[STATS], prop, initArrayType({ rem: re, env }))
@@ -522,7 +504,9 @@ const IfApplyBranch = ({ leaf, branch, re, prop, ref, env }) => {
522
504
  env,
523
505
  prop,
524
506
  leaf: re.at(-1),
525
- re: re.at(-1).slice(2)
507
+ re: re.at(-1).slice(2),
508
+ stack,
509
+ exp
526
510
  })
527
511
  }
528
512
  break
@@ -530,7 +514,7 @@ const IfApplyBranch = ({ leaf, branch, re, prop, ref, env }) => {
530
514
  return setPropToReturnRef(ref[STATS], prop, branch[STATS])
531
515
  }
532
516
  }
533
- const ifExpression = ({ re, env, ref, prop }) => {
517
+ const ifExpression = ({ re, env, ref, prop, stack, exp, check }) => {
534
518
  if (re[0][TYPE] === ATOM || re[1][TYPE] === ATOM)
535
519
  return setPropToAtom(ref[STATS], prop)
536
520
  // TODO check that both brancehs are predicates if one is
@@ -539,6 +523,7 @@ const ifExpression = ({ re, env, ref, prop }) => {
539
523
  const alt = isLeaf(re[1]) ? re[1] : re[1][0]
540
524
  const concequent = env[conc[VALUE]]
541
525
  const alternative = env[alt[VALUE]]
526
+
542
527
  // TODO make this more simple - it's so many different things just because types are functions or not
543
528
  // WHY not consiter making return types for everything
544
529
  if (concequent)
@@ -556,7 +541,10 @@ const ifExpression = ({ re, env, ref, prop }) => {
556
541
  re: re[0],
557
542
  prop,
558
543
  env,
559
- ref
544
+ ref,
545
+ stack,
546
+ exp,
547
+ check
560
548
  })
561
549
  }
562
550
  if (alternative) {
@@ -574,13 +562,16 @@ const ifExpression = ({ re, env, ref, prop }) => {
574
562
  re: re[1],
575
563
  prop,
576
564
  env,
577
- ref
565
+ ref,
566
+ stack,
567
+ exp,
568
+ check
578
569
  })
579
570
  }
580
571
  }
581
572
  }
582
573
  }
583
- const resolveCondition = ({ rem, name, env, exp, prop }) => {
574
+ const resolveCondition = ({ rem, name, env, exp, prop, stack, check }) => {
584
575
  const ret = rem[0]
585
576
  const re = rem.slice(2)
586
577
  const ref = env[name]
@@ -588,7 +579,7 @@ const resolveCondition = ({ rem, name, env, exp, prop }) => {
588
579
  checkPredicateName(exp, [[WORD, name], isLeaf(re[1]) ? re[1] : re[1][0]])
589
580
  switch (ret[VALUE]) {
590
581
  case KEYWORDS.IF:
591
- ifExpression({ re, env, ref, prop })
582
+ ifExpression({ re, env, ref, prop, exp, stack, check })
592
583
  break
593
584
  default:
594
585
  if (env[ret[VALUE]]) setPropRef(ref[STATS], prop, env[ret[VALUE]][STATS])
@@ -651,7 +642,7 @@ const resolveSetter = (first, rest, env, stack) => {
651
642
  getSubType(env[right[VALUE]][STATS])
652
643
  )
653
644
  } else
654
- retry(env[right[VALUE]][STATS], [first[VALUE], rest], stack, () =>
645
+ once(env[right[VALUE]][STATS], [first[VALUE], rest], stack, () =>
655
646
  resolveSetter(first, rest, env, stack)
656
647
  )
657
648
  }
@@ -688,19 +679,20 @@ const resolveSetter = (first, rest, env, stack) => {
688
679
  current[STATS][TYPE_PROP][1] = new Set([
689
680
  ...getSubReturn(env[right[VALUE]][STATS])
690
681
  ])
691
- } else
692
- retry(env[right[VALUE]][STATS], [first[VALUE], rest], stack, () =>
693
- resolveSetter(first, rest, env, stack)
694
- )
682
+ }
683
+ // else
684
+ // retry(env[right[VALUE]][STATS], [first[VALUE], rest], stack, () =>
685
+ // resolveSetter(first, rest, env, stack)
686
+ // )
695
687
  }
696
688
  break
697
689
  }
698
690
  setTypeToCollection(current[STATS])
699
- // Retry setting the sub-type if infered it out later
700
- if (!hasSubType(current[STATS]) || getSubType(current[STATS]).has(UNKNOWN))
701
- retry(current[STATS], [first[VALUE], rest], stack, () =>
702
- resolveSetter(first, rest, env, stack)
703
- )
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
+ // )
704
696
  }
705
697
  }
706
698
  const resolveGetter = ({ rem, prop, name, env }) => {
@@ -787,7 +779,7 @@ const resolveReturnType = ({
787
779
  setPropToSubReturn(env[name][STATS], prop, initArrayType({ rem, env }))
788
780
  break
789
781
  case KEYWORDS.IF:
790
- resolveCondition({ rem, name, env, exp, prop })
782
+ resolveCondition({ rem, name, env, exp, prop, stack, check })
791
783
  break
792
784
  default:
793
785
  {
@@ -795,7 +787,7 @@ const resolveReturnType = ({
795
787
  GETTERS_SET.has(returns[VALUE]) &&
796
788
  !resolveGetter({ rem, prop, name, env })
797
789
  )
798
- return retry(env[name][STATS], [returns, env], stack, () => {
790
+ return once(env[name][STATS], [returns, env], stack, () => {
799
791
  resolveReturnType({
800
792
  returns,
801
793
  rem,
@@ -824,7 +816,6 @@ const resolveReturnType = ({
824
816
  // ALWAYS APPLY
825
817
  // rest.at(-1)[0][TYPE] === APPLY
826
818
  // Here is upon application to store the result in the variable
827
-
828
819
  if (isUnknownType(env[name][STATS]))
829
820
  stagger(stack, 'prepend', exp, () => {
830
821
  if (isGenericReturn(env[returns[VALUE]][STATS])) {
@@ -1020,7 +1011,7 @@ export const typeCheck = (ast) => {
1020
1011
  getReturn(actual[STATS])
1021
1012
  )}) (${stringifyArgs(exp)}) (check #779)`
1022
1013
  )
1023
- else if (notABooleanReturn(expected[STATS], actual[STATS]))
1014
+ else if (!eualSubReturn(expected[STATS], actual[STATS]))
1024
1015
  throw new TypeError(
1025
1016
  `Incorrect return type for (${
1026
1017
  expected[STATS][SIGNATURE]
@@ -1033,7 +1024,7 @@ export const typeCheck = (ast) => {
1033
1024
  )}) (${stringifyArgs(exp)}) (check #783)`
1034
1025
  )
1035
1026
  else
1036
- retry(
1027
+ once(
1037
1028
  actual[STATS],
1038
1029
  [[WORD, lambdaName], local],
1039
1030
  stack,
@@ -1042,54 +1033,45 @@ export const typeCheck = (ast) => {
1042
1033
  }
1043
1034
  match1()
1044
1035
  for (let j = 0; j < args[i][STATS][ARGUMENTS].length; ++j) {
1045
- const match2 = () => {
1046
- const actual = local[lambdaName][STATS][ARGUMENTS][j]
1047
- const expected = args[i][STATS][ARGUMENTS][j]
1048
- if (
1049
- !isUnknownType(actual[STATS]) &&
1050
- !isUnknownType(expected[STATS]) &&
1051
- !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)`
1052
1055
  )
1053
- throw new TypeError(
1054
- `Incorrect type for (${
1055
- KEYWORDS.ANONYMOUS_FUNCTION
1056
- }) (${
1057
- args[i][STATS][SIGNATURE]
1058
- }) argument at position (${j}) named as (${
1059
- local[lambdaName][STATS][ARGUMENTS][j][STATS][
1060
- SIGNATURE
1061
- ]
1062
- }). Expected (${toTypeNames(
1063
- getType(expected[STATS])
1064
- )}) but got (${toTypeNames(
1065
- getType(actual[STATS])
1066
- )}) (${stringifyArgs(exp)}) (check #780)`
1067
- )
1068
- else if (
1069
- notABooleanReturn(expected[STATS], actual[STATS])
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)`
1070
1067
  )
1071
- throw new TypeError(
1072
- `Incorrect return type for (${
1073
- expected[STATS][SIGNATURE]
1074
- }) the (${
1075
- KEYWORDS.ANONYMOUS_FUNCTION
1076
- }) argument of (${
1077
- first[VALUE]
1078
- }) at position (${i}). Expected (${toTypeNames(
1079
- getReturn(expected[STATS])
1080
- )}) but got (${toTypeNames(
1081
- getReturn(actual[STATS])
1082
- )}) (${stringifyArgs(exp)}) (check #784)`
1083
- )
1084
- else
1085
- retry(
1086
- actual[STATS],
1087
- [[WORD, lambdaName], local],
1088
- stack,
1089
- match2
1090
- )
1091
- }
1092
- match2()
1068
+ // else
1069
+ // retry(
1070
+ // actual[STATS],
1071
+ // [[WORD, lambdaName], local],
1072
+ // stack,
1073
+ // match2
1074
+ // )
1093
1075
  }
1094
1076
  }
1095
1077
  } else {
@@ -1281,11 +1263,11 @@ export const typeCheck = (ast) => {
1281
1263
  [TYPE_PROP]: [UNKNOWN],
1282
1264
  [RETURNS]: [UNKNOWN],
1283
1265
  [ARGUMENTS]: [],
1266
+ argIndex: i,
1284
1267
  retried: 0,
1285
1268
  counter: 0
1286
1269
  }
1287
1270
  }
1288
-
1289
1271
  const ref = env[copy[SCOPE_NAME]]
1290
1272
  if (!ref) continue
1291
1273
  ref[STATS][ARGUMENTS][i] = copy[param[VALUE]]
@@ -1320,7 +1302,8 @@ export const typeCheck = (ast) => {
1320
1302
  env: copy,
1321
1303
  exp,
1322
1304
  stack,
1323
- prop: RETURNS
1305
+ prop: RETURNS,
1306
+ check
1324
1307
  })
1325
1308
  break
1326
1309
  default:
@@ -1584,76 +1567,6 @@ export const typeCheck = (ast) => {
1584
1567
  )
1585
1568
  }
1586
1569
  }
1587
- // DEFINED LAMBDAS TYPE CHECKING
1588
- // #C1
1589
- // TODO delete this maybe
1590
- // It will not be possilbe to know return type
1591
- const match1 = () => {
1592
- const actual = env[name]
1593
- const expected = args[i]
1594
- if (
1595
- !isUnknownReturn(expected[STATS]) &&
1596
- !isUnknownReturn(actual[STATS]) &&
1597
- !equalReturns(expected[STATS], actual[STATS])
1598
- ) {
1599
- throw new TypeError(
1600
- `Incorrect return type for (${
1601
- expected[STATS][SIGNATURE]
1602
- }) the (${
1603
- KEYWORDS.ANONYMOUS_FUNCTION
1604
- }) argument of (${
1605
- first[VALUE]
1606
- }) at position (${i}). Expected (${toTypeNames(
1607
- getReturn(expected[STATS])
1608
- )}) but got (${toTypeNames(
1609
- getReturn(actual[STATS])
1610
- )}) (${stringifyArgs(exp)}) (check #782)`
1611
- )
1612
- } else
1613
- retry(
1614
- actual[STATS],
1615
- [first, env],
1616
- stack,
1617
- match1
1618
- )
1619
- }
1620
- match1()
1621
- for (
1622
- let j = 0;
1623
- j < args[i][STATS][ARGUMENTS].length;
1624
- ++j
1625
- ) {
1626
- const match2 = () => {
1627
- const actual = env[name][STATS][ARGUMENTS][j]
1628
- const expected = args[i][STATS][ARGUMENTS][j]
1629
- if (
1630
- !isUnknownType(actual[STATS]) &&
1631
- !isUnknownType(expected[STATS]) &&
1632
- !equalTypes(actual[STATS], expected[STATS])
1633
- )
1634
- throw new TypeError(
1635
- `Incorrect type for (${
1636
- KEYWORDS.ANONYMOUS_FUNCTION
1637
- }) (${
1638
- args[i][STATS][SIGNATURE]
1639
- }) argument at position (${j}) named as (${
1640
- actual[STATS][SIGNATURE]
1641
- }). Expected (${toTypeNames(
1642
- getType(expected[STATS])
1643
- )}) but got (${toTypeNames(
1644
- getType(actual[STATS])
1645
- )}) (${stringifyArgs(exp)}) (check #781)`
1646
- )
1647
- else
1648
- retry(
1649
- actual[STATS],
1650
- [first, env],
1651
- stack,
1652
- match2
1653
- )
1654
- }
1655
- match2()
1656
- }
1657
1570
  }
1658
1571
  break
1659
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'