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 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!) (clear!) (void) (fez-manual)
249
+ (apply) (case) (assert) (log!) (log-string!) (log-char!) (clear!)
250
+ (void) (fez-manual)
250
251
  ```
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.1.24",
5
+ "version": "1.1.25",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
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)`,
@@ -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
@@ -50,6 +50,7 @@ export const KEYWORDS = {
50
50
  TEST_BED: 'assert',
51
51
  LOG: 'log!',
52
52
  LOG_STRING: 'log-string!',
53
+ LOG_CHAR: 'log-char!',
53
54
  CLEAR_CONSOLE: 'clear!',
54
55
  DOC: 'fez-manual'
55
56
  }
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) => source.replaceAll(/\'\(/g, '(array ')
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, '')