fez-lisp 1.5.59 → 1.5.61
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 +182 -177
package/package.json
CHANGED
package/src/check.js
CHANGED
@@ -84,10 +84,8 @@ const formatType = (name, env) => {
|
|
84
84
|
`${x[STATS][SIGNATURE]} ${x[STATS][TYPE_PROP].map(
|
85
85
|
toTypeNames
|
86
86
|
).join(' ')}${
|
87
|
-
x[STATS][
|
88
|
-
?
|
89
|
-
x[STATS][RETURNS][1] ?? x[STATS][RETURNS][0]
|
90
|
-
)}`
|
87
|
+
getSuffix(x[STATS][SIGNATURE]) === PREDICATE_SUFFIX
|
88
|
+
? ' ' + toTypeNames(PREDICATE)
|
91
89
|
: ''
|
92
90
|
}`
|
93
91
|
)
|
@@ -1298,7 +1296,7 @@ export const typeCheck = (ast) => {
|
|
1298
1296
|
first[VALUE]
|
1299
1297
|
}). Expected (= 2) but got ${rest.length} (${stringifyArgs(
|
1300
1298
|
exp
|
1301
|
-
)})
|
1299
|
+
)})`
|
1302
1300
|
)
|
1303
1301
|
} else {
|
1304
1302
|
const name = rest[0][VALUE]
|
@@ -1519,19 +1517,13 @@ export const typeCheck = (ast) => {
|
|
1519
1517
|
const right = isL ? rest.at(-1) : rest.at(-1)[0]
|
1520
1518
|
if (isL && right[TYPE] === ATOM) {
|
1521
1519
|
const isPredicate = getSuffix(name) === PREDICATE_SUFFIX
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
right[VALUE]
|
1530
|
-
} which is not a (${toTypeNames(
|
1531
|
-
PREDICATE
|
1532
|
-
)}). Either remove (${PREDICATE_SUFFIX}) or change the value to ${TRUE} or ${FALSE} (check #20)`
|
1533
|
-
)
|
1534
|
-
}
|
1520
|
+
// This never happens
|
1521
|
+
// if (
|
1522
|
+
// isPredicate &&
|
1523
|
+
// right[VALUE] !== TRUE &&
|
1524
|
+
// right[VALUE] !== FALSE
|
1525
|
+
// ) {
|
1526
|
+
// }
|
1535
1527
|
env[name] = {
|
1536
1528
|
[STATS]: {
|
1537
1529
|
retried: 0,
|
@@ -1642,7 +1634,7 @@ export const typeCheck = (ast) => {
|
|
1642
1634
|
first[VALUE]
|
1643
1635
|
}). Expected at least 1 (the lambda body) but got 1 (${stringifyArgs(
|
1644
1636
|
exp
|
1645
|
-
)})
|
1637
|
+
)})`
|
1646
1638
|
)
|
1647
1639
|
}
|
1648
1640
|
const params = exp.slice(1, -1)
|
@@ -1776,164 +1768,141 @@ export const typeCheck = (ast) => {
|
|
1776
1768
|
// type check
|
1777
1769
|
const PRED_TYPE = args[i][STATS][TYPE_PROP][1]
|
1778
1770
|
const MAIN_TYPE = args[i][STATS][TYPE_PROP][0]
|
1779
|
-
if (PRED_TYPE != undefined) {
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
|
1794
|
-
|
1795
|
-
|
1796
|
-
|
1797
|
-
)
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
)
|
1816
|
-
|
1817
|
-
}
|
1818
|
-
} else {
|
1819
|
-
const current = rest[i][0]
|
1820
|
-
if (current[TYPE] === APPLY) {
|
1821
|
-
if (current[VALUE] == KEYWORDS.CALL_FUNCTION) {
|
1822
|
-
if (isLeaf(rest[i].at(-1))) {
|
1823
|
-
const fnName = rest[i].at(-1)[VALUE]
|
1824
|
-
const fn = env[fnName]
|
1825
|
-
if (fn && fn[STATS][RETURNS][0] !== MAIN_TYPE) {
|
1771
|
+
if (PRED_TYPE != undefined && !isLeaf(rest[i])) {
|
1772
|
+
const current = rest[i][0]
|
1773
|
+
if (current[TYPE] === APPLY) {
|
1774
|
+
if (current[VALUE] == KEYWORDS.CALL_FUNCTION) {
|
1775
|
+
if (isLeaf(rest[i].at(-1))) {
|
1776
|
+
const fnName = rest[i].at(-1)[VALUE]
|
1777
|
+
const fn = env[fnName]
|
1778
|
+
if (fn && fn[STATS][RETURNS][0] !== MAIN_TYPE) {
|
1779
|
+
errorStack.add(
|
1780
|
+
`Incorrect type of argument (${i}) for (${
|
1781
|
+
first[VALUE]
|
1782
|
+
}). Expected (${toTypeNames(
|
1783
|
+
MAIN_TYPE
|
1784
|
+
)}) but got an (${toTypeNames(
|
1785
|
+
fn[STATS][RETURNS][0]
|
1786
|
+
)}) (${stringifyArgs(exp)}) (check #26)`
|
1787
|
+
)
|
1788
|
+
}
|
1789
|
+
if (fn && fn[STATS][RETURNS][1] !== PRED_TYPE) {
|
1790
|
+
errorStack.add(
|
1791
|
+
`Incorrect type of argument (${i}) for (${
|
1792
|
+
first[VALUE]
|
1793
|
+
}). Expected (${toTypeNames(
|
1794
|
+
PRED_TYPE
|
1795
|
+
)}) but got an (${toTypeNames(
|
1796
|
+
fn[STATS][RETURNS][1] ??
|
1797
|
+
fn[STATS][RETURNS][0]
|
1798
|
+
)}) which is neither ${TRUE} or ${FALSE} (${stringifyArgs(
|
1799
|
+
exp
|
1800
|
+
)}) (check #27)`
|
1801
|
+
)
|
1802
|
+
}
|
1803
|
+
} else {
|
1804
|
+
const body = rest[i].at(-1).at(-1)
|
1805
|
+
const rem = hasBlock(body) ? body.at(-1) : body
|
1806
|
+
const returns = isLeaf(rem) ? rem : rem[0]
|
1807
|
+
if (returns[TYPE] === ATOM) {
|
1808
|
+
if (MAIN_TYPE !== ATOM) {
|
1826
1809
|
errorStack.add(
|
1827
|
-
`Incorrect type of argument
|
1810
|
+
`Incorrect type of argument ${i} for (${
|
1828
1811
|
first[VALUE]
|
1829
1812
|
}). Expected (${toTypeNames(
|
1830
1813
|
MAIN_TYPE
|
1831
1814
|
)}) but got an (${toTypeNames(
|
1832
|
-
|
1833
|
-
)})
|
1815
|
+
ATOM
|
1816
|
+
)}) (${stringifyArgs(exp)}) (check #27)`
|
1834
1817
|
)
|
1835
1818
|
}
|
1836
|
-
if (
|
1819
|
+
if (
|
1820
|
+
PRED_TYPE &&
|
1821
|
+
PRED_TYPE === PREDICATE &&
|
1822
|
+
returns[VALUE] !== TRUE &&
|
1823
|
+
returns[VALUE] !== FALSE
|
1824
|
+
) {
|
1837
1825
|
errorStack.add(
|
1838
|
-
`Incorrect type of argument
|
1826
|
+
`Incorrect type of argument ${i} for (${
|
1839
1827
|
first[VALUE]
|
1840
1828
|
}). Expected (${toTypeNames(
|
1841
1829
|
PRED_TYPE
|
1842
1830
|
)}) but got an (${toTypeNames(
|
1843
|
-
|
1844
|
-
fn[STATS][RETURNS][0]
|
1831
|
+
ATOM
|
1845
1832
|
)}) which is neither ${TRUE} or ${FALSE} (${stringifyArgs(
|
1846
1833
|
exp
|
1847
1834
|
)}) (check #27)`
|
1848
1835
|
)
|
1849
1836
|
}
|
1850
|
-
} else {
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
)
|
1865
|
-
}
|
1866
|
-
if (
|
1867
|
-
PRED_TYPE &&
|
1868
|
-
PRED_TYPE === PREDICATE &&
|
1869
|
-
returns[VALUE] !== TRUE &&
|
1870
|
-
returns[VALUE] !== FALSE
|
1871
|
-
) {
|
1872
|
-
errorStack.add(
|
1873
|
-
`Incorrect type of argument ${i} for (${
|
1874
|
-
first[VALUE]
|
1875
|
-
}). Expected (${toTypeNames(
|
1876
|
-
PRED_TYPE
|
1877
|
-
)}) but got an (${toTypeNames(
|
1878
|
-
ATOM
|
1879
|
-
)}) which is neither ${TRUE} or ${FALSE} (${stringifyArgs(
|
1880
|
-
exp
|
1881
|
-
)}) (check #27)`
|
1882
|
-
)
|
1883
|
-
}
|
1884
|
-
} else if (env[returns[VALUE]]) {
|
1885
|
-
if (
|
1886
|
-
MAIN_TYPE !==
|
1887
|
-
env[returns[VALUE]][STATS][RETURNS][0]
|
1888
|
-
) {
|
1889
|
-
errorStack.add(
|
1890
|
-
`Incorrect type of argument ${i} for (${
|
1891
|
-
first[VALUE]
|
1892
|
-
}). Expected (${toTypeNames(
|
1893
|
-
MAIN_TYPE
|
1894
|
-
)}) but got (${toTypeNames(
|
1895
|
-
env[returns[VALUE]][STATS][TYPE_PROP]
|
1896
|
-
)}) (${stringifyArgs(exp)}) (check #29)`
|
1897
|
-
)
|
1898
|
-
}
|
1899
|
-
if (
|
1900
|
-
PRED_TYPE &&
|
1901
|
-
PRED_TYPE !==
|
1902
|
-
env[returns[VALUE]][STATS][RETURNS][1]
|
1903
|
-
) {
|
1904
|
-
errorStack.add(
|
1905
|
-
`Incorrect type of argument ${i} for (${
|
1906
|
-
first[VALUE]
|
1907
|
-
}). Expected (${toTypeNames(
|
1908
|
-
PRED_TYPE
|
1909
|
-
)}) but got (${toTypeNames(
|
1910
|
-
env[returns[VALUE]][STATS][RETURNS][1]
|
1911
|
-
)}) (${stringifyArgs(exp)}) (check #28)`
|
1912
|
-
)
|
1913
|
-
}
|
1837
|
+
} else if (env[returns[VALUE]]) {
|
1838
|
+
if (
|
1839
|
+
MAIN_TYPE !==
|
1840
|
+
env[returns[VALUE]][STATS][RETURNS][0]
|
1841
|
+
) {
|
1842
|
+
errorStack.add(
|
1843
|
+
`Incorrect type of argument ${i} for (${
|
1844
|
+
first[VALUE]
|
1845
|
+
}). Expected (${toTypeNames(
|
1846
|
+
MAIN_TYPE
|
1847
|
+
)}) but got (${toTypeNames(
|
1848
|
+
env[returns[VALUE]][STATS][TYPE_PROP]
|
1849
|
+
)}) (${stringifyArgs(exp)}) (check #29)`
|
1850
|
+
)
|
1914
1851
|
}
|
1852
|
+
// Never happens because there is only 1 sub type at the moment
|
1853
|
+
// if (
|
1854
|
+
// PRED_TYPE &&
|
1855
|
+
// PRED_TYPE !==
|
1856
|
+
// env[returns[VALUE]][STATS][RETURNS][1]
|
1857
|
+
// ) {
|
1858
|
+
// }
|
1915
1859
|
}
|
1916
|
-
} else if (
|
1917
|
-
PRED_TYPE &&
|
1918
|
-
env[current[VALUE]] &&
|
1919
|
-
env[current[VALUE]][STATS][RETURNS][1] !==
|
1920
|
-
PRED_TYPE
|
1921
|
-
) {
|
1922
|
-
errorStack.add(
|
1923
|
-
`Incorrect type of arguments (${i}) for (${
|
1924
|
-
first[VALUE]
|
1925
|
-
}). Expected (${toTypeNames(
|
1926
|
-
PRED_TYPE
|
1927
|
-
)}) but got (${toTypeNames(
|
1928
|
-
env[current[VALUE]][STATS][RETURNS][1] ??
|
1929
|
-
env[current[VALUE]][STATS][RETURNS][0]
|
1930
|
-
)}) (${stringifyArgs(exp)}) (check #21)`
|
1931
|
-
)
|
1932
1860
|
}
|
1861
|
+
} else if (
|
1862
|
+
PRED_TYPE &&
|
1863
|
+
env[current[VALUE]] &&
|
1864
|
+
env[current[VALUE]][STATS][RETURNS][1] !== PRED_TYPE
|
1865
|
+
) {
|
1866
|
+
errorStack.add(
|
1867
|
+
`Incorrect type of arguments (${i}) for (${
|
1868
|
+
first[VALUE]
|
1869
|
+
}). Expected (${toTypeNames(
|
1870
|
+
PRED_TYPE
|
1871
|
+
)}) but got (${toTypeNames(
|
1872
|
+
env[current[VALUE]][STATS][RETURNS][1] ??
|
1873
|
+
env[current[VALUE]][STATS][RETURNS][0]
|
1874
|
+
)}) (${stringifyArgs(exp)}) (check #21)`
|
1875
|
+
)
|
1933
1876
|
}
|
1934
1877
|
}
|
1935
1878
|
}
|
1936
1879
|
|
1880
|
+
// if (PRED_TYPE != undefined) {
|
1881
|
+
// if (isLeaf(rest[i])) {
|
1882
|
+
// // if (rest[i][TYPE] === WORD) {
|
1883
|
+
// // Never reached because there is only 1 subtype
|
1884
|
+
// // if (
|
1885
|
+
// // !isSpecial &&
|
1886
|
+
// // env[rest[i][VALUE]] &&
|
1887
|
+
// // PRED_TYPE !==
|
1888
|
+
// // env[rest[i][VALUE]][STATS][RETURNS][1]
|
1889
|
+
// // ) {
|
1890
|
+
// // }
|
1891
|
+
// // }
|
1892
|
+
// // never happens
|
1893
|
+
// // else if (rest[i][TYPE] === ATOM) {
|
1894
|
+
// // if (
|
1895
|
+
// // PRED_TYPE === PREDICATE &&
|
1896
|
+
// // rest[i][VALUE] !== TRUE &&
|
1897
|
+
// // rest[i][VALUE] !== FALSE
|
1898
|
+
// // ) {
|
1899
|
+
// // }
|
1900
|
+
// // }
|
1901
|
+
// } else {
|
1902
|
+
// // above code used to be ere
|
1903
|
+
// }
|
1904
|
+
// }
|
1905
|
+
|
1937
1906
|
if (first[TYPE] === APPLY && isSpecial) {
|
1938
1907
|
const isCast = STATIC_TYPES_SET.has(first[VALUE])
|
1939
1908
|
const expectedArgs = env[first[VALUE]][STATS][ARGUMENTS]
|
@@ -1957,21 +1926,13 @@ export const typeCheck = (ast) => {
|
|
1957
1926
|
env[CAR][STATS][RETURNS][0]
|
1958
1927
|
)}) (${stringifyArgs(exp)}) (check #1)`
|
1959
1928
|
)
|
1960
|
-
} else if (
|
1961
|
-
PRED_TYPE &&
|
1962
|
-
env[CAR][STATS][RETURNS][1] !== PRED_TYPE
|
1963
|
-
) {
|
1964
|
-
errorStack.add(
|
1965
|
-
`Incorrect type of arguments for special form (${
|
1966
|
-
first[VALUE]
|
1967
|
-
}). Expected (${toTypeNames(
|
1968
|
-
PRED_TYPE
|
1969
|
-
)}) but got (${toTypeNames(
|
1970
|
-
env[CAR][STATS][RETURNS][1] ??
|
1971
|
-
env[CAR][STATS][RETURNS][0]
|
1972
|
-
)}) (${stringifyArgs(exp)}) (check #13)`
|
1973
|
-
)
|
1974
1929
|
}
|
1930
|
+
// never reached because there is only 1 subtype at the moment
|
1931
|
+
// else if (
|
1932
|
+
// PRED_TYPE &&
|
1933
|
+
// env[CAR][STATS][RETURNS][1] !== PRED_TYPE
|
1934
|
+
// ) {
|
1935
|
+
// }
|
1975
1936
|
}
|
1976
1937
|
} else {
|
1977
1938
|
switch (rest[i][TYPE]) {
|
@@ -1996,7 +1957,7 @@ export const typeCheck = (ast) => {
|
|
1996
1957
|
)}) (${stringifyArgs(exp)}) (check #3)`
|
1997
1958
|
)
|
1998
1959
|
} else if (
|
1999
|
-
PRED_TYPE &&
|
1960
|
+
PRED_TYPE === PREDICATE &&
|
2000
1961
|
env[CAR][STATS][RETURNS][1] !==
|
2001
1962
|
PRED_TYPE &&
|
2002
1963
|
!isCast
|
@@ -2036,6 +1997,21 @@ export const typeCheck = (ast) => {
|
|
2036
1997
|
)}) (${stringifyArgs(exp)}) (check #2)`
|
2037
1998
|
)
|
2038
1999
|
}
|
2000
|
+
if (
|
2001
|
+
PRED_TYPE === PREDICATE &&
|
2002
|
+
rest[i][VALUE] !== TRUE &&
|
2003
|
+
rest[i][VALUE] !== FALSE
|
2004
|
+
) {
|
2005
|
+
errorStack.add(
|
2006
|
+
`Incorrect type of argument (${i}) for special form (${
|
2007
|
+
first[VALUE]
|
2008
|
+
}). Expected (${toTypeNames(
|
2009
|
+
PRED_TYPE
|
2010
|
+
)}) but got (${toTypeNames(
|
2011
|
+
rest[i][VALUE]
|
2012
|
+
)}) (${stringifyArgs(exp)}) (check #5)`
|
2013
|
+
)
|
2014
|
+
}
|
2039
2015
|
break
|
2040
2016
|
}
|
2041
2017
|
}
|
@@ -2053,16 +2029,45 @@ export const typeCheck = (ast) => {
|
|
2053
2029
|
rest[i][TYPE] === WORD && env[rest[i][VALUE]]
|
2054
2030
|
? env[rest[i][VALUE]][STATS][TYPE_PROP][0]
|
2055
2031
|
: rest[i][TYPE]
|
2056
|
-
if (
|
2057
|
-
(
|
2058
|
-
T === ATOM &&
|
2059
|
-
args[i][STATS][TYPE_PROP][0] !== ATOM) ||
|
2060
|
-
(env[rest[i][VALUE]] &&
|
2061
|
-
env[rest[i][VALUE]][STATS][TYPE_PROP][0] !==
|
2062
|
-
UNKNOWN &&
|
2032
|
+
if (T === ATOM) {
|
2033
|
+
if (
|
2063
2034
|
args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
|
2064
|
-
|
2065
|
-
|
2035
|
+
args[i][STATS][TYPE_PROP][0] !== ATOM
|
2036
|
+
) {
|
2037
|
+
errorStack.add(
|
2038
|
+
`Incorrect type of arguments ${i} for (${
|
2039
|
+
first[VALUE]
|
2040
|
+
}). Expected (${toTypeNames(
|
2041
|
+
args[i][STATS][TYPE_PROP][0]
|
2042
|
+
)}) but got (${toTypeNames(
|
2043
|
+
T
|
2044
|
+
)}) (${stringifyArgs(exp)}) (check #10)`
|
2045
|
+
)
|
2046
|
+
} else if (
|
2047
|
+
args[i][STATS][RETURNS][0] === ATOM &&
|
2048
|
+
args[i][STATS][RETURNS][1] === PREDICATE &&
|
2049
|
+
rest[i][VALUE] !== TRUE &&
|
2050
|
+
rest[i][VALUE] !== FALSE
|
2051
|
+
) {
|
2052
|
+
errorStack.add(
|
2053
|
+
`Incorrect type of arguments ${i} for (${
|
2054
|
+
first[VALUE]
|
2055
|
+
}). Expected (${toTypeNames(
|
2056
|
+
args[i][STATS][RETURNS][1]
|
2057
|
+
)}) but got (${toTypeNames(
|
2058
|
+
T
|
2059
|
+
)}) (${stringifyArgs(exp)}) (check #13)`
|
2060
|
+
)
|
2061
|
+
}
|
2062
|
+
}
|
2063
|
+
|
2064
|
+
if (
|
2065
|
+
env[rest[i][VALUE]] &&
|
2066
|
+
env[rest[i][VALUE]][STATS][TYPE_PROP][0] !==
|
2067
|
+
UNKNOWN &&
|
2068
|
+
args[i][STATS][TYPE_PROP][0] !== UNKNOWN &&
|
2069
|
+
env[rest[i][VALUE]][STATS][TYPE_PROP][0] !==
|
2070
|
+
args[i][STATS][TYPE_PROP][0]
|
2066
2071
|
) {
|
2067
2072
|
errorStack.add(
|
2068
2073
|
`Incorrect type of arguments ${i} for (${
|