fez-lisp 1.5.58 → 1.5.60

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.5.58",
5
+ "version": "1.5.60",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/check.js CHANGED
@@ -117,7 +117,7 @@ const getScopeNames = (scope) => {
117
117
  }
118
118
  const withScope = (name, scope) => {
119
119
  const chain = getScopeNames(scope)
120
- return `${chain
120
+ return `${chain.length === 1 ? '· ' : ''}${chain
121
121
  .map((x) => (Number.isInteger(+x) ? '~' : x))
122
122
  .join(' ')} ${name}`
123
123
  }
@@ -1298,7 +1298,7 @@ export const typeCheck = (ast) => {
1298
1298
  first[VALUE]
1299
1299
  }). Expected (= 2) but got ${rest.length} (${stringifyArgs(
1300
1300
  exp
1301
- )}) (check #10)`
1301
+ )})`
1302
1302
  )
1303
1303
  } else {
1304
1304
  const name = rest[0][VALUE]
@@ -1519,19 +1519,13 @@ export const typeCheck = (ast) => {
1519
1519
  const right = isL ? rest.at(-1) : rest.at(-1)[0]
1520
1520
  if (isL && right[TYPE] === ATOM) {
1521
1521
  const isPredicate = getSuffix(name) === PREDICATE_SUFFIX
1522
- if (
1523
- isPredicate &&
1524
- right[VALUE] !== TRUE &&
1525
- right[VALUE] !== FALSE
1526
- ) {
1527
- warningStack.add(
1528
- `${name} ends in (${PREDICATE_SUFFIX}) but is assigned to ${
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
- }
1522
+ // This never happens
1523
+ // if (
1524
+ // isPredicate &&
1525
+ // right[VALUE] !== TRUE &&
1526
+ // right[VALUE] !== FALSE
1527
+ // ) {
1528
+ // }
1535
1529
  env[name] = {
1536
1530
  [STATS]: {
1537
1531
  retried: 0,
@@ -1642,7 +1636,7 @@ export const typeCheck = (ast) => {
1642
1636
  first[VALUE]
1643
1637
  }). Expected at least 1 (the lambda body) but got 1 (${stringifyArgs(
1644
1638
  exp
1645
- )}) (check #10)`
1639
+ )})`
1646
1640
  )
1647
1641
  }
1648
1642
  const params = exp.slice(1, -1)
@@ -1776,164 +1770,141 @@ export const typeCheck = (ast) => {
1776
1770
  // type check
1777
1771
  const PRED_TYPE = args[i][STATS][TYPE_PROP][1]
1778
1772
  const MAIN_TYPE = args[i][STATS][TYPE_PROP][0]
1779
- if (PRED_TYPE != undefined) {
1780
- if (isLeaf(rest[i])) {
1781
- if (rest[i][TYPE] === WORD) {
1782
- if (
1783
- !isSpecial &&
1784
- env[rest[i][VALUE]] &&
1785
- PRED_TYPE !==
1786
- env[rest[i][VALUE]][STATS][RETURNS][1]
1787
- ) {
1788
- errorStack.add(
1789
- `Incorrect type of argument (${i}) for (${
1790
- first[VALUE]
1791
- }). Expected (${toTypeNames(
1792
- PRED_TYPE
1793
- )}) but got (${toTypeNames(
1794
- env[rest[i][VALUE]][STATS][RETURNS][1] ??
1795
- env[rest[i][VALUE]][STATS][TYPE_PROP][0]
1796
- )}) (${stringifyArgs(exp)}) (check #16)`
1797
- )
1798
- }
1799
- } else if (rest[i][TYPE] === ATOM) {
1800
- if (
1801
- PRED_TYPE === PREDICATE &&
1802
- rest[i][VALUE] !== TRUE &&
1803
- rest[i][VALUE] !== FALSE
1804
- ) {
1805
- errorStack.add(
1806
- `Incorrect type of arguments for (${
1807
- first[VALUE]
1808
- }). Expected (${toTypeNames(
1809
- PRED_TYPE
1810
- )}) but got an (${toTypeNames(
1811
- rest[i][TYPE]
1812
- )}) which is neither ${TRUE} or ${FALSE} (${stringifyArgs(
1813
- exp
1814
- )}) (check #22)`
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) {
1773
+ if (PRED_TYPE != undefined && !isLeaf(rest[i])) {
1774
+ const current = rest[i][0]
1775
+ if (current[TYPE] === APPLY) {
1776
+ if (current[VALUE] == KEYWORDS.CALL_FUNCTION) {
1777
+ if (isLeaf(rest[i].at(-1))) {
1778
+ const fnName = rest[i].at(-1)[VALUE]
1779
+ const fn = env[fnName]
1780
+ if (fn && fn[STATS][RETURNS][0] !== MAIN_TYPE) {
1781
+ errorStack.add(
1782
+ `Incorrect type of argument (${i}) for (${
1783
+ first[VALUE]
1784
+ }). Expected (${toTypeNames(
1785
+ MAIN_TYPE
1786
+ )}) but got an (${toTypeNames(
1787
+ fn[STATS][RETURNS][0]
1788
+ )}) (${stringifyArgs(exp)}) (check #26)`
1789
+ )
1790
+ }
1791
+ if (fn && fn[STATS][RETURNS][1] !== PRED_TYPE) {
1792
+ errorStack.add(
1793
+ `Incorrect type of argument (${i}) for (${
1794
+ first[VALUE]
1795
+ }). Expected (${toTypeNames(
1796
+ PRED_TYPE
1797
+ )}) but got an (${toTypeNames(
1798
+ fn[STATS][RETURNS][1] ??
1799
+ fn[STATS][RETURNS][0]
1800
+ )}) which is neither ${TRUE} or ${FALSE} (${stringifyArgs(
1801
+ exp
1802
+ )}) (check #27)`
1803
+ )
1804
+ }
1805
+ } else {
1806
+ const body = rest[i].at(-1).at(-1)
1807
+ const rem = hasBlock(body) ? body.at(-1) : body
1808
+ const returns = isLeaf(rem) ? rem : rem[0]
1809
+ if (returns[TYPE] === ATOM) {
1810
+ if (MAIN_TYPE !== ATOM) {
1826
1811
  errorStack.add(
1827
- `Incorrect type of argument (${i}) for (${
1812
+ `Incorrect type of argument ${i} for (${
1828
1813
  first[VALUE]
1829
1814
  }). Expected (${toTypeNames(
1830
1815
  MAIN_TYPE
1831
1816
  )}) but got an (${toTypeNames(
1832
- fn[STATS][RETURNS][0]
1833
- )}) (${stringifyArgs(exp)}) (check #26)`
1817
+ ATOM
1818
+ )}) (${stringifyArgs(exp)}) (check #27)`
1834
1819
  )
1835
1820
  }
1836
- if (fn && fn[STATS][RETURNS][1] !== PRED_TYPE) {
1821
+ if (
1822
+ PRED_TYPE &&
1823
+ PRED_TYPE === PREDICATE &&
1824
+ returns[VALUE] !== TRUE &&
1825
+ returns[VALUE] !== FALSE
1826
+ ) {
1837
1827
  errorStack.add(
1838
- `Incorrect type of argument (${i}) for (${
1828
+ `Incorrect type of argument ${i} for (${
1839
1829
  first[VALUE]
1840
1830
  }). Expected (${toTypeNames(
1841
1831
  PRED_TYPE
1842
1832
  )}) but got an (${toTypeNames(
1843
- fn[STATS][RETURNS][1] ??
1844
- fn[STATS][RETURNS][0]
1833
+ ATOM
1845
1834
  )}) which is neither ${TRUE} or ${FALSE} (${stringifyArgs(
1846
1835
  exp
1847
1836
  )}) (check #27)`
1848
1837
  )
1849
1838
  }
1850
- } else {
1851
- const body = rest[i].at(-1).at(-1)
1852
- const rem = hasBlock(body) ? body.at(-1) : body
1853
- const returns = isLeaf(rem) ? rem : rem[0]
1854
- if (returns[TYPE] === ATOM) {
1855
- if (MAIN_TYPE !== ATOM) {
1856
- errorStack.add(
1857
- `Incorrect type of argument ${i} for (${
1858
- first[VALUE]
1859
- }). Expected (${toTypeNames(
1860
- MAIN_TYPE
1861
- )}) but got an (${toTypeNames(
1862
- ATOM
1863
- )}) (${stringifyArgs(exp)}) (check #27)`
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
- }
1839
+ } else if (env[returns[VALUE]]) {
1840
+ if (
1841
+ MAIN_TYPE !==
1842
+ env[returns[VALUE]][STATS][RETURNS][0]
1843
+ ) {
1844
+ errorStack.add(
1845
+ `Incorrect type of argument ${i} for (${
1846
+ first[VALUE]
1847
+ }). Expected (${toTypeNames(
1848
+ MAIN_TYPE
1849
+ )}) but got (${toTypeNames(
1850
+ env[returns[VALUE]][STATS][TYPE_PROP]
1851
+ )}) (${stringifyArgs(exp)}) (check #29)`
1852
+ )
1914
1853
  }
1854
+ // Never happens because there is only 1 sub type at the moment
1855
+ // if (
1856
+ // PRED_TYPE &&
1857
+ // PRED_TYPE !==
1858
+ // env[returns[VALUE]][STATS][RETURNS][1]
1859
+ // ) {
1860
+ // }
1915
1861
  }
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
1862
  }
1863
+ } else if (
1864
+ PRED_TYPE &&
1865
+ env[current[VALUE]] &&
1866
+ env[current[VALUE]][STATS][RETURNS][1] !== PRED_TYPE
1867
+ ) {
1868
+ errorStack.add(
1869
+ `Incorrect type of arguments (${i}) for (${
1870
+ first[VALUE]
1871
+ }). Expected (${toTypeNames(
1872
+ PRED_TYPE
1873
+ )}) but got (${toTypeNames(
1874
+ env[current[VALUE]][STATS][RETURNS][1] ??
1875
+ env[current[VALUE]][STATS][RETURNS][0]
1876
+ )}) (${stringifyArgs(exp)}) (check #21)`
1877
+ )
1933
1878
  }
1934
1879
  }
1935
1880
  }
1936
1881
 
1882
+ // if (PRED_TYPE != undefined) {
1883
+ // if (isLeaf(rest[i])) {
1884
+ // // if (rest[i][TYPE] === WORD) {
1885
+ // // Never reached because there is only 1 subtype
1886
+ // // if (
1887
+ // // !isSpecial &&
1888
+ // // env[rest[i][VALUE]] &&
1889
+ // // PRED_TYPE !==
1890
+ // // env[rest[i][VALUE]][STATS][RETURNS][1]
1891
+ // // ) {
1892
+ // // }
1893
+ // // }
1894
+ // // never happens
1895
+ // // else if (rest[i][TYPE] === ATOM) {
1896
+ // // if (
1897
+ // // PRED_TYPE === PREDICATE &&
1898
+ // // rest[i][VALUE] !== TRUE &&
1899
+ // // rest[i][VALUE] !== FALSE
1900
+ // // ) {
1901
+ // // }
1902
+ // // }
1903
+ // } else {
1904
+ // // above code used to be ere
1905
+ // }
1906
+ // }
1907
+
1937
1908
  if (first[TYPE] === APPLY && isSpecial) {
1938
1909
  const isCast = STATIC_TYPES_SET.has(first[VALUE])
1939
1910
  const expectedArgs = env[first[VALUE]][STATS][ARGUMENTS]
@@ -1957,21 +1928,13 @@ export const typeCheck = (ast) => {
1957
1928
  env[CAR][STATS][RETURNS][0]
1958
1929
  )}) (${stringifyArgs(exp)}) (check #1)`
1959
1930
  )
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
1931
  }
1932
+ // never reached because there is only 1 subtype at the moment
1933
+ // else if (
1934
+ // PRED_TYPE &&
1935
+ // env[CAR][STATS][RETURNS][1] !== PRED_TYPE
1936
+ // ) {
1937
+ // }
1975
1938
  }
1976
1939
  } else {
1977
1940
  switch (rest[i][TYPE]) {