fez-lisp 1.5.112 → 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 +41 -19
- 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],
|
@@ -854,6 +866,13 @@ export const typeCheck = (ast, error = true) => {
|
|
854
866
|
alternative[i] = rest[i][2]
|
855
867
|
check([first, ...concequent], env, scope)
|
856
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
|
+
)
|
857
876
|
} else if (
|
858
877
|
!isUnknownReturn(env[name][STATS]) &&
|
859
878
|
!compareTypeWithReturn(args[i][STATS], env[name][STATS])
|
@@ -868,8 +887,9 @@ export const typeCheck = (ast, error = true) => {
|
|
868
887
|
)}) (${stringifyArgs(exp)}) (check #1)`
|
869
888
|
)
|
870
889
|
else if (
|
890
|
+
!isUnknownReturn(env[name][STATS]) &&
|
871
891
|
notABooleanReturn(args[i][STATS], env[name][STATS])
|
872
|
-
)
|
892
|
+
)
|
873
893
|
throw new TypeError(
|
874
894
|
`Incorrect type of argument (${i}) for special form (${
|
875
895
|
first[VALUE]
|
@@ -879,7 +899,7 @@ export const typeCheck = (ast, error = true) => {
|
|
879
899
|
getReturns(env[name][STATS])
|
880
900
|
)}) (${stringifyArgs(exp)}) (check #201)`
|
881
901
|
)
|
882
|
-
|
902
|
+
else {
|
883
903
|
if (env[name] && getType(env[name][STATS]) === APPLY)
|
884
904
|
switch (first[VALUE]) {
|
885
905
|
case KEYWORDS.IF:
|
@@ -893,6 +913,7 @@ export const typeCheck = (ast, error = true) => {
|
|
893
913
|
setReturn(env[name][STATS], args[i][STATS])
|
894
914
|
break
|
895
915
|
}
|
916
|
+
|
896
917
|
// TODO also handle casting
|
897
918
|
}
|
898
919
|
} else {
|
@@ -915,6 +936,7 @@ export const typeCheck = (ast, error = true) => {
|
|
915
936
|
)}) (${stringifyArgs(exp)}) (check #3)`
|
916
937
|
)
|
917
938
|
else if (
|
939
|
+
!isUnknownType(env[name][STATS]) &&
|
918
940
|
notABooleanType(args[i][STATS], env[name][STATS])
|
919
941
|
)
|
920
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'
|