fez-lisp 1.3.13 → 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.
@@ -132,7 +132,6 @@ export const SLICE = [
132
132
  [0, 'lambda'],
133
133
  [1, 'arr'],
134
134
  [1, 'start'],
135
- [1, 'end'],
136
135
  [
137
136
  [0, 'do'],
138
137
  [
@@ -140,7 +139,10 @@ export const SLICE = [
140
139
  [1, 'bounds'],
141
140
  [
142
141
  [0, '-'],
143
- [1, 'end'],
142
+ [
143
+ [0, 'length'],
144
+ [1, 'arr']
145
+ ],
144
146
  [1, 'start']
145
147
  ]
146
148
  ],
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.13",
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
@@ -385,52 +387,111 @@ export const deSuggarAst = (ast, scope) => {
385
387
  let newScope
386
388
  exp.length = 0
387
389
  switch (left[0][VALUE]) {
388
- case KEYWORDS.CREATE_ARRAY:
389
- {
390
- if (
391
- !isLeaf(right) &&
392
- right[0][TYPE] === APPLY &&
393
- right[0][VALUE] === KEYWORDS.CREATE_ARRAY
394
- ) {
395
- const values = right.slice(1)
396
- newScope = indexes.map((i) => [
397
- [APPLY, KEYWORDS.DEFINE_VARIABLE],
398
- vars[i],
399
- values[i]
400
- ])
401
- if (isSlicing)
402
- newScope.push([
390
+ case KEYWORDS.CREATE_ARRAY:
391
+ {
392
+ if (
393
+ !isLeaf(right) &&
394
+ right[0][TYPE] === APPLY &&
395
+ right[0][VALUE] === KEYWORDS.CREATE_ARRAY
396
+ ) {
397
+ const values = right.slice(1)
398
+ newScope = indexes.map((i) => [
403
399
  [APPLY, KEYWORDS.DEFINE_VARIABLE],
404
- lastLeft,
405
- [
406
- [APPLY, KEYWORDS.CREATE_ARRAY],
407
- ...values.slice(indexes.at(-1) + 1)
408
- ]
400
+ vars[i],
401
+ values[i]
409
402
  ])
410
- } else {
411
- newScope = indexes.map((i) => [
412
- [APPLY, KEYWORDS.DEFINE_VARIABLE],
413
- vars[i],
414
- [[APPLY, KEYWORDS.GET_ARRAY], right, [ATOM, i]]
415
- ])
416
- if (isSlicing)
417
- newScope.push([
403
+ if (isSlicing)
404
+ newScope.push([
405
+ [APPLY, KEYWORDS.DEFINE_VARIABLE],
406
+ lastLeft,
407
+ [
408
+ [APPLY, KEYWORDS.CREATE_ARRAY],
409
+ ...values.slice(indexes.at(-1) + 1)
410
+ ]
411
+ ])
412
+ } else {
413
+ newScope = indexes.map((i) => [
418
414
  [APPLY, KEYWORDS.DEFINE_VARIABLE],
419
- lastLeft,
420
- [
421
- [APPLY, KEYWORDS.CALL_FUNCTION],
422
- SLICE,
423
- right,
424
- [ATOM, indexes.at(-1) + 1],
425
- [[APPLY, KEYWORDS.ARRAY_LENGTH], right]
426
- ]
427
- ])
415
+ vars[i],
416
+ [[APPLY, KEYWORDS.GET_ARRAY], right, [ATOM, i]]
417
+ ])
418
+ if (isSlicing)
419
+ newScope.push([
420
+ [APPLY, KEYWORDS.DEFINE_VARIABLE],
421
+ lastLeft,
422
+ [
423
+ [APPLY, KEYWORDS.CALL_FUNCTION],
424
+ SLICE,
425
+ right,
426
+ [ATOM, indexes.at(-1) + 1]
427
+ ]
428
+ ])
429
+ }
430
+ exp.iron = true
431
+ exp.push(newScope)
432
+ deSuggarAst(exp)
428
433
  }
429
- exp.iron = true
430
- exp.push(newScope)
431
- deSuggarAst(exp)
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
432
494
  }
433
- break
434
495
  }
435
496
  }
436
497
  }
@@ -439,9 +500,10 @@ export const deSuggarAst = (ast, scope) => {
439
500
  prev = first
440
501
  }
441
502
  break
442
- default: {
443
- iron(scope)
444
- for (const e of exp) evaluate(e)
503
+ default:
504
+ {
505
+ iron(scope)
506
+ for (const e of exp) evaluate(e)
445
507
  }
446
508
  break
447
509
  }
@@ -469,23 +531,23 @@ export const replaceStrings = (source) => {
469
531
  }
470
532
  const iron = (scope) => {
471
533
  const indecies = scope
472
- .map((x, i) => {
473
- return x.iron ? i : -1
474
- })
475
- .filter((x) => x !== -1)
476
- if (indecies.length) {
477
- const set = new Set(indecies)
478
- const copy = []
479
- for (let i = 0; i < scope.length; ++i) {
480
- if (set.has(i)) {
481
- delete scope[i].iron
482
- copy.push(...scope[i][0])
483
- } else {
484
- copy.push(scope[i])
534
+ .map((x, i) => {
535
+ return x.iron ? i : -1
536
+ })
537
+ .filter((x) => x !== -1)
538
+ if (indecies.length) {
539
+ const set = new Set(indecies)
540
+ const copy = []
541
+ for (let i = 0; i < scope.length; ++i) {
542
+ if (set.has(i)) {
543
+ delete scope[i].iron
544
+ copy.push(...scope[i][0])
545
+ } else {
546
+ copy.push(scope[i])
547
+ }
485
548
  }
549
+ for (let i = 0; i < copy.length; ++i) scope[i] = copy[i]
486
550
  }
487
- for (let i = 0; i < copy.length; ++i) scope[i] = copy[i]
488
- }
489
551
  }
490
552
  export const replaceQuotes = (source) =>
491
553
  source