fez-lisp 1.6.68 → 1.6.69
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 +68 -8
- package/src/macros.js +14 -0
package/package.json
CHANGED
package/src/check.js
CHANGED
@@ -612,13 +612,63 @@ const resolveCondition = ({ rem, name, env, exp, prop, stack, check }) => {
|
|
612
612
|
break
|
613
613
|
}
|
614
614
|
}
|
615
|
+
const resolveGetterRec = ([head, tail], env, times = 0) => {
|
616
|
+
if (GET_ARRAY_INFERENCE_SET.has(head[VALUE])) {
|
617
|
+
return resolveGetterRec(tail, env, ++times)
|
618
|
+
} else {
|
619
|
+
switch (head) {
|
620
|
+
case APPLY:
|
621
|
+
break
|
622
|
+
case WORD:
|
623
|
+
{
|
624
|
+
if (env[tail][STATS][TYPE_PROP][0] === UNKNOWN) return
|
625
|
+
const types = env[tail][STATS][TYPE_PROP][1].types
|
626
|
+
const sub = types.at(-1)
|
627
|
+
const type =
|
628
|
+
sub === ATOM || sub === NUMBER || sub === BOOLEAN
|
629
|
+
? ATOM
|
630
|
+
: sub === APPLY
|
631
|
+
? APPLY
|
632
|
+
: COLLECTION
|
633
|
+
const len = types.length ? types.length + 1 : times + 1
|
634
|
+
return [times, len, type, types]
|
635
|
+
}
|
636
|
+
break
|
637
|
+
}
|
638
|
+
}
|
639
|
+
}
|
615
640
|
const resolveGetter = ({ rem, prop, name, env, caller, exp }) => {
|
616
641
|
const array = isLeaf(rem[1]) ? rem[1] : rem[1][0]
|
617
642
|
if (!env[array[VALUE]] || !env[name]) return true
|
618
643
|
switch (array[TYPE]) {
|
619
644
|
case APPLY:
|
620
645
|
// TODO: figure out recursively what is the inner type of all nested getters
|
621
|
-
if (GET_ARRAY_INFERENCE_SET.has(array[VALUE]))
|
646
|
+
if (GET_ARRAY_INFERENCE_SET.has(array[VALUE])) {
|
647
|
+
const rec = resolveGetterRec(rem, env)
|
648
|
+
if (!rec) return true
|
649
|
+
const [times, level, type, types] = resolveGetterRec(rem, env)
|
650
|
+
if (times >= level)
|
651
|
+
throw new RangeError(
|
652
|
+
`(${caller}) is trying to access nested structure at level (${level}) which is deeper than it's (${times}) levels at (${stringifyArgs(
|
653
|
+
exp
|
654
|
+
)}) (check #1003)`
|
655
|
+
)
|
656
|
+
if (times === level - 1) {
|
657
|
+
setPropToType(env[name][STATS], prop, {
|
658
|
+
[TYPE_PROP]: types.length
|
659
|
+
? [type, new SubType([types.at(-1)])]
|
660
|
+
: [UNKNOWN]
|
661
|
+
})
|
662
|
+
} else {
|
663
|
+
setPropToType(env[name][STATS], prop, {
|
664
|
+
[TYPE_PROP]: types.length
|
665
|
+
? [COLLECTION, new SubType(types.slice(times))]
|
666
|
+
: [UNKNOWN]
|
667
|
+
})
|
668
|
+
}
|
669
|
+
return true
|
670
|
+
}
|
671
|
+
|
622
672
|
if (
|
623
673
|
getReturn(env[array[VALUE]][STATS]) === UNKNOWN ||
|
624
674
|
getReturn(env[array[VALUE]][STATS]) === ANY
|
@@ -644,8 +694,12 @@ const resolveGetter = ({ rem, prop, name, env, caller, exp }) => {
|
|
644
694
|
setPropToReturn(env[name][STATS], prop, {
|
645
695
|
[RETURNS]: [f, new SubType(r)]
|
646
696
|
})
|
647
|
-
} else
|
648
|
-
|
697
|
+
} else if (rightSub.has(APPLY)) {
|
698
|
+
// TODOD: abstractions go here but what can we do with them
|
699
|
+
// perhaps show the signature?
|
700
|
+
setPropToAbstraction(env[name][STATS], prop)
|
701
|
+
}
|
702
|
+
}
|
649
703
|
break
|
650
704
|
case WORD:
|
651
705
|
{
|
@@ -675,8 +729,12 @@ const resolveGetter = ({ rem, prop, name, env, caller, exp }) => {
|
|
675
729
|
setPropToType(env[name][STATS], prop, {
|
676
730
|
[TYPE_PROP]: [f, new SubType(r)]
|
677
731
|
})
|
678
|
-
} else
|
679
|
-
|
732
|
+
} else if (rightSub.has(APPLY)) {
|
733
|
+
// TODOD: abstractions go here but what can we do with them
|
734
|
+
// perhaps show the signature?
|
735
|
+
setPropToAbstraction(env[name][STATS], prop)
|
736
|
+
}
|
737
|
+
}
|
680
738
|
}
|
681
739
|
break
|
682
740
|
}
|
@@ -837,11 +895,13 @@ const initArrayType = ({ rem, env }) => {
|
|
837
895
|
ret[0].length = 0
|
838
896
|
const subT = new SubType([COLLECTION])
|
839
897
|
ret[0].push(COLLECTION, subT)
|
840
|
-
while (head && !isSubType(head[1])) {
|
841
|
-
subT.
|
898
|
+
while (Array.isArray(head) && !isSubType(head[1])) {
|
899
|
+
if (head[0] === APPLY) subT.types.push(APPLY)
|
900
|
+
else subT.add(COLLECTION)
|
842
901
|
head = head[0]
|
843
902
|
}
|
844
|
-
if (head && head[1].types.length)
|
903
|
+
if (Array.isArray(head) && head[1].types.length)
|
904
|
+
subT.add(head[1].types[0])
|
845
905
|
}
|
846
906
|
const [main, sub] = ret[0]
|
847
907
|
if (isSubType(sub) && sub.types.at(-1) === COLLECTION) sub.types.pop()
|
package/src/macros.js
CHANGED
@@ -114,6 +114,20 @@ export const deSuggarAst = (ast, scope) => {
|
|
114
114
|
// }
|
115
115
|
// }
|
116
116
|
// break
|
117
|
+
case PLACEHOLDER:
|
118
|
+
{
|
119
|
+
exp.length = 0
|
120
|
+
rest.reverse()
|
121
|
+
let temp = exp
|
122
|
+
for (let i = 0; i < rest.length; i += 1) {
|
123
|
+
if (i < rest.length - 1) {
|
124
|
+
temp.push([APPLY, SUGGAR.GET_ARRAY], [], rest[i])
|
125
|
+
temp = temp.at(-2)
|
126
|
+
} else temp.push(...rest[i])
|
127
|
+
}
|
128
|
+
deSuggarAst(exp, scope)
|
129
|
+
}
|
130
|
+
break
|
117
131
|
case KEYWORDS.GET_ARRAY:
|
118
132
|
if (rest.length === 1) {
|
119
133
|
exp[0][VALUE] = 'math:var-get'
|