fez-lisp 1.6.57 → 1.6.59

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.57",
5
+ "version": "1.6.59",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -1003,9 +1003,9 @@ export const typeCheck = (
1003
1003
  throw new TypeError(
1004
1004
  `Incorrect type of argument (${i}) for (${
1005
1005
  first[VALUE]
1006
- }). Expected (${toTypeNames(
1007
- getType(expected)
1008
- )}) but got (${toTypeNames(getReturn(actual))}) (${stringifyArgs(
1006
+ }). Expected (${formatSubType(
1007
+ getTypes(expected)
1008
+ )}) but got (${formatSubType(getReturns(actual))}) (${stringifyArgs(
1009
1009
  exp
1010
1010
  )}) (check #16)`
1011
1011
  )
@@ -1111,10 +1111,10 @@ export const typeCheck = (
1111
1111
  local[lambdaName][STATS][ARGUMENTS][j][STATS][
1112
1112
  SIGNATURE
1113
1113
  ]
1114
- }). Expected (${toTypeNames(
1115
- getType(expected[STATS])
1116
- )}) but got (${toTypeNames(
1117
- getType(actual[STATS])
1114
+ }). Expected (${formatSubType(
1115
+ getTypes(expected[STATS])
1116
+ )}) but got (${formatSubType(
1117
+ getTypes(actual[STATS])
1118
1118
  )}) (${stringifyArgs(exp)}) (check #780)`
1119
1119
  )
1120
1120
  else if (!equalSubReturns(expected[STATS], actual[STATS]))
@@ -1123,10 +1123,10 @@ export const typeCheck = (
1123
1123
  expected[STATS][SIGNATURE]
1124
1124
  }) the (${KEYWORDS.ANONYMOUS_FUNCTION}) argument of (${
1125
1125
  first[VALUE]
1126
- }) at position (${i}). Expected (${toTypeNames(
1127
- getReturn(expected[STATS])
1128
- )}) but got (${toTypeNames(
1129
- getReturn(actual[STATS])
1126
+ }) at position (${i}). Expected (${formatSubType(
1127
+ getReturns(expected[STATS])
1128
+ )}) but got (${formatSubType(
1129
+ getReturns(actual[STATS])
1130
1130
  )}) (${stringifyArgs(exp)}) (check #784)`
1131
1131
  )
1132
1132
  // else
@@ -1690,13 +1690,9 @@ export const typeCheck = (
1690
1690
  first[VALUE]
1691
1691
  }). Expected (${formatSubType(
1692
1692
  getTypes(args[i][STATS])
1693
- )}) but got (${
1694
- rest[i][TYPE] === ATOM
1695
- ? toTypeNames(rest[i][TYPE])
1696
- : formatSubType(
1697
- getTypes(env[rest[i][VALUE]][STATS])
1698
- )
1699
- }) (${stringifyArgs(exp)}) (check #203)`
1693
+ )}) but got (${toTypeNames(
1694
+ NUMBER
1695
+ )}) (${stringifyArgs(exp)}) (check #203)`
1700
1696
  )
1701
1697
  }
1702
1698
  break
@@ -1719,8 +1715,8 @@ export const typeCheck = (
1719
1715
  first[VALUE]
1720
1716
  }) at position (${i}). Expected (${
1721
1717
  STATIC_TYPES.ABSTRACTION
1722
- }) but got (${toTypeNames(
1723
- getType(args[i][STATS])
1718
+ }) but got (${formatSubType(
1719
+ getTypes(args[i][STATS])
1724
1720
  )}) (${stringifyArgs(exp)}) (check #111)`
1725
1721
  )
1726
1722
  else if (getType(args[i][STATS]) === APPLY)
package/src/types.js CHANGED
@@ -88,6 +88,7 @@ export const toTypeNames = (type) => {
88
88
  case BOOLEAN:
89
89
  return 'Boolean'
90
90
  case ATOM:
91
+ return 'Atom'
91
92
  case NUMBER:
92
93
  return 'Number'
93
94
  // case ATOM:
@@ -1538,3 +1539,12 @@ export const filteredDefinedTypes = (program, lib, libT) => {
1538
1539
  export const definedTypes = (T) => fromSourceToType(T)
1539
1540
  export const withStdDefinedTypes = (ast) =>
1540
1541
  withCtxTypes(definedTypes(filteredDefinedTypes(ast, std, stdT)))
1542
+
1543
+ export const extractTypes = (source) => {
1544
+ let types
1545
+ const src = source.replaceAll(/\(the.+\)/g, (match, token) => {
1546
+ types = match
1547
+ return ''
1548
+ })
1549
+ return [src, types]
1550
+ }
package/src/utils.js CHANGED
@@ -21,6 +21,7 @@ import { type, typeCheck, withScope } from './check.js'
21
21
  import stdT from '../lib/baked/std-T.js'
22
22
  import {
23
23
  definedTypes,
24
+ extractTypes,
24
25
  filteredDefinedTypes,
25
26
  formatAstTypes,
26
27
  withCtxTypes
@@ -380,8 +381,8 @@ export const init = () => {
380
381
  console.log('Added directory src in root')
381
382
  writeFileSync('./src/main.lisp', '')
382
383
  console.log('Added file main.lisp in src')
383
- writeFileSync('./src/types.lisp', '')
384
- console.log('Added file types.lisp in src')
384
+ // writeFileSync('./src/types.lisp', '')
385
+ // console.log('Added file types.lisp in src')
385
386
  writeFileSync(
386
387
  'index.js',
387
388
  `import { compile, enhance, parse, LISP, UTILS } from "fez-lisp";
@@ -406,16 +407,17 @@ export const dev = (source, types) => {
406
407
  };
407
408
  export const comp = (source) => compile(enhance(parse(source)));
408
409
  const file = readFileSync("./src/main.lisp", "utf-8");
410
+ const [src, typ] = UTILS.extractTypes(file);
409
411
  switch (process.argv[2]) {
410
412
  case "comp":
411
413
  writeFileSync(
412
414
  "./src/main.js",
413
- "var _ = " + comp(file) + "; console.log(_)"
415
+ "var _ = " + comp(src) + "; console.log(_)"
414
416
  );
415
417
  break;
416
418
  case "dev":
417
419
  default:
418
- dev(file, readFileSync("./src/types.lisp", "utf-8"));
420
+ dev(src, typ);
419
421
  break;
420
422
  }
421
423
  `
@@ -424,7 +426,7 @@ switch (process.argv[2]) {
424
426
  console.log(
425
427
  `Done!
426
428
 
427
- Write code in main.lisp and types (if any) in types.lisp
429
+ Write code in main.lisp
428
430
  Run node index.js with the following flags:
429
431
  - dev (static type check and run time validations)
430
432
  - comp (compile Fez to JavaScript file main.js)
@@ -440,6 +442,7 @@ That's it! You are all set!
440
442
  }
441
443
 
442
444
  export const UTILS = {
445
+ extractTypes,
443
446
  init,
444
447
  debug,
445
448
  startDebug,