fez-lisp 1.1.24 → 1.1.26
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/README.md +2 -1
- package/package.json +1 -1
- package/src/compiler.js +1 -0
- package/src/interpreter.js +48 -27
- package/src/keywords.js +1 -0
- package/src/utils.js +5 -1
package/README.md
CHANGED
@@ -246,5 +246,6 @@ console.log(fez(tree(`(+ (|> 1 (+ 2) (* 3) (- 1)) (- (* (+ 1 2) 3) 1))`)))
|
|
246
246
|
(/) (+) (*) (-) (=) (<) (>) (>=) (<=) (&) (~) (|) (^) (<<) (>>) (>>>)
|
247
247
|
(|>) (mod) (let) (if) (unless) (not) (and) (or) (cond) (atom?) (lambda)
|
248
248
|
(car) (cdr) (cons) (length) (do) (array) (array:set!) (array:get)
|
249
|
-
(apply) (case) (assert) (log!) (log-string!) (
|
249
|
+
(apply) (case) (assert) (log!) (log-string!) (log-char!) (clear!)
|
250
|
+
(void) (fez-manual)
|
250
251
|
```
|
package/package.json
CHANGED
package/src/compiler.js
CHANGED
@@ -94,6 +94,7 @@ const Helpers = {
|
|
94
94
|
return args.at(-1) ? 1 : 0
|
95
95
|
}`,
|
96
96
|
logEffect: `logEffect=(msg)=>{console.log(msg);return msg}`,
|
97
|
+
logCharEffect: `logCharEffect=(msg)=>{console.log(String.fromCharCode(msg));return msg}`,
|
97
98
|
logStringEffect: `logStringEffect=(msg)=>{console.log(msg.map(x=>String.fromCharCode(x)).join(''));return msg}`,
|
98
99
|
clearEffect: `clearEffect=()=>{console.clear();return 0}`,
|
99
100
|
array_cons: `array_cons=(A, ...B)=> B.reduce((a, b) => a.concat(b), A)`,
|
package/src/interpreter.js
CHANGED
@@ -859,6 +859,25 @@ const keywords = {
|
|
859
859
|
console.log(expression.map((x) => String.fromCharCode(x)).join(''))
|
860
860
|
return expression
|
861
861
|
},
|
862
|
+
[KEYWORDS.LOG_CHAR]: (args, env) => {
|
863
|
+
if (args.length !== 1)
|
864
|
+
throw new RangeError(
|
865
|
+
`Invalid number of arguments to (${
|
866
|
+
KEYWORDS.LOG_CHAR
|
867
|
+
}) (= 1 required) (${KEYWORDS.LOG_CHAR} ${stringifyArgs(args)})`
|
868
|
+
)
|
869
|
+
const expression = evaluate(args[0], env)
|
870
|
+
if (typeof expression !== 'number')
|
871
|
+
throw new TypeError(
|
872
|
+
`Argument of (${KEYWORDS.LOG_CHAR}) must be a (${
|
873
|
+
KEYWORDS.NUMBER_TYPE
|
874
|
+
}) but got (${expression}) (${KEYWORDS.LOG_CHAR} ${stringifyArgs(
|
875
|
+
args
|
876
|
+
)})`
|
877
|
+
)
|
878
|
+
console.log(String.fromCharCode(expression))
|
879
|
+
return expression
|
880
|
+
},
|
862
881
|
[KEYWORDS.CLEAR_CONSOLE]: (args) => {
|
863
882
|
if (args.length)
|
864
883
|
throw new RangeError(
|
@@ -925,33 +944,35 @@ export const deSuggar = (ast) => {
|
|
925
944
|
case APPLY:
|
926
945
|
{
|
927
946
|
switch (first[VALUE]) {
|
928
|
-
case KEYWORDS.BLOCK:
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
947
|
+
// case KEYWORDS.BLOCK:
|
948
|
+
// {
|
949
|
+
// if (
|
950
|
+
// prev == undefined ||
|
951
|
+
// (prev &&
|
952
|
+
// prev[TYPE] === APPLY &&
|
953
|
+
// prev[VALUE] !== KEYWORDS.ANONYMOUS_FUNCTION)
|
954
|
+
// )
|
955
|
+
// throw new SyntaxError(
|
956
|
+
// `Can only use (${KEYWORDS.BLOCK}) as a body of a (${
|
957
|
+
// KEYWORDS.ANONYMOUS_FUNCTION
|
958
|
+
// }) (${stringifyArgs(exp)})`
|
959
|
+
// )
|
960
|
+
// }
|
961
|
+
// break
|
962
|
+
// case KEYWORDS.DEFINE_VARIABLE:
|
963
|
+
// {
|
964
|
+
// if (
|
965
|
+
// rest[1] &&
|
966
|
+
// rest[1][0] &&
|
967
|
+
// rest[1][0][TYPE] === APPLY &&
|
968
|
+
// rest[1][0][VALUE] === KEYWORDS.BLOCK
|
969
|
+
// ) {
|
970
|
+
// throw new SyntaxError(
|
971
|
+
// `Can't use (${KEYWORDS.BLOCK}) in (${KEYWORDS.DEFINE_VARIABLE})`
|
972
|
+
// )
|
973
|
+
// }
|
974
|
+
// }
|
975
|
+
// break
|
955
976
|
case KEYWORDS.PIPE:
|
956
977
|
{
|
957
978
|
if (rest.length < 1)
|
package/src/keywords.js
CHANGED
package/src/utils.js
CHANGED
@@ -9,6 +9,7 @@ export const logError = (error) =>
|
|
9
9
|
export const logSuccess = (output) => console.log(output, '\x1b[0m')
|
10
10
|
export const replaceStrings = (source) => {
|
11
11
|
const quotes = source.match(/"(.*?)"/g)
|
12
|
+
// TODO handle escaping
|
12
13
|
if (quotes)
|
13
14
|
for (const q of quotes)
|
14
15
|
source = source.replaceAll(
|
@@ -20,7 +21,10 @@ export const replaceStrings = (source) => {
|
|
20
21
|
)
|
21
22
|
return source
|
22
23
|
}
|
23
|
-
export const replaceQuotes = (source) =>
|
24
|
+
export const replaceQuotes = (source) =>
|
25
|
+
source.replaceAll(/\'\(/g, '(array ').replaceAll(/\(\)/g, '(array)')
|
26
|
+
// export const replaceEmptyArrays = (source) =>
|
27
|
+
// source
|
24
28
|
export const removeNoCode = (source) =>
|
25
29
|
source
|
26
30
|
.replace(/;.+/g, '')
|