fez-lisp 1.3.12 → 1.3.14
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.
- package/index.js +2 -19
- package/lib/baked/macros.js +4 -2
- package/package.json +1 -1
- package/src/macros.js +60 -60
package/index.js
CHANGED
@@ -1,22 +1,5 @@
|
|
1
1
|
import { evaluate } from './src/evaluator.js'
|
2
2
|
import { LISP, AST } from './src/parser.js'
|
3
|
-
import { fez,
|
3
|
+
import { fez, prep } from './src/utils.js'
|
4
4
|
import std from './lib/baked/std.js'
|
5
|
-
|
6
|
-
import { WORD, APPLY, ATOM, VALUE, TYPE } from './src/keywords.js'
|
7
|
-
const types = { WORD, APPLY, ATOM, VALUE, TYPE }
|
8
|
-
export {
|
9
|
-
fez,
|
10
|
-
keywords,
|
11
|
-
evaluate,
|
12
|
-
std,
|
13
|
-
types,
|
14
|
-
tree,
|
15
|
-
ast,
|
16
|
-
src,
|
17
|
-
js,
|
18
|
-
prep,
|
19
|
-
dependencies,
|
20
|
-
LISP,
|
21
|
-
AST
|
22
|
-
}
|
5
|
+
export { fez, evaluate, std, prep, LISP, AST }
|
package/lib/baked/macros.js
CHANGED
@@ -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
|
-
[
|
142
|
+
[
|
143
|
+
[0, 'length'],
|
144
|
+
[1, 'arr']
|
145
|
+
],
|
144
146
|
[1, 'start']
|
145
147
|
]
|
146
148
|
],
|
package/package.json
CHANGED
package/src/macros.js
CHANGED
@@ -385,52 +385,51 @@ export const deSuggarAst = (ast, scope) => {
|
|
385
385
|
let newScope
|
386
386
|
exp.length = 0
|
387
387
|
switch (left[0][VALUE]) {
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
[APPLY, KEYWORDS.DEFINE_VARIABLE],
|
398
|
-
vars[i],
|
399
|
-
values[i]
|
400
|
-
])
|
401
|
-
if (isSlicing)
|
402
|
-
newScope.push([
|
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) => [
|
403
397
|
[APPLY, KEYWORDS.DEFINE_VARIABLE],
|
404
|
-
|
405
|
-
[
|
406
|
-
[APPLY, KEYWORDS.CREATE_ARRAY],
|
407
|
-
...values.slice(indexes.at(-1) + 1)
|
408
|
-
]
|
398
|
+
vars[i],
|
399
|
+
values[i]
|
409
400
|
])
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
401
|
+
if (isSlicing)
|
402
|
+
newScope.push([
|
403
|
+
[APPLY, KEYWORDS.DEFINE_VARIABLE],
|
404
|
+
lastLeft,
|
405
|
+
[
|
406
|
+
[APPLY, KEYWORDS.CREATE_ARRAY],
|
407
|
+
...values.slice(indexes.at(-1) + 1)
|
408
|
+
]
|
409
|
+
])
|
410
|
+
} else {
|
411
|
+
newScope = indexes.map((i) => [
|
418
412
|
[APPLY, KEYWORDS.DEFINE_VARIABLE],
|
419
|
-
|
420
|
-
[
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
[
|
425
|
-
|
426
|
-
|
427
|
-
|
413
|
+
vars[i],
|
414
|
+
[[APPLY, KEYWORDS.GET_ARRAY], right, [ATOM, i]]
|
415
|
+
])
|
416
|
+
if (isSlicing)
|
417
|
+
newScope.push([
|
418
|
+
[APPLY, KEYWORDS.DEFINE_VARIABLE],
|
419
|
+
lastLeft,
|
420
|
+
[
|
421
|
+
[APPLY, KEYWORDS.CALL_FUNCTION],
|
422
|
+
SLICE,
|
423
|
+
right,
|
424
|
+
[ATOM, indexes.at(-1) + 1]
|
425
|
+
]
|
426
|
+
])
|
427
|
+
}
|
428
|
+
exp.iron = true
|
429
|
+
exp.push(newScope)
|
430
|
+
deSuggarAst(exp)
|
428
431
|
}
|
429
|
-
|
430
|
-
exp.push(newScope)
|
431
|
-
deSuggarAst(exp)
|
432
|
-
}
|
433
|
-
break
|
432
|
+
break
|
434
433
|
}
|
435
434
|
}
|
436
435
|
}
|
@@ -439,9 +438,10 @@ export const deSuggarAst = (ast, scope) => {
|
|
439
438
|
prev = first
|
440
439
|
}
|
441
440
|
break
|
442
|
-
default:
|
443
|
-
|
444
|
-
|
441
|
+
default:
|
442
|
+
{
|
443
|
+
iron(scope)
|
444
|
+
for (const e of exp) evaluate(e)
|
445
445
|
}
|
446
446
|
break
|
447
447
|
}
|
@@ -469,23 +469,23 @@ export const replaceStrings = (source) => {
|
|
469
469
|
}
|
470
470
|
const iron = (scope) => {
|
471
471
|
const indecies = scope
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
if (indecies.length) {
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
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])
|
485
|
+
}
|
485
486
|
}
|
487
|
+
for (let i = 0; i < copy.length; ++i) scope[i] = copy[i]
|
486
488
|
}
|
487
|
-
for (let i = 0; i < copy.length; ++i) scope[i] = copy[i]
|
488
|
-
}
|
489
489
|
}
|
490
490
|
export const replaceQuotes = (source) =>
|
491
491
|
source
|