@mark1russell7/vex-compiler 0.17.2 → 0.19.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/README.md +35 -3
- package/build/facts-3ZtCfd0v.d.ts +37 -0
- package/build/facts-3ZtCfd0v.d.ts.map +1 -0
- package/build/index.d.ts +163 -97
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1168 -4234
- package/build/index.js.map +1 -1
- package/build/memo-J-Km2qc0.js +577 -0
- package/build/memo-J-Km2qc0.js.map +1 -0
- package/build/module-entry.d.ts +105 -0
- package/build/module-entry.d.ts.map +1 -0
- package/build/module-entry.js +7005 -0
- package/build/module-entry.js.map +1 -0
- package/package.json +17 -6
- package/src/facts.ts +52 -41
- package/src/fn-text.ts +58 -0
- package/src/index.ts +2 -3
- package/src/js.ts +59 -33
- package/src/loop.ts +98 -10
- package/src/lower.ts +610 -128
- package/src/memo.ts +215 -94
- package/src/module-entry.ts +7 -0
- package/src/module-tidy.ts +502 -0
- package/src/module.ts +3166 -714
- package/src/runtime.ts +326 -36
- package/src/scope-key.ts +283 -0
- package/src/sheet-order.ts +13 -99
- package/src/tiers.ts +27 -12
- package/src/unshared.ts +125 -0
package/README.md
CHANGED
|
@@ -45,8 +45,8 @@ Property P17 compares `tiered` with `evaluate` on random programs, random spaces
|
|
|
45
45
|
|
|
46
46
|
These cases operate in tier 1:
|
|
47
47
|
|
|
48
|
-
-
|
|
49
|
-
-
|
|
48
|
+
- An `each` with an error item, because generated code makes no error values.
|
|
49
|
+
- `errors` of an array with a hole, and the axis `list` over an error item. A list op on a list value or an array and the axis `list` are in tier 2.
|
|
50
50
|
- An error of an extension, and each exception that is not an error of an op.
|
|
51
51
|
|
|
52
52
|
A program keeps the value of each node that depends only on the space, for each space (COMPILE.MEMO). Thus a run at each key of a space computes such a node once, for example a total of a column. A node that reads the origin only through a few values, its keys, has an entry for each value of its keys (COMPILE.GROUP). Thus "the largest width in the column of the origin" evaluates once for each column. A space does not change, so the values stay correct.
|
|
@@ -69,9 +69,41 @@ The source has no name and no literal of the program. It reads each one from a l
|
|
|
69
69
|
|
|
70
70
|
`tiered`, `generate` and `emitModule` take an expression or a document of coeval, as `toDocument` of `@mark1russell7/vex` gives it.
|
|
71
71
|
|
|
72
|
+
### The options of a module
|
|
73
|
+
|
|
74
|
+
`emitModule` and `emitSheetModule` come from the entry `@mark1russell7/vex-compiler/module`. This entry loads a parser, and the root entry does not. They take these options:
|
|
75
|
+
|
|
76
|
+
| Option | What it does |
|
|
77
|
+
|---|---|
|
|
78
|
+
| `schema` | The kinds of the fields of the records and of the variables. A field can have a `ListKind`. |
|
|
79
|
+
| `domains` | The domains of the ops of the program |
|
|
80
|
+
| `name` | The name of the function of the module. The default is `run`. |
|
|
81
|
+
| `space` | `"array"`, `"tree"` or `"graph"`. The default is `"array"`. |
|
|
82
|
+
| `fuse` | `false` prints the code without the fusion of the list ops. The default is `true`. |
|
|
83
|
+
| `faults` | `throw` lets a fault of the printed code leave the run. An exception of a function of a domain stays an error of Vex. The default is `value`, which gives an error of Vex for each exception. |
|
|
84
|
+
| `lists` | `"envelope"` gives each list of the input and of the result as a `vex.list`. `"plain"` gives plain arrays of the values, with `VEX_ERROR` for an error item. The default is `"envelope"`. |
|
|
85
|
+
| `keys` | `true` makes the run take the keys of its records as its last argument. The default is `false`. |
|
|
86
|
+
|
|
87
|
+
`emitSheetModule` also takes `cells`, `kinds` and `budget`.
|
|
88
|
+
|
|
89
|
+
With `fuse`, a value that does not depend on the key is one `vex.list` at each key, and this object is frozen. Each other `vex.list` of a result is not frozen.
|
|
90
|
+
|
|
91
|
+
With `lists: "plain"`, the key of an item of the input is the text of its position, and the result has no keys. A list in a record or in an argument of an op stays a `vex.list`. The module prints no types, so the host declares `T[]` for a list of `T`.
|
|
92
|
+
|
|
93
|
+
With `keys: true`, the last argument of the run is an array with one different text for each record. `get`, `without`, each `vex.list` and the move `key` use these texts. A program that reads no key of a record keeps its text, so the option costs no bytes there. In an array space, a program that reads a key has no offset and no axis `window`.
|
|
94
|
+
|
|
72
95
|
## Speed
|
|
73
96
|
|
|
74
|
-
The speed gate compares tier 2 with hand-written loops
|
|
97
|
+
The speed gate compares tier 2 with hand-written loops, in 5 CI runs on 2026-10-30. Lower is better.
|
|
98
|
+
|
|
99
|
+
| Program | Tier 2 / loops | Tier 1 / loops |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| The nearest other box, at each of 60 keys | 1.50 to 1.67 | 16.6 to 21.2 |
|
|
102
|
+
| One step of the Game of Life, 16 by 16 | 1.22 to 1.30 | 38.0 to 40.6 |
|
|
103
|
+
| The shapes module of ireko, 1111 nodes | 1.30 to 1.72 | |
|
|
104
|
+
| The radial module of ireko | 2.62 to 3.34 | |
|
|
105
|
+
|
|
106
|
+
`bench/gate.ts` gives the limits and the runs that set them. The plan of the compiler is in [`docs/COMPILER.md`](https://github.com/mark1russell7/vex/blob/main/docs/COMPILER.md).
|
|
75
107
|
|
|
76
108
|
## License
|
|
77
109
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AnyDomain, ExtHandler, FreeFn, PrimitiveKind } from "@mark1russell7/vex";
|
|
2
|
+
/** The function of an op of a domain, or a method. */
|
|
3
|
+
type Method = (...args: unknown[]) => unknown;
|
|
4
|
+
/**
|
|
5
|
+
* The kind of a value that the compiler knows: a primitive type, or `domain:Name`. The second kind is for a value of
|
|
6
|
+
* the domain `Name` without a primitive type (KIND.DOMAIN).
|
|
7
|
+
*/
|
|
8
|
+
type Kind = PrimitiveKind | `domain:${string}`;
|
|
9
|
+
/**
|
|
10
|
+
* The kind of a list: the kind of its items, which can be a list too. A column of lists of a module of a sheet has such a
|
|
11
|
+
* kind (COMPILE.MODULE.SHEET.LIST). With `texts`, a key of an item can be a key of a list literal or of `fill`, not the
|
|
12
|
+
* key of a record. A field of the schema can have such a kind too (COMPILE.MODULE.LIST.INPUT), and a variable of the
|
|
13
|
+
* schema can have it (COMPILE.MODULE.LIST.VAR).
|
|
14
|
+
*/
|
|
15
|
+
interface ListKind {
|
|
16
|
+
readonly list: Kind | ListKind;
|
|
17
|
+
readonly texts?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The kinds that a host declares (docs/COMPILER.md §3.2): the kind of each field of the records, and of each variable of
|
|
21
|
+
* the run. A read of a declared field or variable checks the kind. When the check fails, tier 1 evaluates the program.
|
|
22
|
+
* A field and a variable can hold a list (COMPILE.MODULE.LIST.INPUT, COMPILE.MODULE.LIST.VAR). Tier 2 does not check
|
|
23
|
+
* the kind of such a field or variable.
|
|
24
|
+
*/
|
|
25
|
+
interface Schema {
|
|
26
|
+
readonly fields?: Readonly<Record<string, Kind | ListKind>>;
|
|
27
|
+
readonly vars?: Readonly<Record<string, Kind | ListKind>>;
|
|
28
|
+
}
|
|
29
|
+
/** The options of a program: the domains, the free functions and the extension handlers, and the schema of the host. */
|
|
30
|
+
interface Options {
|
|
31
|
+
readonly domains?: readonly AnyDomain[];
|
|
32
|
+
readonly fns?: Readonly<Record<string, FreeFn>>;
|
|
33
|
+
readonly extensions?: Readonly<Record<string, ExtHandler>>;
|
|
34
|
+
readonly schema?: Schema;
|
|
35
|
+
}
|
|
36
|
+
export { Schema as a, Options as i, ListKind as n, Method as r, Kind as t };
|
|
37
|
+
//# sourceMappingURL=facts-3ZtCfd0v.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"facts-3ZtCfd0v.d.ts","names":[],"sources":["../src/facts.ts"],"mappings":";;KAsBY,aAAa;;;;;KAMb,OAAO;;;;;;;UAcF;WACN,MAAM,OAAO;WACb;;;;;;;;UASM;WACN,SAAS,SAAS,eAAe,OAAO;WACxC,OAAO,SAAS,eAAe,OAAO;;;UAIhC;WACN,mBAAmB;WACnB,MAAM,SAAS,eAAe;WAC9B,aAAa,SAAS,eAAe;WACrC,SAAS"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,40 +1,12 @@
|
|
|
1
|
-
import { Addr, AnyDomain, Axis, CellFormulas, CompileOptions, Envelope, Expr, ExtHandler, FreeFn, PrimitiveKind, Program, Space } from "@mark1russell7/vex";
|
|
2
|
-
/** The function of an op of a domain, or a method. */
|
|
3
|
-
type Method = (...args: unknown[]) => unknown;
|
|
4
1
|
/**
|
|
5
|
-
* The
|
|
6
|
-
* the domain `Name` without a primitive type (KIND.DOMAIN).
|
|
2
|
+
* The Vex compiler (docs/COMPILER.md): generated JavaScript for Vex programs, with the results of the interpreter.
|
|
7
3
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* The kind of a list: the kind of its items, which can be a list too. A column of lists of a module of a sheet has such a
|
|
11
|
-
* kind (COMPILE.MODULE.SHEET.LIST). With `texts`, a key of an item can be a key of a list literal or of `fill`, not the
|
|
12
|
-
* key of a record. A field of the schema can have such a kind too (COMPILE.MODULE.LIST.INPUT).
|
|
13
|
-
*/
|
|
14
|
-
interface ListKind {
|
|
15
|
-
readonly list: Kind | ListKind;
|
|
16
|
-
readonly texts?: boolean;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* The kinds that a host declares (docs/COMPILER.md §3.2): the kind of each field of the records, and of each variable of
|
|
20
|
-
* the run. A read of a declared field or variable checks the kind. When the check fails, tier 1 evaluates the program.
|
|
21
|
-
* A field can hold a list (COMPILE.MODULE.LIST.INPUT). Tier 2 does not check the kind of such a field.
|
|
22
|
-
*/
|
|
23
|
-
interface Schema {
|
|
24
|
-
readonly fields?: Readonly<Record<string, Kind | ListKind>>;
|
|
25
|
-
readonly vars?: Readonly<Record<string, Kind>>;
|
|
26
|
-
}
|
|
27
|
-
/** The options of a program: the domains, the free functions and the extension handlers, and the schema of the host. */
|
|
28
|
-
interface Options {
|
|
29
|
-
readonly domains?: readonly AnyDomain[];
|
|
30
|
-
readonly fns?: Readonly<Record<string, FreeFn>>;
|
|
31
|
-
readonly extensions?: Readonly<Record<string, ExtHandler>>;
|
|
32
|
-
readonly schema?: Schema;
|
|
33
|
-
}
|
|
4
|
+
import { a as Schema, i as Options, r as Method } from "./facts-3ZtCfd0v.js";
|
|
5
|
+
import { Addr, AnyDomain, Axis, CompileOptions, Envelope, ErrorText, Expr, FixJoin, FreeFn, PrimitiveKind, Program, Space, VexError } from "@mark1russell7/vex";
|
|
34
6
|
/** The functions of the runtime that generated code calls. Each one gives `FALLBACK` for a value it cannot give. */
|
|
35
|
-
type RuntimeFn = "has" | "addr" | "table" | "keys" | "step" | "result" | "opts" | "rec" | "list" | "frozen" | "ext" | "var";
|
|
7
|
+
type RuntimeFn = "has" | "addr" | "table" | "keys" | "rowIndex" | "rounds" | "step" | "result" | "opts" | "rec" | "list" | "items" | "frozen" | "ext" | "var" | "err" | "raise" | "args" | "bad" | "invalid";
|
|
36
8
|
/** The primitive operations of the loop IR. They copy no arithmetic of a domain (§4.2). */
|
|
37
|
-
type PrimOp = "+" | "/" | "===" | "!==" | "!" | "||" | "&&" | "min" | "max" | "isNumber" | "isBoolean" | "isString" | "isValue" | "isObject" | "get" | "member" | "records" | "recordAt" | "keysOf" | "idxOf" | "memoGet" | "memoPut" | "entryValue" | "entryOk";
|
|
9
|
+
type PrimOp = "+" | "/" | "===" | "!==" | "!" | "||" | "&&" | "min" | "max" | "isNumber" | "isFinite" | "isBoolean" | "isString" | "isValue" | "isObject" | "unless" | "get" | "member" | "records" | "recordAt" | "keysOf" | "idxOf" | "valuesOf" | "memoGet" | "memoPut" | "entryValue" | "entryOk";
|
|
38
10
|
/** A value of the loop IR. */
|
|
39
11
|
type LExpr = {
|
|
40
12
|
readonly t: "const";
|
|
@@ -50,6 +22,11 @@ type LExpr = {
|
|
|
50
22
|
readonly v: boolean;
|
|
51
23
|
} | {
|
|
52
24
|
readonly t: "fallback";
|
|
25
|
+
} | {
|
|
26
|
+
readonly t: "none";
|
|
27
|
+
} | {
|
|
28
|
+
readonly t: "site";
|
|
29
|
+
readonly i: number;
|
|
53
30
|
} | {
|
|
54
31
|
readonly t: "array";
|
|
55
32
|
readonly items: readonly LExpr[];
|
|
@@ -74,17 +51,103 @@ type LExpr = {
|
|
|
74
51
|
readonly axis: number;
|
|
75
52
|
readonly args: readonly [LExpr, LExpr, LExpr];
|
|
76
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* The site of an error: the facts of the error that the lowering knows (docs/COMPILER.md §4.1). The operands of a
|
|
56
|
+
* failure give the other facts. Each site has the path of its node, and `materialize` of the runtime reads it.
|
|
57
|
+
*/
|
|
58
|
+
type ErrorSite = {
|
|
59
|
+
readonly t: "key";
|
|
60
|
+
} | {
|
|
61
|
+
readonly t: "text";
|
|
62
|
+
readonly text: ErrorText;
|
|
63
|
+
readonly path: readonly number[];
|
|
64
|
+
} | {
|
|
65
|
+
readonly t: "call";
|
|
66
|
+
readonly name: string;
|
|
67
|
+
readonly path: readonly number[];
|
|
68
|
+
} | {
|
|
69
|
+
readonly t: "missing";
|
|
70
|
+
readonly where: string;
|
|
71
|
+
readonly path: readonly number[];
|
|
72
|
+
} | {
|
|
73
|
+
readonly t: "boolean";
|
|
74
|
+
readonly op: string;
|
|
75
|
+
readonly i: number;
|
|
76
|
+
readonly path: readonly number[];
|
|
77
|
+
} | {
|
|
78
|
+
readonly t: "items";
|
|
79
|
+
readonly op: string;
|
|
80
|
+
readonly what: "numbers" | "booleans";
|
|
81
|
+
readonly path: readonly number[];
|
|
82
|
+
} | {
|
|
83
|
+
readonly t: "until";
|
|
84
|
+
readonly path: readonly number[];
|
|
85
|
+
} | {
|
|
86
|
+
readonly t: "limit";
|
|
87
|
+
readonly path: readonly number[];
|
|
88
|
+
} | {
|
|
89
|
+
readonly t: "fixLimit";
|
|
90
|
+
readonly name: string;
|
|
91
|
+
readonly path: readonly number[];
|
|
92
|
+
} | {
|
|
93
|
+
readonly t: "row";
|
|
94
|
+
readonly name: string;
|
|
95
|
+
readonly join: FixJoin;
|
|
96
|
+
readonly path: readonly number[];
|
|
97
|
+
} | {
|
|
98
|
+
readonly t: "lastKey";
|
|
99
|
+
readonly name: string;
|
|
100
|
+
readonly path: readonly number[];
|
|
101
|
+
} | {
|
|
102
|
+
readonly t: "rows";
|
|
103
|
+
readonly path: readonly number[];
|
|
104
|
+
} | {
|
|
105
|
+
readonly t: "test";
|
|
106
|
+
readonly path: readonly number[];
|
|
107
|
+
} | {
|
|
108
|
+
readonly t: "listAxis";
|
|
109
|
+
readonly path: readonly number[];
|
|
110
|
+
} | {
|
|
111
|
+
readonly t: "op";
|
|
112
|
+
readonly op: string;
|
|
113
|
+
readonly path: readonly number[];
|
|
114
|
+
} | {
|
|
115
|
+
readonly t: "step";
|
|
116
|
+
readonly path: readonly number[];
|
|
117
|
+
} | {
|
|
118
|
+
readonly t: "ext";
|
|
119
|
+
readonly kind: string;
|
|
120
|
+
readonly path: readonly number[];
|
|
121
|
+
} | {
|
|
122
|
+
readonly t: "addr";
|
|
123
|
+
readonly at: Addr;
|
|
124
|
+
readonly path: readonly number[];
|
|
125
|
+
} | {
|
|
126
|
+
readonly t: "axis";
|
|
127
|
+
readonly axis: Exclude<Axis, {
|
|
128
|
+
readonly t: "where";
|
|
129
|
+
}>;
|
|
130
|
+
readonly path: readonly number[];
|
|
131
|
+
} | {
|
|
132
|
+
readonly t: "args";
|
|
133
|
+
readonly what: string;
|
|
134
|
+
readonly path: readonly number[];
|
|
135
|
+
};
|
|
77
136
|
/**
|
|
78
137
|
* What a failed check does. The interpreter gives an error value at the node of the check, and the context of the node
|
|
79
138
|
* decides what happens to that error:
|
|
80
139
|
*
|
|
81
|
-
* - `return`: the program stops with
|
|
140
|
+
* - `return`: the program stops with the lazy error of the check.
|
|
141
|
+
* - `stop`: the program stops with `FALLBACK`, and tier 1 evaluates it again. The check has no lazy error.
|
|
82
142
|
* - `continue`: the item of a list op is an error item. The list op skips it, as the interpreter does. With the option
|
|
83
143
|
* `strict`, the list op fails instead, and `strict.else` tells what that failure does.
|
|
84
|
-
* - `break`: the first argument of `ifError
|
|
144
|
+
* - `break`: the block ends. For the first argument of `ifError`, the second argument then gives the value. With `keep`,
|
|
145
|
+
* the local `keep` gets the lazy error, so a later read of it can stop the program.
|
|
85
146
|
*/
|
|
86
147
|
type Fail = {
|
|
87
148
|
readonly t: "return";
|
|
149
|
+
} | {
|
|
150
|
+
readonly t: "stop";
|
|
88
151
|
} | {
|
|
89
152
|
readonly t: "continue";
|
|
90
153
|
readonly label: number;
|
|
@@ -95,6 +158,7 @@ type Fail = {
|
|
|
95
158
|
} | {
|
|
96
159
|
readonly t: "break";
|
|
97
160
|
readonly label: number;
|
|
161
|
+
readonly keep?: number;
|
|
98
162
|
};
|
|
99
163
|
/** A statement of the loop IR. */
|
|
100
164
|
type LStmt = {
|
|
@@ -110,9 +174,11 @@ type LStmt = {
|
|
|
110
174
|
readonly ok: LExpr;
|
|
111
175
|
readonly reason: string;
|
|
112
176
|
readonly fail: Fail;
|
|
177
|
+
readonly error?: LExpr;
|
|
113
178
|
} | {
|
|
114
179
|
readonly t: "fail";
|
|
115
180
|
readonly fail: Fail;
|
|
181
|
+
readonly error?: LExpr;
|
|
116
182
|
} | {
|
|
117
183
|
readonly t: "if";
|
|
118
184
|
readonly cond: LExpr;
|
|
@@ -130,6 +196,9 @@ type LStmt = {
|
|
|
130
196
|
readonly t: "block";
|
|
131
197
|
readonly label: number;
|
|
132
198
|
readonly body: readonly LStmt[];
|
|
199
|
+
} | {
|
|
200
|
+
readonly t: "break";
|
|
201
|
+
readonly label: number;
|
|
133
202
|
} | {
|
|
134
203
|
readonly t: "repeat";
|
|
135
204
|
readonly label: number;
|
|
@@ -168,7 +237,7 @@ type Generated = {
|
|
|
168
237
|
readonly ok: false;
|
|
169
238
|
readonly reason: string;
|
|
170
239
|
};
|
|
171
|
-
/** A function of tier 2. It gives the value of the program, or `FALLBACK
|
|
240
|
+
/** A function of tier 2. It gives the value of the program, or `FALLBACK` for each other result. */
|
|
172
241
|
type Tier2 = (space: Space, origin: string, vars: Readonly<Record<string, unknown>> | undefined, tables: Readonly<Record<string, Space>> | undefined) => unknown;
|
|
173
242
|
/**
|
|
174
243
|
* This function lowers an expression or a document and prints its source for the options (DOC.ENTRY). The op tables of
|
|
@@ -186,7 +255,7 @@ export declare function load(generated: Extract<Generated, {
|
|
|
186
255
|
interface TierStats {
|
|
187
256
|
/** The number of runs. */
|
|
188
257
|
readonly runs: number;
|
|
189
|
-
/** The number of runs where tier 2 gave
|
|
258
|
+
/** The number of runs where tier 2 gave no result, so tier 1 gave it. A run that tier 2 ends with an error is no fallback. */
|
|
190
259
|
readonly fallbacks: number;
|
|
191
260
|
}
|
|
192
261
|
/** A program with tiers. It has the interface `Program` of the core, so it can replace a compiled program. */
|
|
@@ -198,67 +267,11 @@ interface TieredProgram extends Program {
|
|
|
198
267
|
readonly stats: TierStats;
|
|
199
268
|
}
|
|
200
269
|
/**
|
|
201
|
-
* This function compiles an expression or a document into tier 2 if it can, and else into tier 1 (DOC.ENTRY).
|
|
202
|
-
*
|
|
203
|
-
* tier 2 makes no trace.
|
|
270
|
+
* This function compiles an expression or a document into tier 2 if it can, and else into tier 1 (DOC.ENTRY). Tier 2
|
|
271
|
+
* gives a value or an error. When it gives no result, tier 1 does that evaluation again. A run with a trace and
|
|
272
|
+
* `explain` always use tier 1, because tier 2 makes no trace.
|
|
204
273
|
*/
|
|
205
274
|
export declare function tiered(source: Expr | Envelope, options?: GenerateOptions): TieredProgram;
|
|
206
|
-
/** The options of a standalone module. */
|
|
207
|
-
interface ModuleOptions {
|
|
208
|
-
readonly domains?: readonly AnyDomain[];
|
|
209
|
-
/** The kinds of the fields of the records and of the variables. A module reads only the names of its schema. */
|
|
210
|
-
readonly schema: Schema;
|
|
211
|
-
/**
|
|
212
|
-
* The name of the function that the module exports. The default is `run`. A reserved word, a name that the module
|
|
213
|
-
* declares and a global that a module reads (`MODULE_GLOBALS`) are not names of the run (V-060).
|
|
214
|
-
*/
|
|
215
|
-
readonly name?: string;
|
|
216
|
-
/**
|
|
217
|
-
* The space of the records. In each space, the key of a record is the text of its position. The default `array`
|
|
218
|
-
* has no parents. A `tree` takes the parents as the third argument of the run (COMPILE.MODULE.TREE). Each entry
|
|
219
|
-
* is the position of the parent of its record, or -1 for a root. A `graph` takes the edges as the third argument
|
|
220
|
-
* (COMPILE.MODULE.GRAPH). Each entry is an array of the positions of the ends of the edges from its record, in order.
|
|
221
|
-
*/
|
|
222
|
-
readonly space?: "array" | "tree" | "graph";
|
|
223
|
-
}
|
|
224
|
-
/** The options of a module of a sheet (COMPILE.MODULE.SHEET): the options of a module, and the parts of a sheet. */
|
|
225
|
-
interface SheetModuleOptions extends ModuleOptions {
|
|
226
|
-
/** The cells with their own formula (SHEET.CELL.FORMULA). The formula of a cell replaces the formula of its column at its key. */
|
|
227
|
-
readonly cells?: CellFormulas;
|
|
228
|
-
/**
|
|
229
|
-
* The kind of the values of each column. The printer prints each column after the columns that it reads. A column
|
|
230
|
-
* that a formula reads before its own formula prints needs its kind here, for example a column that reads itself.
|
|
231
|
-
* A column of lists has a `ListKind` (COMPILE.MODULE.SHEET.LIST).
|
|
232
|
-
*/
|
|
233
|
-
readonly kinds?: Readonly<Record<string, Kind | ListKind>>;
|
|
234
|
-
/** The budget of the stack of the search of a run, in estimated frames, as in `SheetRun`. The default is 3000. */
|
|
235
|
-
readonly budget?: number;
|
|
236
|
-
}
|
|
237
|
-
/** The source of a standalone module, or the reason that the program cannot be one. */
|
|
238
|
-
type Emitted = {
|
|
239
|
-
readonly ok: true;
|
|
240
|
-
readonly source: string;
|
|
241
|
-
} | {
|
|
242
|
-
readonly ok: false;
|
|
243
|
-
readonly reason: string;
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* This function prints a program as a standalone ES module. The module exports `VexContractError`, `VEX_ERROR` and a
|
|
247
|
-
* function that takes the records and the variables and gives the value at each key. A module of a tree space takes
|
|
248
|
-
* the parents too. The function is pure, so a build can use it. The program can be an expression or a document
|
|
249
|
-
* (DOC.ENTRY).
|
|
250
|
-
*/
|
|
251
|
-
export declare function emitModule(source: Expr | Envelope, options: ModuleOptions): Emitted;
|
|
252
|
-
/**
|
|
253
|
-
* This function prints the formula columns of a sheet as a standalone ES module (COMPILE.MODULE.SHEET). The function of
|
|
254
|
-
* the module takes the records and the variables, and the parents for a tree. It gives an object with an array for
|
|
255
|
-
* each column: the result of the column at each key, or `VEX_ERROR`. The results are the results of `SheetRun`.
|
|
256
|
-
*
|
|
257
|
-
* The run fills the columns in the order of `SheetRun.fill`. A read of a finished cell is the read of an array. A read
|
|
258
|
-
* of a cell that is not finished starts the search of `SheetRun`, with the same budget of the stack. Each cell on a
|
|
259
|
-
* cycle of reads gives `VEX_ERROR`.
|
|
260
|
-
*/
|
|
261
|
-
export declare function emitSheetModule(columns: ReadonlyMap<string, Expr>, options: SheetModuleOptions): Emitted;
|
|
262
275
|
/** The value of a program that stops at a failed check. */
|
|
263
276
|
export declare const FALLBACK: unique symbol;
|
|
264
277
|
type Fallback = typeof FALLBACK;
|
|
@@ -284,6 +297,10 @@ interface Targets {
|
|
|
284
297
|
readonly keys: readonly string[];
|
|
285
298
|
readonly idx: readonly (number | undefined)[];
|
|
286
299
|
}
|
|
300
|
+
/** The targets of the axis `list`: the key, the value and the position of each item, in the order of the loop. */
|
|
301
|
+
interface ListTargets extends Targets {
|
|
302
|
+
readonly values: readonly unknown[];
|
|
303
|
+
}
|
|
287
304
|
/** An entry of a memo: the value of a node for one space, or no value after an error. */
|
|
288
305
|
interface MemoEntry {
|
|
289
306
|
readonly v: unknown;
|
|
@@ -297,6 +314,33 @@ interface Memo {
|
|
|
297
314
|
get(s: Space, keys: readonly unknown[]): MemoEntry | undefined;
|
|
298
315
|
put(s: Space, keys: readonly unknown[], v: unknown, ok: boolean): MemoEntry;
|
|
299
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* The detail of the failure of an op or of an extension, with the meaning of the two variables of the record:
|
|
319
|
+
* - `threw`: an op threw, and `a` is the thrown value.
|
|
320
|
+
* - `lift`: `fromScalar` threw. `a` is the thrown value, and `b` the name of the domain.
|
|
321
|
+
* - `valid`: a check `valid` threw. `a` is the thrown value, and `b` the name of the domain.
|
|
322
|
+
* - `bad`: a result failed its checks, and `a` is the result.
|
|
323
|
+
* - `param`: an argument has the wrong kind, and `a` is a `ParamFailure`.
|
|
324
|
+
* - `no-op`: no domain and no function has the op. `a` tells if the op has a receiver, and `b` is the receiver.
|
|
325
|
+
* - `no-step`: no domain gives a step of `reduce`, and `a` is the accumulator.
|
|
326
|
+
* - `no-handler`: an extension has no handler.
|
|
327
|
+
* - `foreign`: a handler gave an error, and `a` is the error.
|
|
328
|
+
* - `list`: a list op or `fill` gave an error of its own, and `a` is the error.
|
|
329
|
+
*/
|
|
330
|
+
type Detail = "threw" | "lift" | "valid" | "bad" | "param" | "no-op" | "no-step" | "no-handler" | "foreign" | "list";
|
|
331
|
+
/**
|
|
332
|
+
* A failure that the program keeps: its site, its position, its operands and the detail of the runtime. `materialize`
|
|
333
|
+
* makes the error of it only if the error is the result of the program.
|
|
334
|
+
*/
|
|
335
|
+
interface LazyError {
|
|
336
|
+
readonly site: ErrorSite;
|
|
337
|
+
readonly origin: string;
|
|
338
|
+
readonly focus: string;
|
|
339
|
+
readonly operands: readonly unknown[];
|
|
340
|
+
readonly detail: Detail;
|
|
341
|
+
readonly a: unknown;
|
|
342
|
+
readonly b: unknown;
|
|
343
|
+
}
|
|
300
344
|
/** The functions of the runtime. The names are the names of `RuntimeFn` in the loop IR. */
|
|
301
345
|
interface Runtime {
|
|
302
346
|
readonly F: Fallback;
|
|
@@ -310,6 +354,10 @@ interface Runtime {
|
|
|
310
354
|
axis(axis: BaseAxis): (s: Space, origin: string, focus: string) => Targets | Fallback;
|
|
311
355
|
table(tables: Readonly<Record<string, Space>> | undefined, name: string): unknown;
|
|
312
356
|
keys(s: Space): readonly string[];
|
|
357
|
+
/** This function gives the index of a key in the keys of a space, or `undefined` for a key outside the space. */
|
|
358
|
+
rowIndex(s: Space, key: string): number | undefined;
|
|
359
|
+
/** This function gives the largest number of rounds of a column of a space (FIX.LIMIT). */
|
|
360
|
+
rounds(s: Space): number;
|
|
313
361
|
/** This function gives the dispatch of an op name with `arity` arguments. Generated code gets it once, when it loads. */
|
|
314
362
|
site(name: string, arity: number): Site;
|
|
315
363
|
/** This function gives a new memo. Generated code gets one for each node of the memo, when it loads. */
|
|
@@ -318,16 +366,34 @@ interface Runtime {
|
|
|
318
366
|
domain(index: number): AnyDomain | undefined;
|
|
319
367
|
/** An exception of an op is the error #CALC! of that op, so this function gives `FALLBACK`. A full call stack goes on. */
|
|
320
368
|
threw(thrown: unknown): Fallback;
|
|
369
|
+
/** This function records a result that failed its checks. It gives `FALLBACK`. */
|
|
370
|
+
bad(value: unknown): Fallback;
|
|
371
|
+
/** This function records an exception of the check `valid` of the domain at an index. It gives `FALLBACK`. */
|
|
372
|
+
invalid(thrown: unknown, domain: number): Fallback;
|
|
373
|
+
/** This function gives the lazy error of a failed check, with the record of the last failure. */
|
|
374
|
+
err(site: ErrorSite, origin: string, focus: string, ...operands: readonly unknown[]): LazyError;
|
|
375
|
+
/** This function gives the lazy error of the arguments that failed, as `#all` of the interpreter: `undefined` for no error. */
|
|
376
|
+
args(site: ErrorSite, origin: string, focus: string, errors: readonly (LazyError | undefined)[]): LazyError | undefined;
|
|
377
|
+
/** This function ends a program with a lazy error. It gives `FALLBACK`, so `load` keeps its contract. */
|
|
378
|
+
raise(error: LazyError): Fallback;
|
|
379
|
+
/** This function gives the error of the last `raise`, once. It gives `undefined` when the run ended in another way. */
|
|
380
|
+
take(): VexError | undefined;
|
|
321
381
|
step(name: string, acc: unknown, value: unknown): unknown;
|
|
322
382
|
result(value: unknown): unknown;
|
|
323
383
|
opts(value: unknown): unknown;
|
|
324
384
|
rec(names: readonly string[], values: readonly unknown[]): unknown;
|
|
325
385
|
list(keys: readonly string[], values: readonly unknown[]): unknown;
|
|
386
|
+
/**
|
|
387
|
+
* This function gives the targets of the axis `list` (AXIS.LIST): the keys, the values and the positions of the items.
|
|
388
|
+
* A value that is not a list gives `FALLBACK`, and the site gives the error. Generated code makes no error item, so an
|
|
389
|
+
* error item throws, and tier 1 gives the result.
|
|
390
|
+
*/
|
|
391
|
+
items(value: unknown, reverse: boolean): ListTargets | Fallback;
|
|
326
392
|
frozen(values: readonly unknown[]): unknown;
|
|
327
393
|
ext(kind: string, data: unknown, s: Space, origin: string, focus: string, path: readonly number[]): unknown;
|
|
328
394
|
var(vars: Readonly<Record<string, unknown>> | undefined, name: string): unknown;
|
|
329
395
|
}
|
|
330
396
|
/** This function makes the runtime of one set of options. */
|
|
331
397
|
export declare function createRuntime(options: RuntimeOptions): Runtime;
|
|
332
|
-
export type {
|
|
398
|
+
export type { ErrorSite, Fail, Fallback, GenerateOptions, Generated, LExpr, LStmt, LazyError, LoopProgram, PrimOp, Runtime, RuntimeFn, RuntimeOptions, Schema, Tier2, TierStats, TieredProgram };
|
|
333
399
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/loop.ts","../src/tiers.ts","../src/runtime.ts"],"mappings":";;;;;;KAoBY;;KAuBA;;KA8BA;WACG;WAAqB;;WACrB;WAAqB;;WACrB;WAAmB;;WACnB;WAAoB;;WACpB;;WAEA;;WAEA;WAAoB;;WACpB;WAAqB,gBAAgB;;WACrC;WAAoB,IAAI;WAAiB,eAAe;;WACxD;WAAoB,IAAI;WAAoB,eAAe;;WAK3D;WAAkB;WAAuB,eAAe;WAAkB,iBAAiB;;WAE3F;WAAoB;;WAEpB;WAAuB;WAAuB,gBAAgB,OAAO,OAAO;;;;;;KAM/E;WAEG;;WAEA;WAAoB,MAAM;WAAoB;;WAE9C;WAAoB;WAAuB;;WAE3C;WAAuB;WAAwB;;WAE/C;WAAuB;WAAqB;WAAoB;;WAEhE;WAAqB;WAAqB;WAAuC;;WAEjF;WAAqB;;WAErB;WAAqB;;WAErB;WAAwB;WAAuB;;WAE/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