fez-lisp 1.3.25 → 1.3.27
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/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/compiler.js +2 -1
- package/src/interpreter.js +4 -3
- package/src/macros.js +52 -56
- package/src/utils.js +1 -1
package/package.json
CHANGED
package/src/compiler.js
CHANGED
@@ -167,7 +167,8 @@ const compile = (tree, Drill) => {
|
|
167
167
|
}
|
168
168
|
}
|
169
169
|
case KEYWORDS.CALL_FUNCTION: {
|
170
|
-
const
|
170
|
+
const first = Arguments.pop()
|
171
|
+
const rest = Arguments
|
171
172
|
const apply = compile(first, Drill)
|
172
173
|
return `${
|
173
174
|
apply[apply.length - 1] === ';'
|
package/src/interpreter.js
CHANGED
@@ -656,10 +656,11 @@ export const keywords = {
|
|
656
656
|
KEYWORDS.CALL_FUNCTION
|
657
657
|
}) (>= 1 required) (${KEYWORDS.CALL_FUNCTION} ${stringifyArgs(args)})`
|
658
658
|
)
|
659
|
-
const
|
659
|
+
const rest = [...args]
|
660
|
+
const first = rest.pop()
|
660
661
|
if (first[TYPE] === WORD && first[VALUE] in keywords)
|
661
662
|
throw new TypeError(
|
662
|
-
`
|
663
|
+
`Preceeding arguments of (${
|
663
664
|
KEYWORDS.CALL_FUNCTION
|
664
665
|
}) must not be an reserved word (${
|
665
666
|
KEYWORDS.CALL_FUNCTION
|
@@ -668,7 +669,7 @@ export const keywords = {
|
|
668
669
|
const apply = evaluate(first, env)
|
669
670
|
if (typeof apply !== 'function')
|
670
671
|
throw new TypeError(
|
671
|
-
`
|
672
|
+
`Last argument of (${KEYWORDS.CALL_FUNCTION}) must be a (${
|
672
673
|
KEYWORDS.ANONYMOUS_FUNCTION
|
673
674
|
}) (${KEYWORDS.CALL_FUNCTION} ${stringifyArgs(args)})`
|
674
675
|
)
|
package/src/macros.js
CHANGED
@@ -179,8 +179,8 @@ export const deSuggarAst = (ast, scope) => {
|
|
179
179
|
exp.length = 0
|
180
180
|
exp.push(
|
181
181
|
[0, KEYWORDS.CALL_FUNCTION],
|
182
|
-
|
183
|
-
|
182
|
+
...rest,
|
183
|
+
INTEGER_DIVISION
|
184
184
|
)
|
185
185
|
} else {
|
186
186
|
exp.length = 1
|
@@ -216,9 +216,9 @@ export const deSuggarAst = (ast, scope) => {
|
|
216
216
|
exp.length = 0
|
217
217
|
exp.push(
|
218
218
|
[0, KEYWORDS.CALL_FUNCTION],
|
219
|
-
EXPONENTIATION,
|
220
219
|
exponent,
|
221
|
-
power
|
220
|
+
power,
|
221
|
+
EXPONENTIATION
|
222
222
|
)
|
223
223
|
}
|
224
224
|
} else {
|
@@ -227,9 +227,9 @@ export const deSuggarAst = (ast, scope) => {
|
|
227
227
|
exp.length = 0
|
228
228
|
exp.push(
|
229
229
|
[0, KEYWORDS.CALL_FUNCTION],
|
230
|
-
EXPONENTIATION,
|
231
230
|
exponent,
|
232
|
-
power
|
231
|
+
power,
|
232
|
+
EXPONENTIATION
|
233
233
|
)
|
234
234
|
}
|
235
235
|
deSuggarAst(exp, scope)
|
@@ -394,14 +394,11 @@ export const deSuggarAst = (ast, scope) => {
|
|
394
394
|
case KEYWORDS.DEFINE_VARIABLE:
|
395
395
|
{
|
396
396
|
if (!isLeaf(exp[1]) && exp[1][0][TYPE] === APPLY) {
|
397
|
-
const left = exp[1]
|
397
|
+
const left = exp[1].slice(1)
|
398
398
|
const right = exp.at(-1)
|
399
|
-
const isList =
|
400
|
-
left[left.length - 2][VALUE] === KEYWORDS.BITWISE_NOT
|
401
399
|
let newScope
|
402
|
-
if (
|
400
|
+
if (exp[1][0][VALUE] === SUGGAR.CREATE_LIST) {
|
403
401
|
const lastLeft = left.pop()
|
404
|
-
left.pop() // tail separator
|
405
402
|
const vars = left
|
406
403
|
if (
|
407
404
|
!isLeaf(right) &&
|
@@ -409,7 +406,7 @@ export const deSuggarAst = (ast, scope) => {
|
|
409
406
|
right[0][VALUE] === SUGGAR.CREATE_LIST
|
410
407
|
) {
|
411
408
|
throw new SyntaxError(
|
412
|
-
`
|
409
|
+
`Destructuring requires right hand side to be a word but got an apply ${stringifyArgs(
|
413
410
|
exp
|
414
411
|
)}`
|
415
412
|
)
|
@@ -450,14 +447,12 @@ export const deSuggarAst = (ast, scope) => {
|
|
450
447
|
}
|
451
448
|
vars[0][TYPE] = WORD
|
452
449
|
exp.length = 0
|
453
|
-
} else {
|
450
|
+
} else if (exp[1][0][VALUE] === KEYWORDS.CREATE_ARRAY) {
|
454
451
|
const lastLeft = left.pop()
|
455
452
|
// const isList = exp[i][exp[i].length - 2][VALUE] === KEYWORDS.BITWISE_NOT
|
456
453
|
const isSlicing = lastLeft[VALUE] !== PLACEHOLDER
|
457
454
|
const vars = left
|
458
|
-
const indexes = vars
|
459
|
-
.map((x, i) => (x[VALUE] === PLACEHOLDER ? -1 : i))
|
460
|
-
.filter((x) => x !== -1)
|
455
|
+
const indexes = vars.map((x, i) => [i, x])
|
461
456
|
vars[0][TYPE] = WORD
|
462
457
|
exp.length = 0
|
463
458
|
if (
|
@@ -466,25 +461,27 @@ export const deSuggarAst = (ast, scope) => {
|
|
466
461
|
right[0][VALUE] === KEYWORDS.CREATE_ARRAY
|
467
462
|
) {
|
468
463
|
throw new SyntaxError(
|
469
|
-
`
|
464
|
+
`Destructuring requires right hand side to be a word but got an apply ${stringifyArgs(
|
470
465
|
exp
|
471
466
|
)}`
|
472
467
|
)
|
473
468
|
} else {
|
474
|
-
newScope = indexes
|
475
|
-
[
|
476
|
-
|
477
|
-
|
478
|
-
|
469
|
+
newScope = indexes
|
470
|
+
.filter((x) => x[1][VALUE] !== PLACEHOLDER)
|
471
|
+
.map(([i]) => [
|
472
|
+
[APPLY, KEYWORDS.DEFINE_VARIABLE],
|
473
|
+
vars[i],
|
474
|
+
[[APPLY, KEYWORDS.GET_ARRAY], right, [ATOM, i]]
|
475
|
+
])
|
479
476
|
if (isSlicing)
|
480
477
|
newScope.push([
|
481
478
|
[APPLY, KEYWORDS.DEFINE_VARIABLE],
|
482
479
|
lastLeft,
|
483
480
|
[
|
484
481
|
[APPLY, KEYWORDS.CALL_FUNCTION],
|
485
|
-
SLICE,
|
486
482
|
right,
|
487
|
-
[ATOM, indexes.at(-1) + 1]
|
483
|
+
[ATOM, indexes.at(-1)[0] + 1],
|
484
|
+
SLICE
|
488
485
|
]
|
489
486
|
])
|
490
487
|
}
|
@@ -500,17 +497,17 @@ export const deSuggarAst = (ast, scope) => {
|
|
500
497
|
const block = exp.at(-1)
|
501
498
|
const newBlock = [[APPLY, KEYWORDS.BLOCK]]
|
502
499
|
for (let i = 1; i < exp.length - 1; ++i) {
|
503
|
-
if (
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
500
|
+
if (
|
501
|
+
!isLeaf(exp[i]) &&
|
502
|
+
exp[i][0][TYPE] === APPLY &&
|
503
|
+
(exp[i][0][VALUE] === KEYWORDS.CREATE_ARRAY ||
|
504
|
+
exp[i][0][VALUE] === SUGGAR.CREATE_LIST)
|
505
|
+
) {
|
506
|
+
if (exp[i][0][VALUE] === SUGGAR.CREATE_LIST) {
|
507
|
+
const left = exp[i].slice(1)
|
509
508
|
const right = [WORD, `_arg${i}`]
|
510
509
|
const lastLeft = left.pop()
|
511
510
|
|
512
|
-
left.pop() // tail separator
|
513
|
-
|
514
511
|
const vars = left
|
515
512
|
const indexes = vars
|
516
513
|
.map((x, i) => [x, i])
|
@@ -552,39 +549,37 @@ export const deSuggarAst = (ast, scope) => {
|
|
552
549
|
left[0][TYPE] = WORD
|
553
550
|
exp[i] = right
|
554
551
|
exp[i].length = 2
|
555
|
-
} else {
|
556
|
-
const left = exp[i]
|
552
|
+
} else if (exp[i][0][VALUE] === KEYWORDS.CREATE_ARRAY) {
|
553
|
+
const left = exp[i].slice(1)
|
557
554
|
const right = [WORD, `_arg${i}`]
|
558
555
|
left[0][TYPE] = WORD
|
559
556
|
const lastLeft = left.pop()
|
560
557
|
const isSlicing = lastLeft[VALUE] !== PLACEHOLDER
|
561
558
|
const vars = left
|
562
|
-
const indexes = vars
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
...indexes.map((i) => [
|
559
|
+
const indexes = vars.map((x, i) => [i, x])
|
560
|
+
// const tempBlcok = [...block[VALUE]]
|
561
|
+
newBlock.push(
|
562
|
+
...indexes
|
563
|
+
.filter((x) => x[1][VALUE] !== PLACEHOLDER)
|
564
|
+
.map(([i]) => [
|
569
565
|
[APPLY, KEYWORDS.DEFINE_VARIABLE],
|
570
566
|
vars[i],
|
571
567
|
[[APPLY, KEYWORDS.GET_ARRAY], right, [ATOM, i]]
|
572
568
|
])
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
}
|
569
|
+
)
|
570
|
+
if (isSlicing)
|
571
|
+
newBlock.push([
|
572
|
+
[APPLY, KEYWORDS.DEFINE_VARIABLE],
|
573
|
+
lastLeft,
|
574
|
+
[
|
575
|
+
[APPLY, KEYWORDS.CALL_FUNCTION],
|
576
|
+
right,
|
577
|
+
[ATOM, indexes.at(-1)[0] + 1],
|
578
|
+
SLICE
|
579
|
+
]
|
580
|
+
])
|
581
|
+
exp[i] = right
|
582
|
+
exp[i].length = 2
|
588
583
|
}
|
589
584
|
exp[exp.length - 1] = newBlock.concat(
|
590
585
|
hasBlock(block) ? block.slice(1) : [block]
|
@@ -610,6 +605,7 @@ export const deSuggarAst = (ast, scope) => {
|
|
610
605
|
}
|
611
606
|
}
|
612
607
|
evaluate(ast)
|
608
|
+
iron(ast)
|
613
609
|
return ast
|
614
610
|
}
|
615
611
|
export const replaceStrings = (source) => {
|
package/src/utils.js
CHANGED
@@ -149,7 +149,7 @@ export const handleUnbalancedParens = (source) => {
|
|
149
149
|
export const removeMutation = (source) => source.replace(new RegExp(/!/g), 'ǃ')
|
150
150
|
const isDefinition = (x) =>
|
151
151
|
x[TYPE] === APPLY && x[VALUE] === KEYWORDS.DEFINE_VARIABLE
|
152
|
-
const toDeps = ([[,[,libs]]]) =>
|
152
|
+
const toDeps = ([[, [, libs]]]) =>
|
153
153
|
libs.reduce(
|
154
154
|
(a, x, i) => a.set(x.at(1)[VALUE], { value: x, index: i }),
|
155
155
|
new Map()
|