@mark1russell7/vex-compiler 0.10.0 → 0.11.0
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/build/index.d.ts.map +1 -1
- package/build/index.js +14 -6
- package/build/index.js.map +1 -1
- package/package.json +4 -4
- package/src/facts.ts +10 -5
- package/src/lower.ts +1 -0
- package/src/module.ts +3 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/vex-compiler",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"description": "The Vex compiler: generated JavaScript for Vex programs, at run time and at build time, with the results of the interpreter.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vex",
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@mark1russell7/cue": "github:mark1russell7/cue",
|
|
46
|
-
"@mark1russell7/vex-domains": "0.
|
|
47
|
-
"@mark1russell7/vex-testkit": "0.
|
|
46
|
+
"@mark1russell7/vex-domains": "0.11.0",
|
|
47
|
+
"@mark1russell7/vex-testkit": "0.11.0",
|
|
48
48
|
"@types/node": "^26.6.4",
|
|
49
49
|
"fast-check": "^4.10.2",
|
|
50
50
|
"typescript": "^7.0.2",
|
|
51
51
|
"vitest": "^5.0.3"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@mark1russell7/vex": "0.
|
|
54
|
+
"@mark1russell7/vex": "0.11.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "tsdown",
|
package/src/facts.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* whose op the interpreter takes first, and the kinds and the lifts of its parameters. The facts come from the op
|
|
4
4
|
* tables, so the same options always give the same facts, and the same source.
|
|
5
5
|
*/
|
|
6
|
-
import { children, isListOp, isOpName, liftsAt, listOf, type AnyDomain, type Expr, type ExtHandler, type FreeFn, type OpSpec, type ParamKind, type PrimitiveKind, type ReturnKind } from "@mark1russell7/vex";
|
|
6
|
+
import { children, isListOp, isOpName, isVexList, liftsAt, listOf, type AnyDomain, type Expr, type ExtHandler, type FreeFn, type OpSpec, type ParamKind, type PrimitiveKind, type ReturnKind } from "@mark1russell7/vex";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The most bodies of functions that tier 2 puts at the calls of one program. A function that calls another function
|
|
@@ -11,12 +11,16 @@ import { children, isListOp, isOpName, liftsAt, listOf, type AnyDomain, type Exp
|
|
|
11
11
|
*/
|
|
12
12
|
export const MAX_CALLS = 10_000;
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The list ops that give a list, or read a position or a key of a list (LIST.SORT, LIST.TAKE, LIST.NTH, LIST.BUILD,
|
|
16
|
+
* LIST.GET).
|
|
17
|
+
*/
|
|
18
|
+
const ORDER_OPS: ReadonlySet<string> = new Set(["sortBy", "take", "nth", "drop", "append", "flat", "without", "get"]);
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
|
-
* This function gives the reason that tier 2 cannot take a program with lists as values. The reason is the axis `list
|
|
19
|
-
*
|
|
21
|
+
* This function gives the reason that tier 2 cannot take a program with lists as values. The reason is the axis `list`,
|
|
22
|
+
* an op on the order or the keys of a list, or a list literal. Tier 1 evaluates such a program. It uses a stack, not
|
|
23
|
+
* recursion.
|
|
20
24
|
*/
|
|
21
25
|
export function listReason(expr: Expr): string | undefined {
|
|
22
26
|
const todo: Expr[] = [expr];
|
|
@@ -24,6 +28,7 @@ export function listReason(expr: Expr): string | undefined {
|
|
|
24
28
|
if ((x.tag === "each" || x.tag === "fold") && listOf(x.axis) !== undefined) return 'the program has the axis "list", and tier 2 does not have lists as values yet';
|
|
25
29
|
// Stryker disable next-line ConditionalExpression: a node that is not an app has no field op, so the set does not have it
|
|
26
30
|
if (x.tag === "app" && ORDER_OPS.has(x.op)) return `the program has the list op "${x.op}", and tier 2 does not have lists as values yet`;
|
|
31
|
+
if (x.tag === "lit" && isVexList(x.value)) return "the program has a list literal, and tier 2 does not have lists as values yet";
|
|
27
32
|
todo.push(...children(x));
|
|
28
33
|
}
|
|
29
34
|
return undefined;
|
package/src/lower.ts
CHANGED
|
@@ -567,6 +567,7 @@ class Lowerer {
|
|
|
567
567
|
case "append":
|
|
568
568
|
case "flat":
|
|
569
569
|
case "without":
|
|
570
|
+
case "get":
|
|
570
571
|
/* v8 ignore next -- @preserve */
|
|
571
572
|
// Stryker disable next-line all: listReason stops these ops before the lowering
|
|
572
573
|
throw new Unsupported(`the list op "${op}"`);
|
package/src/module.ts
CHANGED
|
@@ -369,8 +369,8 @@ const NEEDS: Readonly<Record<Helper, readonly Helper[]>> = {
|
|
|
369
369
|
const LIST_OPS: ReadonlySet<string> = new Set(["count", "sum", "mean", "min", "max", "any", "all", "none", "first"]);
|
|
370
370
|
const NUMBER_LIST_OPS: ReadonlySet<string> = new Set(["count", "sum", "mean", "min", "max"]);
|
|
371
371
|
const BOOLEAN_LIST_OPS: ReadonlySet<string> = new Set(["any", "all", "none"]);
|
|
372
|
-
/** The list ops that build a list from lists (LIST.BUILD). A module gives a reason for them. */
|
|
373
|
-
const BUILD_OPS: ReadonlySet<string> = new Set(["drop", "append", "flat", "without"]);
|
|
372
|
+
/** The list ops that build a list from lists (LIST.BUILD), and `get` (LIST.GET). A module gives a reason for them. */
|
|
373
|
+
const BUILD_OPS: ReadonlySet<string> = new Set(["drop", "append", "flat", "without", "get"]);
|
|
374
374
|
|
|
375
375
|
/** This function gives the kind of the result of a list op: first gives the kind of its items. */
|
|
376
376
|
const listKind = (op: string, item: Kind | undefined): Kind | undefined => (NUMBER_LIST_OPS.has(op) ? "number" : BOOLEAN_LIST_OPS.has(op) ? "boolean" : item);
|
|
@@ -1196,7 +1196,7 @@ class Printer {
|
|
|
1196
1196
|
const [head] = args;
|
|
1197
1197
|
if (LIST_OPS.has(op) && head?.tag === "each") return this.#list(op, head, args.slice(1), ctx);
|
|
1198
1198
|
if (head !== undefined && (op === "sortBy" || op === "take")) return this.#order(op, head, args.slice(1), ctx);
|
|
1199
|
-
// LIST.BUILD: a module does not have the ops that build a list yet. The interpreter evaluates them.
|
|
1199
|
+
// LIST.BUILD and LIST.GET: a module does not have the ops that build a list, or get, yet. The interpreter evaluates them.
|
|
1200
1200
|
if (head !== undefined && BUILD_OPS.has(op) && this.#isList(head, ctx)) throw new NotStandalone(`the list op "${op}" is not in a module yet`);
|
|
1201
1201
|
if (head !== undefined && (LIST_OPS.has(op) || op === "nth") && this.#isList(head, ctx)) return this.#overList(op, head, args.slice(1), ctx);
|
|
1202
1202
|
const raw = args.map((x) => this.expr(x, ctx));
|