fez-lisp 1.5.53 → 1.5.56
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 +20 -11
- package/src/keywords.js +6 -3
- package/src/macros.js +5 -0
- package/src/parser.js +0 -4
package/package.json
CHANGED
package/src/check.js
CHANGED
@@ -8,6 +8,7 @@ import {
|
|
8
8
|
PLACEHOLDER,
|
9
9
|
PREDICATE_SUFFIX,
|
10
10
|
SPECIAL_FORMS_SET,
|
11
|
+
STATIC_TYPES_SET,
|
11
12
|
TRUE,
|
12
13
|
TYPE,
|
13
14
|
VALUE,
|
@@ -34,11 +35,10 @@ const PREDICATE = 3
|
|
34
35
|
const COLLECTION = 4
|
35
36
|
const RETRY_COUNT = 1
|
36
37
|
const DEFINITON_RETRY_COUNT = 1
|
37
|
-
const SUB = 2
|
38
38
|
const toTypeNames = (type) => {
|
39
39
|
switch (type) {
|
40
40
|
case APPLY:
|
41
|
-
return '
|
41
|
+
return 'Abstraction'
|
42
42
|
case ATOM:
|
43
43
|
return 'Atom'
|
44
44
|
case UNKNOWN:
|
@@ -1234,7 +1234,7 @@ export const typeCheck = (ast) => {
|
|
1234
1234
|
const [first, ...rest] = isLeaf(exp) ? [exp] : exp
|
1235
1235
|
if (first === undefined) {
|
1236
1236
|
throw new TypeError(
|
1237
|
-
`(lambda) invocation with missing (
|
1237
|
+
`(lambda) invocation with missing (Abstraction) name () Provide an (Abstraction) name as the (1) argument.`
|
1238
1238
|
)
|
1239
1239
|
}
|
1240
1240
|
switch (first[TYPE]) {
|
@@ -1593,7 +1593,7 @@ export const typeCheck = (ast) => {
|
|
1593
1593
|
// }
|
1594
1594
|
check(rest.at(-1), env, scope)
|
1595
1595
|
}
|
1596
|
-
Types.set(withScope(name, env), formatType(name, env))
|
1596
|
+
Types.set(withScope(name, env), () => formatType(name, env))
|
1597
1597
|
}
|
1598
1598
|
}
|
1599
1599
|
break
|
@@ -1897,18 +1897,18 @@ export const typeCheck = (ast) => {
|
|
1897
1897
|
}
|
1898
1898
|
|
1899
1899
|
if (first[TYPE] === APPLY && isSpecial) {
|
1900
|
+
const isCast = STATIC_TYPES_SET.has(first[VALUE])
|
1900
1901
|
const expectedArgs = env[first[VALUE]][STATS][ARGUMENTS]
|
1901
1902
|
for (let i = 0; i < rest.length; ++i) {
|
1902
1903
|
const PRED_TYPE = args[i][STATS][TYPE_PROP][1]
|
1903
1904
|
const MAIN_TYPE = expectedArgs[i][STATS][TYPE_PROP][0]
|
1904
|
-
|
1905
|
-
if (MAIN_TYPE === UNKNOWN) continue
|
1905
|
+
if (MAIN_TYPE === UNKNOWN && !isCast) continue
|
1906
1906
|
if (!isLeaf(rest[i])) {
|
1907
1907
|
const CAR = rest[i][0][VALUE]
|
1908
1908
|
const isKnown =
|
1909
1909
|
env[CAR] &&
|
1910
1910
|
env[CAR][STATS][RETURNS][0] !== UNKNOWN
|
1911
|
-
if (isKnown) {
|
1911
|
+
if (isKnown && !isCast) {
|
1912
1912
|
if (env[CAR][STATS][RETURNS][0] !== MAIN_TYPE) {
|
1913
1913
|
errorStack.add(
|
1914
1914
|
`Incorrect type of argument (${i}) for special form (${
|
@@ -1943,7 +1943,7 @@ export const typeCheck = (ast) => {
|
|
1943
1943
|
const isKnown =
|
1944
1944
|
env[CAR] &&
|
1945
1945
|
env[CAR][STATS][TYPE_PROP][0] !== UNKNOWN
|
1946
|
-
if (isKnown) {
|
1946
|
+
if (isKnown && !isCast) {
|
1947
1947
|
if (
|
1948
1948
|
MAIN_TYPE !==
|
1949
1949
|
env[CAR][STATS][TYPE_PROP][0]
|
@@ -1959,7 +1959,9 @@ export const typeCheck = (ast) => {
|
|
1959
1959
|
)
|
1960
1960
|
} else if (
|
1961
1961
|
PRED_TYPE &&
|
1962
|
-
env[CAR][STATS][RETURNS][1] !==
|
1962
|
+
env[CAR][STATS][RETURNS][1] !==
|
1963
|
+
PRED_TYPE &&
|
1964
|
+
!isCast
|
1963
1965
|
)
|
1964
1966
|
errorStack.add(
|
1965
1967
|
`Incorrect type of argument (${i}) for special form (${
|
@@ -1972,8 +1974,15 @@ export const typeCheck = (ast) => {
|
|
1972
1974
|
)}) (${stringifyArgs(exp)}) (check #6)`
|
1973
1975
|
)
|
1974
1976
|
} else if (env[rest[i][VALUE]]) {
|
1975
|
-
|
1976
|
-
|
1977
|
+
if (isCast) {
|
1978
|
+
env[rest[i][VALUE]][STATS][TYPE_PROP] =
|
1979
|
+
root[first[VALUE]][STATS][RETURNS]
|
1980
|
+
root[first[VALUE]][STATS][RETURNS] =
|
1981
|
+
root[first[VALUE]][STATS][RETURNS]
|
1982
|
+
} else {
|
1983
|
+
env[rest[i][VALUE]][STATS][TYPE_PROP][0] =
|
1984
|
+
MAIN_TYPE
|
1985
|
+
}
|
1977
1986
|
}
|
1978
1987
|
}
|
1979
1988
|
break
|
package/src/keywords.js
CHANGED
@@ -9,12 +9,13 @@ export const PLACEHOLDER = '.'
|
|
9
9
|
export const MUTATION_SUFFIX = '!'
|
10
10
|
export const PREDICATE_SUFFIX = '?'
|
11
11
|
export const STATIC_TYPES = {
|
12
|
-
APPLICATION: '
|
12
|
+
APPLICATION: 'Abstraction',
|
13
13
|
UNKNOWN: 'Unknown',
|
14
14
|
ATOM: 'Atom',
|
15
15
|
COLLECTION: 'Collection',
|
16
16
|
PREDICATE: 'Predicate'
|
17
17
|
}
|
18
|
+
export const STATIC_TYPES_SET = new Set(Object.values(STATIC_TYPES))
|
18
19
|
export const KEYWORDS = {
|
19
20
|
LOOP: 'loop',
|
20
21
|
CREATE_ARRAY: 'array',
|
@@ -70,7 +71,9 @@ export const DEBUG = {
|
|
70
71
|
SIGNATURE: '?',
|
71
72
|
LIST_THEMES: 'theme?',
|
72
73
|
SET_THEME: 'theme!',
|
73
|
-
TYPE_SIGNATURE: '
|
74
|
+
TYPE_SIGNATURE: 't?'
|
74
75
|
}
|
75
76
|
|
76
|
-
export const SPECIAL_FORMS_SET = new Set(
|
77
|
+
export const SPECIAL_FORMS_SET = new Set(
|
78
|
+
Object.values(KEYWORDS).concat(Object.values(STATIC_TYPES))
|
79
|
+
)
|
package/src/macros.js
CHANGED
@@ -863,6 +863,11 @@ const iron = (scope) => {
|
|
863
863
|
for (let i = 0; i < copy.length; ++i) scope[i] = copy[i]
|
864
864
|
}
|
865
865
|
}
|
866
|
+
export const seeIfProgramIsInvalid = (source) => {
|
867
|
+
if (source.includes('()') || source.includes(',') || source.includes(';'))
|
868
|
+
throw new SyntaxError(`Failed to parse due to invalid lisp programm near`)
|
869
|
+
return source
|
870
|
+
}
|
866
871
|
export const replaceQuotes = (source) =>
|
867
872
|
source
|
868
873
|
.replaceAll(/\[/g, `(${KEYWORDS.CREATE_ARRAY} `)
|
package/src/parser.js
CHANGED
@@ -11,10 +11,6 @@ export const LISP = {
|
|
11
11
|
const cursor = source[i]
|
12
12
|
if (cursor === '(') {
|
13
13
|
const temp = []
|
14
|
-
if (head == undefined)
|
15
|
-
throw new SyntaxError(
|
16
|
-
`Failed to parse due to invalid lisp programm near ${acc}`
|
17
|
-
)
|
18
14
|
head.push(temp)
|
19
15
|
stack.push(head)
|
20
16
|
head = temp
|