@mark1russell7/vex-compiler 0.17.1 → 0.18.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 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
- - A list value with an error item, because generated code makes no error values.
49
- - A list op on a list value from a binding or a variable. A list op over an axis is one loop in tier 2.
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. On 2026-10-13, the nearest other box was 1.0 to 1.1 times the loops, and the Game of Life was 1.05 to 1.13 times. Tier 1 was 80 and 120 times. The plan of the compiler is in [`docs/COMPILER.md`](https://github.com/mark1russell7/vex/blob/main/docs/COMPILER.md).
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,9 @@
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
- /**
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).
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
- }
1
+ import { a as Schema, i as Options, r as Method } from "./facts-3ZtCfd0v.js";
2
+ import { Addr, AnyDomain, Axis, CompileOptions, Envelope, ErrorText, Expr, FixJoin, FreeFn, PrimitiveKind, Program, Space, VexError } from "@mark1russell7/vex";
34
3
  /** 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";
4
+ type RuntimeFn = "has" | "addr" | "table" | "keys" | "rowIndex" | "rounds" | "step" | "result" | "opts" | "rec" | "list" | "items" | "frozen" | "ext" | "var" | "err" | "raise" | "args" | "bad" | "invalid";
36
5
  /** 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";
6
+ type PrimOp = "+" | "/" | "===" | "!==" | "!" | "||" | "&&" | "min" | "max" | "isNumber" | "isFinite" | "isBoolean" | "isString" | "isValue" | "isObject" | "unless" | "get" | "member" | "records" | "recordAt" | "keysOf" | "idxOf" | "valuesOf" | "memoGet" | "memoPut" | "entryValue" | "entryOk";
38
7
  /** A value of the loop IR. */
39
8
  type LExpr = {
40
9
  readonly t: "const";
@@ -50,6 +19,11 @@ type LExpr = {
50
19
  readonly v: boolean;
51
20
  } | {
52
21
  readonly t: "fallback";
22
+ } | {
23
+ readonly t: "none";
24
+ } | {
25
+ readonly t: "site";
26
+ readonly i: number;
53
27
  } | {
54
28
  readonly t: "array";
55
29
  readonly items: readonly LExpr[];
@@ -74,17 +48,103 @@ type LExpr = {
74
48
  readonly axis: number;
75
49
  readonly args: readonly [LExpr, LExpr, LExpr];
76
50
  };
51
+ /**
52
+ * The site of an error: the facts of the error that the lowering knows (docs/COMPILER.md §4.1). The operands of a
53
+ * failure give the other facts. Each site has the path of its node, and `materialize` of the runtime reads it.
54
+ */
55
+ type ErrorSite = {
56
+ readonly t: "key";
57
+ } | {
58
+ readonly t: "text";
59
+ readonly text: ErrorText;
60
+ readonly path: readonly number[];
61
+ } | {
62
+ readonly t: "call";
63
+ readonly name: string;
64
+ readonly path: readonly number[];
65
+ } | {
66
+ readonly t: "missing";
67
+ readonly where: string;
68
+ readonly path: readonly number[];
69
+ } | {
70
+ readonly t: "boolean";
71
+ readonly op: string;
72
+ readonly i: number;
73
+ readonly path: readonly number[];
74
+ } | {
75
+ readonly t: "items";
76
+ readonly op: string;
77
+ readonly what: "numbers" | "booleans";
78
+ readonly path: readonly number[];
79
+ } | {
80
+ readonly t: "until";
81
+ readonly path: readonly number[];
82
+ } | {
83
+ readonly t: "limit";
84
+ readonly path: readonly number[];
85
+ } | {
86
+ readonly t: "fixLimit";
87
+ readonly name: string;
88
+ readonly path: readonly number[];
89
+ } | {
90
+ readonly t: "row";
91
+ readonly name: string;
92
+ readonly join: FixJoin;
93
+ readonly path: readonly number[];
94
+ } | {
95
+ readonly t: "lastKey";
96
+ readonly name: string;
97
+ readonly path: readonly number[];
98
+ } | {
99
+ readonly t: "rows";
100
+ readonly path: readonly number[];
101
+ } | {
102
+ readonly t: "test";
103
+ readonly path: readonly number[];
104
+ } | {
105
+ readonly t: "listAxis";
106
+ readonly path: readonly number[];
107
+ } | {
108
+ readonly t: "op";
109
+ readonly op: string;
110
+ readonly path: readonly number[];
111
+ } | {
112
+ readonly t: "step";
113
+ readonly path: readonly number[];
114
+ } | {
115
+ readonly t: "ext";
116
+ readonly kind: string;
117
+ readonly path: readonly number[];
118
+ } | {
119
+ readonly t: "addr";
120
+ readonly at: Addr;
121
+ readonly path: readonly number[];
122
+ } | {
123
+ readonly t: "axis";
124
+ readonly axis: Exclude<Axis, {
125
+ readonly t: "where";
126
+ }>;
127
+ readonly path: readonly number[];
128
+ } | {
129
+ readonly t: "args";
130
+ readonly what: string;
131
+ readonly path: readonly number[];
132
+ };
77
133
  /**
78
134
  * What a failed check does. The interpreter gives an error value at the node of the check, and the context of the node
79
135
  * decides what happens to that error:
80
136
  *
81
- * - `return`: the program stops with `FALLBACK`, and tier 1 evaluates it again.
137
+ * - `return`: the program stops with the lazy error of the check.
138
+ * - `stop`: the program stops with `FALLBACK`, and tier 1 evaluates it again. The check has no lazy error.
82
139
  * - `continue`: the item of a list op is an error item. The list op skips it, as the interpreter does. With the option
83
140
  * `strict`, the list op fails instead, and `strict.else` tells what that failure does.
84
- * - `break`: the first argument of `ifError` failed, so the block ends, and the second argument gives the value.
141
+ * - `break`: the block ends. For the first argument of `ifError`, the second argument then gives the value. With `keep`,
142
+ * the local `keep` gets the lazy error, so a later read of it can stop the program.
85
143
  */
86
144
  type Fail = {
87
145
  readonly t: "return";
146
+ } | {
147
+ readonly t: "stop";
88
148
  } | {
89
149
  readonly t: "continue";
90
150
  readonly label: number;
@@ -95,6 +155,7 @@ type Fail = {
95
155
  } | {
96
156
  readonly t: "break";
97
157
  readonly label: number;
158
+ readonly keep?: number;
98
159
  };
99
160
  /** A statement of the loop IR. */
100
161
  type LStmt = {
@@ -110,9 +171,11 @@ type LStmt = {
110
171
  readonly ok: LExpr;
111
172
  readonly reason: string;
112
173
  readonly fail: Fail;
174
+ readonly error?: LExpr;
113
175
  } | {
114
176
  readonly t: "fail";
115
177
  readonly fail: Fail;
178
+ readonly error?: LExpr;
116
179
  } | {
117
180
  readonly t: "if";
118
181
  readonly cond: LExpr;
@@ -130,6 +193,9 @@ type LStmt = {
130
193
  readonly t: "block";
131
194
  readonly label: number;
132
195
  readonly body: readonly LStmt[];
196
+ } | {
197
+ readonly t: "break";
198
+ readonly label: number;
133
199
  } | {
134
200
  readonly t: "repeat";
135
201
  readonly label: number;
@@ -168,7 +234,7 @@ type Generated = {
168
234
  readonly ok: false;
169
235
  readonly reason: string;
170
236
  };
171
- /** A function of tier 2. It gives the value of the program, or `FALLBACK`. */
237
+ /** A function of tier 2. It gives the value of the program, or `FALLBACK` for each other result. */
172
238
  type Tier2 = (space: Space, origin: string, vars: Readonly<Record<string, unknown>> | undefined, tables: Readonly<Record<string, Space>> | undefined) => unknown;
173
239
  /**
174
240
  * This function lowers an expression or a document and prints its source for the options (DOC.ENTRY). The op tables of
@@ -186,7 +252,7 @@ export declare function load(generated: Extract<Generated, {
186
252
  interface TierStats {
187
253
  /** The number of runs. */
188
254
  readonly runs: number;
189
- /** The number of runs where tier 2 gave `FALLBACK`, so tier 1 gave the result. */
255
+ /** 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
256
  readonly fallbacks: number;
191
257
  }
192
258
  /** A program with tiers. It has the interface `Program` of the core, so it can replace a compiled program. */
@@ -198,67 +264,11 @@ interface TieredProgram extends Program {
198
264
  readonly stats: TierStats;
199
265
  }
200
266
  /**
201
- * This function compiles an expression or a document into tier 2 if it can, and else into tier 1 (DOC.ENTRY). After a
202
- * failed check of tier 2, tier 1 does that evaluation again. A run with a trace and `explain` always use tier 1, because
203
- * tier 2 makes no trace.
267
+ * This function compiles an expression or a document into tier 2 if it can, and else into tier 1 (DOC.ENTRY). Tier 2
268
+ * gives a value or an error. When it gives no result, tier 1 does that evaluation again. A run with a trace and
269
+ * `explain` always use tier 1, because tier 2 makes no trace.
204
270
  */
205
271
  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
272
  /** The value of a program that stops at a failed check. */
263
273
  export declare const FALLBACK: unique symbol;
264
274
  type Fallback = typeof FALLBACK;
@@ -284,6 +294,10 @@ interface Targets {
284
294
  readonly keys: readonly string[];
285
295
  readonly idx: readonly (number | undefined)[];
286
296
  }
297
+ /** The targets of the axis `list`: the key, the value and the position of each item, in the order of the loop. */
298
+ interface ListTargets extends Targets {
299
+ readonly values: readonly unknown[];
300
+ }
287
301
  /** An entry of a memo: the value of a node for one space, or no value after an error. */
288
302
  interface MemoEntry {
289
303
  readonly v: unknown;
@@ -297,6 +311,33 @@ interface Memo {
297
311
  get(s: Space, keys: readonly unknown[]): MemoEntry | undefined;
298
312
  put(s: Space, keys: readonly unknown[], v: unknown, ok: boolean): MemoEntry;
299
313
  }
314
+ /**
315
+ * The detail of the failure of an op or of an extension, with the meaning of the two variables of the record:
316
+ * - `threw`: an op threw, and `a` is the thrown value.
317
+ * - `lift`: `fromScalar` threw. `a` is the thrown value, and `b` the name of the domain.
318
+ * - `valid`: a check `valid` threw. `a` is the thrown value, and `b` the name of the domain.
319
+ * - `bad`: a result failed its checks, and `a` is the result.
320
+ * - `param`: an argument has the wrong kind, and `a` is a `ParamFailure`.
321
+ * - `no-op`: no domain and no function has the op. `a` tells if the op has a receiver, and `b` is the receiver.
322
+ * - `no-step`: no domain gives a step of `reduce`, and `a` is the accumulator.
323
+ * - `no-handler`: an extension has no handler.
324
+ * - `foreign`: a handler gave an error, and `a` is the error.
325
+ * - `list`: a list op or `fill` gave an error of its own, and `a` is the error.
326
+ */
327
+ type Detail = "threw" | "lift" | "valid" | "bad" | "param" | "no-op" | "no-step" | "no-handler" | "foreign" | "list";
328
+ /**
329
+ * A failure that the program keeps: its site, its position, its operands and the detail of the runtime. `materialize`
330
+ * makes the error of it only if the error is the result of the program.
331
+ */
332
+ interface LazyError {
333
+ readonly site: ErrorSite;
334
+ readonly origin: string;
335
+ readonly focus: string;
336
+ readonly operands: readonly unknown[];
337
+ readonly detail: Detail;
338
+ readonly a: unknown;
339
+ readonly b: unknown;
340
+ }
300
341
  /** The functions of the runtime. The names are the names of `RuntimeFn` in the loop IR. */
301
342
  interface Runtime {
302
343
  readonly F: Fallback;
@@ -310,6 +351,10 @@ interface Runtime {
310
351
  axis(axis: BaseAxis): (s: Space, origin: string, focus: string) => Targets | Fallback;
311
352
  table(tables: Readonly<Record<string, Space>> | undefined, name: string): unknown;
312
353
  keys(s: Space): readonly string[];
354
+ /** This function gives the index of a key in the keys of a space, or `undefined` for a key outside the space. */
355
+ rowIndex(s: Space, key: string): number | undefined;
356
+ /** This function gives the largest number of rounds of a column of a space (FIX.LIMIT). */
357
+ rounds(s: Space): number;
313
358
  /** This function gives the dispatch of an op name with `arity` arguments. Generated code gets it once, when it loads. */
314
359
  site(name: string, arity: number): Site;
315
360
  /** This function gives a new memo. Generated code gets one for each node of the memo, when it loads. */
@@ -318,16 +363,34 @@ interface Runtime {
318
363
  domain(index: number): AnyDomain | undefined;
319
364
  /** An exception of an op is the error #CALC! of that op, so this function gives `FALLBACK`. A full call stack goes on. */
320
365
  threw(thrown: unknown): Fallback;
366
+ /** This function records a result that failed its checks. It gives `FALLBACK`. */
367
+ bad(value: unknown): Fallback;
368
+ /** This function records an exception of the check `valid` of the domain at an index. It gives `FALLBACK`. */
369
+ invalid(thrown: unknown, domain: number): Fallback;
370
+ /** This function gives the lazy error of a failed check, with the record of the last failure. */
371
+ err(site: ErrorSite, origin: string, focus: string, ...operands: readonly unknown[]): LazyError;
372
+ /** This function gives the lazy error of the arguments that failed, as `#all` of the interpreter: `undefined` for no error. */
373
+ args(site: ErrorSite, origin: string, focus: string, errors: readonly (LazyError | undefined)[]): LazyError | undefined;
374
+ /** This function ends a program with a lazy error. It gives `FALLBACK`, so `load` keeps its contract. */
375
+ raise(error: LazyError): Fallback;
376
+ /** This function gives the error of the last `raise`, once. It gives `undefined` when the run ended in another way. */
377
+ take(): VexError | undefined;
321
378
  step(name: string, acc: unknown, value: unknown): unknown;
322
379
  result(value: unknown): unknown;
323
380
  opts(value: unknown): unknown;
324
381
  rec(names: readonly string[], values: readonly unknown[]): unknown;
325
382
  list(keys: readonly string[], values: readonly unknown[]): unknown;
383
+ /**
384
+ * This function gives the targets of the axis `list` (AXIS.LIST): the keys, the values and the positions of the items.
385
+ * A value that is not a list gives `FALLBACK`, and the site gives the error. Generated code makes no error item, so an
386
+ * error item throws, and tier 1 gives the result.
387
+ */
388
+ items(value: unknown, reverse: boolean): ListTargets | Fallback;
326
389
  frozen(values: readonly unknown[]): unknown;
327
390
  ext(kind: string, data: unknown, s: Space, origin: string, focus: string, path: readonly number[]): unknown;
328
391
  var(vars: Readonly<Record<string, unknown>> | undefined, name: string): unknown;
329
392
  }
330
393
  /** This function makes the runtime of one set of options. */
331
394
  export declare function createRuntime(options: RuntimeOptions): Runtime;
332
- export type { Emitted, Fallback, GenerateOptions, Generated, LExpr, LStmt, ListKind, LoopProgram, ModuleOptions, PrimOp, Runtime, RuntimeFn, RuntimeOptions, Schema, SheetModuleOptions, Tier2, TierStats, TieredProgram };
395
+ export type { ErrorSite, Fail, Fallback, GenerateOptions, Generated, LExpr, LStmt, LazyError, LoopProgram, PrimOp, Runtime, RuntimeFn, RuntimeOptions, Schema, Tier2, TierStats, TieredProgram };
333
396
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/facts.ts","../src/loop.ts","../src/tiers.ts","../src/module.ts","../src/runtime.ts"],"mappings":";;KAqCY,aAAa;;;;;KAMb,OAAO;;;;;;UAaF;WACN,MAAM,OAAO;WACb;;;;;;;UAQM;WACN,SAAS,SAAS,eAAe,OAAO;WACxC,OAAO,SAAS,eAAe;;;UAIzB;WACN,mBAAmB;WACnB,MAAM,SAAS,eAAe;WAC9B,aAAa,SAAS,eAAe;WACrC,SAAS;;;KCzDR;;KAeA;;KA2BA;WACG;WAAqB;;WACrB;WAAqB;;WACrB;WAAmB;;WACnB;WAAoB;;WACpB;;WACA;WAAqB,gBAAgB;;WACrC;WAAoB,IAAI;WAAiB,eAAe;;WACxD;WAAoB,IAAI;WAAoB,eAAe;;WAK3D;WAAkB;WAA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