@mark1russell7/vex 0.20.0 → 0.20.2
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 +23 -1
- package/build/index.d.ts +2 -536
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -6585
- package/build/index.js.map +1 -1
- package/build/ir-Bqheqnw2.d.ts +537 -0
- package/build/ir-Bqheqnw2.d.ts.map +1 -0
- package/build/json-jnuvuBtf.js +6588 -0
- package/build/json-jnuvuBtf.js.map +1 -0
- package/build/query.d.ts +172 -0
- package/build/query.d.ts.map +1 -0
- package/build/query.js +333 -0
- package/build/query.js.map +1 -0
- package/package.json +6 -2
- package/src/query.ts +445 -0
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domains. A domain tells which values belong to it and which ops it has. The domain object owns this data.
|
|
3
|
+
* Vex does not write to the prototypes of domain classes, and an import has no side effects.
|
|
4
|
+
*/
|
|
5
|
+
/** An algebraic law that an op claims. `@mark1russell7/vex-testkit` checks each claim with property tests. */
|
|
6
|
+
type Law = "commutative" | "associative" | "idempotent";
|
|
7
|
+
/** The kind of a parameter. The interpreter checks the arguments of an op that declares its parameters. */
|
|
8
|
+
type ParamKind = "domain" | "number" | "boolean" | "string" | "any";
|
|
9
|
+
/**
|
|
10
|
+
* The kind of the result of an op. It is a kind of a parameter, or `domain:Name` for a value of the domain `Name`. It is
|
|
11
|
+
* `list:Kind` for a `vex.list` with items of a primitive type.
|
|
12
|
+
*/
|
|
13
|
+
type ReturnKind = ParamKind | `domain:${string}` | `list:${PrimitiveKind}`;
|
|
14
|
+
/**
|
|
15
|
+
* How the size of one argument adds to the size of the result of an op (LOOP.SIZE.OPS). The size of a value counts the
|
|
16
|
+
* texts, the fields, the keys and the items in it.
|
|
17
|
+
*
|
|
18
|
+
* - `0`: the argument does not add to the size.
|
|
19
|
+
* - `1`: the size of the argument adds one time.
|
|
20
|
+
* - `"scaled"`: the size of the argument adds a fixed number of times, for example two times.
|
|
21
|
+
* - `"many"`: the size of the argument adds more than one time.
|
|
22
|
+
* - `"unbounded"`: the size of the result has no bound in the size of the argument.
|
|
23
|
+
* - `"text"`: the size adds one time for a text, and a fixed number of times for another value, as its JSON text.
|
|
24
|
+
* - `"copies"`: the size adds one time for each copy. The first argument is the number of the copies.
|
|
25
|
+
* - `"each"`: the size adds one time for each item of the first argument.
|
|
26
|
+
* - `"number"`: the argument is a number that sets a count. A literal number gives that count, and another number
|
|
27
|
+
* gives a fixed bound.
|
|
28
|
+
* - `"limit"`: the size adds one time for each item that the literal number at the position `limit` keeps. Each item
|
|
29
|
+
* adds a key with a fixed bound. Without a literal number, this use is the same as `"many"`.
|
|
30
|
+
*/
|
|
31
|
+
type SizeUse = 0 | 1 | "scaled" | "many" | "unbounded" | "text" | "copies" | "each" | "number" | "limit";
|
|
32
|
+
/**
|
|
33
|
+
* A measure of a value for the check of sizes (LOOP.SIZE.OPS). `size` is the size of the value, and `count` is the
|
|
34
|
+
* number of its items. `inner` is the sum of the counts of the values of its items. `item` is the size of its largest
|
|
35
|
+
* item. The items of a record are its fields, and a text is its own item. `part` is the largest `item` of its items. It is
|
|
36
|
+
* not larger than `item`.
|
|
37
|
+
*/
|
|
38
|
+
type SizeMeasure = "size" | "count" | "inner" | "item" | "part";
|
|
39
|
+
/** One term of a size rule: a use of the same measure of the argument, or a use of the measure that the pair names. */
|
|
40
|
+
type SizeTerm = SizeUse | readonly [use: SizeUse, of: SizeMeasure];
|
|
41
|
+
/**
|
|
42
|
+
* The size rule of an op: how the measures of its result follow from its arguments (LOOP.SIZE.OPS). The check of sizes
|
|
43
|
+
* reads it in the steps of `fold` and `iterate` (LOOP.SIZE).
|
|
44
|
+
*
|
|
45
|
+
* - `"scalar"`: the result is a number or a boolean.
|
|
46
|
+
* - `"fixed"`: the result has a size with a fixed bound, for example a 2D vector.
|
|
47
|
+
* - `"reduce"`: the rule of the list op `reduce`. The op that its second argument names gives the size.
|
|
48
|
+
* - A record: `SizeTerms`.
|
|
49
|
+
*/
|
|
50
|
+
type SizeRule = "scalar" | "fixed" | "reduce" | SizeTerms;
|
|
51
|
+
/**
|
|
52
|
+
* The size rule of an op as data (LOOP.SIZE.OPS). `size`, `count`, `inner`, `item` and `part` have one term for each
|
|
53
|
+
* argument. `rest` is the use of the arguments after them, and its default is `"many"`. Without `count`, `inner` or `item`,
|
|
54
|
+
* that measure of the result is its size. Without `part`, the largest part of the result is its largest item. The terms of
|
|
55
|
+
* `item` and `part` give the largest bound of the arguments, because the largest item comes from one argument. A literal
|
|
56
|
+
* number at the position `limit` sets the count. With `keys: "position"`, the items get their positions as new keys. With
|
|
57
|
+
* `constant: true`, the result can also hold a part with a fixed size. With `union: true`, the result holds each key of
|
|
58
|
+
* its arguments one time, so the bound of the result is the largest bound of the arguments.
|
|
59
|
+
*
|
|
60
|
+
* `byParts` is a second rule for a result that is a part of an argument, or that holds a fixed number of its items. The
|
|
61
|
+
* second reading of the check uses this rule (LOOP.SIZE.READINGS). A rule with `limit` keeps the first rule when the limit
|
|
62
|
+
* is not a literal number or when a key can be long.
|
|
63
|
+
*/
|
|
64
|
+
interface SizeTerms {
|
|
65
|
+
readonly size: readonly SizeTerm[];
|
|
66
|
+
readonly count?: readonly SizeTerm[];
|
|
67
|
+
readonly inner?: readonly SizeTerm[];
|
|
68
|
+
readonly item?: readonly SizeTerm[];
|
|
69
|
+
readonly part?: readonly SizeTerm[];
|
|
70
|
+
readonly rest?: SizeUse;
|
|
71
|
+
readonly limit?: number;
|
|
72
|
+
readonly keys?: "position";
|
|
73
|
+
readonly constant?: true;
|
|
74
|
+
readonly union?: true;
|
|
75
|
+
readonly byParts?: SizeTerms;
|
|
76
|
+
}
|
|
77
|
+
/** The description of one op of a domain. */
|
|
78
|
+
interface OpSpec<D = never> {
|
|
79
|
+
/**
|
|
80
|
+
* The implementation, for an op that is not a method of the value (static-land style). The first argument
|
|
81
|
+
* is the receiver. Without `fn`, the interpreter calls the method of the receiver with the same name.
|
|
82
|
+
*/
|
|
83
|
+
readonly fn?: (self: D, ...args: never[]) => unknown;
|
|
84
|
+
/** The laws that the op claims. */
|
|
85
|
+
readonly laws?: readonly Law[];
|
|
86
|
+
/** The identity element of the op, for reductions over an empty list. */
|
|
87
|
+
readonly identity?: () => D;
|
|
88
|
+
/** Scalar lifting: `true` lifts each number argument with `fromScalar`. An array sets it for each argument. */
|
|
89
|
+
readonly liftScalar?: boolean | readonly boolean[];
|
|
90
|
+
/** The kinds of the parameters after the receiver. When set, the interpreter checks the arguments. */
|
|
91
|
+
readonly params?: readonly ParamKind[];
|
|
92
|
+
/**
|
|
93
|
+
* The kind of the result. It is `domain` for a value of this domain, or `domain:Name` for a value of the domain `Name`.
|
|
94
|
+
* It is `list:Kind` for a `vex.list` with items of that primitive type (KIND.RETURNS.LIST). A compiler reads it to know
|
|
95
|
+
* the kinds of the values of a program (KIND.RETURNS). The interpreter does not check it, and the law checker of the
|
|
96
|
+
* test kit does.
|
|
97
|
+
*/
|
|
98
|
+
readonly returns?: ReturnKind;
|
|
99
|
+
/**
|
|
100
|
+
* The size rule of the op (LOOP.SIZE.OPS). Without it, an op whose result is a number or a boolean has the rule
|
|
101
|
+
* `"scalar"`. An op of a domain with `size: "fixed"` has the rule `"fixed"`. Another op has no rule, so a step of a
|
|
102
|
+
* loop cannot use its result in the size of a list name (LOOP.SIZE).
|
|
103
|
+
*/
|
|
104
|
+
readonly size?: SizeRule;
|
|
105
|
+
/**
|
|
106
|
+
* This field gives the direction of the result of the op for each argument, with the receiver first (FIX.OPS). `up`
|
|
107
|
+
* means that the result does not fall as the argument rises. `down` means that the result does not rise. An op without
|
|
108
|
+
* it cannot take a value that reads `last`, and an argument without a direction must not read `last`.
|
|
109
|
+
*/
|
|
110
|
+
readonly monotone?: readonly Monotone[];
|
|
111
|
+
}
|
|
112
|
+
/** A direction of an op: the result follows the argument (`up`) or moves against it (`down`). */
|
|
113
|
+
type Monotone = "up" | "down";
|
|
114
|
+
/**
|
|
115
|
+
* The form of a domain in a standalone module (COMPILE.MODULE.FORM). A module has no import, so it cannot hold a value of
|
|
116
|
+
* a class. Each part replaces the part of the domain with the same name, only in a module. A compiler copies the text of
|
|
117
|
+
* each function, so a function reads only its parameters.
|
|
118
|
+
*/
|
|
119
|
+
interface ModuleForm {
|
|
120
|
+
/** The test of a value in a module. */
|
|
121
|
+
readonly is?: (u: unknown) => boolean;
|
|
122
|
+
/** The scalar lift in a module. */
|
|
123
|
+
readonly fromScalar?: (n: number) => unknown;
|
|
124
|
+
/** Some values of the module form. A compiler checks each copy with them. */
|
|
125
|
+
readonly samples?: () => readonly unknown[];
|
|
126
|
+
/**
|
|
127
|
+
* The plain data of a literal of the program, or `undefined` for a value of another domain. This function runs in the
|
|
128
|
+
* compiler, not in a module, so it can read a class.
|
|
129
|
+
*/
|
|
130
|
+
readonly literal?: (value: unknown) => Readonly<Record<string, unknown>> | undefined;
|
|
131
|
+
/** The parts of each op in a module. */
|
|
132
|
+
readonly ops?: Readonly<Record<string, {
|
|
133
|
+
readonly fn?: (self: never, ...args: never[]) => unknown;
|
|
134
|
+
readonly identity?: () => unknown;
|
|
135
|
+
readonly returns?: ReturnKind;
|
|
136
|
+
}>>;
|
|
137
|
+
}
|
|
138
|
+
/** A JavaScript type of primitive values that a domain can accept. */
|
|
139
|
+
type PrimitiveKind = "number" | "string" | "boolean";
|
|
140
|
+
/** This function gives the kind of the items of a result of the kind `list:Kind`, or `undefined` for another kind. */
|
|
141
|
+
declare const listItemKind: (r: ReturnKind | undefined) => PrimitiveKind | undefined;
|
|
142
|
+
/** The type of an op that lifts number arguments. Use it to type the ops of a domain under `isolatedDeclarations`. */
|
|
143
|
+
type LiftedOp<D> = OpSpec<D> & {
|
|
144
|
+
readonly liftScalar: true;
|
|
145
|
+
};
|
|
146
|
+
/** The type of an op with an implementation function `F`. */
|
|
147
|
+
type FnOp<D, F extends (self: D, ...args: never[]) => unknown> = OpSpec<D> & {
|
|
148
|
+
readonly fn: F;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* The type of an op table: each name in `Names` is an op, and each name in `Lifted` lifts number arguments.
|
|
152
|
+
* Use it to type the ops of a domain under `isolatedDeclarations`.
|
|
153
|
+
*/
|
|
154
|
+
type OpTable<D, Names extends string, Lifted extends string = never> = { readonly [N in Names]: N extends Lifted ? LiftedOp<D> : OpSpec<D>; };
|
|
155
|
+
/** The description of a domain, as a caller gives it to `defineDomain`. */
|
|
156
|
+
interface DomainSpec<Name extends string, D, Ops extends Readonly<Record<string, OpSpec<D>>>> {
|
|
157
|
+
/** The name of the domain. */
|
|
158
|
+
readonly name: Name;
|
|
159
|
+
/** The runtime test for the values of the domain. It must not give false positives. */
|
|
160
|
+
readonly is: (u: unknown) => u is D;
|
|
161
|
+
/**
|
|
162
|
+
* The JavaScript type of the values of the domain, if `is` accepts each value of that type and no other value
|
|
163
|
+
* (KIND.PRIMITIVE). A compiler then finds the op of such a value before a run.
|
|
164
|
+
*/
|
|
165
|
+
readonly primitive?: PrimitiveKind;
|
|
166
|
+
/**
|
|
167
|
+
* The field names of a value, if `is` accepts only plain objects with exactly these fields (KIND.FIELDS). Two domains
|
|
168
|
+
* with different names have no common value, so a compiler finds the domain of such a value before a run.
|
|
169
|
+
*/
|
|
170
|
+
readonly fields?: readonly string[];
|
|
171
|
+
/** The ops of the domain, with their metadata. */
|
|
172
|
+
readonly ops: Ops;
|
|
173
|
+
/**
|
|
174
|
+
* With `"fixed"`, each value of the domain has a size with a fixed bound, for example a 2D vector. Then each op of the
|
|
175
|
+
* domain has the size rule `"fixed"` or `"scalar"`, unless the op has its own rule (LOOP.SIZE.OPS).
|
|
176
|
+
*/
|
|
177
|
+
readonly size?: "fixed";
|
|
178
|
+
/** With `"all"`, each method of a value is an op, also without an entry in `ops`. The default is `"declared"`. */
|
|
179
|
+
readonly methods?: "declared" | "all";
|
|
180
|
+
/** The scalar lift: it makes a domain value from a number. */
|
|
181
|
+
readonly fromScalar?: (n: number) => D;
|
|
182
|
+
/** A check of the values that ops give. A value that fails the check gives the error `#NUM!`. */
|
|
183
|
+
readonly valid?: (d: D) => boolean;
|
|
184
|
+
/** A short text for a value, for traces and the site. */
|
|
185
|
+
readonly show?: (d: D) => string;
|
|
186
|
+
/** The JSON form of a value, for literals in serialized programs. */
|
|
187
|
+
readonly encode?: (d: D) => unknown;
|
|
188
|
+
/** The value of a JSON form that `encode` made. */
|
|
189
|
+
readonly decode?: (json: unknown) => D;
|
|
190
|
+
/**
|
|
191
|
+
* Some values of the domain. A compiler gives them to an op and to its copy in a module: the two must give the same
|
|
192
|
+
* results (KIND.DOMAIN).
|
|
193
|
+
*/
|
|
194
|
+
readonly samples?: () => readonly D[];
|
|
195
|
+
/** The form of the domain in a standalone module, for a domain with values of a class (COMPILE.MODULE.FORM). */
|
|
196
|
+
readonly moduleForm?: ModuleForm;
|
|
197
|
+
}
|
|
198
|
+
/** A domain. Make one with `defineDomain`. */
|
|
199
|
+
interface Domain<Name extends string = string, D = unknown, Ops extends Readonly<Record<string, OpSpec<D>>> = Readonly<Record<string, OpSpec<D>>>> extends DomainSpec<Name, D, Ops> {
|
|
200
|
+
readonly kind: "vex.domain";
|
|
201
|
+
}
|
|
202
|
+
/** A domain with any value type. The interpreter uses this type. */
|
|
203
|
+
type AnyDomain = Domain<string, any, Readonly<Record<string, OpSpec<any>>>>;
|
|
204
|
+
/** This function makes a domain. The result is frozen. */
|
|
205
|
+
declare function defineDomain<const Name extends string, D, const Ops extends Readonly<Record<string, OpSpec<D>>>>(spec: DomainSpec<Name, D, Ops>): Domain<Name, D, Ops>;
|
|
206
|
+
/** This function tells if a name can be an op name. */
|
|
207
|
+
declare const isOpName: (name: string) => boolean;
|
|
208
|
+
/**
|
|
209
|
+
* This function finds a method on a value: an own function property, or a function on the prototype chain.
|
|
210
|
+
* It stops at `Object.prototype` and `Function.prototype`, so inherited members (for example `toString`) are not ops.
|
|
211
|
+
*/
|
|
212
|
+
declare function findMethod(self: unknown, name: string): ((...args: unknown[]) => unknown) | undefined;
|
|
213
|
+
/** An op that the interpreter found for a receiver. */
|
|
214
|
+
interface ResolvedOp {
|
|
215
|
+
readonly domain: AnyDomain;
|
|
216
|
+
readonly spec: OpSpec<unknown>;
|
|
217
|
+
readonly call: (args: readonly unknown[]) => unknown;
|
|
218
|
+
}
|
|
219
|
+
/** This function finds the op `name` for `self` in one domain. It gives `undefined` if the domain does not have it. */
|
|
220
|
+
declare function resolveOp(domain: AnyDomain, self: unknown, name: string): ResolvedOp | undefined;
|
|
221
|
+
/** This function gives the domain of a value: the first domain whose `is` accepts it. */
|
|
222
|
+
declare function domainOf(domains: readonly AnyDomain[], value: unknown): AnyDomain | undefined;
|
|
223
|
+
/** This function tells if the `liftScalar` setting lifts the argument at `index`. */
|
|
224
|
+
declare const liftsAt: (lift: OpSpec<unknown>["liftScalar"], index: number) => boolean;
|
|
225
|
+
/**
|
|
226
|
+
* One move of an address. The moves of an address apply in order, from the focus of the evaluation. The key of `key`
|
|
227
|
+
* and the position of `index` can be an expression, which evaluates before the moves (NAV.COMPUTED).
|
|
228
|
+
*/
|
|
229
|
+
type Move = {
|
|
230
|
+
readonly t: "key";
|
|
231
|
+
readonly key: string | Expr;
|
|
232
|
+
} | {
|
|
233
|
+
readonly t: "index";
|
|
234
|
+
readonly i: number | Expr;
|
|
235
|
+
} | {
|
|
236
|
+
readonly t: "other";
|
|
237
|
+
} | {
|
|
238
|
+
readonly t: "offset";
|
|
239
|
+
readonly d: readonly number[];
|
|
240
|
+
} | {
|
|
241
|
+
readonly t: "origin";
|
|
242
|
+
} | {
|
|
243
|
+
readonly t: "parent";
|
|
244
|
+
};
|
|
245
|
+
/** A move with a fixed key or position: a move with no expression. */
|
|
246
|
+
type FixedMove = Exclude<Move, {
|
|
247
|
+
readonly t: "key" | "index";
|
|
248
|
+
}> | {
|
|
249
|
+
readonly t: "key";
|
|
250
|
+
readonly key: string;
|
|
251
|
+
} | {
|
|
252
|
+
readonly t: "index";
|
|
253
|
+
readonly i: number;
|
|
254
|
+
};
|
|
255
|
+
/** An address: a list of moves. The empty list is the focus. */
|
|
256
|
+
type Addr = readonly Move[];
|
|
257
|
+
/** An axis: the relation between a position and the targets that a body reads. */
|
|
258
|
+
type Axis = {
|
|
259
|
+
readonly t: "all";
|
|
260
|
+
} | {
|
|
261
|
+
readonly t: "others";
|
|
262
|
+
} | {
|
|
263
|
+
readonly t: "other";
|
|
264
|
+
} | {
|
|
265
|
+
readonly t: "neighbors";
|
|
266
|
+
readonly n: 4 | 8;
|
|
267
|
+
} | {
|
|
268
|
+
readonly t: "children";
|
|
269
|
+
} | {
|
|
270
|
+
readonly t: "ancestors";
|
|
271
|
+
} | {
|
|
272
|
+
readonly t: "descendants";
|
|
273
|
+
} | {
|
|
274
|
+
readonly t: "siblings";
|
|
275
|
+
} | {
|
|
276
|
+
readonly t: "window";
|
|
277
|
+
readonly from: number;
|
|
278
|
+
readonly to: number;
|
|
279
|
+
} | {
|
|
280
|
+
readonly t: "table";
|
|
281
|
+
readonly name: string;
|
|
282
|
+
} | {
|
|
283
|
+
readonly t: "successors";
|
|
284
|
+
} | {
|
|
285
|
+
readonly t: "predecessors";
|
|
286
|
+
} | {
|
|
287
|
+
readonly t: "reachable";
|
|
288
|
+
} | {
|
|
289
|
+
readonly t: "list";
|
|
290
|
+
readonly list: Expr;
|
|
291
|
+
} | {
|
|
292
|
+
readonly t: "reverse";
|
|
293
|
+
readonly axis: Axis;
|
|
294
|
+
} | {
|
|
295
|
+
readonly t: "where";
|
|
296
|
+
readonly axis: Axis;
|
|
297
|
+
readonly test: Expr;
|
|
298
|
+
};
|
|
299
|
+
/** A Vex expression. */
|
|
300
|
+
type Expr = {
|
|
301
|
+
readonly tag: "lit";
|
|
302
|
+
readonly value: unknown;
|
|
303
|
+
} | {
|
|
304
|
+
readonly tag: "ref";
|
|
305
|
+
readonly path: readonly string[];
|
|
306
|
+
readonly at?: Addr;
|
|
307
|
+
} | {
|
|
308
|
+
readonly tag: "app";
|
|
309
|
+
readonly op: string;
|
|
310
|
+
readonly args: readonly Expr[];
|
|
311
|
+
} | {
|
|
312
|
+
readonly tag: "let";
|
|
313
|
+
readonly bind: Readonly<Record<string, Expr>>;
|
|
314
|
+
readonly body: Expr;
|
|
315
|
+
} | {
|
|
316
|
+
readonly tag: "var";
|
|
317
|
+
readonly name: string;
|
|
318
|
+
} | {
|
|
319
|
+
readonly tag: "rec";
|
|
320
|
+
readonly fields: Readonly<Record<string, Expr>>;
|
|
321
|
+
} | {
|
|
322
|
+
readonly tag: "each";
|
|
323
|
+
readonly axis: Axis;
|
|
324
|
+
readonly body: Expr;
|
|
325
|
+
readonly at?: Addr;
|
|
326
|
+
readonly as?: ItemNames;
|
|
327
|
+
} | {
|
|
328
|
+
readonly tag: "fold";
|
|
329
|
+
readonly axis: Axis;
|
|
330
|
+
readonly init: Names;
|
|
331
|
+
readonly step: Names;
|
|
332
|
+
readonly result: Expr;
|
|
333
|
+
readonly at?: Addr;
|
|
334
|
+
readonly as?: ItemNames;
|
|
335
|
+
} | {
|
|
336
|
+
readonly tag: "iterate";
|
|
337
|
+
readonly limit: number | DataLimit;
|
|
338
|
+
readonly init: Names;
|
|
339
|
+
readonly step: Names;
|
|
340
|
+
readonly until?: Expr;
|
|
341
|
+
readonly result: Expr;
|
|
342
|
+
} | {
|
|
343
|
+
readonly tag: "fix";
|
|
344
|
+
readonly name: string;
|
|
345
|
+
readonly join: FixJoin;
|
|
346
|
+
readonly init: Expr;
|
|
347
|
+
readonly step: Expr;
|
|
348
|
+
} | {
|
|
349
|
+
readonly tag: "last";
|
|
350
|
+
readonly name: string;
|
|
351
|
+
} | {
|
|
352
|
+
readonly tag: "fn";
|
|
353
|
+
readonly params: readonly string[];
|
|
354
|
+
readonly body: Expr;
|
|
355
|
+
} | {
|
|
356
|
+
readonly tag: "call";
|
|
357
|
+
readonly fn: string;
|
|
358
|
+
readonly args: readonly Expr[];
|
|
359
|
+
} | {
|
|
360
|
+
readonly tag: "ext";
|
|
361
|
+
readonly kind: string;
|
|
362
|
+
readonly data: unknown;
|
|
363
|
+
};
|
|
364
|
+
/** The names of a loop and an expression for each (LOOP.NAMES). */
|
|
365
|
+
type Names = Readonly<Record<string, Expr>>;
|
|
366
|
+
/**
|
|
367
|
+
* The names of the items of a loop over the axis `list`. The first name holds the value of the item, and the second
|
|
368
|
+
* its position (AXIS.LIST.ITEM, AXIS.LIST.INDEX). The body of `each` and the steps of `fold` see them (AXIS.LIST.SCOPE).
|
|
369
|
+
*/
|
|
370
|
+
type ItemNames = readonly [item: string] | readonly [item: string, index: string];
|
|
371
|
+
/** The joins of `fix`. The join `or` or `max` moves a row up, and `and` or `min` moves a row down (FIX.JOIN). */
|
|
372
|
+
type FixJoin = "or" | "and" | "max" | "min";
|
|
373
|
+
/** The largest number of steps of `iterate` (ITERATE.LIMIT). */
|
|
374
|
+
declare const MAX_ITERATIONS = 1e5;
|
|
375
|
+
/**
|
|
376
|
+
* The limit of `iterate` from the size of the data (ITERATE.LIMIT.DATA): the number of targets of an axis. This is the
|
|
377
|
+
* number of steps that a `fold` over the axis makes. The axis `list` gives the count of a list. This limit needs step B.
|
|
378
|
+
*/
|
|
379
|
+
interface DataLimit {
|
|
380
|
+
readonly axis: Axis;
|
|
381
|
+
}
|
|
382
|
+
/** The tag of an expression kind. */
|
|
383
|
+
type ExprTag = Expr["tag"];
|
|
384
|
+
/** An expression of one kind. */
|
|
385
|
+
type ExprOf<T extends ExprTag> = Extract<Expr, {
|
|
386
|
+
readonly tag: T;
|
|
387
|
+
}>;
|
|
388
|
+
/** This function makes a literal. */
|
|
389
|
+
declare const lit: (value: unknown) => ExprOf<"lit">;
|
|
390
|
+
/** This function splits a dotted path, for example `"pos.x"`, into its segments. */
|
|
391
|
+
declare const toPath: (path: string | readonly string[]) => readonly string[];
|
|
392
|
+
/** This function makes a reference to a field path. With `at`, the reference reads at that address. */
|
|
393
|
+
declare function ref(path: string | readonly string[], at?: Addr): ExprOf<"ref">;
|
|
394
|
+
/** This function makes the application of an op to arguments. For a method op, the first argument is the receiver. */
|
|
395
|
+
declare const app: (op: string, ...args: readonly Expr[]) => ExprOf<"app">;
|
|
396
|
+
/** This function binds names to expressions for the body. */
|
|
397
|
+
declare const let_: (bind: Readonly<Record<string, Expr>>, body: Expr) => ExprOf<"let">;
|
|
398
|
+
/** This function makes a reference to a bound name. */
|
|
399
|
+
declare const v: (name: string) => ExprOf<"var">;
|
|
400
|
+
/** This function makes a record from field expressions. */
|
|
401
|
+
declare const rec: (fields: Readonly<Record<string, Expr>>) => ExprOf<"rec">;
|
|
402
|
+
/**
|
|
403
|
+
* This function evaluates `body` once for each target of `axis`. The result is a list. With `at`, the axis finds its
|
|
404
|
+
* targets from the key of that address, not from the focus. With `as`, the body of a loop over the axis `list` reads the
|
|
405
|
+
* value of each item and its position by these names (AXIS.LIST.ITEM, AXIS.LIST.INDEX).
|
|
406
|
+
*/
|
|
407
|
+
declare function each(axis: Axis, body: Expr, at?: Addr, as?: ItemNames): ExprOf<"each">;
|
|
408
|
+
/**
|
|
409
|
+
* This function makes a fold: a step at each target of `axis`, in order. `init` gives the names and their first
|
|
410
|
+
* values, and `step` gives the next values. `result` gives the value from the last values (LOOP.NAMES, FOLD.ORDER). With
|
|
411
|
+
* `as`, the steps of a fold over the axis `list` read the value of each item and its position by these names
|
|
412
|
+
* (AXIS.LIST.ITEM, AXIS.LIST.INDEX).
|
|
413
|
+
*/
|
|
414
|
+
declare function fold(axis: Axis, init: Names, step: Names, result: Expr, at?: Addr, as?: ItemNames): ExprOf<"fold">;
|
|
415
|
+
/**
|
|
416
|
+
* This function makes an iteration: up to `limit` steps. `init` gives the names and their first values, and `step`
|
|
417
|
+
* gives the next values. A true `until` stops it, and `result` gives the value (ITERATE.LIMIT, ITERATE.UNTIL).
|
|
418
|
+
*/
|
|
419
|
+
declare function iterate(limit: number | DataLimit, init: Names, step: Names, result: Expr, until?: Expr): ExprOf<"iterate">;
|
|
420
|
+
/**
|
|
421
|
+
* This function makes a fixed-point column (FIX.ROUNDS). `init` gives the first value of each row. `step` gives the next
|
|
422
|
+
* value of each row, and it reads the last round with `last`. `join` joins each next value to the old value of its row.
|
|
423
|
+
*/
|
|
424
|
+
declare function fix(name: string, join: FixJoin, init: Expr, step: Expr): ExprOf<"fix">;
|
|
425
|
+
/** This function makes a read of the value of the focus in the last round of the `fix` with the name `name` (FIX.LAST). */
|
|
426
|
+
declare function last(name: string): ExprOf<"last">;
|
|
427
|
+
/** This function makes the limit of `iterate` from the size of the data: the number of targets of an axis (ITERATE.LIMIT.DATA). */
|
|
428
|
+
declare const dataLimit: (axis: Axis) => DataLimit;
|
|
429
|
+
/** This function gives the axis of the data limit of an iteration, or `undefined` for a limit that is a number. */
|
|
430
|
+
declare const limitAxis: (e: ExprOf<"iterate">) => Axis | undefined;
|
|
431
|
+
/**
|
|
432
|
+
* This function gives the parts of an iteration with a data limit, for a walk that tells the axes apart. The parts are
|
|
433
|
+
* an `each` over the axis, and the iteration without its axis. An iteration with a number has `undefined`.
|
|
434
|
+
*/
|
|
435
|
+
declare function splitLimit(e: ExprOf<"iterate">): readonly [ExprOf<"each">, ExprOf<"iterate">] | undefined;
|
|
436
|
+
/**
|
|
437
|
+
* This function makes a function (FN.BIND): the names of its parameters and its body. A function is only the value of
|
|
438
|
+
* a binding of `let`. The body sees the names of the place of that `let`, so a function cannot call itself.
|
|
439
|
+
*/
|
|
440
|
+
declare const fn: (params: readonly string[], body: Expr) => ExprOf<"fn">;
|
|
441
|
+
/** This function makes a call of a bound function (FN.CALL). The body evaluates at the position of the call. */
|
|
442
|
+
declare const call: (name: string, ...args: Expr[]) => ExprOf<"call">;
|
|
443
|
+
/** This function makes an expression of an extension kind. */
|
|
444
|
+
declare const ext: (kind: string, data: unknown) => ExprOf<"ext">;
|
|
445
|
+
/** The move to an absolute key. The key can be an expression that gives a text. */
|
|
446
|
+
declare function key(k: string): FixedMove;
|
|
447
|
+
declare function key(k: string | Expr): Move;
|
|
448
|
+
/** The move to a position in the key order. The position can be an expression that gives a number. */
|
|
449
|
+
declare function index(i: number): FixedMove;
|
|
450
|
+
declare function index(i: number | Expr): Move;
|
|
451
|
+
/** This function gives the expression of a move with a computed key or position, or `undefined`. */
|
|
452
|
+
declare function moveExpr(m: Move): Expr | undefined;
|
|
453
|
+
/** This function gives the expressions of the computed moves of an address, in the order of the moves. */
|
|
454
|
+
declare const addrExprs: (at: Addr | undefined) => readonly Expr[];
|
|
455
|
+
/** This function tells if each move of an address is fixed. */
|
|
456
|
+
declare const isFixedAddr: (at: Addr | undefined) => at is readonly FixedMove[];
|
|
457
|
+
/** The move to the other key of a space with two keys. */
|
|
458
|
+
declare const other: FixedMove;
|
|
459
|
+
/** The relative move in an array (one number) or a grid (two numbers). */
|
|
460
|
+
declare const offset: (...d: readonly number[]) => FixedMove;
|
|
461
|
+
/** The move back to the origin of the evaluation. */
|
|
462
|
+
declare const origin: FixedMove;
|
|
463
|
+
/** The move to the parent of the focus in a tree space. */
|
|
464
|
+
declare const parent: FixedMove;
|
|
465
|
+
/** The axes. */
|
|
466
|
+
declare const axes: {
|
|
467
|
+
/** Each key of the space. */
|
|
468
|
+
readonly all: Axis;
|
|
469
|
+
/** Each key except the focus. */
|
|
470
|
+
readonly others: Axis;
|
|
471
|
+
/** The other key of a pair. */
|
|
472
|
+
readonly other: Axis;
|
|
473
|
+
/** The neighbors of the focus in a grid. */
|
|
474
|
+
readonly neighbors: (n?: 4 | 8) => Axis;
|
|
475
|
+
/** The children of the focus in a tree, in key order. */
|
|
476
|
+
readonly children: Axis;
|
|
477
|
+
/** The ancestors of the focus in a tree: the parent first, the root last. */
|
|
478
|
+
readonly ancestors: Axis;
|
|
479
|
+
/** The descendants of the focus in a tree, depth first, each parent before its children. */
|
|
480
|
+
readonly descendants: Axis;
|
|
481
|
+
/** The other children of the parent of the focus. For a root, the other roots. */
|
|
482
|
+
readonly siblings: Axis;
|
|
483
|
+
/**
|
|
484
|
+
* The keys at the offsets from `from` to `to` of the focus, in order: a window of rows. The offset 0 is the focus. In
|
|
485
|
+
* a tree space, the offsets go among the siblings. An offset outside the space has no target.
|
|
486
|
+
*/
|
|
487
|
+
readonly window: (from: number, to: number) => Axis;
|
|
488
|
+
/**
|
|
489
|
+
* Each key of the table `name` of the evaluation, in key order. The body evaluates in the space of that table, and
|
|
490
|
+
* there the origin is the target.
|
|
491
|
+
*/
|
|
492
|
+
readonly table: (name: string) => Axis;
|
|
493
|
+
/** The keys at the ends of the edges from the focus, in a graph space. In a tree space, the children. */
|
|
494
|
+
readonly successors: Axis;
|
|
495
|
+
/** The keys with an edge to the focus, in key order. In a tree space, the parent. */
|
|
496
|
+
readonly predecessors: Axis;
|
|
497
|
+
/** Each key that a path of edges reaches from the focus, in breadth-first order, without the focus. */
|
|
498
|
+
readonly reachable: Axis;
|
|
499
|
+
/**
|
|
500
|
+
* The targets of `axis` in the reverse order (AXIS.REVERSE). The inner axis is a base axis: not `where`, `reverse` or
|
|
501
|
+
* `table`. A test goes outside: `where(reverse(axis), test)`.
|
|
502
|
+
*/
|
|
503
|
+
readonly reverse: (axis: Axis) => Axis;
|
|
504
|
+
/**
|
|
505
|
+
* The keys of the items of the list that `list` gives, in the order of the list (AXIS.LIST). The expression evaluates
|
|
506
|
+
* before the targets. An error item gives an error item for its target.
|
|
507
|
+
*/
|
|
508
|
+
readonly list: (list: Expr) => Axis;
|
|
509
|
+
/** The targets of `axis` where `test` gives `true`. */
|
|
510
|
+
readonly where: (axis: Axis, test: Expr) => Axis;
|
|
511
|
+
};
|
|
512
|
+
/** This function tells if a value is a valid move. The expression of a computed move must be valid too. */
|
|
513
|
+
declare function isMove(u: unknown): u is Move;
|
|
514
|
+
/** This function tells if a value is a valid axis. It checks the tests of `where` too. */
|
|
515
|
+
declare function isAxis(u: unknown): u is Axis;
|
|
516
|
+
/** This function tells if a value is a valid expression. It checks the whole tree. */
|
|
517
|
+
declare function isExpr(u: unknown): u is Expr;
|
|
518
|
+
/**
|
|
519
|
+
* This function gives the reason that a value is not a valid expression, or `undefined` for a valid expression
|
|
520
|
+
* (EVAL.SHAPE). An expression from a newer version of Vex can have a tag that this version does not know. Unlike
|
|
521
|
+
* `isExpr`, it accepts a number that is not whole in a move or in a window, because it has a meaning at run time.
|
|
522
|
+
*/
|
|
523
|
+
declare function shapeError(u: unknown): string | undefined;
|
|
524
|
+
/**
|
|
525
|
+
* This function gives the child expressions of an expression, in the order of their child index. The expressions of
|
|
526
|
+
* the computed moves of an address come last. They evaluate at the position of their node, also for an axis.
|
|
527
|
+
*/
|
|
528
|
+
declare function children(e: Expr): readonly Expr[];
|
|
529
|
+
/**
|
|
530
|
+
* This function gives the expressions of an axis, in the order of their child indexes. The expression of the axis
|
|
531
|
+
* `list` comes first, and then the tests of the `where` axes from the inside out. It uses a loop, not recursion.
|
|
532
|
+
*/
|
|
533
|
+
declare function axisExprs(a: Axis): readonly Expr[];
|
|
534
|
+
/** This function gives the expression of the axis `list` inside an axis, through `where` and `reverse`, if it has one. */
|
|
535
|
+
declare function listOf(a: Axis): Expr | undefined;
|
|
536
|
+
export { LiftedOp as $, iterate as A, other as B, fn as C, isExpr as D, isAxis as E, listOf as F, splitLimit as G, rec as H, lit as I, AnyDomain as J, toPath as K, moveExpr as L, last as M, let_ as N, isFixedAddr as O, limitAxis as P, Law as Q, offset as R, fix as S, index as T, ref as U, parent as V, shapeError as W, DomainSpec as X, Domain as Y, FnOp as Z, call as _, liftsAt as _t, ExprOf as a, PrimitiveKind as at, each as b, FixedMove as c, SizeMeasure as ct, Move as d, SizeTerms as dt, ModuleForm as et, Names as f, SizeUse as ft, axisExprs as g, isOpName as gt, axes as h, findMethod as ht, Expr as i, ParamKind as it, key as j, isMove as k, ItemNames as l, SizeRule as lt, app as m, domainOf as mt, Axis as n, OpSpec as nt, ExprTag as o, ResolvedOp as ot, addrExprs as p, defineDomain as pt, v as q, DataLimit as r, OpTable as rt, FixJoin as s, ReturnKind as st, Addr as t, Monotone as tt, MAX_ITERATIONS as u, SizeTerm as ut, children as v, listItemKind as vt, fold as w, ext as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