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 +1 -1
- package/src/check.js +16 -20
- package/src/types.js +10 -0
- package/src/utils.js +8 -5
package/package.json
CHANGED
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 (${
|
1007
|
-
|
1008
|
-
)}) but got (${
|
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 (${
|
1115
|
-
|
1116
|
-
)}) but got (${
|
1117
|
-
|
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 (${
|
1127
|
-
|
1128
|
-
)}) but got (${
|
1129
|
-
|
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
|
-
|
1695
|
-
|
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 (${
|
1723
|
-
|
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(
|
415
|
+
"var _ = " + comp(src) + "; console.log(_)"
|
414
416
|
);
|
415
417
|
break;
|
416
418
|
case "dev":
|
417
419
|
default:
|
418
|
-
dev(
|
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
|
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,
|