fez-lisp 1.5.111 → 1.5.114
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/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/check.js +49 -20
- package/src/types.js +1 -0
package/package.json
CHANGED
package/src/check.js
CHANGED
@@ -43,7 +43,8 @@ import {
|
|
43
43
|
FALSE_WORD,
|
44
44
|
BOOLEAN_SUBTYPE,
|
45
45
|
formatSubType,
|
46
|
-
PREDICATE
|
46
|
+
PREDICATE,
|
47
|
+
IS_ARGUMENT
|
47
48
|
} from './types.js'
|
48
49
|
import {
|
49
50
|
Brr,
|
@@ -269,18 +270,28 @@ const IsPredicate = (leaf) =>
|
|
269
270
|
(PREDICATES_OUTPUT_SET.has(leaf[VALUE]) ||
|
270
271
|
getSuffix(leaf[VALUE]) === PREDICATE_SUFFIX))
|
271
272
|
|
272
|
-
const notABooleanType = (a, b) =>
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
273
|
+
const notABooleanType = (a, b) => {
|
274
|
+
return (
|
275
|
+
hasSubType(a) &&
|
276
|
+
getSubType(a).has(PREDICATE) &&
|
277
|
+
!isUnknownType(b) &&
|
278
|
+
!isAnyType(b) &&
|
279
|
+
(!isAtomType(b) ||
|
280
|
+
!hasSubType(b) ||
|
281
|
+
getSubType(a).difference(getSubType(b)).size !== 0)
|
282
|
+
)
|
283
|
+
}
|
284
|
+
const notABooleanReturn = (a, b) => {
|
285
|
+
return (
|
286
|
+
hasSubType(a) &&
|
287
|
+
getSubType(a).has(PREDICATE) &&
|
288
|
+
!isUnknownReturn(b) &&
|
289
|
+
!isAnyReturn(b) &&
|
290
|
+
(!isAtomReturn(b) ||
|
291
|
+
!hasSubReturn(b) ||
|
292
|
+
getSubType(a).difference(getSubReturn(b)).size !== 0)
|
293
|
+
)
|
294
|
+
}
|
284
295
|
const isAtomABoolean = (atom) => atom === TRUE || atom === FALSE
|
285
296
|
const checkPredicateName = (exp, rest) => {
|
286
297
|
if (getSuffix(rest[0][VALUE]) === PREDICATE_SUFFIX) {
|
@@ -383,11 +394,11 @@ const IfApplyBranch = ({ leaf, branch, re, prop, ref, env }) => {
|
|
383
394
|
break
|
384
395
|
case KEYWORDS.CALL_FUNCTION:
|
385
396
|
if (re.at(-1)[TYPE] === WORD) {
|
386
|
-
if (env[re.at(-1)[VALUE]])
|
397
|
+
if (env[re.at(-1)[VALUE]] && re.at(-1)[VALUE] !== ref[STATS][SIGNATURE])
|
387
398
|
setPropToReturnRef(ref[STATS], prop, env[re.at(-1)[VALUE]][STATS])
|
388
399
|
} else {
|
389
400
|
const returns = returnType(re.at(-1))
|
390
|
-
if (env[returns[VALUE]])
|
401
|
+
if (env[returns[VALUE]] && returns[VALUE] !== ref[STATS][SIGNATURE])
|
391
402
|
IfApplyBranch({
|
392
403
|
branch: env[returns[VALUE]],
|
393
404
|
ref,
|
@@ -423,7 +434,7 @@ const ifExpression = ({ re, env, ref, prop }) => {
|
|
423
434
|
// Making sure the recursive function don't look for their own return type
|
424
435
|
concequent[STATS][SIGNATURE] !== ref[STATS][SIGNATURE]
|
425
436
|
) {
|
426
|
-
|
437
|
+
IfApplyBranch({
|
427
438
|
leaf: conc,
|
428
439
|
branch: concequent,
|
429
440
|
re: re[0],
|
@@ -441,7 +452,7 @@ const ifExpression = ({ re, env, ref, prop }) => {
|
|
441
452
|
// Making sure the recursive function don't look for their own return type
|
442
453
|
alternative[STATS][SIGNATURE] !== ref[STATS][SIGNATURE]
|
443
454
|
) {
|
444
|
-
|
455
|
+
IfApplyBranch({
|
445
456
|
leaf: alt,
|
446
457
|
branch: alternative,
|
447
458
|
re: re[1],
|
@@ -690,6 +701,7 @@ export const typeCheck = (ast, error = true) => {
|
|
690
701
|
)
|
691
702
|
copy[param[VALUE]] = {
|
692
703
|
[STATS]: {
|
704
|
+
[IS_ARGUMENT]: true,
|
693
705
|
[SIGNATURE]: param[VALUE],
|
694
706
|
[TYPE_PROP]: [UNKNOWN],
|
695
707
|
[RETURNS]: [UNKNOWN],
|
@@ -847,7 +859,21 @@ export const typeCheck = (ast, error = true) => {
|
|
847
859
|
if (!isResLeaf) {
|
848
860
|
const name = rest[i][0][VALUE]
|
849
861
|
if (!env[name]) continue
|
850
|
-
if (
|
862
|
+
if (name === KEYWORDS.IF) {
|
863
|
+
const concequent = [...rest]
|
864
|
+
const alternative = [...rest]
|
865
|
+
concequent[i] = rest[i][1]
|
866
|
+
alternative[i] = rest[i][2]
|
867
|
+
check([first, ...concequent], env, scope)
|
868
|
+
check([first, ...alternative], env, scope)
|
869
|
+
} else if (
|
870
|
+
isUnknownReturn(env[name][STATS]) &&
|
871
|
+
!env[name][STATS][IS_ARGUMENT]
|
872
|
+
) {
|
873
|
+
return retry(env[name][STATS], stack, () =>
|
874
|
+
check(exp, env, scope)
|
875
|
+
)
|
876
|
+
} else if (
|
851
877
|
!isUnknownReturn(env[name][STATS]) &&
|
852
878
|
!compareTypeWithReturn(args[i][STATS], env[name][STATS])
|
853
879
|
)
|
@@ -861,8 +887,9 @@ export const typeCheck = (ast, error = true) => {
|
|
861
887
|
)}) (${stringifyArgs(exp)}) (check #1)`
|
862
888
|
)
|
863
889
|
else if (
|
890
|
+
!isUnknownReturn(env[name][STATS]) &&
|
864
891
|
notABooleanReturn(args[i][STATS], env[name][STATS])
|
865
|
-
)
|
892
|
+
)
|
866
893
|
throw new TypeError(
|
867
894
|
`Incorrect type of argument (${i}) for special form (${
|
868
895
|
first[VALUE]
|
@@ -872,7 +899,7 @@ export const typeCheck = (ast, error = true) => {
|
|
872
899
|
getReturns(env[name][STATS])
|
873
900
|
)}) (${stringifyArgs(exp)}) (check #201)`
|
874
901
|
)
|
875
|
-
|
902
|
+
else {
|
876
903
|
if (env[name] && getType(env[name][STATS]) === APPLY)
|
877
904
|
switch (first[VALUE]) {
|
878
905
|
case KEYWORDS.IF:
|
@@ -886,6 +913,7 @@ export const typeCheck = (ast, error = true) => {
|
|
886
913
|
setReturn(env[name][STATS], args[i][STATS])
|
887
914
|
break
|
888
915
|
}
|
916
|
+
|
889
917
|
// TODO also handle casting
|
890
918
|
}
|
891
919
|
} else {
|
@@ -908,6 +936,7 @@ export const typeCheck = (ast, error = true) => {
|
|
908
936
|
)}) (${stringifyArgs(exp)}) (check #3)`
|
909
937
|
)
|
910
938
|
else if (
|
939
|
+
!isUnknownType(env[name][STATS]) &&
|
911
940
|
notABooleanType(args[i][STATS], env[name][STATS])
|
912
941
|
)
|
913
942
|
throw new TypeError(
|
package/src/types.js
CHANGED
@@ -25,6 +25,7 @@ export const ANY = 4
|
|
25
25
|
export const ANONYMOUS_FUNCTION_TYPE_PREFIX = 'lambda::annonymous::'
|
26
26
|
export const MAX_ARGUMENT_RETRY = 1
|
27
27
|
export const MAX_RETRY_DEFINITION = 100
|
28
|
+
export const IS_ARGUMENT = 'is_arg'
|
28
29
|
export const NIL = 'nil'
|
29
30
|
export const TRUE_WORD = 'true'
|
30
31
|
export const FALSE_WORD = 'false'
|