fez-lisp 1.5.33 → 1.5.34
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 +1 -1
- package/src/check.js +181 -221
package/package.json
CHANGED
package/src/check.js
CHANGED
@@ -505,138 +505,111 @@ export const typeCheck = (ast) => {
|
|
505
505
|
key.str,
|
506
506
|
`Trying to call undefined (lambda) ${first[VALUE]} (check #9)`
|
507
507
|
)
|
508
|
-
else
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
508
|
+
else {
|
509
|
+
if (
|
510
|
+
env[first[VALUE]][STATS].type === APPLY &&
|
511
|
+
env[first[VALUE]][STATS][ARGS_COUNT] !== VARIADIC &&
|
512
|
+
env[first[VALUE]][STATS][ARGS_COUNT] !== rest.length
|
513
|
+
) {
|
514
|
+
errorStack.set(
|
515
|
+
key.str,
|
516
|
+
`Incorrect number of arguments for (${
|
517
|
+
first[VALUE]
|
518
|
+
}). Expected (= ${
|
519
|
+
env[first[VALUE]][STATS][ARGS_COUNT]
|
520
|
+
}) but got ${rest.length} (${stringifyArgs(
|
521
|
+
exp
|
522
|
+
)}) (check #8)`
|
523
|
+
)
|
524
|
+
} else {
|
525
|
+
const isSpecial = SPECIAL_FORMS_SET.has(first[VALUE])
|
525
526
|
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
527
|
+
if (first[TYPE] === APPLY && !isSpecial) {
|
528
|
+
if (env[first[VALUE]][STATS].type === ATOM) {
|
529
|
+
errorStack.set(
|
530
|
+
key.str,
|
531
|
+
`(${first[VALUE]}) is not a (lambda) (${stringifyArgs(
|
532
|
+
exp
|
533
|
+
)}) (check #12)`
|
534
|
+
)
|
535
|
+
} else if (!env[first[VALUE]][STATS][ARGS_COUNT]) {
|
536
|
+
env[first[VALUE]][STATS][RETURNS] = UNKNOWN
|
537
|
+
env[first[VALUE]][STATS].type = APPLY
|
538
|
+
env[first[VALUE]][STATS][ARGS_COUNT] = rest.length
|
539
|
+
}
|
538
540
|
}
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
if (
|
545
|
-
args[i][STATS] &&
|
546
|
-
args[i][STATS].type === APPLY &&
|
547
|
-
env[rest[i][VALUE]] &&
|
548
|
-
env[rest[i][VALUE]][STATS] &&
|
549
|
-
env[rest[i][VALUE]][STATS][ARGS_COUNT] &&
|
550
|
-
args[i][STATS][ARGS_COUNT] !== VARIADIC &&
|
551
|
-
env[rest[i][VALUE]][STATS][ARGS_COUNT] !== VARIADIC
|
552
|
-
) {
|
541
|
+
// also type of arg
|
542
|
+
const args = env[first[VALUE]][STATS][ARGS]
|
543
|
+
if (args) {
|
544
|
+
for (let i = 0; i < args.length; ++i) {
|
545
|
+
// type check
|
553
546
|
if (
|
554
|
-
|
555
|
-
|
547
|
+
first[TYPE] === APPLY &&
|
548
|
+
isSpecial &&
|
549
|
+
env[first[VALUE]][STATS][ARGS_COUNT] !== VARIADIC
|
556
550
|
) {
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
}
|
568
|
-
} else if (
|
569
|
-
args[i][STATS] &&
|
570
|
-
args[i][STATS].type === APPLY &&
|
571
|
-
!isLeaf(rest[i]) &&
|
572
|
-
rest[i][0][TYPE] === APPLY &&
|
573
|
-
rest[i][0][VALUE] === KEYWORDS.ANONYMOUS_FUNCTION
|
574
|
-
) {
|
575
|
-
if (args[i][STATS][ARGS_COUNT] !== rest[i].length - 2)
|
576
|
-
errorStack.set(
|
577
|
-
key.str,
|
578
|
-
`Incorrect number of arguments for (${
|
579
|
-
first[VALUE]
|
580
|
-
}). Expected (= ${
|
581
|
-
args[i][STATS][ARGS_COUNT]
|
582
|
-
}) but got ${rest.length} (${stringifyArgs(
|
583
|
-
exp
|
584
|
-
)}) (check #6)`
|
585
|
-
)
|
586
|
-
}
|
587
|
-
|
588
|
-
// type check
|
589
|
-
if (
|
590
|
-
first[TYPE] === APPLY &&
|
591
|
-
isSpecial &&
|
592
|
-
env[first[VALUE]][STATS][ARGS_COUNT] !== VARIADIC
|
593
|
-
) {
|
594
|
-
const expectedArgs = env[first[VALUE]][STATS][ARGS]
|
595
|
-
for (let i = 0; i < rest.length; ++i) {
|
596
|
-
if (expectedArgs[i][TYPE] === UNKNOWN) continue
|
597
|
-
if (!isLeaf(rest[i])) {
|
598
|
-
const CAR = rest[i][0][VALUE]
|
599
|
-
if (
|
600
|
-
env[CAR] &&
|
601
|
-
env[CAR][STATS][RETURNS] != undefined &&
|
602
|
-
env[CAR][STATS][RETURNS] !== UNKNOWN &&
|
603
|
-
env[CAR][STATS][RETURNS] !== expectedArgs[i][TYPE]
|
604
|
-
) {
|
605
|
-
// console.log(env[CAR][STATS], expectedArgs[i][TYPE])
|
606
|
-
errorStack.set(
|
607
|
-
key.str,
|
608
|
-
`Incorrect type of arguments for special form (${
|
609
|
-
first[VALUE]
|
610
|
-
}). Expected (${toTypeNames(
|
551
|
+
const expectedArgs = env[first[VALUE]][STATS][ARGS]
|
552
|
+
for (let i = 0; i < rest.length; ++i) {
|
553
|
+
if (expectedArgs[i][TYPE] === UNKNOWN) continue
|
554
|
+
if (!isLeaf(rest[i])) {
|
555
|
+
const CAR = rest[i][0][VALUE]
|
556
|
+
if (
|
557
|
+
env[CAR] &&
|
558
|
+
env[CAR][STATS][RETURNS] != undefined &&
|
559
|
+
env[CAR][STATS][RETURNS] !== UNKNOWN &&
|
560
|
+
env[CAR][STATS][RETURNS] !==
|
611
561
|
expectedArgs[i][TYPE]
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
562
|
+
) {
|
563
|
+
// console.log(env[CAR][STATS], expectedArgs[i][TYPE])
|
564
|
+
errorStack.set(
|
565
|
+
key.str,
|
566
|
+
`Incorrect type of arguments for special form (${
|
567
|
+
first[VALUE]
|
568
|
+
}). Expected (${toTypeNames(
|
569
|
+
expectedArgs[i][TYPE]
|
570
|
+
)}) but got (${toTypeNames(
|
571
|
+
env[CAR][STATS][RETURNS]
|
572
|
+
)}) (${stringifyArgs(exp)}) (check #1)`
|
573
|
+
)
|
574
|
+
}
|
575
|
+
// else {
|
576
|
+
// console.log(env[CAR])
|
577
|
+
// }
|
616
578
|
}
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
579
|
+
if (
|
580
|
+
env[rest[i][VALUE]] &&
|
581
|
+
expectedArgs[i][TYPE] !== rest[i][TYPE]
|
582
|
+
) {
|
583
|
+
switch (rest[i][TYPE]) {
|
584
|
+
case UNKNOWN:
|
585
|
+
env[first[VALUE]][STATS].type =
|
586
|
+
expectedArgs[i][TYPE]
|
587
|
+
break
|
588
|
+
case WORD:
|
589
|
+
const T = env[rest[i][VALUE]][STATS].type
|
590
|
+
if (Array.isArray(T)) {
|
591
|
+
const TT = T[VALUE]
|
592
|
+
if (
|
593
|
+
env[TT][STATS][RETURNS] &&
|
594
|
+
env[TT][STATS][RETURNS] !== UNKNOWN &&
|
595
|
+
expectedArgs[i][TYPE] !==
|
596
|
+
env[TT][STATS][RETURNS]
|
597
|
+
)
|
598
|
+
errorStack.set(
|
599
|
+
key.str,
|
600
|
+
`Incorrect type of arguments for special form (${
|
601
|
+
first[VALUE]
|
602
|
+
}). Expected (${toTypeNames(
|
603
|
+
expectedArgs[i][TYPE]
|
604
|
+
)}) but got (${toTypeNames(
|
605
|
+
rest[i][TYPE]
|
606
|
+
)}) (${stringifyArgs(exp)}) (check #2)`
|
607
|
+
)
|
608
|
+
} else if (
|
609
|
+
T !== UNKNOWN &&
|
610
|
+
expectedArgs[i][TYPE] !== UNKNOWN &&
|
611
|
+
expectedArgs[i][TYPE] !== T
|
612
|
+
) {
|
640
613
|
errorStack.set(
|
641
614
|
key.str,
|
642
615
|
`Incorrect type of arguments for special form (${
|
@@ -644,66 +617,89 @@ export const typeCheck = (ast) => {
|
|
644
617
|
}). Expected (${toTypeNames(
|
645
618
|
expectedArgs[i][TYPE]
|
646
619
|
)}) but got (${toTypeNames(
|
647
|
-
|
648
|
-
)}) (${stringifyArgs(exp)}) (check #
|
620
|
+
T
|
621
|
+
)}) (${stringifyArgs(exp)}) (check #3)`
|
649
622
|
)
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
623
|
+
} else {
|
624
|
+
env[rest[i][VALUE]][STATS].type =
|
625
|
+
expectedArgs[i][TYPE]
|
626
|
+
}
|
627
|
+
break
|
628
|
+
case APPLY:
|
629
|
+
case ATOM:
|
655
630
|
errorStack.set(
|
656
631
|
key.str,
|
657
|
-
`Incorrect type of arguments for
|
632
|
+
`Incorrect type of arguments for (${
|
658
633
|
first[VALUE]
|
659
634
|
}). Expected (${toTypeNames(
|
660
635
|
expectedArgs[i][TYPE]
|
661
636
|
)}) but got (${toTypeNames(
|
662
|
-
|
663
|
-
)}) (${stringifyArgs(exp)}) (check #
|
637
|
+
rest[i][TYPE]
|
638
|
+
)}) (${stringifyArgs(exp)}) (check #5)`
|
664
639
|
)
|
665
|
-
|
666
|
-
|
667
|
-
expectedArgs[i][TYPE]
|
668
|
-
}
|
669
|
-
break
|
670
|
-
case APPLY:
|
671
|
-
case ATOM:
|
672
|
-
errorStack.set(
|
673
|
-
key.str,
|
674
|
-
`Incorrect type of arguments for (${
|
675
|
-
first[VALUE]
|
676
|
-
}). Expected (${toTypeNames(
|
677
|
-
expectedArgs[i][TYPE]
|
678
|
-
)}) but got (${toTypeNames(
|
679
|
-
rest[i][TYPE]
|
680
|
-
)}) (${stringifyArgs(exp)}) (check #5)`
|
681
|
-
)
|
682
|
-
break
|
640
|
+
break
|
641
|
+
}
|
683
642
|
}
|
684
643
|
}
|
685
644
|
}
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
645
|
+
// type checking
|
646
|
+
else if (
|
647
|
+
rest[i] &&
|
648
|
+
args[i][STATS] &&
|
649
|
+
rest[i][TYPE] !== args[i][STATS].type
|
650
|
+
) {
|
651
|
+
if (isLeaf(rest[i])) {
|
652
|
+
const T =
|
653
|
+
rest[i][TYPE] === WORD && env[rest[i][VALUE]]
|
654
|
+
? env[rest[i][VALUE]][STATS].type
|
655
|
+
: rest[i][TYPE]
|
656
|
+
if (
|
657
|
+
(args[i][STATS].type !== UNKNOWN &&
|
658
|
+
T === ATOM &&
|
659
|
+
args[i][STATS].type !== ATOM) ||
|
660
|
+
(env[rest[i][VALUE]] &&
|
661
|
+
env[rest[i][VALUE]][STATS].type !== UNKNOWN &&
|
662
|
+
args[i][STATS].type !== UNKNOWN &&
|
663
|
+
env[rest[i][VALUE]][STATS].type !==
|
664
|
+
args[i][STATS].type)
|
665
|
+
) {
|
666
|
+
errorStack.set(
|
667
|
+
key.str,
|
668
|
+
`Incorrect type of arguments ${i} for (${
|
669
|
+
first[VALUE]
|
670
|
+
}). Expected (${toTypeNames(
|
671
|
+
args[i][STATS].type
|
672
|
+
)}) but got (${toTypeNames(
|
673
|
+
T
|
674
|
+
)}) (${stringifyArgs(exp)})`
|
675
|
+
)
|
676
|
+
} else {
|
677
|
+
// env[rest[i][VALUE]][STATS] THiss SHOULD BE
|
678
|
+
const retry = env[rest[i][VALUE]]
|
679
|
+
if (
|
680
|
+
retry &&
|
681
|
+
!retry.retried &&
|
682
|
+
args[i][STATS].type === UNKNOWN
|
683
|
+
) {
|
684
|
+
retry.retried = true
|
685
|
+
stack.unshift(() => check(exp, env, scope))
|
686
|
+
}
|
687
|
+
// console.log(
|
688
|
+
// first[VALUE],
|
689
|
+
// env[first[VALUE]][STATS],
|
690
|
+
// rest[i][TYPE],
|
691
|
+
// args[i][STATS].type
|
692
|
+
// )
|
693
|
+
}
|
694
|
+
} else if (
|
695
|
+
rest[i].length &&
|
696
|
+
SPECIAL_FORMS_SET.has(rest[i][0][VALUE]) &&
|
697
|
+
env[rest[i][0][VALUE]] &&
|
698
|
+
env[rest[i][0][VALUE]][STATS][RETURNS] !==
|
699
|
+
UNKNOWN &&
|
700
|
+
args[i][STATS].type !== UNKNOWN &&
|
701
|
+
env[rest[i][0][VALUE]][STATS][RETURNS] !==
|
702
|
+
args[i][STATS].type
|
707
703
|
) {
|
708
704
|
errorStack.set(
|
709
705
|
key.str,
|
@@ -711,58 +707,22 @@ export const typeCheck = (ast) => {
|
|
711
707
|
first[VALUE]
|
712
708
|
}). Expected (${toTypeNames(
|
713
709
|
args[i][STATS].type
|
714
|
-
)}) but got (${toTypeNames(
|
715
|
-
|
716
|
-
)})`
|
710
|
+
)}) but got (${toTypeNames(
|
711
|
+
env[rest[i][0][VALUE]][STATS][RETURNS]
|
712
|
+
)}) (${stringifyArgs(exp)}) (check #4)`
|
717
713
|
)
|
718
714
|
} else {
|
719
|
-
// env[rest[i][VALUE]][STATS] THiss SHOULD BE
|
720
|
-
const retry = env[rest[i][VALUE]]
|
721
715
|
if (
|
722
|
-
|
723
|
-
|
724
|
-
args[i][STATS].type === UNKNOWN
|
716
|
+
rest[i].length &&
|
717
|
+
env[rest[i][0][VALUE]] &&
|
718
|
+
args[i][STATS].type === UNKNOWN &&
|
719
|
+
!env[rest[i][0][VALUE]].retried
|
725
720
|
) {
|
726
|
-
|
721
|
+
env[rest[i][0][VALUE]].retried = true
|
722
|
+
if (!scope[SCOPE_NAME])
|
723
|
+
scope[SCOPE_NAME] = scope[1][VALUE]
|
727
724
|
stack.unshift(() => check(exp, env, scope))
|
728
725
|
}
|
729
|
-
// console.log(
|
730
|
-
// first[VALUE],
|
731
|
-
// env[first[VALUE]][STATS],
|
732
|
-
// rest[i][TYPE],
|
733
|
-
// args[i][STATS].type
|
734
|
-
// )
|
735
|
-
}
|
736
|
-
} else if (
|
737
|
-
rest[i].length &&
|
738
|
-
SPECIAL_FORMS_SET.has(rest[i][0][VALUE]) &&
|
739
|
-
env[rest[i][0][VALUE]] &&
|
740
|
-
env[rest[i][0][VALUE]][STATS][RETURNS] !== UNKNOWN &&
|
741
|
-
args[i][STATS].type !== UNKNOWN &&
|
742
|
-
env[rest[i][0][VALUE]][STATS][RETURNS] !==
|
743
|
-
args[i][STATS].type
|
744
|
-
) {
|
745
|
-
errorStack.set(
|
746
|
-
key.str,
|
747
|
-
`Incorrect type of arguments ${i} for (${
|
748
|
-
first[VALUE]
|
749
|
-
}). Expected (${toTypeNames(
|
750
|
-
args[i][STATS].type
|
751
|
-
)}) but got (${toTypeNames(
|
752
|
-
env[rest[i][0][VALUE]][STATS][RETURNS]
|
753
|
-
)}) (${stringifyArgs(exp)})`
|
754
|
-
)
|
755
|
-
} else {
|
756
|
-
if (
|
757
|
-
rest[i].length &&
|
758
|
-
env[rest[i][0][VALUE]] &&
|
759
|
-
args[i][STATS].type === UNKNOWN &&
|
760
|
-
!env[rest[i][0][VALUE]].retried
|
761
|
-
) {
|
762
|
-
env[rest[i][0][VALUE]].retried = true
|
763
|
-
if (!scope[SCOPE_NAME])
|
764
|
-
scope[SCOPE_NAME] = scope[1][VALUE]
|
765
|
-
stack.unshift(() => check(exp, env, scope))
|
766
726
|
}
|
767
727
|
}
|
768
728
|
}
|