fez-lisp 1.6.20 → 1.6.22

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "fez-lisp",
3
3
  "description": "Lisp interpreted & compiled to JavaScript",
4
4
  "author": "AT290690",
5
- "version": "1.6.20",
5
+ "version": "1.6.22",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
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.length === 1 ? '; ' : ''}${chain.join(' ')} ${name}`
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,8 @@ 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 (!env[env[SCOPE_NAME]]) break
1208
+ // If current scope is root then these are user defined types
1209
+ if (env[SCOPE_NAME] === rootScopeIndex) break
1208
1210
  }
1209
1211
  // Predicate name consistency
1210
1212
  const rightHand = rest.at(-1)
@@ -1429,34 +1431,9 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1429
1431
  check
1430
1432
  })
1431
1433
  })
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
1434
  })
1458
1435
  }
1459
- check(rest.at(-1), copy, copy)
1436
+ check(rest.at(-1), copy, [])
1460
1437
  }
1461
1438
 
1462
1439
  break
@@ -1480,7 +1457,7 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1480
1457
  castReturn(ref[STATS], caster[STATS])
1481
1458
  else if (isUnknownType(ref[STATS]))
1482
1459
  castType(ref[STATS], caster[STATS])
1483
- check(rest[0], env, env)
1460
+ check(rest[0], env, exp)
1484
1461
  }
1485
1462
  break
1486
1463
  default:
@@ -1610,17 +1587,17 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1610
1587
  args[i][STATS],
1611
1588
  env[name][STATS]
1612
1589
  )
1613
- if (isKnown && !eqTypes)
1590
+ if (isKnown && !eqTypes) {
1614
1591
  throw new TypeError(
1615
1592
  `Incorrect type of argument (${i}) for (${
1616
1593
  first[VALUE]
1617
- }). Expected (${toTypeNames(
1618
- getType(args[i][STATS])
1619
- )}) but got (${toTypeNames(
1620
- getType(env[name][STATS])
1594
+ }). Expected (${formatSubType(
1595
+ getTypes(args[i][STATS])
1596
+ )}) but got (${formatSubType(
1597
+ getTypes(env[name][STATS])
1621
1598
  )}) (${stringifyArgs(exp)}) (check #3)`
1622
1599
  )
1623
- else if (isKnown && eqTypes && !eqSubTypes) {
1600
+ } else if (isKnown && eqTypes && !eqSubTypes) {
1624
1601
  throw new TypeError(
1625
1602
  `Incorrect type of argument (${i}) for (${
1626
1603
  first[VALUE]