fez-lisp 1.1.24 → 1.1.25
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -1
- package/package.json +1 -1
- package/src/compiler.js +1 -0
- package/src/interpreter.js +19 -0
- 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(
|
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, '')
|