fez-lisp 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "fez-lisp",
3
3
  "description": "Immutable Lisp interpreted & compiled to JavaScript",
4
4
  "author": "AT290690",
5
- "version": "1.0.7",
5
+ "version": "1.0.8",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/compiler.js CHANGED
@@ -23,6 +23,14 @@ return result
23
23
  isAtom: `atomPredicate=(value)=>typeof value==='number'||typeof value==='string'`,
24
24
  error: `_error=(error)=>{
25
25
  throw new Error(error)
26
+ }`,
27
+ set: `set=(array,index,value)=>{
28
+ array=[...array]
29
+ if (index < 0) {
30
+ const target = array.length + index
31
+ while (array.length !== target) array.pop()
32
+ } else array[index] = value;
33
+ return array
26
34
  }`,
27
35
  setArray: `setEffect=(array,index,value)=>{
28
36
  if (index < 0) {
@@ -210,6 +218,7 @@ const compile = (tree, Variables) => {
210
218
  case KEYWORDS.CONCATENATION:
211
219
  return '(' + parseArgs(Arguments, Variables, '+') + ');'
212
220
  case KEYWORDS.EQUAL:
221
+ case KEYWORDS.EQUALITY:
213
222
  return handleBoolean(`(${parseArgs(Arguments, Variables, '===')});`)
214
223
  case KEYWORDS.GREATHER_THAN_OR_EQUAL:
215
224
  case KEYWORDS.LESS_THAN_OR_EQUAL:
@@ -234,6 +243,9 @@ const compile = (tree, Variables) => {
234
243
  : `(${parseArgs(Arguments, Variables, token)});`
235
244
  : `(0);`
236
245
  case KEYWORDS.ADDITION:
246
+ return Arguments.length
247
+ ? `(${parseArgs(Arguments, Variables, token)});`
248
+ : `(0);`
237
249
  case KEYWORDS.BITWISE_AND:
238
250
  case KEYWORDS.BITWISE_OR:
239
251
  case KEYWORDS.BITWISE_XOR:
@@ -309,6 +321,8 @@ const compile = (tree, Variables) => {
309
321
  }
310
322
  case KEYWORDS.SERIALISE:
311
323
  return `_serialise(${compile(Arguments[0], Variables)});`
324
+ case KEYWORDS.SET_IMMUTABLE_ARRAY:
325
+ return `set(${parseArgs(Arguments, Variables)}));`
312
326
  case KEYWORDS.SET_ARRAY:
313
327
  return `setEffect(${parseArgs(Arguments, Variables)});`
314
328
  case KEYWORDS.NOT_COMPILED_BLOCK:
package/src/enums.js CHANGED
@@ -54,6 +54,7 @@ export const KEYWORDS = {
54
54
  CONDITION: 'cond',
55
55
 
56
56
  NOT: 'not',
57
+ EQUALITY: 'eq',
57
58
  EQUAL: '=',
58
59
  LESS_THAN: '<',
59
60
  GREATHER_THAN: '>',
@@ -76,4 +77,5 @@ export const KEYWORDS = {
76
77
  SERIALISE: 'serialise',
77
78
 
78
79
  SET_ARRAY: 'set!',
80
+ SET_IMMUTABLE_ARRAY: 'set',
79
81
  }
@@ -9,18 +9,18 @@ export const evaluate = (exp, env) => {
9
9
  case WORD: {
10
10
  const word = env[first[VALUE]]
11
11
  if (word == undefined)
12
- throw new ReferenceError(`Undefined variable ${first[VALUE]}.`)
12
+ throw new ReferenceError(`Undefined variable ${first[VALUE]}`)
13
13
  return word
14
14
  }
15
15
  case APPLY:
16
16
  const apply = env[first[VALUE]]
17
17
  if (apply == undefined)
18
18
  throw new ReferenceError(
19
- `Undefined (${KEYWORDS.ANONYMOUS_FUNCTION}) ${first[VALUE]}.`
19
+ `Undefined (${KEYWORDS.ANONYMOUS_FUNCTION}) ${first[VALUE]}`
20
20
  )
21
21
  if (typeof apply !== 'function')
22
22
  throw new TypeError(
23
- `${first[VALUE]} is not a (${KEYWORDS.ANONYMOUS_FUNCTION}).`
23
+ `${first[VALUE]} is not a (${KEYWORDS.ANONYMOUS_FUNCTION})`
24
24
  )
25
25
  return apply(rest, env)
26
26
  case ATOM:
package/src/parser.js CHANGED
@@ -46,7 +46,8 @@ export const parse = (source) => {
46
46
  export const stringify = (ast) => {
47
47
  if (ast == undefined) return '()'
48
48
  else if (typeof ast === 'object')
49
- if (Array.isArray(ast)) return `(array ${ast.map(stringify).join(' ')})`
49
+ if (Array.isArray(ast))
50
+ return ast.length ? `(array ${ast.map(stringify).join(' ')})` : '()'
50
51
  else
51
52
  return `(array ${Object.entries(ast)
52
53
  .map(([key, value]) => `("${key}" ${stringify(value)})`)