fez-lisp 1.3.14 → 1.3.15

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/macros.js +62 -0
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.3.14",
5
+ "version": "1.3.15",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/macros.js CHANGED
@@ -59,6 +59,8 @@ export const deSuggarAst = (ast, scope) => {
59
59
  exp.length = 0
60
60
  exp.push(...INTEGER_DIVISION)
61
61
  break
62
+ default:
63
+ break
62
64
  }
63
65
  }
64
66
  break
@@ -430,6 +432,66 @@ export const deSuggarAst = (ast, scope) => {
430
432
  deSuggarAst(exp)
431
433
  }
432
434
  break
435
+ default:
436
+ break
437
+ }
438
+ }
439
+ }
440
+ break
441
+ case KEYWORDS.ANONYMOUS_FUNCTION:
442
+ {
443
+ const body = exp.at(-1)
444
+ const block =
445
+ body[0][TYPE] === APPLY && body[0][VALUE] === KEYWORDS.BLOCK
446
+ ? body[1]
447
+ : body
448
+ const newBlock = [[APPLY, KEYWORDS.BLOCK]]
449
+ for (let i = 1; i < exp.length - 1; ++i) {
450
+ if (
451
+ !isLeaf(exp[i]) &&
452
+ exp[i][0][TYPE] === APPLY &&
453
+ exp[i][0][VALUE] === KEYWORDS.CREATE_ARRAY
454
+ ) {
455
+ const left = exp[i]
456
+ const right = [WORD, `_arg${i}`]
457
+ const lastLeft = left.pop()
458
+ const isSlicing = lastLeft[VALUE] !== PLACEHOLDER
459
+ const vars = left.slice(1)
460
+ const indexes = vars
461
+ .map((x, i) => (x[VALUE] === PLACEHOLDER ? -1 : i))
462
+ .filter((x) => x !== -1)
463
+ switch (left[0][VALUE]) {
464
+ case KEYWORDS.CREATE_ARRAY:
465
+ {
466
+ // const tempBlcok = [...block[VALUE]]
467
+ newBlock.push(
468
+ ...indexes.map((i) => [
469
+ [APPLY, KEYWORDS.DEFINE_VARIABLE],
470
+ vars[i],
471
+ [[APPLY, KEYWORDS.GET_ARRAY], right, [ATOM, i]]
472
+ ])
473
+ )
474
+ if (isSlicing)
475
+ newBlock.push([
476
+ [APPLY, KEYWORDS.DEFINE_VARIABLE],
477
+ lastLeft,
478
+ [
479
+ [APPLY, KEYWORDS.CALL_FUNCTION],
480
+ SLICE,
481
+ right,
482
+ [ATOM, indexes.at(-1) + 1]
483
+ ]
484
+ ])
485
+ exp[i] = right
486
+ exp[i].length = 2
487
+ }
488
+ exp[exp.length - 1] = newBlock.concat([block])
489
+ deSuggarAst(block)
490
+
491
+ break
492
+ default:
493
+ break
494
+ }
433
495
  }
434
496
  }
435
497
  }