fez-lisp 1.6.19 → 1.6.21
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 +14 -36
package/package.json
CHANGED
package/src/check.js
CHANGED
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
VALUE,
|
17
17
|
WORD
|
18
18
|
} from './keywords.js'
|
19
|
-
import { isLeaf } from './parser.js'
|
19
|
+
import { isLeaf, LISP } from './parser.js'
|
20
20
|
import {
|
21
21
|
SPECIAL_FORM_TYPES,
|
22
22
|
toTypeNames,
|
@@ -461,7 +461,7 @@ const getScopeNames = (scope) => {
|
|
461
461
|
}
|
462
462
|
const withScope = (name, scope) => {
|
463
463
|
const chain = getScopeNames(scope)
|
464
|
-
return `${chain.
|
464
|
+
return `${chain.join(' ')} ${name}`
|
465
465
|
}
|
466
466
|
const retry = (stats, ctx, stack, cb, method = 'prepend') => {
|
467
467
|
if (
|
@@ -993,6 +993,7 @@ const stagger = (stack, method, data, fn) => {
|
|
993
993
|
export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
|
994
994
|
const Types = new Map()
|
995
995
|
const stack = new Brr()
|
996
|
+
const rootScopeIndex = 1
|
996
997
|
let scopeIndex = 0
|
997
998
|
// TODO also handle casting
|
998
999
|
const match = ({ rest, args, i, env, scope, exp }) => {
|
@@ -1204,7 +1205,9 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
|
|
1204
1205
|
)
|
1205
1206
|
if (name in env) {
|
1206
1207
|
Types.set(withScope(name, env), () => formatType(name, env))
|
1207
|
-
if (
|
1208
|
+
if (env[SCOPE_NAME] === rootScopeIndex) {
|
1209
|
+
break
|
1210
|
+
}
|
1208
1211
|
}
|
1209
1212
|
// Predicate name consistency
|
1210
1213
|
const rightHand = rest.at(-1)
|
@@ -1429,34 +1432,9 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
|
|
1429
1432
|
check
|
1430
1433
|
})
|
1431
1434
|
})
|
1432
|
-
// const ret = returns[0]
|
1433
|
-
// switch (ret[VALUE]) {
|
1434
|
-
// case KEYWORDS.IF:
|
1435
|
-
// resolveCondition({
|
1436
|
-
// rem: returns,
|
1437
|
-
// name: ref[STATS][SIGNATURE],
|
1438
|
-
// env: copy,
|
1439
|
-
// exp,
|
1440
|
-
// stack,
|
1441
|
-
// prop: RETURNS,
|
1442
|
-
// check
|
1443
|
-
// })
|
1444
|
-
// break
|
1445
|
-
// default:
|
1446
|
-
// if (copy[ret[VALUE]]) {
|
1447
|
-
// if (isUnknownReturn(copy[ret[VALUE]][STATS])) {
|
1448
|
-
// once(ref[STATS], copy[ret[VALUE]][STATS])
|
1449
|
-
// } else setReturnRef(ref[STATS], copy[ret[VALUE]][STATS])
|
1450
|
-
// } else
|
1451
|
-
// stagger(stack, 'append', [ret, copy], () => {
|
1452
|
-
// if (copy[ret[VALUE]])
|
1453
|
-
// setReturnRef(ref[STATS], copy[ret[VALUE]][STATS])
|
1454
|
-
// })
|
1455
|
-
// break
|
1456
|
-
// }
|
1457
1435
|
})
|
1458
1436
|
}
|
1459
|
-
check(rest.at(-1), copy,
|
1437
|
+
check(rest.at(-1), copy, [])
|
1460
1438
|
}
|
1461
1439
|
|
1462
1440
|
break
|
@@ -1480,7 +1458,7 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
|
|
1480
1458
|
castReturn(ref[STATS], caster[STATS])
|
1481
1459
|
else if (isUnknownType(ref[STATS]))
|
1482
1460
|
castType(ref[STATS], caster[STATS])
|
1483
|
-
check(rest[0], env,
|
1461
|
+
check(rest[0], env, exp)
|
1484
1462
|
}
|
1485
1463
|
break
|
1486
1464
|
default:
|
@@ -1610,17 +1588,17 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
|
|
1610
1588
|
args[i][STATS],
|
1611
1589
|
env[name][STATS]
|
1612
1590
|
)
|
1613
|
-
if (isKnown && !eqTypes)
|
1591
|
+
if (isKnown && !eqTypes) {
|
1614
1592
|
throw new TypeError(
|
1615
1593
|
`Incorrect type of argument (${i}) for (${
|
1616
1594
|
first[VALUE]
|
1617
|
-
}). Expected (${
|
1618
|
-
|
1619
|
-
)}) but got (${
|
1620
|
-
|
1595
|
+
}). Expected (${formatSubType(
|
1596
|
+
getTypes(args[i][STATS])
|
1597
|
+
)}) but got (${formatSubType(
|
1598
|
+
getTypes(env[name][STATS])
|
1621
1599
|
)}) (${stringifyArgs(exp)}) (check #3)`
|
1622
1600
|
)
|
1623
|
-
else if (isKnown && eqTypes && !eqSubTypes) {
|
1601
|
+
} else if (isKnown && eqTypes && !eqSubTypes) {
|
1624
1602
|
throw new TypeError(
|
1625
1603
|
`Incorrect type of argument (${i}) for (${
|
1626
1604
|
first[VALUE]
|