fez-lisp 1.6.25 → 1.6.26

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.25",
5
+ "version": "1.6.26",
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, LISP } from './parser.js'
19
+ import { isLeaf } from './parser.js'
20
20
  import {
21
21
  SPECIAL_FORM_TYPES,
22
22
  toTypeNames,
@@ -91,6 +91,9 @@ export const identity = (name) => [
91
91
  [1, 'x']
92
92
  ]
93
93
  ]
94
+ export const typeSetDefaultFunction = (Types, name, env, exp) =>
95
+ Types.set(withScope(name, env), () => formatType(name, env))
96
+
94
97
  const returnType = (rest) => {
95
98
  const body = rest.at(-1)
96
99
  const rem = hasBlock(body) ? body.at(-1) : body
@@ -459,7 +462,7 @@ const getScopeNames = (scope) => {
459
462
  }
460
463
  return scopeNames.reverse()
461
464
  }
462
- const withScope = (name, scope) => {
465
+ export const withScope = (name, scope) => {
463
466
  const chain = getScopeNames(scope)
464
467
  return `${chain.join(' ')} ${name}`
465
468
  }
@@ -990,7 +993,11 @@ const checkReturnType = ({ exp, stack, name, env, check }) => {
990
993
  const stagger = (stack, method, data, fn) => {
991
994
  stack[method]({ data, fn })
992
995
  }
993
- export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
996
+ export const typeCheck = (
997
+ ast,
998
+ ctx = SPECIAL_FORM_TYPES,
999
+ typeSet = typeSetDefaultFunction
1000
+ ) => {
994
1001
  const Types = new Map()
995
1002
  const stack = new Brr()
996
1003
  const rootScopeIndex = 1
@@ -1204,7 +1211,8 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1204
1211
  )})`
1205
1212
  )
1206
1213
  if (name in env) {
1207
- Types.set(withScope(name, env), () => formatType(name, env))
1214
+ typeSet(Types, name, env, exp)
1215
+ // Types.set(withScope(name, env), () => formatType(name, env))
1208
1216
  // If current scope is root then these are user defined types
1209
1217
  if (env[SCOPE_NAME] === rootScopeIndex) break
1210
1218
  }
@@ -1344,7 +1352,8 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
1344
1352
  }
1345
1353
  check(rightHand, env, scope)
1346
1354
  }
1347
- Types.set(withScope(name, env), () => formatType(name, env))
1355
+ typeSet(Types, name, env, exp)
1356
+ // Types.set(withScope(name, env), () => formatType(name, env))
1348
1357
  break
1349
1358
  case KEYWORDS.ANONYMOUS_FUNCTION:
1350
1359
  {
package/src/types.js CHANGED
@@ -1368,7 +1368,47 @@ export const formatType = (name, env) => {
1368
1368
  : `(let ${name} ${formatSubType(getTypes(stats))})`
1369
1369
  : name
1370
1370
  }
1371
-
1371
+ export const formatInlineType = (name, env) => {
1372
+ const stats = env[name][STATS]
1373
+ return stats
1374
+ ? getType(stats) === APPLY
1375
+ ? `(lambda ${
1376
+ stats[ARG_COUNT] === VARIADIC
1377
+ ? '... '
1378
+ : stats[ARGUMENTS]?.length
1379
+ ? stats[ARGUMENTS].map(
1380
+ (x, i) =>
1381
+ `${
1382
+ getType(x[STATS]) === APPLY
1383
+ ? `${formatType(i, stats[ARGUMENTS])}`
1384
+ : `${formatSubType(getTypes(x[STATS]))}`
1385
+ }`
1386
+ ).join(' ') + ' '
1387
+ : ''
1388
+ // TODO format returned functions when type support is added
1389
+ }(${KEYWORDS.BLOCK} ${formatSubType(getReturns(stats))}))`
1390
+ : formatSubType(getTypes(stats))
1391
+ : name
1392
+ }
1393
+ export const formatAstTypes = (name, env) => {
1394
+ const stats = env[name][STATS]
1395
+ return stats
1396
+ ? getType(stats) === APPLY
1397
+ ? [
1398
+ stats[ARG_COUNT] === VARIADIC
1399
+ ? '...'
1400
+ : stats[ARGUMENTS]?.length
1401
+ ? stats[ARGUMENTS].map((x, i) =>
1402
+ getType(x[STATS]) === APPLY
1403
+ ? formatType(i, stats[ARGUMENTS])
1404
+ : formatSubType(getTypes(x[STATS]))
1405
+ )
1406
+ : '',
1407
+ formatSubType(getReturns(stats))
1408
+ ]
1409
+ : formatSubType(getTypes(stats))
1410
+ : name
1411
+ }
1372
1412
  export const validateLambda = (exp, name) => {
1373
1413
  if (exp.length === 1)
1374
1414
  throw new TypeError(