fez-lisp 1.1.24 → 1.1.26

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.26",
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(
@@ -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
- if (
931
- prev == undefined ||
932
- (prev &&
933
- prev[TYPE] === APPLY &&
934
- prev[VALUE] !== KEYWORDS.ANONYMOUS_FUNCTION)
935
- )
936
- throw new SyntaxError(
937
- `Can only use (${KEYWORDS.BLOCK}) as a body of a (${KEYWORDS.ANONYMOUS_FUNCTION})`
938
- )
939
- }
940
- break
941
- // case KEYWORDS.DEFINE_VARIABLE:
942
- // {
943
- // if (
944
- // rest[1] &&
945
- // rest[1][0] &&
946
- // rest[1][0][TYPE] === APPLY &&
947
- // rest[1][0][VALUE] === KEYWORDS.BLOCK
948
- // ) {
949
- // throw new SyntaxError(
950
- // `Can't use (${KEYWORDS.BLOCK}) in (${KEYWORDS.DEFINE_VARIABLE})`
951
- // )
952
- // }
953
- // }
954
- break
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
@@ -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, '')