@mark1russell7/vex 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +79 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +353 -27
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/builder.ts +120 -20
- package/src/deps.ts +49 -4
- package/src/evaluate.ts +111 -2
- package/src/ir.ts +62 -9
- package/src/json.ts +15 -1
- package/src/list.ts +3 -3
- package/src/sheet.ts +11 -4
- package/src/space.ts +8 -0
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["spaces","keyMove","indexMove","offsetMove","otherMove","originMove","parentMove","iterateExpr","foldExpr","cellRef"],"sources":["../src/result.ts","../src/errors.ts","../src/ir.ts","../src/space.ts","../src/domain.ts","../src/list.ts","../src/evaluate.ts","../src/deps.ts","../src/json.ts","../src/traversal.ts","../src/sheet.ts","../src/builder.ts"],"sourcesContent":["import type { Optional as FamilyOptional } from \"@mark1russell7/optional\";\nimport type { VexError } from \"./errors.ts\";\n\n/**\n * A value that is there, or not there. This is the public result of a Vex program. It is the Optional of the\n * family (`@mark1russell7/optional`), so render and Vex give and take the same values. The import is a type import\n * only: the build copies the type into the declarations, so the package has no runtime dependency.\n */\nexport type Optional<T> = FamilyOptional<T>;\n\n/** A value, or the error that tells why there is no value. The interpreter uses this type. */\nexport type Result<T> = { readonly ok: true; readonly value: T } | { readonly ok: false; readonly error: VexError };\n\nconst NONE: Optional<never> = Object.freeze({ tag: \"none\" });\n\n/** This function makes an `Optional` that holds `value`. */\nexport const some = <T>(value: T): Optional<T> => ({ tag: \"some\", value });\n\n/** This function gives the shared empty `Optional`. */\nexport const none = <T = never>(): Optional<T> => NONE;\n\n/** This function makes a successful `Result`. */\nexport const ok = <T>(value: T): Result<T> => ({ ok: true, value });\n\n/** This function makes a failed `Result`. */\nexport const fail = <T = never>(error: VexError): Result<T> => ({ ok: false, error });\n\n/** This function tells if an `Optional` holds a value. */\nexport const isSome = <T>(o: Optional<T>): o is { readonly tag: \"some\"; readonly value: T } => o.tag === \"some\";\n\n/** This function tells if an `Optional` is empty. */\nexport const isNone = <T>(o: Optional<T>): o is { readonly tag: \"none\" } => o.tag === \"none\";\n\n/** This function changes a `Result` into an `Optional`. The error is lost. */\nexport const toOptional = <T>(r: Result<T>): Optional<T> => (r.ok ? some(r.value) : none());\n\n/** This function gives the value of an `Optional`, or `fallback` if it is empty. */\nexport const getOr = <T, U>(o: Optional<T>, fallback: U): T | U => (o.tag === \"some\" ? o.value : fallback);\n\n/** This function applies `f` to the value of a `Result`. An error stays the same. */\nexport const mapResult = <T, U>(r: Result<T>, f: (value: T) => U): Result<U> => (r.ok ? ok(f(r.value)) : r);\n\n/** This function applies `f` to the value of a `Result`, and `f` gives a `Result`. An error stays the same. */\nexport const chainResult = <T, U>(r: Result<T>, f: (value: T) => Result<U>): Result<U> => (r.ok ? f(r.value) : r);\n","/**\n * The error codes of Vex. The names come from the spreadsheet error values, because a Vex program is a\n * spreadsheet formula over records.\n */\nexport type ErrorCode = \"#REF!\" | \"#N/A\" | \"#VALUE!\" | \"#NAME?\" | \"#NUM!\" | \"#CALC!\" | \"#ARGS\" | \"#CYCLE!\" | \"#DEPTH!\";\n\n/** The cause of an error, in more detail than the code. */\nexport type ErrorKind =\n | \"unknown-key\"\n | \"not-a-pair\"\n | \"out-of-bounds\"\n | \"no-offset\"\n | \"no-grid\"\n | \"no-tree\"\n | \"no-table\"\n | \"no-graph\"\n | \"missing-field\"\n | \"empty\"\n | \"not-instance\"\n | \"kind-mismatch\"\n | \"unknown-op\"\n | \"unbound\"\n | \"not-finite\"\n | \"invalid-value\"\n | \"threw\"\n | \"undefined-result\"\n | \"args\"\n | \"cycle\"\n | \"depth\"\n | \"bad-expression\"\n | \"limit\";\n\nconst CODE_OF: Readonly<Record<ErrorKind, ErrorCode>> = {\n \"unknown-key\": \"#REF!\",\n \"not-a-pair\": \"#REF!\",\n \"out-of-bounds\": \"#REF!\",\n \"no-offset\": \"#REF!\",\n \"no-grid\": \"#REF!\",\n \"no-tree\": \"#REF!\",\n \"no-table\": \"#REF!\",\n \"no-graph\": \"#REF!\",\n \"missing-field\": \"#N/A\",\n empty: \"#N/A\",\n \"not-instance\": \"#VALUE!\",\n \"kind-mismatch\": \"#VALUE!\",\n \"bad-expression\": \"#VALUE!\",\n \"unknown-op\": \"#NAME?\",\n unbound: \"#NAME?\",\n \"not-finite\": \"#NUM!\",\n \"invalid-value\": \"#NUM!\",\n limit: \"#NUM!\",\n threw: \"#CALC!\",\n \"undefined-result\": \"#CALC!\",\n args: \"#ARGS\",\n cycle: \"#CYCLE!\",\n depth: \"#DEPTH!\",\n};\n\n/**\n * This function tells if an exception is the report of the engine that the call stack is full. V8 and JavaScriptCore\n * throw a `RangeError`. SpiderMonkey throws an `InternalError` (\"too much recursion\").\n */\nexport function isStackOverflow(thrown: unknown): boolean {\n if (!(thrown instanceof Error)) return false;\n return (thrown instanceof RangeError && /call stack/i.test(thrown.message)) || (thrown.name === \"InternalError\" && /recursion/i.test(thrown.message));\n}\n\n/** This function tells if an error is `#DEPTH!`. `ifError` and the reductions that skip errors do not hide it (EVAL.DEPTH). */\nexport const isDepthError = (e: VexError): boolean => e.kind === \"depth\";\n\n/** A Vex error. It is a value: a program can catch it with `ifError`, except `#DEPTH!`. */\nexport interface VexError {\n /** The spreadsheet-style code, for example `#REF!`. */\n readonly code: ErrorCode;\n /** The cause in more detail. */\n readonly kind: ErrorKind;\n /** A sentence that tells what went wrong. */\n readonly message: string;\n /** The position of the failed node in the expression tree. The root is `[]`. */\n readonly path: readonly number[];\n /** The key where the evaluation started. */\n readonly origin?: string;\n /** The key where relative references read when the error occurred. */\n readonly focus?: string;\n /** The op name, for errors of an op. */\n readonly op?: string;\n /** The errors of the arguments, for the code `#ARGS`. */\n readonly causes?: readonly VexError[];\n /** The value that an op threw, for the kind `threw`. */\n readonly thrown?: unknown;\n}\n\n/** The details that a caller can give to `vexError`. */\nexport interface ErrorDetails {\n readonly path?: readonly number[];\n readonly origin?: string;\n readonly focus?: string;\n readonly op?: string;\n readonly causes?: readonly VexError[];\n readonly thrown?: unknown;\n}\n\n/** This function gives the code of an error kind. */\nexport const codeOf = (kind: ErrorKind): ErrorCode => CODE_OF[kind];\n\n/** This function makes a `VexError`. */\nexport function vexError(kind: ErrorKind, message: string, details: ErrorDetails = {}): VexError {\n return {\n code: CODE_OF[kind],\n kind,\n message,\n path: details.path ?? [],\n ...(details.origin === undefined ? {} : { origin: details.origin }),\n ...(details.focus === undefined ? {} : { focus: details.focus }),\n ...(details.op === undefined ? {} : { op: details.op }),\n ...(details.causes === undefined ? {} : { causes: details.causes }),\n ...(details.thrown === undefined ? {} : { thrown: details.thrown }),\n };\n}\n\n/** This function gives a short text for an error, for example `#REF! unknown-key: there is no key \"Z\"`. */\nexport const formatError = (e: VexError): string => `${e.code} ${e.kind}: ${e.message}`;\n","/**\n * The expression IR of Vex. It is plain JSON data. Its first three kinds (`lit`, `ref`, `app`) have the same\n * shape as the expressions of `render`.\n */\n\n/**\n * One move of an address. The moves of an address apply in order, from the focus of the evaluation. The key of `key`\n * and the position of `index` can be an expression, which evaluates before the moves (NAV.COMPUTED).\n */\nexport type Move =\n | { readonly t: \"key\"; readonly key: string | Expr }\n | { readonly t: \"index\"; readonly i: number | Expr }\n | { readonly t: \"other\" }\n | { readonly t: \"offset\"; readonly d: readonly number[] }\n | { readonly t: \"origin\" }\n | { readonly t: \"parent\" };\n\n/** A move with a fixed key or position: a move with no expression. */\nexport type FixedMove = Exclude<Move, { readonly t: \"key\" | \"index\" }> | { readonly t: \"key\"; readonly key: string } | { readonly t: \"index\"; readonly i: number };\n\n/** An address: a list of moves. The empty list is the focus. */\nexport type Addr = readonly Move[];\n\n/** An axis: the relation between a position and the targets that a body reads. */\nexport type Axis =\n | { readonly t: \"all\" }\n | { readonly t: \"others\" }\n | { readonly t: \"other\" }\n | { readonly t: \"neighbors\"; readonly n: 4 | 8 }\n | { readonly t: \"children\" }\n | { readonly t: \"ancestors\" }\n | { readonly t: \"descendants\" }\n | { readonly t: \"siblings\" }\n | { readonly t: \"window\"; readonly from: number; readonly to: number }\n | { readonly t: \"table\"; readonly name: string }\n | { readonly t: \"successors\" }\n | { readonly t: \"predecessors\" }\n | { readonly t: \"reachable\" }\n | { readonly t: \"where\"; readonly axis: Axis; readonly test: Expr };\n\n/** A Vex expression. */\nexport type Expr =\n | { readonly tag: \"lit\"; readonly value: unknown }\n | { readonly tag: \"ref\"; readonly path: readonly string[]; readonly at?: Addr }\n | { readonly tag: \"app\"; readonly op: string; readonly args: readonly Expr[] }\n | { readonly tag: \"let\"; readonly bind: Readonly<Record<string, Expr>>; readonly body: Expr }\n | { readonly tag: \"var\"; readonly name: string }\n | { readonly tag: \"rec\"; readonly fields: Readonly<Record<string, Expr>> }\n | { readonly tag: \"each\"; readonly axis: Axis; readonly body: Expr; readonly at?: Addr }\n | { readonly tag: \"fold\"; readonly axis: Axis; readonly init: Names; readonly step: Names; readonly result: Expr; readonly at?: Addr }\n | { readonly tag: \"iterate\"; readonly limit: number; readonly init: Names; readonly step: Names; readonly until?: Expr; readonly result: Expr }\n | { readonly tag: \"ext\"; readonly kind: string; readonly data: unknown };\n\n/** The names of a loop and an expression for each (LOOP.NAMES). */\nexport type Names = Readonly<Record<string, Expr>>;\n\n/** The largest number of steps of `iterate` (ITERATE.LIMIT). */\nexport const MAX_ITERATIONS = 100_000;\n\n/** The tag of an expression kind. */\nexport type ExprTag = Expr[\"tag\"];\n\n/** An expression of one kind. */\nexport type ExprOf<T extends ExprTag> = Extract<Expr, { readonly tag: T }>;\n\n// ---------------------------------------------------------------- constructors\n\n/** This function makes a literal. */\nexport const lit = (value: unknown): ExprOf<\"lit\"> => ({ tag: \"lit\", value });\n\n/** This function splits a dotted path, for example `\"pos.x\"`, into its segments. */\nexport const toPath = (path: string | readonly string[]): readonly string[] =>\n typeof path === \"string\" ? path.split(\".\").filter((s) => s.length > 0) : path;\n\n/** This function makes a reference to a field path. With `at`, the reference reads at that address. */\nexport function ref(path: string | readonly string[], at?: Addr): ExprOf<\"ref\"> {\n const segments = toPath(path);\n return at === undefined || at.length === 0 ? { tag: \"ref\", path: segments } : { tag: \"ref\", path: segments, at };\n}\n\n/** This function makes the application of an op to arguments. For a method op, the first argument is the receiver. */\nexport const app = (op: string, ...args: readonly Expr[]): ExprOf<\"app\"> => ({ tag: \"app\", op, args });\n\n/** This function binds names to expressions for the body. */\nexport const let_ = (bind: Readonly<Record<string, Expr>>, body: Expr): ExprOf<\"let\"> => ({ tag: \"let\", bind, body });\n\n/** This function makes a reference to a bound name. */\nexport const v = (name: string): ExprOf<\"var\"> => ({ tag: \"var\", name });\n\n/** This function makes a record from field expressions. */\nexport const rec = (fields: Readonly<Record<string, Expr>>): ExprOf<\"rec\"> => ({ tag: \"rec\", fields });\n\n/**\n * This function evaluates `body` once for each target of `axis`. The result is a list. With `at`, the axis finds its\n * targets from the key of that address, not from the focus.\n */\nexport function each(axis: Axis, body: Expr, at?: Addr): ExprOf<\"each\"> {\n return at === undefined || at.length === 0 ? { tag: \"each\", axis, body } : { tag: \"each\", axis, body, at };\n}\n\n/**\n * This function makes a fold: a step at each target of `axis`, in order. `init` gives the names and their first\n * values, and `step` gives the next values. `result` gives the value from the last values (LOOP.NAMES, FOLD.ORDER).\n */\nexport function fold(axis: Axis, init: Names, step: Names, result: Expr, at?: Addr): ExprOf<\"fold\"> {\n return at === undefined || at.length === 0 ? { tag: \"fold\", axis, init, step, result } : { tag: \"fold\", axis, init, step, result, at };\n}\n\n/**\n * This function makes an iteration: up to `limit` steps. `init` gives the names and their first values, and `step`\n * gives the next values. A true `until` stops it, and `result` gives the value (ITERATE.LIMIT, ITERATE.UNTIL).\n */\nexport function iterate(limit: number, init: Names, step: Names, result: Expr, until?: Expr): ExprOf<\"iterate\"> {\n return until === undefined ? { tag: \"iterate\", limit, init, step, result } : { tag: \"iterate\", limit, init, step, until, result };\n}\n\n/** This function makes an expression of an extension kind. */\nexport const ext = (kind: string, data: unknown): ExprOf<\"ext\"> => ({ tag: \"ext\", kind, data });\n\n// ---------------------------------------------------------------- moves and axes\n\n/** The move to an absolute key. The key can be an expression that gives a text. */\nexport function key(k: string): FixedMove;\nexport function key(k: string | Expr): Move;\nexport function key(k: string | Expr): Move {\n return { t: \"key\", key: k };\n}\n/** The move to a position in the key order. The position can be an expression that gives a number. */\nexport function index(i: number): FixedMove;\nexport function index(i: number | Expr): Move;\nexport function index(i: number | Expr): Move {\n return { t: \"index\", i };\n}\n\n/** This function gives the expression of a move with a computed key or position, or `undefined`. */\nexport function moveExpr(m: Move): Expr | undefined {\n if (m.t === \"key\") return typeof m.key === \"string\" ? undefined : m.key;\n return m.t === \"index\" && typeof m.i !== \"number\" ? m.i : undefined;\n}\n\n/** This function gives the expressions of the computed moves of an address, in the order of the moves. */\nexport const addrExprs = (at: Addr | undefined): readonly Expr[] => (at ?? []).flatMap((m) => moveExpr(m) ?? []);\n\n/** This function tells if each move of an address is fixed. */\nexport const isFixedAddr = (at: Addr | undefined): at is readonly FixedMove[] => addrExprs(at).length === 0;\n/** The move to the other key of a space with two keys. */\nexport const other: FixedMove = Object.freeze({ t: \"other\" });\n/** The relative move in an array (one number) or a grid (two numbers). */\nexport const offset = (...d: readonly number[]): FixedMove => ({ t: \"offset\", d });\n/** The move back to the origin of the evaluation. */\nexport const origin: FixedMove = Object.freeze({ t: \"origin\" });\n/** The move to the parent of the focus in a tree space. */\nexport const parent: FixedMove = Object.freeze({ t: \"parent\" });\n\n/** The axes. */\nexport const axes = {\n /** Each key of the space. */\n all: Object.freeze({ t: \"all\" }) as Axis,\n /** Each key except the focus. */\n others: Object.freeze({ t: \"others\" }) as Axis,\n /** The other key of a pair. */\n other: Object.freeze({ t: \"other\" }) as Axis,\n /** The neighbors of the focus in a grid. */\n neighbors: (n: 4 | 8 = 8): Axis => ({ t: \"neighbors\", n }),\n /** The children of the focus in a tree, in key order. */\n children: Object.freeze({ t: \"children\" }) as Axis,\n /** The ancestors of the focus in a tree: the parent first, the root last. */\n ancestors: Object.freeze({ t: \"ancestors\" }) as Axis,\n /** The descendants of the focus in a tree, depth first, each parent before its children. */\n descendants: Object.freeze({ t: \"descendants\" }) as Axis,\n /** The other children of the parent of the focus. For a root, the other roots. */\n siblings: Object.freeze({ t: \"siblings\" }) as Axis,\n /**\n * 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\n * a tree space, the offsets go among the siblings. An offset outside the space has no target.\n */\n window: (from: number, to: number): Axis => ({ t: \"window\", from, to }),\n /**\n * Each key of the table `name` of the evaluation, in key order. The body evaluates in the space of that table, and\n * there the origin is the target.\n */\n table: (name: string): Axis => ({ t: \"table\", name }),\n /** The keys at the ends of the edges from the focus, in a graph space. In a tree space, the children. */\n successors: Object.freeze({ t: \"successors\" }) as Axis,\n /** The keys with an edge to the focus, in key order. In a tree space, the parent. */\n predecessors: Object.freeze({ t: \"predecessors\" }) as Axis,\n /** Each key that a path of edges reaches from the focus, in breadth-first order, without the focus. */\n reachable: Object.freeze({ t: \"reachable\" }) as Axis,\n /** The targets of `axis` where `test` gives `true`. */\n where: (axis: Axis, test: Expr): Axis => ({ t: \"where\", axis, test }),\n} as const;\n\n// ---------------------------------------------------------------- validation\n\nconst isObject = (u: unknown): u is Readonly<Record<string, unknown>> => typeof u === \"object\" && u !== null;\n\nconst isStringArray = (u: unknown): u is readonly string[] => Array.isArray(u) && u.every((s) => typeof s === \"string\");\n\n/** This function tells if a value is a valid move. The expression of a computed move must be valid too. */\nexport function isMove(u: unknown): u is Move {\n const exprs = moveParts(u);\n return exprs !== undefined && exprs.every(isExpr);\n}\n\n/**\n * A test of the numbers of a move or of a window. The JSON form needs whole numbers. An expression in code can have any\n * number, and a number that is not whole has a meaning at run time (EVAL.SHAPE).\n */\ntype NumberTest = (x: unknown) => boolean;\n\nconst anyNumber: NumberTest = (x) => typeof x === \"number\";\n\n/** This function checks the fixed parts of a move. It gives the expressions of the move, or `undefined` for a bad move. */\nfunction moveParts(u: unknown, isNumber: NumberTest = Number.isInteger): readonly unknown[] | undefined {\n if (!isObject(u)) return undefined;\n switch (u[\"t\"]) {\n case \"key\":\n return typeof u[\"key\"] === \"string\" ? [] : isObject(u[\"key\"]) ? [u[\"key\"]] : undefined;\n case \"index\":\n return isNumber(u[\"i\"]) ? [] : isObject(u[\"i\"]) ? [u[\"i\"]] : undefined;\n case \"offset\":\n return Array.isArray(u[\"d\"]) && u[\"d\"].every((n) => isNumber(n)) ? [] : undefined;\n case \"other\":\n case \"origin\":\n case \"parent\":\n return [];\n default:\n return undefined;\n }\n}\n\n/** This function tells if a value is a valid axis. It checks the tests of `where` too. */\nexport function isAxis(u: unknown): u is Axis {\n return badPart([{ axis: true, u }], true) === undefined;\n}\n\n/** This function tells if a value is a valid expression. It checks the whole tree. */\nexport function isExpr(u: unknown): u is Expr {\n return badPart([{ axis: false, u }], true) === undefined;\n}\n\n/** The tags of the expressions of this version of Vex. */\nconst TAGS: ReadonlySet<unknown> = new Set([\"lit\", \"ref\", \"app\", \"let\", \"var\", \"rec\", \"each\", \"fold\", \"iterate\", \"ext\"]);\n\n/**\n * This function gives the reason that a value is not a valid expression, or `undefined` for a valid expression\n * (EVAL.SHAPE). An expression from a newer version of Vex can have a tag that this version does not know. Unlike\n * `isExpr`, it accepts a number that is not whole in a move or in a window, because it has a meaning at run time.\n */\nexport function shapeError(u: unknown): string | undefined {\n const bad = badPart([{ axis: false, u }], false);\n if (bad === undefined) return undefined;\n const tag = isObject(bad.u) ? bad.u[\"tag\"] : undefined;\n if (bad.axis) return \"the expression has an axis that is not valid\";\n if (typeof tag === \"string\" && !TAGS.has(tag)) return `the expression has a node with the tag \"${tag}\", and this version of Vex does not know it`;\n return typeof tag === \"string\" ? `the expression has a node \"${tag}\" with parts that are not valid` : \"the expression has a part that is not a node\";\n}\n\n/**\n * This function checks the names of a loop: `init` and `step` are records, and each name of `step` is a name of `init`.\n * It gives the expressions of `init`, of `step` and `result`, or `undefined` (LOOP.NAMES).\n */\nfunction loopParts(u: Readonly<Record<string, unknown>>): readonly unknown[] | undefined {\n const { init, step } = u;\n if (!isObject(init) || Array.isArray(init) || !isObject(step) || Array.isArray(step)) return undefined;\n if (!Object.keys(step).every((n) => Object.hasOwn(init, n))) return undefined;\n return [...Object.values(init), ...Object.values(step), u[\"result\"]];\n}\n\n/** This function checks the fixed parts of an address. It gives the expressions of its moves, or `undefined`. */\nfunction addrParts(u: unknown, isNumber: NumberTest): readonly unknown[] | undefined {\n if (u === undefined) return [];\n if (!Array.isArray(u)) return undefined;\n const out: unknown[] = [];\n for (const m of u) {\n const parts = moveParts(m, isNumber);\n if (parts === undefined) return undefined;\n out.push(...parts);\n }\n return out;\n}\n\n/**\n * This function checks a tree of expressions and axes, and it gives the first part that is not valid. It uses a stack,\n * not recursion, so the input can be deep. For example, a deep JSON file from a stranger does not need a deep call\n * stack (EVAL.NESTING). With `whole`, the numbers of the moves and of the windows must be whole, as the JSON form needs.\n */\nfunction badPart(todo: { readonly axis: boolean; readonly u: unknown }[], whole: boolean): { readonly axis: boolean; readonly u: unknown } | undefined {\n const moveNumber = whole ? Number.isInteger : anyNumber;\n const windowNumber = whole ? Number.isSafeInteger : anyNumber;\n const push = (axis: boolean, values: readonly unknown[]): void => {\n for (const u of values) todo.push({ axis, u });\n };\n for (let item = todo.pop(); item !== undefined; item = todo.pop()) {\n const { u } = item;\n if (!isObject(u)) return item;\n if (item.axis) {\n const t = u[\"t\"];\n if (t === \"neighbors\") {\n if (u[\"n\"] !== 4 && u[\"n\"] !== 8) return item;\n } else if (t === \"window\") {\n if (!windowNumber(u[\"from\"]) || !windowNumber(u[\"to\"])) return item;\n } else if (t === \"table\") {\n if (typeof u[\"name\"] !== \"string\") return item;\n } else if (t === \"where\") {\n push(true, [u[\"axis\"]]);\n push(false, [u[\"test\"]]);\n } else if (![\"all\", \"others\", \"other\", \"children\", \"ancestors\", \"descendants\", \"siblings\", \"successors\", \"predecessors\", \"reachable\"].includes(t as string)) {\n return item;\n }\n continue;\n }\n switch (u[\"tag\"]) {\n case \"lit\":\n if (!(\"value\" in u)) return item;\n break;\n case \"ref\": {\n const at = addrParts(u[\"at\"], moveNumber);\n if (!isStringArray(u[\"path\"]) || at === undefined) return item;\n push(false, at);\n break;\n }\n case \"app\":\n if (typeof u[\"op\"] !== \"string\" || !Array.isArray(u[\"args\"])) return item;\n push(false, u[\"args\"]);\n break;\n case \"let\":\n if (!isObject(u[\"bind\"]) || Array.isArray(u[\"bind\"])) return item;\n push(false, [...Object.values(u[\"bind\"]), u[\"body\"]]);\n break;\n case \"var\":\n if (typeof u[\"name\"] !== \"string\") return item;\n break;\n case \"rec\":\n if (!isObject(u[\"fields\"]) || Array.isArray(u[\"fields\"])) return item;\n push(false, Object.values(u[\"fields\"]));\n break;\n case \"each\": {\n const at = addrParts(u[\"at\"], moveNumber);\n if (at === undefined) return item;\n push(true, [u[\"axis\"]]);\n push(false, [u[\"body\"], ...at]);\n break;\n }\n case \"fold\": {\n const at = addrParts(u[\"at\"], moveNumber);\n const names = loopParts(u);\n if (at === undefined || names === undefined) return item;\n push(true, [u[\"axis\"]]);\n push(false, [...names, ...at]);\n break;\n }\n case \"iterate\": {\n const limit = u[\"limit\"];\n const names = loopParts(u);\n if (typeof limit !== \"number\" || !Number.isInteger(limit) || limit < 0 || limit > MAX_ITERATIONS || names === undefined) return item;\n push(false, [...names, ...(u[\"until\"] === undefined ? [] : [u[\"until\"]])]);\n break;\n }\n case \"ext\":\n if (typeof u[\"kind\"] !== \"string\" || !(\"data\" in u)) return item;\n break;\n default:\n return item;\n }\n }\n return undefined;\n}\n\n/**\n * This function gives the child expressions of an expression, in the order of their child index. The expressions of\n * the computed moves of an address come last. They evaluate at the position of their node, also for an axis.\n */\nexport function children(e: Expr): readonly Expr[] {\n switch (e.tag) {\n case \"app\":\n return e.args;\n case \"let\":\n return [...Object.values(e.bind), e.body];\n case \"rec\":\n return Object.values(e.fields);\n case \"each\":\n return [e.body, ...whereTests(e.axis), ...addrExprs(e.at)];\n case \"fold\":\n return [...Object.values(e.init), ...Object.values(e.step), ...whereTests(e.axis), ...addrExprs(e.at), e.result];\n case \"iterate\":\n return [...Object.values(e.init), ...Object.values(e.step), ...(e.until === undefined ? [] : [e.until]), e.result];\n case \"ref\":\n return addrExprs(e.at);\n case \"lit\":\n case \"var\":\n case \"ext\":\n return [];\n }\n}\n\n/** This function gives the tests of the `where` axes of an axis, from the inside out. It uses a loop, not recursion. */\nfunction whereTests(a: Axis): readonly Expr[] {\n const out: Expr[] = [];\n for (let x: Axis = a; x.t === \"where\"; x = x.axis) out.unshift(x.test);\n return out;\n}\n","import { vexError } from \"./errors.ts\";\nimport { moveExpr, type Addr, type Axis, type FixedMove } from \"./ir.ts\";\nimport { fail, ok, type Result } from \"./result.ts\";\n\n/** The kind of a space. The kind sets which moves and axes are valid. */\nexport type SpaceKind = \"record\" | \"array\" | \"grid\" | \"tree\" | \"graph\";\n\n/**\n * A space: an immutable collection of records with keys. A Vex program evaluates at one key of a space.\n * Nothing changes a space after it is made.\n */\nexport interface Space<K extends string = string, O = unknown> {\n readonly kind: SpaceKind;\n /** The keys, in their order. */\n readonly keys: readonly K[];\n /**\n * The record of each key, in the order of `keys` (SPACE.RECORDS). A compiler reads a record by its index with it.\n * A space without it gives each record with `get` only.\n */\n readonly records?: readonly (O | undefined)[];\n /** This function tells if the space has the key `k`. */\n has(k: string): k is K;\n /** This function gives the record at the key `k`, or `undefined`. */\n get(k: string): O | undefined;\n /** The position of each key, for array and grid spaces. An array key has one number, a grid key has two. */\n coords(k: string): readonly number[] | undefined;\n /** The key at a position, or `undefined`. */\n keyAt(coords: readonly number[]): K | undefined;\n /** The parent of the key `k` in a tree space, or `undefined` for a root. Other spaces do not have it. */\n parentOf?(k: string): K | undefined;\n /** The children of the key `k` in a tree space, in key order. Other spaces do not have it. */\n childrenOf?(k: string): readonly K[];\n /** The keys at the ends of the edges from `k`, in a graph space or a tree space. Other spaces do not have it. */\n successorsOf?(k: string): readonly K[];\n /** The keys with an edge to `k`, in key order, in a graph space or a tree space. Other spaces do not have it. */\n predecessorsOf?(k: string): readonly K[];\n}\n\n/** The key type of a grid space. */\nexport type GridKey = `${number},${number}`;\n\n/** The key type of an array space. */\nexport type ArrayKey = `${number}`;\n\nclass RecordSpace<K extends string, O> implements Space<K, O> {\n readonly kind: SpaceKind = \"record\";\n readonly keys: readonly K[];\n readonly records: readonly O[];\n readonly #records: ReadonlyMap<string, O>;\n\n constructor(records: Readonly<Record<K, O>>) {\n const entries = Object.entries(records) as [K, O][];\n this.keys = Object.freeze(entries.map(([k]) => k));\n this.records = Object.freeze(entries.map(([, o]) => o));\n this.#records = new Map(entries);\n }\n\n has(k: string): k is K {\n return this.#records.has(k);\n }\n get(k: string): O | undefined {\n return this.#records.get(k);\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n coords(): readonly number[] | undefined {\n return undefined;\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n keyAt(): K | undefined {\n return undefined;\n }\n}\n\nclass ArraySpace<O> implements Space<ArrayKey, O> {\n readonly kind: SpaceKind = \"array\";\n readonly keys: readonly ArrayKey[];\n readonly records: readonly O[];\n\n constructor(items: readonly O[]) {\n this.keys = Object.freeze(Array.from(items, (_item, i): ArrayKey => `${i}`));\n this.records = Object.freeze(Array.from(items));\n }\n\n // The key at the position i is the text of i, so the position of a key finds it. A text that is not a key of the\n // space, for example \"01\" or \"1.0\", has no key at its position.\n has(k: string): k is ArrayKey {\n return this.keys[Number(k)] === k;\n }\n get(k: string): O | undefined {\n return this.has(k) ? this.records[Number(k)] : undefined;\n }\n coords(k: string): readonly number[] | undefined {\n return this.has(k) ? [Number(k)] : undefined;\n }\n keyAt(coords: readonly number[]): ArrayKey | undefined {\n return coords.length === 1 ? this.keys[Number(coords[0])] : undefined;\n }\n}\n\nclass GridSpace<O> implements Space<GridKey, O> {\n readonly kind: SpaceKind = \"grid\";\n readonly keys: readonly GridKey[];\n readonly records: readonly O[];\n readonly #cells: ReadonlyMap<string, O>;\n readonly #coords: ReadonlyMap<string, readonly number[]>;\n\n constructor(rows: readonly (readonly O[])[]) {\n const entries = rows.flatMap((row, i) => row.map((cell, j): [GridKey, O, readonly number[]] => [`${i},${j}`, cell, Object.freeze([i, j])]));\n this.keys = Object.freeze(entries.map(([k]) => k));\n this.records = Object.freeze(entries.map(([, o]) => o));\n this.#cells = new Map(entries.map(([k, cell]) => [k, cell]));\n this.#coords = new Map(entries.map(([k, , c]) => [k, c]));\n }\n\n has(k: string): k is GridKey {\n return this.#cells.has(k);\n }\n get(k: string): O | undefined {\n return this.#cells.get(k);\n }\n coords(k: string): readonly number[] | undefined {\n return this.#coords.get(k);\n }\n keyAt(coords: readonly number[]): GridKey | undefined {\n // Each key has two coordinates, so a list with more or fewer coordinates gives no key.\n const k = coords.join(\",\");\n return this.has(k) ? k : undefined;\n }\n}\n\nclass TreeSpace<K extends string, O> implements Space<K, O> {\n readonly kind: SpaceKind = \"tree\";\n readonly keys: readonly K[];\n readonly records: readonly O[];\n readonly #records: ReadonlyMap<string, O>;\n readonly #parents: ReadonlyMap<string, K>;\n readonly #children: ReadonlyMap<string, readonly K[]>;\n\n constructor(records: Readonly<Record<K, O>>, parents: Readonly<Partial<Record<K, K | null>>>) {\n const entries = Object.entries(records) as [K, O][];\n this.keys = Object.freeze(entries.map(([k]) => k));\n this.records = Object.freeze(entries.map(([, o]) => o));\n this.#records = new Map(entries);\n const parentOf = new Map<string, K>();\n for (const [k, p] of Object.entries(parents) as [K, K | null | undefined][]) {\n if (!this.#records.has(k)) throw new TypeError(`the tree has no key \"${k}\", but the parents name it`);\n if (p === null || p === undefined) continue;\n if (!this.#records.has(p)) throw new TypeError(`the parent \"${p}\" of \"${k}\" is not a key of the tree`);\n parentOf.set(k, p);\n }\n // A parent chain that comes back to a key of the same walk is a cycle, not a tree. Each key is in one walk\n // only: a walk stops at a key that an earlier walk proved to reach a root. Thus the check is linear.\n const reachesRoot = new Set<string>();\n for (const k of this.keys) {\n const walk = new Set<string>();\n for (let p: string | undefined = k; p !== undefined && !reachesRoot.has(p); p = parentOf.get(p)) {\n if (walk.has(p)) throw new TypeError(`the parents of \"${k}\" make a cycle, so the space is not a tree`);\n walk.add(p);\n }\n for (const w of walk) reachesRoot.add(w);\n }\n this.#parents = parentOf;\n const children = new Map<string, K[]>(this.keys.map((k) => [k, []]));\n for (const k of this.keys) {\n const p = parentOf.get(k);\n // Each parent is a key, so its list exists, and the test of p only skips the roots.\n // Stryker disable next-line ConditionalExpression,OptionalChaining: a root has no list to push to\n if (p !== undefined) children.get(p)?.push(k);\n }\n this.#children = new Map([...children].map(([k, c]) => [k, Object.freeze(c)]));\n }\n\n has(k: string): k is K {\n return this.#records.has(k);\n }\n get(k: string): O | undefined {\n return this.#records.get(k);\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n coords(): readonly number[] | undefined {\n return undefined;\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n keyAt(): K | undefined {\n return undefined;\n }\n // In a tree, the edges go from a parent to its children.\n successorsOf(k: string): readonly K[] {\n return this.childrenOf(k);\n }\n predecessorsOf(k: string): readonly K[] {\n const p = this.#parents.get(k);\n return p === undefined ? [] : [p];\n }\n parentOf(k: string): K | undefined {\n return this.#parents.get(k);\n }\n childrenOf(k: string): readonly K[] {\n return this.#children.get(k) ?? [];\n }\n}\n\n/** The constructors of spaces. */\n/** The empty list of keys. */\nconst NO_KEYS: readonly never[] = Object.freeze([]);\n\nclass GraphSpace<K extends string, O> implements Space<K, O> {\n readonly kind: SpaceKind = \"graph\";\n readonly keys: readonly K[];\n readonly records: readonly O[];\n readonly #records: ReadonlyMap<string, O>;\n readonly #out: ReadonlyMap<string, readonly K[]>;\n readonly #in: ReadonlyMap<string, readonly K[]>;\n\n constructor(records: Readonly<Record<K, O>>, edges: Readonly<Partial<Record<K, readonly K[]>>>) {\n const entries = Object.entries(records) as [K, O][];\n this.keys = Object.freeze(entries.map(([k]) => k));\n this.records = Object.freeze(entries.map(([, o]) => o));\n this.#records = new Map(entries);\n const out = new Map<string, readonly K[]>();\n for (const [k, to] of Object.entries(edges) as [K, readonly K[] | undefined][]) {\n if (!this.#records.has(k)) throw new TypeError(`the graph has no key \"${k}\", but the edges name it`);\n // A second edge to the same key is the same edge.\n const ends = [...new Set(to ?? NO_KEYS)];\n for (const t of ends) if (!this.#records.has(t)) throw new TypeError(`the edge from \"${k}\" goes to \"${t}\", which is not a key of the graph`);\n out.set(k, Object.freeze(ends));\n }\n this.#out = out;\n // The predecessors in key order: the keys in key order, and the ends of the edges of each key.\n const into = new Map<string, K[]>();\n for (const k of this.keys) {\n for (const t of out.get(k) ?? NO_KEYS) {\n const from = into.get(t);\n if (from === undefined) into.set(t, [k]);\n else from.push(k);\n }\n }\n this.#in = new Map([...into].map(([k, from]) => [k, Object.freeze(from)]));\n }\n\n has(k: string): k is K {\n return this.#records.has(k);\n }\n get(k: string): O | undefined {\n return this.#records.get(k);\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n coords(): readonly number[] | undefined {\n return undefined;\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n keyAt(): K | undefined {\n return undefined;\n }\n successorsOf(k: string): readonly K[] {\n return this.#out.get(k) ?? NO_KEYS;\n }\n predecessorsOf(k: string): readonly K[] {\n return this.#in.get(k) ?? NO_KEYS;\n }\n}\n\nexport const space = {\n /** This function makes a space from the entries of an object. The keys are the property names. */\n record<const R extends Readonly<Record<string, unknown>>>(records: R): Space<keyof R & string, R[keyof R]> {\n return new RecordSpace<keyof R & string, R[keyof R]>(records);\n },\n /** This function makes a space from an array. The keys are `\"0\"`, `\"1\"` and so on. */\n array<O>(items: readonly O[]): Space<ArrayKey, O> {\n return new ArraySpace(items);\n },\n /** This function makes a space from rows of cells. The key of a cell is `\"row,column\"`. */\n grid<O>(rows: readonly (readonly O[])[]): Space<GridKey, O> {\n return new GridSpace(rows);\n },\n /**\n * This function makes a tree space: the records by key, and the parent of each key. A key without a parent, or\n * with the parent `null`, is a root. A parent that is not a key, or a cycle of parents, throws a `TypeError`.\n */\n tree<const R extends Readonly<Record<string, unknown>>>(records: R, parents: Readonly<Partial<Record<keyof R & string, (keyof R & string) | null>>>): Space<keyof R & string, R[keyof R]> {\n return new TreeSpace<keyof R & string, R[keyof R]>(records, parents);\n },\n /**\n * This function makes a graph space: the records by key, and the edges from each key, in order. An edge to a key\n * that is not in the graph throws a `TypeError`. A graph can have cycles, and an edge can go from a key to itself.\n */\n graph<const R extends Readonly<Record<string, unknown>>>(records: R, edges: Readonly<Partial<Record<keyof R & string, readonly (keyof R & string)[]>>>): Space<keyof R & string, R[keyof R]> {\n return new GraphSpace<keyof R & string, R[keyof R]>(records, edges);\n },\n} as const;\n\n/** The position of an evaluation: the key where it started, and the key where relative references read. */\nexport interface Position {\n readonly origin: string;\n readonly focus: string;\n}\n\n/** This function applies one move to the focus. It gives the new focus, or a `#REF!` error. */\nexport function applyMove(s: Space, at: Position, m: FixedMove): Result<string> {\n const refError = (kind: \"unknown-key\" | \"not-a-pair\" | \"out-of-bounds\" | \"no-offset\" | \"no-tree\", message: string): Result<string> =>\n fail(vexError(kind, message, { origin: at.origin, focus: at.focus }));\n switch (m.t) {\n case \"key\":\n return s.has(m.key) ? ok(m.key) : refError(\"unknown-key\", `the space has no key \"${m.key}\"`);\n case \"index\": {\n const k = s.keys[m.i];\n return k !== undefined ? ok(k) : refError(\"out-of-bounds\", `the space has no key at index ${m.i}`);\n }\n case \"other\": {\n if (s.keys.length !== 2) return refError(\"not-a-pair\", `\"other\" needs a space with 2 keys, but this space has ${s.keys.length}`);\n const [a, b] = s.keys;\n // A pair has two keys, so `a` and `b` are defined.\n /* v8 ignore next -- @preserve */\n return ok(at.focus === a ? (b ?? at.focus) : (a ?? at.focus));\n }\n case \"offset\": {\n // In a tree space, an offset with one number moves among the siblings in key order. The roots are siblings.\n const parentOf = s.parentOf?.bind(s);\n const childrenOf = s.childrenOf?.bind(s);\n if (parentOf !== undefined && childrenOf !== undefined && m.d.length === 1) {\n const p = parentOf(at.focus);\n const group = p === undefined ? s.keys.filter((k) => parentOf(k) === undefined) : childrenOf(p);\n const i = group.indexOf(at.focus);\n const k = i < 0 ? undefined : group[i + (m.d[0] ?? 0)];\n return k === undefined ? refError(\"out-of-bounds\", `the offset [${m.d.join(\",\")}] from \"${at.focus}\" is outside its siblings`) : ok(k);\n }\n const c = s.coords(at.focus);\n if (c === undefined || c.length !== m.d.length) {\n return refError(\"no-offset\", `an offset of length ${m.d.length} is not valid in a ${s.kind} space`);\n }\n // The lengths are equal, so each index of `c` is also an index of `m.d`.\n /* v8 ignore next -- @preserve */\n const target = c.map((x, i) => x + (m.d[i] ?? 0));\n const k = s.keyAt(target);\n return k === undefined ? refError(\"out-of-bounds\", `the offset [${m.d.join(\",\")}] from \"${at.focus}\" is outside the space`) : ok(k);\n }\n case \"origin\":\n return ok(at.origin);\n case \"parent\": {\n if (s.parentOf === undefined) return refError(\"no-tree\", `\"parent\" needs a tree space, but this space is a ${s.kind}`);\n const p = s.parentOf(at.focus);\n return p === undefined ? refError(\"out-of-bounds\", `the key \"${at.focus}\" is a root, so it has no parent`) : ok(p);\n }\n }\n}\n\n/**\n * This function gives the fixed moves of an address. `values` has the value of the expression of each computed move,\n * in order (NAV.COMPUTED). A key that is not a text, or a position that is not a number, gives `#VALUE!`.\n */\nexport function fixAddr(addr: Addr, values: readonly unknown[], at: Position): Result<readonly FixedMove[]> {\n const out: FixedMove[] = [];\n let next = 0;\n for (const m of addr) {\n if (moveExpr(m) === undefined) {\n out.push(m as FixedMove);\n continue;\n }\n const u = values[next++];\n if (m.t === \"key\" && typeof u === \"string\") out.push({ t: \"key\", key: u });\n else if (m.t === \"index\" && typeof u === \"number\") out.push({ t: \"index\", i: u });\n else return fail(vexError(\"kind-mismatch\", m.t === \"key\" ? `the key of a move is a ${typeof u}, not a text` : `the position of a move is a ${typeof u}, not a number`, at));\n }\n return ok(out);\n}\n\n/** This function applies the moves of an address in order. It gives the key where the address points. */\nexport function resolveAddr(s: Space, at: Position, addr: readonly FixedMove[] | undefined): Result<string> {\n let focus = at.focus;\n for (const m of addr ?? []) {\n const r = applyMove(s, { origin: at.origin, focus }, m);\n if (!r.ok) return r;\n focus = r.value;\n }\n return ok(focus);\n}\n\nconst NEIGHBORS_4: readonly (readonly [number, number])[] = [[-1, 0], [0, -1], [0, 1], [1, 0]];\nconst NEIGHBORS_8: readonly (readonly [number, number])[] = [\n [-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1],\n];\n\n/** The axes of a tree space. */\ntype TreeAxis = \"children\" | \"ancestors\" | \"descendants\" | \"siblings\";\n\nfunction treeTargets(s: Space, at: Position, t: TreeAxis): Result<readonly string[]> {\n const parentOf = s.parentOf?.bind(s);\n const childrenOf = s.childrenOf?.bind(s);\n if (parentOf === undefined || childrenOf === undefined) {\n return fail(vexError(\"no-tree\", `\"${t}\" needs a tree space, but this space is a ${s.kind}`, at));\n }\n switch (t) {\n case \"children\":\n return ok(childrenOf(at.focus));\n case \"ancestors\": {\n const out: string[] = [];\n for (let p = parentOf(at.focus); p !== undefined; p = parentOf(p)) out.push(p);\n return ok(out);\n }\n case \"descendants\": {\n // A depth-first walk with a stack, so a deep tree does not need a deep call stack.\n const out: string[] = [];\n const stack = childrenOf(at.focus).toReversed();\n for (let k = stack.pop(); k !== undefined; k = stack.pop()) {\n out.push(k);\n stack.push(...childrenOf(k).toReversed());\n }\n return ok(out);\n }\n case \"siblings\": {\n const p = parentOf(at.focus);\n const group = p === undefined ? s.keys.filter((k) => parentOf(k) === undefined) : childrenOf(p);\n return ok(group.filter((k) => k !== at.focus));\n }\n }\n}\n\n/**\n * This function gives the targets of a base axis at a focus. It does not handle `where`, because the\n * interpreter must evaluate the test.\n */\nexport function axisTargets(s: Space, at: Position, a: Exclude<Axis, { readonly t: \"where\" }>): Result<readonly string[]> {\n switch (a.t) {\n case \"all\":\n return ok(s.keys);\n case \"others\":\n return ok(s.keys.filter((k) => k !== at.focus));\n case \"other\": {\n const r = applyMove(s, at, { t: \"other\" });\n return r.ok ? ok([r.value]) : r;\n }\n case \"neighbors\": {\n if (s.kind !== \"grid\") return fail(vexError(\"no-grid\", `\"neighbors\" needs a grid space, but this space is a ${s.kind}`, at));\n const deltas = a.n === 4 ? NEIGHBORS_4 : NEIGHBORS_8;\n return ok(\n deltas.flatMap((d) => {\n const r = applyMove(s, at, { t: \"offset\", d });\n return r.ok ? [r.value] : [];\n }),\n );\n }\n case \"children\":\n case \"ancestors\":\n case \"descendants\":\n case \"siblings\":\n return treeTargets(s, at, a.t);\n case \"window\":\n return windowTargets(s, at, a.from, a.to);\n case \"successors\":\n case \"predecessors\":\n case \"reachable\":\n return graphTargets(s, at, a.t);\n case \"table\":\n // The evaluator gives the axis table the space of its table. Here, without the tables, it has no targets.\n return fail(vexError(\"no-table\", `the axis \"table\" needs the tables of the evaluation, and \"${a.name}\" is not one of them`, at));\n }\n}\n\n/**\n * This function gives the targets of an axis of a graph. `reachable` has each key that a path of one or more edges\n * reaches from the focus, once, in the order of a breadth-first search. The focus is not a target of `reachable`.\n */\nfunction graphTargets(s: Space, at: Position, t: \"successors\" | \"predecessors\" | \"reachable\"): Result<readonly string[]> {\n const successorsOf = s.successorsOf?.bind(s);\n const predecessorsOf = s.predecessorsOf?.bind(s);\n if (successorsOf === undefined || predecessorsOf === undefined) {\n return fail(vexError(\"no-graph\", `\"${t}\" needs a graph space or a tree space, but this space is a ${s.kind}`, at));\n }\n if (t === \"successors\") return ok(successorsOf(at.focus));\n if (t === \"predecessors\") return ok(predecessorsOf(at.focus));\n // A queue, not recursion, so a long path does not need a deep call stack. A loop over an array also reads the\n // keys that the loop adds to it.\n const seen = new Set<string>([at.focus]);\n const queue: string[] = [at.focus];\n for (const k of queue) {\n for (const next of successorsOf(k)) {\n if (seen.has(next)) continue;\n seen.add(next);\n queue.push(next);\n }\n }\n return ok(queue.slice(1));\n}\n\n/**\n * This function gives the targets of the axis `window(from, to)`: the keys of the moves `offset(d)` for each `d`\n * from `from` to `to`, in order. An offset outside the space has no target. The axis needs an array space or a tree\n * space, where an offset has one number.\n */\nfunction windowTargets(s: Space, at: Position, from: number, to: number): Result<readonly string[]> {\n const tree = s.parentOf !== undefined && s.childrenOf !== undefined;\n if (!tree && s.coords(at.focus)?.length !== 1) {\n return fail(vexError(\"no-offset\", `\"window\" needs an array space or a tree space, but this space is a ${s.kind}`, at));\n }\n // An offset larger than the number of keys has no target, so the loop stays in the size of the space.\n const out: string[] = [];\n for (let d = Math.max(from, -s.keys.length); d <= Math.min(to, s.keys.length); d++) {\n const r = applyMove(s, at, { t: \"offset\", d: [d] });\n if (r.ok) out.push(r.value);\n }\n return ok(out);\n}\n","/**\n * Domains. A domain tells which values belong to it and which ops it has. The domain object owns this data.\n * Vex does not write to the prototypes of domain classes, and an import has no side effects.\n */\n\n/** An algebraic law that an op claims. `@mark1russell7/vex-testkit` checks each claim with property tests. */\nexport type Law = \"commutative\" | \"associative\" | \"idempotent\";\n\n/** The kind of a parameter. The interpreter checks the arguments of an op that declares its parameters. */\nexport type ParamKind = \"domain\" | \"number\" | \"boolean\" | \"string\" | \"any\";\n\n/** The kind of the result of an op: a kind of a parameter, or `domain:Name` for a value of the domain `Name`. */\nexport type ReturnKind = ParamKind | `domain:${string}`;\n\n/** The description of one op of a domain. */\nexport interface OpSpec<D = never> {\n /**\n * The implementation, for an op that is not a method of the value (static-land style). The first argument\n * is the receiver. Without `fn`, the interpreter calls the method of the receiver with the same name.\n */\n readonly fn?: (self: D, ...args: never[]) => unknown;\n /** The laws that the op claims. */\n readonly laws?: readonly Law[];\n /** The identity element of the op, for reductions over an empty list. */\n readonly identity?: () => D;\n /** Scalar lifting: `true` lifts each number argument with `fromScalar`. An array sets it for each argument. */\n readonly liftScalar?: boolean | readonly boolean[];\n /** The kinds of the parameters after the receiver. When set, the interpreter checks the arguments. */\n readonly params?: readonly ParamKind[];\n /**\n * The kind of the result: `domain` for a value of this domain, and `domain:Name` for a value of the domain `Name`. A\n * compiler reads it to know the kinds of the values of a program (KIND.RETURNS). The interpreter does not check it,\n * and the law checker of the test kit does.\n */\n readonly returns?: ReturnKind;\n}\n\n/** A JavaScript type of primitive values that a domain can accept. */\nexport type PrimitiveKind = \"number\" | \"string\" | \"boolean\";\n\n/** The type of an op that lifts number arguments. Use it to type the ops of a domain under `isolatedDeclarations`. */\nexport type LiftedOp<D> = OpSpec<D> & { readonly liftScalar: true };\n\n/** The type of an op with an implementation function `F`. */\nexport type FnOp<D, F extends (self: D, ...args: never[]) => unknown> = OpSpec<D> & { readonly fn: F };\n\n/**\n * The type of an op table: each name in `Names` is an op, and each name in `Lifted` lifts number arguments.\n * Use it to type the ops of a domain under `isolatedDeclarations`.\n */\nexport type OpTable<D, Names extends string, Lifted extends string = never> = {\n readonly [N in Names]: N extends Lifted ? LiftedOp<D> : OpSpec<D>;\n};\n\n/** The description of a domain, as a caller gives it to `defineDomain`. */\nexport interface DomainSpec<Name extends string, D, Ops extends Readonly<Record<string, OpSpec<D>>>> {\n /** The name of the domain. */\n readonly name: Name;\n /** The runtime test for the values of the domain. It must not give false positives. */\n readonly is: (u: unknown) => u is D;\n /**\n * The JavaScript type of the values of the domain, if `is` accepts each value of that type and no other value\n * (KIND.PRIMITIVE). A compiler then finds the op of such a value before a run.\n */\n readonly primitive?: PrimitiveKind;\n /** The ops of the domain, with their metadata. */\n readonly ops: Ops;\n /** With `\"all\"`, each method of a value is an op, also without an entry in `ops`. The default is `\"declared\"`. */\n readonly methods?: \"declared\" | \"all\";\n /** The scalar lift: it makes a domain value from a number. */\n readonly fromScalar?: (n: number) => D;\n /** A check of the values that ops give. A value that fails the check gives the error `#NUM!`. */\n readonly valid?: (d: D) => boolean;\n /** A short text for a value, for traces and the site. */\n readonly show?: (d: D) => string;\n /** The JSON form of a value, for literals in serialized programs. */\n readonly encode?: (d: D) => unknown;\n /** The value of a JSON form that `encode` made. */\n readonly decode?: (json: unknown) => D;\n /**\n * 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\n * results (KIND.DOMAIN).\n */\n readonly samples?: () => readonly D[];\n}\n\n/** A domain. Make one with `defineDomain`. */\nexport interface Domain<Name extends string = string, D = unknown, Ops extends Readonly<Record<string, OpSpec<D>>> = Readonly<Record<string, OpSpec<D>>>>\n extends DomainSpec<Name, D, Ops> {\n readonly kind: \"vex.domain\";\n}\n\n/** A domain with any value type. The interpreter uses this type. */\n// oxlint-disable-next-line typescript/no-explicit-any -- a list of domains with different value types needs `any`: `fn` is contravariant in the value type.\nexport type AnyDomain = Domain<string, any, Readonly<Record<string, OpSpec<any>>>>;\n\n/** This function makes a domain. The result is frozen. */\nexport function defineDomain<const Name extends string, D, const Ops extends Readonly<Record<string, OpSpec<D>>>>(\n spec: DomainSpec<Name, D, Ops>,\n): Domain<Name, D, Ops> {\n return Object.freeze({ ...spec, kind: \"vex.domain\" as const });\n}\n\nconst FORBIDDEN = new Set([\"constructor\", \"__proto__\", \"prototype\", \"__defineGetter__\", \"__defineSetter__\", \"__lookupGetter__\", \"__lookupSetter__\"]);\n\n/** This function tells if a name can be an op name. */\nexport const isOpName = (name: string): boolean => name.length > 0 && !FORBIDDEN.has(name);\n\n/**\n * This function finds a method on a value: an own function property, or a function on the prototype chain.\n * It stops at `Object.prototype` and `Function.prototype`, so inherited members (for example `toString`) are not ops.\n */\nexport function findMethod(self: unknown, name: string): ((...args: unknown[]) => unknown) | undefined {\n if (!isOpName(name)) return undefined;\n // A primitive has no own methods. The loop below stops at null, so null needs no test here.\n if (typeof self !== \"object\" && typeof self !== \"function\") return undefined;\n let o: object | null = self;\n while (o !== null && o !== Object.prototype && o !== Function.prototype) {\n const d = Object.getOwnPropertyDescriptor(o, name);\n if (d !== undefined) {\n return typeof d.value === \"function\" ? (d.value as (...args: unknown[]) => unknown) : undefined;\n }\n o = Object.getPrototypeOf(o) as object | null;\n }\n return undefined;\n}\n\n/** An op that the interpreter found for a receiver. */\nexport interface ResolvedOp {\n readonly domain: AnyDomain;\n readonly spec: OpSpec<unknown>;\n readonly call: (args: readonly unknown[]) => unknown;\n}\n\nconst EMPTY_SPEC: OpSpec<unknown> = Object.freeze({});\n\n/** This function finds the op `name` for `self` in one domain. It gives `undefined` if the domain does not have it. */\nexport function resolveOp(domain: AnyDomain, self: unknown, name: string): ResolvedOp | undefined {\n if (!isOpName(name)) return undefined;\n const declared = Object.hasOwn(domain.ops, name) ? (domain.ops[name] as OpSpec<unknown>) : undefined;\n if (declared?.fn !== undefined) {\n const fn = declared.fn as (self: unknown, ...args: unknown[]) => unknown;\n return { domain, spec: declared, call: (args) => fn(self, ...args) };\n }\n if (declared === undefined && domain.methods !== \"all\") return undefined;\n const method = findMethod(self, name);\n if (method === undefined) return undefined;\n return { domain, spec: declared ?? EMPTY_SPEC, call: (args) => method.apply(self, [...args]) };\n}\n\n/** This function gives the domain of a value: the first domain whose `is` accepts it. */\nexport function domainOf(domains: readonly AnyDomain[], value: unknown): AnyDomain | undefined {\n return domains.find((d) => d.is(value));\n}\n\n/** This function tells if the `liftScalar` setting lifts the argument at `index`. */\nexport const liftsAt = (lift: OpSpec<unknown>[\"liftScalar\"], index: number): boolean =>\n lift === true || (Array.isArray(lift) && lift[index] === true);\n","import type { Result } from \"./result.ts\";\n\n/** One item of a list: the key of the target and the result of the body there. */\nexport interface ListItem<T = unknown> {\n readonly key: string;\n readonly result: Result<T>;\n}\n\n/** The value of an `each` expression: one item for each target of the axis. */\nexport interface VexList<T = unknown> {\n readonly kind: \"vex.list\";\n readonly items: readonly ListItem<T>[];\n}\n\n/** This function makes a list. */\nexport const vexList = <T>(items: readonly ListItem<T>[]): VexList<T> => Object.freeze({ kind: \"vex.list\", items: Object.freeze([...items]) });\n\n/** This function tells if a value is a Vex list. */\nexport const isVexList = (u: unknown): u is VexList =>\n (u as { kind?: unknown } | null | undefined)?.kind === \"vex.list\" && Array.isArray((u as { items?: unknown }).items);\n\n/** The name of a core list op. */\nexport type ListOp = \"count\" | \"sum\" | \"min\" | \"max\" | \"mean\" | \"any\" | \"all\" | \"none\" | \"values\" | \"keys\" | \"reduce\" | \"first\" | \"errors\";\n\n/** The names of the core list ops. They apply when the first argument is a list. */\nexport const LIST_OPS: ReadonlySet<string> = new Set<ListOp>([\"count\", \"sum\", \"min\", \"max\", \"mean\", \"any\", \"all\", \"none\", \"values\", \"keys\", \"reduce\", \"first\", \"errors\"]);\n\n/** This function tells if a name is the name of a core list op. */\nexport const isListOp = (op: string): op is ListOp => LIST_OPS.has(op);\n\n/** The options of a list op. */\nexport interface ListOptions {\n /** With `true`, any error item makes the result that error. The default skips error items. */\n readonly strict?: boolean;\n}\n","import { liftsAt, resolveOp, type AnyDomain, type ParamKind, type ResolvedOp } from \"./domain.ts\";\nimport { formatError, isDepthError, isStackOverflow, vexError, type ErrorKind, type VexError } from \"./errors.ts\";\nimport { addrExprs, children, shapeError, type Addr, type Axis, type Expr, type ExprOf, type FixedMove, type Move } from \"./ir.ts\";\nimport { isListOp, isVexList, vexList, type ListItem, type ListOp, type ListOptions, type VexList } from \"./list.ts\";\nimport { fail, ok, type Result } from \"./result.ts\";\nimport { axisTargets, fixAddr, resolveAddr, type Position, type Space } from \"./space.ts\";\nimport type { Read, Trace, TraceEvent, TraceSink } from \"./trace.ts\";\n\n/** A free function op. The interpreter gives it the values of all arguments. */\nexport type FreeFn = (...args: readonly unknown[]) => unknown;\n\n/** The context of an extension handler. */\nexport interface ExtContext {\n readonly space: Space;\n readonly position: Position;\n readonly path: readonly number[];\n}\n\n/** The handler of an extension expression kind. */\nexport type ExtHandler = (data: unknown, ctx: ExtContext) => Result<unknown>;\n\n/** The options of an evaluation. */\nexport interface EvalOptions {\n /** The space that the program reads. */\n readonly space: Space;\n /** The key where the evaluation starts. Relative references read here. */\n readonly origin: string;\n /** The domains. The interpreter finds the op of a value in the first domain that accepts the value. */\n readonly domains?: readonly AnyDomain[];\n /** Free function ops, for ops that are not domain ops. */\n readonly fns?: Readonly<Record<string, FreeFn>>;\n /** The handlers of extension expression kinds. */\n readonly extensions?: Readonly<Record<string, ExtHandler>>;\n /** Variables that the program can read with `v(name)`. */\n readonly vars?: Readonly<Record<string, unknown>>;\n /** The other spaces of the evaluation, by name. The axis `table(name)` reads them. */\n readonly tables?: Readonly<Record<string, Space>>;\n /** A receiver of trace events. */\n readonly trace?: TraceSink;\n}\n\ntype Env = ReadonlyMap<string, Result<unknown>>;\n\ninterface Frame {\n readonly pos: Position;\n readonly env: Env;\n}\n\n/** The name of a special form. */\nexport type SpecialForm = \"if\" | \"and\" | \"or\" | \"ifError\";\n\n/** The names of the special forms. Their arguments are not evaluated before the call. */\nexport const SPECIAL_FORMS: ReadonlySet<string> = new Set<SpecialForm>([\"if\", \"and\", \"or\", \"ifError\"]);\n\nconst isSpecialForm = (op: string): op is SpecialForm => SPECIAL_FORMS.has(op);\n\n/** The options that a compiled program keeps: the domains, the free functions and the extension handlers. */\nexport type CompileOptions = Pick<EvalOptions, \"domains\" | \"fns\" | \"extensions\">;\n\n/** The options of one run of a compiled program. */\nexport type RunOptions = Pick<EvalOptions, \"space\" | \"origin\" | \"vars\" | \"trace\" | \"tables\">;\n\n/**\n * A compiled program: the expression as a tree of functions. A program evaluates many times at different origins,\n * and over different spaces, without a new walk of the expression.\n */\nexport interface Program {\n /** The expression of the program. */\n readonly expr: Expr;\n /** This method evaluates the program at an origin. It does not throw. */\n run(opts: RunOptions): Result<unknown>;\n /** This method evaluates the program at an origin, with a trace of each node. */\n explain(opts: Omit<RunOptions, \"trace\">): Trace;\n}\n\n/**\n * This function compiles an expression. The result gives the same results and the same traces as `evaluate`,\n * because `evaluate` uses it too.\n */\n/** The deepest nesting of an expression that `compile` accepts (EVAL.NESTING). */\nexport const MAX_NESTING = 500;\n\nconst DEPTH_MESSAGE = \"the evaluation is too deep for the call stack of the engine\";\n\n/** This function gives the number of nodes on the longest path from the root of `e`. It uses a stack, not recursion. */\nexport function nestingOf(e: Expr): number {\n let deepest = 0;\n const todo: [Expr, number][] = [[e, 1]];\n for (let item = todo.pop(); item !== undefined; item = todo.pop()) {\n const [x, d] = item;\n if (d > deepest) deepest = d;\n for (const child of children(x)) todo.push([child, d + 1]);\n }\n return deepest;\n}\n\nexport function compile(expr: Expr, opts: CompileOptions = {}): Program {\n // EVAL.SHAPE: an expression that is not valid, for example from a newer version of Vex, gives an error before a walk.\n // EVAL.NESTING: a program nested too deep gives an error before the compiler walks it with recursion.\n const shape = shapeError(expr);\n const nesting = shape === undefined ? nestingOf(expr) : 0;\n const bad = shape ?? (nesting > MAX_NESTING ? `the expression is nested ${nesting} levels deep, and the limit is ${MAX_NESTING}` : undefined);\n const root: Node = bad === undefined ? new Compiler(opts).node(expr, []) : (f) => fail(vexError(\"bad-expression\", bad, { path: [], origin: f.pos.origin, focus: f.pos.focus }));\n const run = (r: RunOptions): Result<unknown> => {\n const { space, origin } = r;\n if (!space.has(origin)) return fail(vexError(\"unknown-key\", `the space has no key \"${origin}\"`, { origin, focus: origin }));\n const env = new Map<string, Result<unknown>>(Object.entries(r.vars ?? {}).map(([k, val]) => [k, ok(val)]));\n try {\n return root({ pos: { origin, focus: origin }, env }, { space, trace: r.trace, tables: r.tables });\n } catch (thrown) {\n // A defect in an extension handler or in a test of the interpreter itself. Totality still holds.\n if (isStackOverflow(thrown)) return fail(vexError(\"depth\", DEPTH_MESSAGE, { origin, focus: origin, thrown }));\n return fail(vexError(\"threw\", \"the evaluation threw an exception\", { origin, focus: origin, thrown }));\n }\n };\n return {\n expr,\n run,\n explain: (r) => {\n const sink: TraceSink = { events: [] };\n const result = run({ ...r, trace: sink });\n return { events: sink.events, result };\n },\n };\n}\n\n// The cache of compiled programs: one entry for each expression object, for the last options.\nconst CACHE = new WeakMap<Expr, { readonly domains: unknown; readonly fns: unknown; readonly extensions: unknown; readonly program: Program }>();\n\nfunction compiled(expr: Expr, opts: CompileOptions): Program {\n const hit = CACHE.get(expr);\n // Without the cache, each evaluation compiles again: the result is the same, so a mutant that removes a hit is\n // equivalent. A false hit changes results, and the tests find it.\n // Stryker disable next-line ConditionalExpression: a missed hit only compiles again\n if (hit !== undefined && hit.domains === opts.domains && hit.fns === opts.fns && hit.extensions === opts.extensions) return hit.program;\n const program = compile(expr, opts);\n CACHE.set(expr, { domains: opts.domains, fns: opts.fns, extensions: opts.extensions, program });\n return program;\n}\n\n/** This function evaluates an expression at the origin of a space. It does not throw. */\nexport function evaluate(expr: Expr, opts: EvalOptions): Result<unknown> {\n return compiled(expr, opts).run(opts);\n}\n\n/** This function evaluates an expression and records a trace of each node. */\nexport function explain(expr: Expr, opts: Omit<EvalOptions, \"trace\">): Trace {\n return compiled(expr, opts).explain(opts);\n}\n\n/** The state of one run that the nodes read: the space, the trace sink and the other spaces. */\ninterface Ctx {\n readonly space: Space;\n readonly trace: TraceSink | undefined;\n readonly tables: Readonly<Record<string, Space>> | undefined;\n}\n\n/** This function gives the axis inside the `where` axes of an axis. */\nconst baseAxis = (a: Axis): Exclude<Axis, { readonly t: \"where\" }> => (a.t === \"where\" ? baseAxis(a.axis) : a);\n\n/** A compiled node: it evaluates in a frame of a run. */\ntype Node = (f: Frame, c: Ctx) => Result<unknown>;\n\n/** The static facts of a node for its trace events. */\ninterface Info {\n readonly path: readonly number[];\n readonly tag: Expr[\"tag\"];\n readonly label: string;\n}\n\nclass Compiler {\n readonly #domains: readonly AnyDomain[];\n readonly #fns: Readonly<Record<string, FreeFn>> | undefined;\n readonly #extensions: Readonly<Record<string, ExtHandler>> | undefined;\n\n constructor(opts: CompileOptions) {\n // Stryker disable next-line ArrayDeclaration: a list with a value that is not a domain matches no value\n this.#domains = opts.domains ?? [];\n this.#fns = opts.fns;\n this.#extensions = opts.extensions;\n }\n\n #err(kind: ErrorKind, message: string, f: Frame, path: readonly number[], extra: { op?: string; causes?: readonly VexError[]; thrown?: unknown } = {}): Result<never> {\n return fail(vexError(kind, message, { path, origin: f.pos.origin, focus: f.pos.focus, ...extra }));\n }\n\n #emit(c: Ctx, info: Info, f: Frame, result: Result<unknown>, reads?: readonly Read[]): Result<unknown> {\n if (c.trace !== undefined) {\n const event: TraceEvent = {\n path: info.path,\n tag: info.tag,\n label: info.label,\n origin: f.pos.origin,\n focus: f.pos.focus,\n ...(reads === undefined ? {} : { reads }),\n result,\n };\n c.trace.events.push(event);\n }\n return result;\n }\n\n /** This method compiles the expression `e` at the position `path` of the tree. */\n node(e: Expr, path: readonly number[]): Node {\n const info: Info = { path, tag: e.tag, label: labelOf(e) };\n switch (e.tag) {\n case \"lit\": {\n const r = ok(e.value);\n return (f, c) => this.#emit(c, info, f, r);\n }\n case \"ref\":\n return this.#ref(e, info);\n case \"var\": {\n const name = e.name;\n return (f, c) => this.#emit(c, info, f, f.env.get(name) ?? this.#err(\"unbound\", `the name \"${name}\" has no binding`, f, path));\n }\n case \"let\": {\n const binds = Object.entries(e.bind).map(([name, be], i): readonly [string, Node] => [name, this.node(be, [...path, i])]);\n const body = this.node(e.body, [...path, binds.length]);\n return (f, c) => {\n const env = new Map(f.env);\n for (const [name, n] of binds) env.set(name, n(f, c));\n return this.#emit(c, info, f, body({ pos: f.pos, env }, c));\n };\n }\n case \"rec\": {\n const names = Object.keys(e.fields);\n const fields = this.#nodes(Object.values(e.fields), path);\n return (f, c) => {\n const values = this.#all(fields, f, c, path, \"fields\");\n if (!values.ok) return this.#emit(c, info, f, values);\n const out: Record<string, unknown> = {};\n names.forEach((n, i) => {\n out[n] = values.value[i];\n });\n return this.#emit(c, info, f, ok(Object.freeze(out)));\n };\n }\n case \"app\":\n return isSpecialForm(e.op) ? this.#special(e.op, this.#nodes(e.args, path), info) : this.#app(e.op, this.#nodes(e.args, path), info);\n case \"each\":\n return this.#each(e, info);\n case \"fold\":\n return this.#fold(e, info);\n case \"iterate\":\n return this.#iterate(e, info);\n case \"ext\": {\n const extensions = this.#extensions ?? {};\n const handler = Object.hasOwn(extensions, e.kind) ? extensions[e.kind] : undefined;\n const { kind, data } = e;\n if (handler === undefined) return (f, c) => this.#emit(c, info, f, this.#err(\"unknown-op\", `no handler for the extension kind \"${kind}\"`, f, path));\n return (f, c) =>\n this.#emit(c, info, f, this.#locate(this.#guard(() => handler(data, { space: c.space, position: f.pos, path }), f, path, kind), f, path));\n }\n }\n }\n\n #nodes(es: readonly Expr[], path: readonly number[]): readonly Node[] {\n return es.map((x, i) => this.node(x, [...path, i]));\n }\n\n /** This method gives an error of a handler the path, the origin and the focus of its node, if it has no origin. */\n #locate(r: Result<unknown>, f: Frame, path: readonly number[]): Result<unknown> {\n if (r.ok || r.error.origin !== undefined) return r;\n return fail({ ...r.error, path, origin: f.pos.origin, focus: f.pos.focus });\n }\n\n #guard(run: () => Result<unknown>, f: Frame, path: readonly number[], op: string): Result<unknown> {\n try {\n return run();\n } catch (thrown) {\n return this.#threw(thrown, `\"${op}\" threw an exception`, f, path, { op });\n }\n }\n\n /** This method gives the error of an exception: `#DEPTH!` for a full call stack, and `#CALC!` for each other exception. */\n #threw(thrown: unknown, message: string, f: Frame, path: readonly number[], extra: Partial<VexError> = {}): Result<never> {\n return isStackOverflow(thrown) ? this.#err(\"depth\", DEPTH_MESSAGE, f, path, { ...extra, thrown }) : this.#err(\"threw\", message, f, path, { ...extra, thrown });\n }\n\n /**\n * This method compiles an address. Its function gives the key where the address points. The expressions of the\n * computed moves evaluate first, at the position of the node, and their child indexes start at `first`. An error of\n * an expression keeps its path, and an error of a move gets the path of the node.\n */\n #address(at: Addr, path: readonly number[], first: number): (f: Frame, c: Ctx) => Result<string> {\n const nodes = addrExprs(at).map((x, i) => this.node(x, [...path, first + i]));\n const moved = (r: Result<string>): Result<string> => (r.ok ? r : fail({ ...r.error, path }));\n if (nodes.length === 0) return (f, c) => moved(resolveAddr(c.space, f.pos, at as readonly FixedMove[]));\n return (f, c) => {\n const values: unknown[] = [];\n for (const n of nodes) {\n const r = n(f, c);\n if (!r.ok) return r;\n values.push(r.value);\n }\n const fixed = fixAddr(at, values, f.pos);\n return fixed.ok ? moved(resolveAddr(c.space, f.pos, fixed.value)) : moved(fixed);\n };\n }\n\n #ref(e: ExprOf<\"ref\">, info: Info): Node {\n const { path } = info;\n const segs = e.path;\n const at = e.at ?? [];\n const address = this.#address(at, path, 0);\n const label = segs.join(\".\");\n const steps = segs.map((seg, i) => ({ seg, where: segs.slice(0, i + 1).join(\".\"), valid: isFieldName(seg) }));\n return (f, c) => {\n let key = f.pos.focus;\n // The empty address resolves to the focus, so this fast path changes no result.\n // Stryker disable next-line ConditionalExpression,EqualityOperator: resolveAddr of [] gives the focus too\n if (at.length > 0) {\n const where = address(f, c);\n if (!where.ok) return this.#emit(c, info, f, where);\n key = where.value;\n }\n const failed = (r: Result<unknown>): Result<unknown> => this.#emit(c, info, f, r, [{ key, path: segs, ok: false }]);\n const missing = (where: string): Result<unknown> => failed(this.#err(\"missing-field\", `the record at \"${key}\" has no value at \"${where}\"`, f, path));\n let value: unknown = c.space.get(key);\n if (value === undefined || value === null) return missing(label === \"\" ? \"(record)\" : label);\n for (const { seg, where, valid } of steps) {\n if ((typeof value !== \"object\" && typeof value !== \"function\") || !valid) return missing(where);\n try {\n value = Reflect.get(value, seg);\n } catch (thrown) {\n return failed(this.#threw(thrown, `reading \"${where}\" at \"${key}\" threw an exception`, f, path));\n }\n if (value === undefined || value === null) return missing(where);\n }\n return this.#emit(c, info, f, ok(value), [{ key, path: segs, ok: true }]);\n };\n }\n\n /** This method evaluates nodes applicatively. One failure stays as it is. Two or more give `#ARGS`. */\n #all(nodes: readonly Node[], f: Frame, c: Ctx, path: readonly number[], what: string): Result<readonly unknown[]> {\n const values: unknown[] = [];\n let first: VexError | undefined;\n let errors: VexError[] | undefined;\n for (const n of nodes) {\n const r = n(f, c);\n if (r.ok) values.push(r.value);\n else if (first === undefined) first = r.error;\n else (errors ??= [first]).push(r.error);\n }\n if (first === undefined) return ok(values);\n // A #DEPTH! argument is the result, so #ARGS does not wrap it, and ifError cannot hide it.\n const depth = [first, ...(errors ?? [])].find(isDepthError);\n if (depth !== undefined) return fail(depth);\n return errors === undefined ? fail(first) : this.#err(\"args\", `${errors.length} ${what} failed`, f, path, { causes: errors });\n }\n\n #each(e: ExprOf<\"each\">, info: Info): Node {\n const { path } = info;\n const at = e.at ?? [];\n const counter = { next: 1 };\n const targets = this.#targets(e.axis, path, counter);\n const body = this.node(e.body, [...path, 0]);\n const address = this.#address(at, path, counter.next);\n return (f, c) => {\n // An axis with an address finds its targets from the key of the address. The origin does not change.\n let from = f;\n // Stryker disable next-line ConditionalExpression,EqualityOperator: resolveAddr of [] gives the focus too\n if (at.length > 0) {\n const where = address(f, c);\n if (!where.ok) return this.#emit(c, info, f, where);\n from = { pos: { origin: f.pos.origin, focus: where.value }, env: f.env };\n }\n // The axis table moves the evaluation to the space of its table, where the origin of this space is not a key.\n // Thus there the origin is the target, and a value of this space goes in through a variable.\n const base = baseAxis(e.axis);\n let inner = c;\n if (base.t === \"table\") {\n const space = c.tables !== undefined && Object.hasOwn(c.tables, base.name) ? c.tables[base.name] : undefined;\n if (space === undefined) return this.#emit(c, info, f, this.#err(\"no-table\", `the evaluation has no table \"${base.name}\"`, f, path));\n inner = { ...c, space };\n }\n const ts = targets(from, inner);\n if (!ts.ok) return this.#emit(c, info, f, ts);\n const items: ListItem[] = ts.value.map(({ key, test }) => {\n if (test !== undefined && !test.ok) return { key, result: test };\n return { key, result: body({ pos: { origin: base.t === \"table\" ? key : f.pos.origin, focus: key }, env: f.env }, inner) };\n });\n return this.#emit(c, info, f, ok(vexList(items)));\n };\n }\n\n /**\n * This method compiles the names of a loop: `init` at the indexes from 0, and `step` after them (LOOP.NAMES). Its\n * functions give the first values, and the values after one step. The first error stops each of them.\n */\n #names(e: ExprOf<\"fold\"> | ExprOf<\"iterate\">, path: readonly number[]): {\n readonly first: (f: Frame, c: Ctx) => Result<Map<string, Result<unknown>>>;\n readonly next: (f: Frame, c: Ctx) => Result<Map<string, Result<unknown>>>;\n } {\n const inits = Object.entries(e.init).map(([name, x], i) => [name, this.node(x, [...path, i])] as const);\n const steps = Object.entries(e.step).map(([name, x], i) => [name, this.node(x, [...path, inits.length + i])] as const);\n return {\n first: (f, c) => {\n const env = new Map(f.env);\n for (const [name, n] of inits) {\n const r = n(f, c);\n if (!r.ok) return r;\n env.set(name, r);\n }\n return ok(env);\n },\n // Each value of a step reads the values before the step, so the names change only after all the values.\n next: (f, c) => {\n const values: (readonly [string, Result<unknown>])[] = [];\n for (const [name, n] of steps) {\n const r = n(f, c);\n if (!r.ok) return r;\n values.push([name, r]);\n }\n const env = new Map(f.env);\n for (const [name, r] of values) env.set(name, r);\n return ok(env);\n },\n };\n }\n\n /**\n * This method compiles a fold (FOLD.ORDER, FOLD.ERROR). `init` evaluates at the node, then the address and the\n * targets. A step evaluates at each target in order. `result` evaluates at the node with the last values.\n */\n #fold(e: ExprOf<\"fold\">, info: Info): Node {\n const { path } = info;\n const at = e.at ?? [];\n const names = this.#names(e, path);\n const counter = { next: Object.keys(e.init).length + Object.keys(e.step).length };\n const targets = this.#targets(e.axis, path, counter);\n const address = this.#address(at, path, counter.next);\n const result = this.node(e.result, [...path, counter.next + addrExprs(at).length]);\n const base = baseAxis(e.axis);\n return (f, c) => {\n const first = names.first(f, c);\n if (!first.ok) return this.#emit(c, info, f, first);\n let env = first.value;\n let from = f;\n // Stryker disable next-line ConditionalExpression,EqualityOperator: resolveAddr of [] gives the focus too\n if (at.length > 0) {\n const where = address(f, c);\n if (!where.ok) return this.#emit(c, info, f, where);\n from = { pos: { origin: f.pos.origin, focus: where.value }, env: f.env };\n }\n let inner = c;\n if (base.t === \"table\") {\n const space = c.tables !== undefined && Object.hasOwn(c.tables, base.name) ? c.tables[base.name] : undefined;\n if (space === undefined) return this.#emit(c, info, f, this.#err(\"no-table\", `the evaluation has no table \"${base.name}\"`, f, path));\n inner = { ...c, space };\n }\n const ts = targets(from, inner);\n if (!ts.ok) return this.#emit(c, info, f, ts);\n for (const { key, test } of ts.value) {\n if (test !== undefined && !test.ok) return this.#emit(c, info, f, test);\n const after = names.next({ pos: { origin: base.t === \"table\" ? key : f.pos.origin, focus: key }, env }, inner);\n if (!after.ok) return this.#emit(c, info, f, after);\n env = after.value;\n }\n return this.#emit(c, info, f, result({ pos: f.pos, env }, c));\n };\n }\n\n /**\n * This method compiles an iteration (ITERATE.LIMIT, ITERATE.UNTIL, ITERATE.ERROR). The test `until` evaluates before\n * each step and after the last step. `result` evaluates with the last values.\n */\n #iterate(e: ExprOf<\"iterate\">, info: Info): Node {\n const { path } = info;\n const names = this.#names(e, path);\n const untilAt = Object.keys(e.init).length + Object.keys(e.step).length;\n const untilPath = [...path, untilAt];\n const until = e.until === undefined ? undefined : this.node(e.until, untilPath);\n const result = this.node(e.result, [...path, untilAt + (until === undefined ? 0 : 1)]);\n const { limit } = e;\n return (f, c) => {\n const first = names.first(f, c);\n if (!first.ok) return this.#emit(c, info, f, first);\n let env = first.value;\n for (let k = 0; ; k++) {\n const frame: Frame = { pos: f.pos, env };\n if (until !== undefined) {\n const t = until(frame, c);\n if (!t.ok) return this.#emit(c, info, f, t);\n if (t.value === true) break;\n if (t.value !== false) return this.#emit(c, info, f, this.#err(\"kind-mismatch\", `the test \"until\" of \"iterate\" gave a ${typeof t.value}, not a boolean`, f, untilPath));\n }\n if (k === limit) {\n if (until !== undefined) return this.#emit(c, info, f, this.#err(\"limit\", `\"iterate\" made its ${String(limit)} steps, and its test \"until\" is not true`, f, path));\n break;\n }\n const after = names.next(frame, c);\n if (!after.ok) return this.#emit(c, info, f, after);\n env = after.value;\n }\n return this.#emit(c, info, f, result({ pos: f.pos, env }, c));\n };\n }\n\n /** This method compiles the targets of an axis. For `where`, a failed test keeps the target with its error. */\n #targets(a: Axis, path: readonly number[], counter: { next: number }): (f: Frame, c: Ctx) => Result<readonly { readonly key: string; readonly test?: Result<unknown> }[]> {\n if (a.t === \"table\") return (_f, c) => ok(c.space.keys.map((key) => ({ key })));\n if (a.t !== \"where\") {\n return (f, c) => {\n const keys = axisTargets(c.space, f.pos, a);\n return keys.ok ? ok(keys.value.map((key) => ({ key }))) : fail({ ...keys.error, path });\n };\n }\n const inner = this.#targets(a.axis, path, counter);\n const testPath = [...path, counter.next++];\n const test = this.node(a.test, testPath);\n // In the space of the axis table, the origin of the test is the target, as for the body.\n const sameOrigin = baseAxis(a).t === \"table\";\n return (f, c) => {\n const ts = inner(f, c);\n if (!ts.ok) return ts;\n const out: { key: string; test?: Result<unknown> }[] = [];\n for (const t of ts.value) {\n if (t.test !== undefined && !t.test.ok) {\n out.push(t);\n continue;\n }\n const at: Frame = { pos: { origin: sameOrigin ? t.key : f.pos.origin, focus: t.key }, env: f.env };\n const r = test(at, c);\n if (!r.ok) out.push({ key: t.key, test: r });\n else if (r.value === true) out.push({ key: t.key });\n else if (r.value !== false) {\n out.push({ key: t.key, test: this.#err(\"kind-mismatch\", `the test of \"where\" gave a ${typeof r.value}, not a boolean`, at, testPath) });\n }\n }\n return ok(out);\n };\n }\n\n #app(op: string, args: readonly Node[], info: Info): Node {\n const { path } = info;\n const listOp = isListOp(op) ? op : undefined;\n const fn = this.#fns !== undefined && Object.hasOwn(this.#fns, op) ? this.#fns[op] : undefined;\n return (f, c) => {\n const all = this.#all(args, f, c, path, \"arguments\");\n if (!all.ok) return this.#emit(c, info, f, all);\n const values = all.value;\n const self = values[0];\n if (listOp !== undefined && isVexList(self)) return this.#emit(c, info, f, this.#listOp(listOp, self, values.slice(1), f, path));\n let accepted: AnyDomain | undefined;\n // Without arguments, the receiver is undefined, and no domain of a test accepts it.\n // Stryker disable next-line ConditionalExpression,EqualityOperator: the loop finds no domain for undefined\n if (values.length > 0) {\n for (const d of this.#domains) {\n if (!safeIs(d, self)) continue;\n accepted ??= d;\n const resolved = resolveOp(d, self, op);\n if (resolved !== undefined) return this.#emit(c, info, f, this.#call(resolved, op, values.slice(1), f, path));\n }\n }\n if (fn !== undefined) return this.#emit(c, info, f, this.#checkResult(this.#invoke(() => fn(...values), op, f, path), f, path, op));\n if (accepted !== undefined) return this.#emit(c, info, f, this.#err(\"unknown-op\", `the domain \"${accepted.name}\" has no op \"${op}\"`, f, path, { op }));\n if (values.length === 0) return this.#emit(c, info, f, this.#err(\"unknown-op\", `there is no function \"${op}\"`, f, path, { op }));\n return this.#emit(c, info, f, this.#err(\"not-instance\", `no domain accepts the receiver of \"${op}\" (${describeType(self)})`, f, path, { op }));\n };\n }\n\n #special(op: SpecialForm, args: readonly Node[], info: Info): Node {\n const { path } = info;\n const arg = (i: number, f: Frame, c: Ctx): Result<unknown> => {\n const n = args[i];\n return n === undefined ? this.#err(\"bad-expression\", `\"${op}\" needs argument ${i + 1}`, f, path, { op }) : n(f, c);\n };\n const bool = (i: number, f: Frame, c: Ctx): Result<boolean> => {\n const r = arg(i, f, c);\n if (!r.ok) return r;\n return typeof r.value === \"boolean\" ? ok(r.value) : this.#err(\"kind-mismatch\", `argument ${i + 1} of \"${op}\" is a ${describeType(r.value)}, not a boolean`, f, path, { op });\n };\n switch (op) {\n case \"if\":\n return (f, c) => {\n const cond = bool(0, f, c);\n return this.#emit(c, info, f, cond.ok ? arg(cond.value ? 1 : 2, f, c) : cond);\n };\n case \"and\":\n case \"or\": {\n const stop = op === \"or\";\n return (f, c) => {\n if (args.length === 0) return this.#emit(c, info, f, this.#err(\"bad-expression\", `\"${op}\" needs at least 1 argument`, f, path, { op }));\n for (let i = 0; i < args.length; i++) {\n const b = bool(i, f, c);\n if (!b.ok) return this.#emit(c, info, f, b);\n if (b.value === stop) return this.#emit(c, info, f, ok(b.value));\n }\n return this.#emit(c, info, f, ok(!stop));\n };\n }\n case \"ifError\":\n return (f, c) => {\n const first = arg(0, f, c);\n // EVAL.DEPTH: ifError does not hide #DEPTH!, because the engine, not the data, failed.\n return this.#emit(c, info, f, first.ok || isDepthError(first.error) ? first : arg(1, f, c));\n };\n }\n }\n\n #call(op: ResolvedOp, name: string, rest: readonly unknown[], f: Frame, path: readonly number[]): Result<unknown> {\n const { domain, spec } = op;\n const lift = spec.liftScalar;\n const from = domain.fromScalar;\n let callArgs: readonly unknown[] = rest;\n if (lift && from !== undefined) {\n const lifted = this.#invoke(() => rest.map((a, i): unknown => (typeof a === \"number\" && liftsAt(lift, i) ? from(a) : a)), `${domain.name}.fromScalar`, f, path);\n if (!lifted.ok) return lifted;\n callArgs = lifted.value as readonly unknown[];\n }\n if (spec.params !== undefined) {\n for (let i = 0; i < callArgs.length; i++) {\n const kind = spec.params[i] ?? \"any\";\n if (!matchesKind(kind, callArgs[i], domain)) {\n const k: ErrorKind = kind === \"domain\" ? \"not-instance\" : \"kind-mismatch\";\n return this.#err(k, `argument ${i + 1} of \"${name}\" is a ${describeType(callArgs[i])}, not a ${kind === \"domain\" ? domain.name : kind}`, f, path, { op: name });\n }\n }\n }\n return this.#checkResult(this.#invoke(() => op.call(callArgs), name, f, path), f, path, name);\n }\n\n #invoke(run: () => unknown, op: string, f: Frame, path: readonly number[]): Result<unknown> {\n try {\n return ok(run());\n } catch (thrown) {\n return this.#threw(thrown, `\"${op}\" threw an exception`, f, path, { op });\n }\n }\n\n /** This method checks the value that an op gave: no `undefined`, finite numbers, and valid domain values. */\n #checkResult(r: Result<unknown>, f: Frame, path: readonly number[], op: string): Result<unknown> {\n if (!r.ok) return r;\n const value = r.value;\n const extra = { op };\n if (value === undefined || value === null) return this.#err(\"undefined-result\", `\"${op}\" gave no value`, f, path, extra);\n if (typeof value === \"number\" && !Number.isFinite(value)) return this.#err(\"not-finite\", `\"${op}\" gave ${value}`, f, path, extra);\n const d = this.#domains.find((dom) => safeIs(dom, value));\n if (d?.valid !== undefined) {\n let valid: boolean;\n try {\n valid = d.valid(value);\n } catch (thrown) {\n return this.#threw(thrown, `the \"valid\" check of \"${d.name}\" threw an exception`, f, path, extra);\n }\n if (!valid) return this.#err(\"invalid-value\", `\"${op}\" gave a value that is not a valid ${d.name}`, f, path, extra);\n }\n return r;\n }\n\n #listOp(op: ListOp, list: VexList, rest: readonly unknown[], f: Frame, path: readonly number[]): Result<unknown> {\n const optsArg = op === \"reduce\" ? rest[1] : rest[0];\n // A reduction that skips error items does not skip #DEPTH! (EVAL.DEPTH).\n const depth = list.items.find((it) => !it.result.ok && isDepthError(it.result.error))?.result;\n if (depth !== undefined && !depth.ok) return fail(depth.error);\n const strict = (optsArg as ListOptions | null | undefined)?.strict === true;\n const firstError = list.items.find((it) => !it.result.ok)?.result;\n if (strict && firstError !== undefined && !firstError.ok) return fail(firstError.error);\n const okValues = list.items.flatMap((it) => (it.result.ok ? [it.result.value] : []));\n const numbers = (): Result<readonly number[]> => {\n const bad = okValues.find((x) => typeof x !== \"number\");\n return bad === undefined ? ok(okValues as readonly number[]) : this.#err(\"kind-mismatch\", `\"${op}\" needs numbers, but an item is a ${describeType(bad)}`, f, path, { op });\n };\n const booleans = (): Result<readonly boolean[]> => {\n const bad = okValues.find((x) => typeof x !== \"boolean\");\n return bad === undefined ? ok(okValues as readonly boolean[]) : this.#err(\"kind-mismatch\", `\"${op}\" needs booleans, but an item is a ${describeType(bad)}`, f, path, { op });\n };\n const empty = (): Result<never> => this.#err(\"empty\", `\"${op}\" has no values to work with`, f, path, { op });\n switch (op) {\n case \"count\":\n return ok(okValues.length);\n case \"values\":\n return ok(Object.freeze([...okValues]));\n case \"keys\":\n return ok(Object.freeze(list.items.filter((it) => it.result.ok).map((it) => it.key)));\n case \"errors\":\n return ok(Object.freeze(list.items.flatMap((it) => (it.result.ok ? [] : [it.result.error]))));\n case \"first\":\n return okValues.length > 0 ? ok(okValues[0]) : empty();\n case \"sum\": {\n const n = numbers();\n return n.ok ? this.#checkResult(ok(n.value.reduce((s, x) => s + x, 0)), f, path, op) : n;\n }\n case \"mean\": {\n const n = numbers();\n if (!n.ok) return n;\n return n.value.length === 0 ? empty() : this.#checkResult(ok(n.value.reduce((s, x) => s + x, 0) / n.value.length), f, path, op);\n }\n case \"min\":\n case \"max\": {\n const n = numbers();\n if (!n.ok) return n;\n if (n.value.length === 0) return empty();\n return ok(n.value.reduce((best, x) => (op === \"min\" ? Math.min(best, x) : Math.max(best, x))));\n }\n case \"any\":\n case \"all\":\n case \"none\": {\n const b = booleans();\n if (!b.ok) return b;\n if (op === \"any\") return ok(b.value.some((x) => x));\n if (op === \"all\") return ok(b.value.every((x) => x));\n return ok(!b.value.some((x) => x));\n }\n case \"reduce\":\n return this.#reduce(rest[0], okValues, f, path, optsArg);\n }\n }\n\n /**\n * This method folds the values with a domain op, from the left. An empty list gives the identity of the op, if one\n * domain has an identity for the op (LIST.EMPTY). The option `domain` names that domain when more domains have one.\n */\n #reduce(opName: unknown, values: readonly unknown[], f: Frame, path: readonly number[], opts: unknown): Result<unknown> {\n if (typeof opName !== \"string\") return this.#err(\"kind-mismatch\", `\"reduce\" needs an op name, but got a ${describeType(opName)}`, f, path, { op: \"reduce\" });\n if (values.length === 0) {\n const named = (opts as { domain?: unknown } | null | undefined)?.domain;\n const candidates = this.#domains.filter((d) => Object.hasOwn(d.ops, opName) && (d.ops[opName] as { identity?: () => unknown }).identity !== undefined && (named === undefined || d.name === named));\n if (named !== undefined && !this.#domains.some((d) => d.name === named)) {\n return this.#err(\"unknown-op\", `\"reduce\" names the domain ${JSON.stringify(named)}, but the program has no such domain`, f, path, { op: opName });\n }\n const [only, second] = candidates;\n if (only === undefined) return this.#err(\"empty\", `\"reduce\" with \"${opName}\" has no values and the op has no identity`, f, path, { op: opName });\n if (second !== undefined) {\n const names = candidates.map((d) => d.name).join(\", \");\n return this.#err(\"empty\", `\"reduce\" with \"${opName}\" has no values, and more domains have an identity for it (${names}). Name one with { domain }`, f, path, { op: opName });\n }\n return this.#invoke((only.ops[opName] as { identity: () => unknown }).identity, opName, f, path);\n }\n let acc: unknown = values[0];\n for (let i = 1; i < values.length; i++) {\n const d = this.#domains.find((dom) => safeIs(dom, acc) && resolveOp(dom, acc, opName) !== undefined);\n const op = d === undefined ? undefined : resolveOp(d, acc, opName);\n if (op === undefined) return this.#err(\"unknown-op\", `no domain gives \"${opName}\" for a ${describeType(acc)}`, f, path, { op: opName });\n const r = this.#call(op, opName, [values[i]], f, path);\n if (!r.ok) return r;\n acc = r.value;\n }\n return ok(acc);\n }\n}\n\nconst FORBIDDEN_FIELDS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n/** This function tells if a segment of a path can name a field. A compiler uses the same rule as the interpreter. */\nexport const isFieldName = (seg: string): boolean => seg.length > 0 && !FORBIDDEN_FIELDS.has(seg);\n\n/** This function runs the `is` test of a domain. A test that throws counts as `false`. */\n// Stryker disable BlockStatement: an empty catch gives undefined, which also counts as false\nexport function safeIs(d: AnyDomain, value: unknown): boolean {\n try {\n return d.is(value);\n } catch {\n return false;\n }\n}\n// Stryker restore BlockStatement\n\n\n/** This function tells if an argument has the kind of a parameter of an op of the domain `domain`. */\nexport function matchesKind(kind: ParamKind, value: unknown, domain: AnyDomain): boolean {\n switch (kind) {\n case \"domain\":\n return safeIs(domain, value);\n case \"number\":\n return typeof value === \"number\";\n case \"boolean\":\n return typeof value === \"boolean\";\n case \"string\":\n return typeof value === \"string\";\n case \"any\":\n return true;\n }\n}\n\n/** This function gives a short name for the type of a value, for error messages. */\nexport function describeType(u: unknown): string {\n if (u === null) return \"null\";\n if (Array.isArray(u)) return \"array\";\n if (isVexList(u)) return \"list\";\n if (typeof u === \"object\") {\n const name = (Object.getPrototypeOf(u) as { constructor?: { name?: unknown } } | null)?.constructor?.name;\n return typeof name === \"string\" && name !== \"Object\" ? name : \"object\";\n }\n return typeof u;\n}\n\n/** This function gives the label of a node, for traces. */\nexport function labelOf(e: Expr): string {\n switch (e.tag) {\n case \"lit\":\n return previewValue(e.value);\n case \"ref\":\n return e.path.length === 0 ? \"(record)\" : e.path.join(\".\");\n case \"app\":\n return e.op;\n case \"let\":\n return `let ${Object.keys(e.bind).join(\", \")}`;\n case \"var\":\n return e.name;\n case \"rec\":\n return `{ ${Object.keys(e.fields).join(\", \")} }`;\n case \"each\":\n case \"fold\":\n return e.at === undefined ? `${e.tag} ${e.axis.t}` : `${e.tag} ${e.axis.t} from ${e.at.map(moveText).join(\".\")}`;\n case \"iterate\":\n return `iterate ${String(e.limit)}`;\n case \"ext\":\n return e.kind;\n }\n}\n\n/** This function gives a short text for a move, for the label of an axis with an address. */\nfunction moveText(m: Move): string {\n switch (m.t) {\n case \"key\":\n return `key(${typeof m.key === \"string\" ? m.key : labelOf(m.key)})`;\n case \"index\":\n return `index(${typeof m.i === \"number\" ? String(m.i) : labelOf(m.i)})`;\n case \"offset\":\n return `offset(${m.d.join(\", \")})`;\n case \"other\":\n case \"origin\":\n case \"parent\":\n return m.t;\n }\n}\n\n/** This function gives a short text for a value. */\nexport function previewValue(u: unknown): string {\n // JSON has no NaN and no Infinity, so a number gets its own text. JSON gives the text of the other primitives.\n if (typeof u === \"number\") return String(u);\n if (isVexList(u)) return `list(${u.items.length})`;\n try {\n const json = JSON.stringify(u);\n // A function, a symbol and undefined have no JSON form.\n // Stryker disable next-line ConditionalExpression: without the test, undefined.length throws, and the catch gives the same text\n if (json !== undefined) return json.length > 60 ? `${json.slice(0, 57)}...` : json;\n } catch {\n // A value with cycles has no JSON form.\n }\n return describeType(u);\n}\n\n// The reads of a reference show the key and the path, for example \"read B.position\" or \"no value at A.mass\".\nconst formatRead = (r: Read): string => `${r.ok ? \"read\" : \"no value at\"} ${r.key}.${r.path.length === 0 ? \"(record)\" : r.path.join(\".\")}`;\n\n/**\n * This function gives a text form of a trace. Each event has one line, in finish order. The indent of a line\n * shows the depth of the node. A domain with `show` gives the text of its values. The golden tests compare this text.\n */\n// Stryker disable next-line ArrayDeclaration: a list with a value that is not a domain shows no value\nexport function formatTrace(trace: Trace, domains: readonly AnyDomain[] = []): string {\n const show = (u: unknown): string => {\n if (isVexList(u)) return `[${u.items.map((it) => `${it.key}: ${result(it.result)}`).join(\", \")}]`;\n const d = domains.find((dom) => dom.show !== undefined && safeIs(dom, u));\n try {\n // Stryker disable next-line ConditionalExpression,OptionalChaining: without a domain, d.show throws, and the catch gives the same text\n if (d?.show !== undefined) return d.show(u);\n } catch {\n // A show function that throws gives the default text.\n }\n return previewValue(u);\n };\n const result = (r: Result<unknown>): string => (r.ok ? show(r.value) : formatError(r.error));\n const line = (e: TraceEvent): string => {\n const reads = e.reads === undefined ? \"\" : ` [${e.reads.map(formatRead).join(\", \")}]`;\n return `${\" \".repeat(e.path.length)}${e.label} @${e.focus}${reads} = ${result(e.result)}`;\n };\n const lines = trace.events.map(line);\n return [...lines, `result = ${result(trace.result)}`, \"\"].join(\"\\n\");\n}\n\n/** This function gives the number of nodes of an expression. */\nexport const sizeOf = (e: Expr): number => 1 + children(e).reduce((s, c) => s + sizeOf(c), 0);\n","import { addrExprs, children, type Addr, type Axis, type Expr } from \"./ir.ts\";\n\n/** One static read of a program: a field path at an address, inside zero or more axes. */\nexport interface Dependency {\n /** The address of the read. The empty address is the focus. */\n readonly at: Addr;\n /** The field path of the read. */\n readonly path: readonly string[];\n /** The axes around the read, from the outside to the inside. Inside an axis, the focus is the target. */\n readonly axes: readonly Axis[\"t\"][];\n /** The address of each axis in `axes`, in the same order. The empty address is the focus. */\n readonly axisAt: readonly Addr[];\n}\n\n/**\n * This function gives the static reads of an expression. A host can use them to recompute a program only\n * when a field that it reads changes. A computed move reads a key that only a run knows. Its address keeps the\n * expression, and the reads of that expression are in the list too (NAV.COMPUTED).\n */\nexport function deps(e: Expr): readonly Dependency[] {\n const out: Dependency[] = [];\n // A stack, not recursion, so a deep expression needs no deep call stack. The children go on the stack in reverse\n // order, so the reads come out in the order of a depth-first walk.\n const todo: { readonly x: Expr; readonly axes: readonly Axis[\"t\"][]; readonly axisAt: readonly Addr[] }[] = [{ x: e, axes: [], axisAt: [] }];\n for (let item = todo.pop(); item !== undefined; item = todo.pop()) {\n const { x } = item;\n if (x.tag === \"ref\") out.push({ at: x.at ?? [], path: x.path, axes: item.axes, axisAt: item.axisAt });\n const all = children(x);\n const axial = x.tag === \"each\" || x.tag === \"fold\";\n // Inside the axis: the body or the values of the step, and the tests of where. The values of init, the result of a\n // fold and the expressions of an address evaluate at the node, outside the axis.\n const first = x.tag === \"fold\" ? Object.keys(x.init).length : 0;\n const last = axial ? all.length - addrExprs(x.at).length - (x.tag === \"fold\" ? 1 : 0) : 0;\n const axes = axial ? [...item.axes, x.axis.t] : item.axes;\n const axisAt = axial ? [...item.axisAt, x.at ?? []] : item.axisAt;\n for (let i = all.length - 1; i >= 0; i--) todo.push(i >= first && i < last ? { x: all[i] as Expr, axes, axisAt } : { ...item, x: all[i] as Expr });\n }\n return out;\n}\n","import type { AnyDomain } from \"./domain.ts\";\nimport { isStackOverflow, vexError } from \"./errors.ts\";\nimport { isExpr, type Expr } from \"./ir.ts\";\nimport { fail, ok, type Result } from \"./result.ts\";\n\n/**\n * The JSON form of the values in a literal. JSON data stays as it is, with three exceptions. Each exception is a record\n * with the key `$vex`:\n *\n * - `{ \"$vex\": \"domain\", \"domain\": name, \"value\": v }`: a value of a domain, with the `encode` of the domain.\n * - `{ \"$vex\": \"number\", \"value\": \"-0\" }`: a number that JSON has no text for: `-0`, `NaN`, `Infinity` or `-Infinity`.\n * - `{ \"$vex\": \"escape\", \"value\": record }`: a record of the data that has the key `$vex` itself (IR.JSON.ESCAPE).\n *\n * A record with the key `$vex` and another form stays data, so a file from an older version reads as before.\n *\n * The functions walk the tree of the expression, so only the value of a literal gets this form. A field of a literal\n * that looks like an expression stays data. The data of an extension is plain JSON, as before.\n */\ntype Encoded =\n | { readonly $vex: \"domain\"; readonly domain: string; readonly value: unknown }\n | { readonly $vex: \"number\"; readonly value: \"-0\" | \"NaN\" | \"Infinity\" | \"-Infinity\" }\n | { readonly $vex: \"escape\"; readonly value: Readonly<Record<string, unknown>> };\n\nconst isRecord = (u: unknown): u is Readonly<Record<string, unknown>> => typeof u === \"object\" && u !== null && !Array.isArray(u);\n\nconst isPlainRecord = (u: unknown): u is Readonly<Record<string, unknown>> => {\n if (!isRecord(u)) return false;\n const proto: unknown = Object.getPrototypeOf(u);\n return proto === Object.prototype || proto === null;\n};\n\n/** This function gives the JSON form of a value, or the reason why the value has no JSON form. */\nfunction encodeValue(u: unknown, domains: readonly AnyDomain[]): Result<unknown> {\n if (u === null || typeof u === \"string\" || typeof u === \"boolean\") return ok(u);\n if (typeof u === \"number\") {\n if (Object.is(u, -0)) return ok({ $vex: \"number\", value: \"-0\" } satisfies Encoded);\n // Stryker disable next-line EqualityOperator: here u is an infinity, so u > 0 and u >= 0 are the same test\n return Number.isFinite(u) ? ok(u) : ok({ $vex: \"number\", value: Number.isNaN(u) ? \"NaN\" : u > 0 ? \"Infinity\" : \"-Infinity\" } satisfies Encoded);\n }\n if (Array.isArray(u)) {\n const out: unknown[] = [];\n for (const x of u) {\n const r = encodeValue(x, domains);\n if (!r.ok) return r;\n out.push(r.value);\n }\n return ok(out);\n }\n if (isPlainRecord(u)) {\n const out: Record<string, unknown> = {};\n for (const [k, x] of Object.entries(u)) {\n const r = encodeValue(x, domains);\n if (!r.ok) return r;\n out[k] = r.value;\n }\n return ok(Object.hasOwn(u, \"$vex\") ? ({ $vex: \"escape\", value: out } satisfies Encoded) : out);\n }\n // A plain array or record stays data. Another object is a value of a domain, or it has no JSON form.\n const d = domains.find((dom) => dom.encode !== undefined && dom.is(u));\n if (d?.encode !== undefined) return ok({ $vex: \"domain\", domain: d.name, value: d.encode(u) } satisfies Encoded);\n return fail(vexError(\"bad-expression\", \"a literal value is not JSON data and no domain encodes it\"));\n}\n\nconst NUMBERS: Readonly<Record<string, number>> = { \"-0\": -0, NaN: Number.NaN, Infinity: Number.POSITIVE_INFINITY, \"-Infinity\": Number.NEGATIVE_INFINITY };\n\n/** This function reads a value from its JSON form. */\nfunction decodeValue(u: unknown, domains: readonly AnyDomain[]): Result<unknown> {\n if (Array.isArray(u)) {\n const out: unknown[] = [];\n for (const x of u) {\n const r = decodeValue(x, domains);\n if (!r.ok) return r;\n out.push(r.value);\n }\n return ok(out);\n }\n if (!isRecord(u)) return ok(u);\n const fields = (record: Readonly<Record<string, unknown>>): Result<unknown> => {\n const out: Record<string, unknown> = {};\n for (const [k, x] of Object.entries(record)) {\n const r = decodeValue(x, domains);\n if (!r.ok) return r;\n out[k] = r.value;\n }\n return ok(out);\n };\n // A record without the key $vex matches none of the forms below, so it stays data too.\n const kind = u[\"$vex\"];\n if (kind === \"escape\" && isRecord(u[\"value\"])) return fields(u[\"value\"]);\n if (kind === \"number\" && typeof u[\"value\"] === \"string\" && Object.hasOwn(NUMBERS, u[\"value\"])) return ok(NUMBERS[u[\"value\"]]);\n if (kind === \"domain\" && typeof u[\"domain\"] === \"string\") {\n const name = u[\"domain\"];\n const d = domains.find((dom) => dom.name === name);\n if (d?.decode === undefined) return fail(vexError(\"bad-expression\", `no domain \"${name}\" decodes a literal`));\n return ok(d.decode(u[\"value\"]));\n }\n // A form that this version does not know stays data, so a file from an older version reads as before.\n return fields(u);\n}\n\n/** This function applies `f` to each literal value of a JSON tree of an expression. */\nfunction mapValues(u: unknown, f: (value: unknown) => Result<unknown>): Result<unknown> {\n if (!isRecord(u)) return ok(u);\n const out: Record<string, unknown> = { ...u };\n const child = (key: string): Result<unknown> | undefined => {\n const r = mapValues(u[key], f);\n if (r.ok) out[key] = r.value;\n return r.ok ? undefined : r;\n };\n const each = (key: string): Result<unknown> | undefined => {\n const list = u[key];\n if (Array.isArray(list)) {\n const items: unknown[] = [];\n for (const x of list) {\n const r = mapValues(x, f);\n if (!r.ok) return r;\n items.push(r.value);\n }\n out[key] = items;\n } else if (isRecord(list)) {\n const rec: Record<string, unknown> = {};\n for (const [k, x] of Object.entries(list)) {\n const r = mapValues(x, f);\n if (!r.ok) return r;\n rec[k] = r.value;\n }\n out[key] = rec;\n }\n return undefined;\n };\n // The expression of a computed move is a tree of the expression too (NAV.COMPUTED).\n const address = (): Result<unknown> | undefined => {\n const at = u[\"at\"];\n if (!Array.isArray(at)) return undefined;\n const moves: unknown[] = [];\n for (const m of at) {\n const field = isRecord(m) ? (m[\"t\"] === \"key\" ? \"key\" : m[\"t\"] === \"index\" ? \"i\" : undefined) : undefined;\n if (field === undefined || !isRecord(m) || !isRecord(m[field])) {\n moves.push(m);\n continue;\n }\n const r = mapValues(m[field], f);\n if (!r.ok) return r;\n moves.push({ ...m, [field]: r.value });\n }\n out[\"at\"] = moves;\n return undefined;\n };\n const axis = (a: unknown): Result<unknown> => {\n if (!isRecord(a) || a[\"t\"] !== \"where\") return ok(a);\n const inner = axis(a[\"axis\"]);\n if (!inner.ok) return inner;\n const test = mapValues(a[\"test\"], f);\n return test.ok ? ok({ ...a, axis: inner.value, test: test.value }) : test;\n };\n switch (u[\"tag\"]) {\n case \"lit\": {\n if (!Object.hasOwn(u, \"value\")) return ok(out);\n const r = f(u[\"value\"]);\n if (!r.ok) return r;\n out[\"value\"] = r.value;\n return ok(out);\n }\n case \"app\":\n return each(\"args\") ?? ok(out);\n case \"let\":\n return each(\"bind\") ?? child(\"body\") ?? ok(out);\n case \"rec\":\n return each(\"fields\") ?? ok(out);\n case \"each\": {\n const a = axis(u[\"axis\"]);\n if (!a.ok) return a;\n out[\"axis\"] = a.value;\n return child(\"body\") ?? address() ?? ok(out);\n }\n case \"fold\": {\n const a = axis(u[\"axis\"]);\n if (!a.ok) return a;\n out[\"axis\"] = a.value;\n return each(\"init\") ?? each(\"step\") ?? child(\"result\") ?? address() ?? ok(out);\n }\n case \"iterate\":\n return each(\"init\") ?? each(\"step\") ?? (u[\"until\"] === undefined ? undefined : child(\"until\")) ?? child(\"result\") ?? ok(out);\n case \"ref\":\n return address() ?? ok(out);\n default:\n return ok(out);\n }\n}\n\n/**\n * This function gives the JSON text of an expression. A literal value that is a domain value needs a domain with\n * `encode`. A literal value that is not JSON data and has no such domain gives the error `#VALUE!`.\n */\n// Stryker disable next-line ArrayDeclaration: a list with a value that is not a domain encodes no value\nexport function serialize(e: Expr, domains: readonly AnyDomain[] = []): Result<string> {\n try {\n // A getter of a literal value can throw, so the encoding is inside the try too.\n const tree = mapValues(e, (v) => encodeValue(v, domains));\n return tree.ok ? ok(JSON.stringify(tree.value)) : fail(tree.error);\n } catch (thrown) {\n if (isStackOverflow(thrown)) return fail(vexError(\"depth\", \"the expression is too deep for the call stack of the engine\", { thrown }));\n return fail(vexError(\"threw\", \"the expression has no JSON form\", { thrown }));\n }\n}\n\n/** This function reads an expression from JSON text. It checks the whole tree. */\n// Stryker disable next-line ArrayDeclaration: a list with a value that is not a domain decodes no value\nexport function parse(text: string, domains: readonly AnyDomain[] = []): Result<Expr> {\n let raw: unknown;\n try {\n raw = JSON.parse(text);\n } catch (thrown) {\n return fail(vexError(\"bad-expression\", \"the text is not JSON\", { thrown }));\n }\n try {\n const tree = mapValues(raw, (v) => decodeValue(v, domains));\n if (!tree.ok) return fail(tree.error);\n return isExpr(tree.value) ? ok(tree.value) : fail(vexError(\"bad-expression\", \"the JSON is not a valid Vex expression\"));\n } catch (thrown) {\n // A JSON text nested deeper than the call stack, or a decoder of a domain that throws.\n if (isStackOverflow(thrown)) return fail(vexError(\"depth\", \"the JSON is too deep for the call stack of the engine\", { thrown }));\n return fail(vexError(\"threw\", \"a decoder of a domain threw an exception\", { thrown }));\n }\n}\n","import type { AnyDomain } from \"./domain.ts\";\nimport { vexError, type VexError } from \"./errors.ts\";\nimport { evaluate, type FreeFn } from \"./evaluate.ts\";\nimport { app, lit, v } from \"./ir.ts\";\nimport { vexList, type ListItem } from \"./list.ts\";\nimport { fail, none, ok, toOptional, type Optional, type Result } from \"./result.ts\";\nimport { space as spaces, type Space } from \"./space.ts\";\n\n/** A monoid: an associative `concat` with an identity element `empty`. */\nexport interface Monoid<M> {\n readonly empty: M;\n readonly concat: (a: M, b: M) => M;\n}\n\n/** Standard monoids. */\nexport const monoids: {\n readonly sum: Monoid<number>;\n readonly product: Monoid<number>;\n readonly all: Monoid<boolean>;\n readonly any: Monoid<boolean>;\n} = {\n sum: { empty: 0, concat: (a, b) => a + b },\n product: { empty: 1, concat: (a, b) => a * b },\n all: { empty: true, concat: (a, b) => a && b },\n any: { empty: false, concat: (a, b) => a || b },\n};\n\n/** One item of a traversal: the start key and the result there. */\nexport interface TraversalItem<K extends string, T> {\n readonly key: K;\n readonly result: Result<T>;\n}\n\n/**\n * A traversal: the results of one program at each start key. The reductions skip error items by default.\n * After `strict()`, an error item makes the reduction that error.\n */\nexport interface Traversal<K extends string, T> {\n readonly items: readonly TraversalItem<K, T>[];\n /** This method gives a traversal whose reductions fail on the first error item. */\n strict(): Traversal<K, T>;\n /** This method gives the result at one key. */\n get(k: K): Optional<T>;\n /** The values of the items without errors. */\n values(): readonly T[];\n /** The keys of the items without errors. */\n keys(): readonly K[];\n /** The errors of the items with errors. */\n errors(): readonly VexError[];\n count(): Optional<number>;\n sum(this: Traversal<K, number>): Optional<number>;\n mean(this: Traversal<K, number>): Optional<number>;\n min(this: Traversal<K, number>): Optional<number>;\n max(this: Traversal<K, number>): Optional<number>;\n any(this: Traversal<K, boolean>): Optional<boolean>;\n all(this: Traversal<K, boolean>): Optional<boolean>;\n none(this: Traversal<K, boolean>): Optional<boolean>;\n /** This method folds the values with a domain op, from the left. */\n reduce(op: string): Optional<T>;\n /** This method gives the result of a reduction, with its error. */\n reduceResult(op: \"count\" | \"sum\" | \"mean\" | \"min\" | \"max\" | \"any\" | \"all\" | \"none\" | \"reduce\", reduceOp?: string): Result<unknown>;\n /** This method maps each value with `f`. If `f` throws, the item has the error `#CALC!`. */\n map<U>(f: (value: T, key: K) => U): Traversal<K, U>;\n /** This method folds the values with a monoid. */\n fold<M>(monoid: Monoid<M>, f: (value: T) => M): M;\n}\n\ninterface TraversalEnv {\n readonly domains: readonly AnyDomain[];\n readonly options?: { readonly fns?: Readonly<Record<string, FreeFn>> };\n}\n\nconst EMPTY_SPACE: Space = spaces.record({ $: {} });\n\nconst opt = <U>(r: Result<unknown>): Optional<U> => toOptional(r as Result<U>);\n\n/** This function makes a traversal from items. */\nexport function traversal<K extends string, T>(items: readonly TraversalItem<K, T>[], env: TraversalEnv, isStrict = false): Traversal<K, T> {\n const reduce = (op: string, reduceOp?: string): Result<unknown> => {\n const list = vexList(items as readonly ListItem[]);\n const args = [v(\"$list\"), ...(reduceOp === undefined ? [] : [lit(reduceOp)]), ...(isStrict ? [lit({ strict: true })] : [])];\n return evaluate(app(op, ...args), {\n space: EMPTY_SPACE,\n origin: \"$\",\n domains: env.domains,\n vars: { $list: list },\n });\n };\n const t: Traversal<K, T> = {\n items,\n strict: () => traversal(items, env, true),\n get: (k) => {\n const item = items.find((it) => it.key === k);\n return item === undefined ? none() : toOptional(item.result);\n },\n values: () => items.flatMap((it) => (it.result.ok ? [it.result.value] : [])),\n keys: () => items.flatMap((it) => (it.result.ok ? [it.key] : [])),\n errors: () => items.flatMap((it) => (it.result.ok ? [] : [it.result.error])),\n count: () => opt(reduce(\"count\")),\n sum: () => opt(reduce(\"sum\")),\n mean: () => opt(reduce(\"mean\")),\n min: () => opt(reduce(\"min\")),\n max: () => opt(reduce(\"max\")),\n any: () => opt(reduce(\"any\")),\n all: () => opt(reduce(\"all\")),\n none: () => opt(reduce(\"none\")),\n reduce: (op) => opt(reduce(\"reduce\", op)),\n reduceResult: (op, reduceOp) => reduce(op, reduceOp),\n map: <U>(f: (value: T, key: K) => U): Traversal<K, U> =>\n traversal(\n items.map((it): TraversalItem<K, U> => {\n if (!it.result.ok) return { key: it.key, result: it.result };\n try {\n return { key: it.key, result: ok(f(it.result.value, it.key)) };\n } catch (thrown) {\n return { key: it.key, result: fail(vexError(\"threw\", \"the map function threw an exception\", { thrown, focus: it.key })) };\n }\n }),\n env,\n isStrict,\n ),\n fold: <M>(monoid: Monoid<M>, f: (value: T) => M): M => t.values().reduce((acc, x) => monoid.concat(acc, f(x)), monoid.empty),\n };\n return t;\n}\n","/**\n * Sheets: named columns of formulas over a space. A formula can read a column at an address, like a cell\n * reference of a spreadsheet. A cell is one column at one key. A run evaluates each cell once, and each cell on a\n * cycle of reads gives `#CYCLE!`.\n *\n * A cell reference is the extension node `ext(\"vex.cell\", { column, at })`. Thus the IR has no new kind, and the\n * JSON form, `deps` and the traces work without a change.\n *\n * A cell can have its own formula. That formula replaces the formula of the column at the key of the cell. A\n * spreadsheet has the same thing: a cell with a formula that is different from the other formulas of its column.\n */\nimport { vexError } from \"./errors.ts\";\nimport { evaluate, explain, nestingOf, type CompileOptions, type EvalOptions, type ExtHandler, type Program } from \"./evaluate.ts\";\nimport { addrExprs, children, ext, isMove, moveExpr, shapeError, type Axis, type Expr, type FixedMove, type Move } from \"./ir.ts\";\nimport { fail, type Result } from \"./result.ts\";\nimport { resolveAddr, type Space } from \"./space.ts\";\nimport type { Trace } from \"./trace.ts\";\n\n/** The extension kind of a cell reference. */\nexport const CELL_KIND = \"vex.cell\";\n\n/**\n * The data of a cell reference: the column, and the address from the focus. The data of an extension is not an\n * expression, so the address has only fixed moves.\n */\nexport interface CellRef {\n readonly column: string;\n readonly at: readonly FixedMove[];\n}\n\n/** This function makes a cell reference: the column `column` at the address `at` from the focus. */\nexport const cell = (column: string, at: readonly FixedMove[] = []): Expr => ext(CELL_KIND, { column, at } satisfies CellRef);\n\nconst isCellRef = (u: unknown): u is CellRef =>\n typeof u === \"object\" &&\n u !== null &&\n typeof (u as { column?: unknown }).column === \"string\" &&\n Array.isArray((u as { at?: unknown }).at) &&\n (u as { at: readonly unknown[] }).at.every((m) => isMove(m) && moveExpr(m) === undefined);\n\n/** The formulas of single cells: for each column, the formula of each key that has its own formula. */\nexport type CellFormulas = ReadonlyMap<string, ReadonlyMap<string, Expr>>;\n\n/** A table of a run: its space, the formulas of its columns, and the formulas of its cells. */\nexport interface SheetTable {\n readonly space: Space;\n readonly columns: ReadonlyMap<string, Expr>;\n readonly cells?: CellFormulas;\n}\n\n/** The options of a sheet run: the evaluation options without the origin and the trace, and the tables. */\nexport type SheetOptions = Omit<EvalOptions, \"origin\" | \"trace\" | \"tables\"> & {\n /** The cells with their own formula. The formula of a cell replaces the formula of its column at its key. */\n readonly cells?: CellFormulas;\n /** The name of this table, so the axis `table(name)` in a formula of another table can read it. */\n readonly name?: string;\n /** The other tables, by name (SHEET.TABLES). A cell reference reads the table of the space where it evaluates. */\n readonly tables?: ReadonlyMap<string, SheetTable>;\n /**\n * The compiler of the formulas of the columns (SHEET.COMPILE), for example `tiered` of `@mark1russell7/vex-compiler`.\n * Without a compiler, the interpreter evaluates each formula. The compiled program must give the results of the\n * interpreter.\n */\n readonly compile?: CompileFn;\n};\n\n/** A compiler of the formulas of the columns of a run. */\nexport type CompileFn = (expr: Expr, options: CompileOptions) => Program;\n\n/**\n * The compiled programs of the formulas of the columns: one entry for each formula, for the last compiler and options.\n * A compiled program reads the cells of the active run, so each run with the same compiler and options can use it.\n */\nconst PROGRAMS = new WeakMap<Expr, { readonly compile: CompileFn; readonly domains: unknown; readonly fns: unknown; readonly extensions: unknown; readonly program: Program }>();\n\n/** The key of the options without extensions, for the extensions of the compiled programs. */\nconst NO_EXTENSIONS = {};\n\n/** The state of one table in a run. */\ninterface Table {\n /** The words for the table in a message: \"the sheet\" for the main table, or the table and its name. */\n readonly where: string;\n /** A short text for the ids of the cells of the table. */\n readonly tag: string;\n readonly space: Space;\n readonly columns: ReadonlyMap<string, Expr>;\n readonly cells: CellFormulas;\n // For each column, the number of keys at the start of the key order that a warm-up evaluated.\n readonly warmed: Map<string, number>;\n // The position of each key in the key order, made at the first warm-up.\n index: ReadonlyMap<string, number> | undefined;\n /** The result of each finished cell: for each column, the result at each key. */\n readonly done: Map<string, Map<string, Result<unknown>>>;\n}\n\nconst cycleError = (column: string, key: string): Result<never> =>\n fail(vexError(\"cycle\", `the cell \"${column}\" at \"${key}\" is on a cycle of cell references`, { origin: key, focus: key }));\n\n/** The id of a cell. */\nconst idOf = (t: Table, column: string, key: string): string => `${t.tag}\\u0001${column}\\u0000${key}`;\n\n/** This function gives the state of a table at the start of a run. */\nconst tableState = (where: string, i: number, t: SheetTable): Table => ({ where, tag: String(i), space: t.space, columns: t.columns, cells: t.cells ?? new Map(), warmed: new Map(), index: undefined, done: new Map() });\n\n/** This function gives the result of a finished cell, or `undefined`. */\nconst doneOf = (t: Table, column: string, key: string): Result<unknown> | undefined => t.done.get(column)?.get(key);\n\n/** This function keeps the result of a finished cell. */\nfunction setDone(t: Table, column: string, key: string, result: Result<unknown>): void {\n let results = t.done.get(column);\n if (results === undefined) {\n results = new Map();\n t.done.set(column, results);\n }\n results.set(key, result);\n}\n\n/** A direction of the reads of a column from itself: to an earlier key, to a later key, or down a tree to the children. */\ntype Direction = \"before\" | \"after\" | \"down\";\n\n/** This function adds the direction of one move or one axis of a read of a column from itself. */\nfunction addDirection(d: Set<Direction>, m: Move | Axis): void {\n if (m.t === \"offset\" || m.t === \"window\") {\n // An offset moves by its first step that is not 0. A window reads the keys from `from` to `to`.\n const steps = m.t === \"offset\" ? [m.d.find((x) => x !== 0) ?? 0] : [m.from, m.to];\n // A step of 0 reads the cell itself, which is a cycle in each order.\n // Stryker disable next-line EqualityOperator: see the comment above\n if (steps.some((x) => x < 0)) d.add(\"before\");\n // Stryker disable next-line EqualityOperator: see the comment above\n if (steps.some((x) => x > 0)) d.add(\"after\");\n } else if (m.t === \"children\" || m.t === \"descendants\") d.add(\"down\");\n}\n\n/** This function gives the base axis of an axis, and the tests of its `where` axes. */\nfunction partsOf(axis: Axis): { readonly base: Axis; readonly tests: readonly Expr[] } {\n const tests: Expr[] = [];\n let base = axis;\n while (base.t === \"where\") {\n tests.push(base.test);\n base = base.axis;\n }\n return { base, tests };\n}\n\n/**\n * This function gives the columns that the formulas of the column `self` read with a cell reference: its formula and\n * the formulas of its cells. It also gives the directions of their reads of the column itself. A read in the body or\n * in a test of an axis also has the direction of that axis. It walks each expression with a stack, not with recursion.\n */\nfunction readsOf(t: Table, self: string): { readonly columns: ReadonlySet<string>; readonly directions: ReadonlySet<Direction> } {\n const columns = new Set<string>();\n const directions = new Set<Direction>();\n const formula = t.columns.get(self);\n // An expression that is not valid reads no column. Its evaluation gives the error (EVAL.SHAPE).\n const todo: [Expr, Axis | undefined][] = [...(formula === undefined ? [] : [formula]), ...(t.cells.get(self)?.values() ?? [])].filter((e) => shapeError(e) === undefined).map((e) => [e, undefined]);\n for (let item = todo.pop(); item !== undefined; item = todo.pop()) {\n const [e, axis] = item;\n if (e.tag === \"each\" || e.tag === \"fold\") {\n const { base, tests } = partsOf(e.axis);\n for (const x of [...(e.tag === \"each\" ? [e.body] : Object.values(e.step)), ...tests]) todo.push([x, base]);\n // The values of init, the result of a fold and the expressions of the address evaluate at the node, so they keep\n // the outer direction.\n for (const x of [...(e.tag === \"fold\" ? [...Object.values(e.init), e.result] : []), ...addrExprs(e.at)]) todo.push([x, axis]);\n } else if (e.tag !== \"ext\") {\n for (const child of children(e)) todo.push([child, axis]);\n // The data of an extension of another kind can look like a cell reference. It only changes the order of a fill.\n // Stryker disable next-line ConditionalExpression,LogicalOperator: see the comment above\n } else if (e.kind === CELL_KIND && isCellRef(e.data)) {\n columns.add(e.data.column);\n // The directions of the reads of another column only change the order of a fill, because that column comes first.\n // Stryker disable next-line ConditionalExpression: see the comment above\n if (e.data.column === self) for (const m of [...(axis === undefined ? [] : [axis]), ...e.data.at]) addDirection(directions, m);\n }\n }\n return { columns, directions };\n}\n\n/**\n * This function gives the columns of a table in an order where each column comes after the columns that it reads.\n * The columns of a cycle keep their order. The columns with formulas of cells only come last.\n */\nfunction columnOrder(t: Table): readonly string[] {\n const names = new Set([...t.columns.keys(), ...t.cells.keys()]);\n let left = [...names].map((c) => ({ c, needs: [...readsOf(t, c).columns].filter((x) => x !== c && names.has(x)) }));\n const order: string[] = [];\n const placed = new Set<string>();\n // Each pass places each column whose reads are placed. A pass that places no column leaves a cycle, so it places\n // the first column that is left.\n while (left.length > 0) {\n const ready = left.filter((x) => x.needs.every((n) => placed.has(n)));\n for (const x of ready.length > 0 ? ready : left.slice(0, 1)) {\n order.push(x.c);\n placed.add(x.c);\n }\n left = left.filter((x) => !placed.has(x.c));\n }\n return order;\n}\n\n/**\n * This function gives the keys of a space in the order of the reads of a column from itself. A read of a later key\n * reverses the order. In a tree, a read of the children puts the children before their parent.\n */\nfunction keyOrder(s: Space, d: ReadonlySet<Direction>): readonly string[] {\n const reverse = d.has(\"after\") && !d.has(\"before\");\n const childrenOf = s.childrenOf?.bind(s);\n if (childrenOf === undefined) return reverse ? s.keys.toReversed() : s.keys;\n const post = d.has(\"down\");\n // The order with each parent before its children, and the order after the children is that order from the end, with\n // the siblings in the other order. `push` puts the next key to visit at the end of the stack.\n const backwards = post !== reverse;\n const push = (stack: string[], keys: readonly string[]): void => {\n for (const k of backwards ? keys : keys.toReversed()) stack.push(k);\n };\n const isChild = new Set(s.keys.flatMap((k) => childrenOf(k)));\n const stack: string[] = [];\n push(stack, s.keys.filter((k) => !isChild.has(k)));\n const out: string[] = [];\n for (let k = stack.pop(); k !== undefined; k = stack.pop()) {\n out.push(k);\n push(stack, childrenOf(k));\n }\n return post ? out.toReversed() : out;\n}\n\n/** The state of one cell in the search. */\ninterface Visit {\n readonly id: string;\n readonly table: Table;\n readonly column: string;\n readonly key: string;\n readonly index: number;\n low: number;\n reread: boolean;\n result: Result<unknown>;\n /** True when the last evaluation paused, because a cell that it reads is not finished. */\n paused: boolean;\n /** The cell that the evaluation waits for: a cell that the run started, or a cell that paused too. */\n need: Visit | undefined;\n}\n\n/**\n * The budget of the stack for the recursion of a run, in estimated frames. Each engine has more stack than this, so\n * the recursion of a run cannot fill the stack (SHEET.DEEP).\n */\nconst STACK_BUDGET = 3000;\n\n/**\n * One run of a sheet. It keeps the result of each cell that it evaluated. The space does not change, so a cell has\n * one result in a run.\n *\n * The run is a depth-first search with the algorithm of Tarjan for strongly connected components. A cell finishes\n * when its component finishes. Each cell of a component with two or more cells, or with a reference to itself,\n * gives `#CYCLE!`. A read of a cell that is not finished gives `#CYCLE!` too. Thus the order of the evaluations\n * does not change a result, also when `ifError` catches the error of a cycle.\n *\n * The search does not depend on the call stack of the engine (SHEET.DEEP). A read of a cell evaluates that cell\n * with recursion while the stack of the run stays in a budget. When a read is over the budget, the run starts the\n * cell, and the cell that reads it pauses. A paused evaluation reads no other cell and changes no state of the\n * search. The run then evaluates the started cell from its own list, and it evaluates the paused cell again after\n * that cell. A formula is pure (EVAL.PURE), so the second evaluation gives the result of one evaluation.\n *\n * A run can have more tables (SHEET.TABLES). Each table has its own space, and one search covers the cells of all\n * the tables. Thus a cycle across tables gives `#CYCLE!` too.\n */\nexport class SheetRun {\n readonly #main: Table;\n // The tables by name and by space. A cell reference reads the table of the space where it evaluates.\n readonly #byName = new Map<string, Table>();\n readonly #bySpace = new Map<Space, Table>();\n readonly #opts: Omit<EvalOptions, \"origin\" | \"trace\" | \"space\">;\n // The cells on the stack of the search: started, but their component is not finished.\n readonly #visits = new Map<string, Visit>();\n // Stryker disable next-line ArrayDeclaration: the search never reads below the root of a component\n readonly #stack: Visit[] = [];\n // The cell whose formula is in evaluation. At the top level, it is a placeholder that is not a cell.\n #top: Visit;\n // The placeholder at the top in a fill, and true when the evaluation of a fill reads a cell that is not finished.\n readonly #filling: Visit;\n #missed = false;\n #next = 0;\n // The estimated frames of the stack that the evaluations in progress use, and the cost of each program.\n #used = 0;\n readonly #cost = new Map<Expr, number>();\n readonly #budget: number;\n readonly #compile: CompileFn | undefined;\n readonly #compileOptions: CompileOptions;\n // The run that evaluates a formula with a compiled program. Each run is synchronous, so a run inside the evaluation\n // of another run gives the active run back when it ends.\n static #active: SheetRun | undefined;\n // The extensions of the compiled programs, for each object of extensions of the options. Their cell handler reads\n // the cells of the active run, so a compiled program does not depend on one run.\n static readonly #shared = new WeakMap<object, Readonly<Record<string, ExtHandler>>>();\n\n /** `budget` is the budget of the stack in estimated frames. A test can make it small, so the run pauses often. */\n constructor(columns: ReadonlyMap<string, Expr>, opts: SheetOptions, budget: number = STACK_BUDGET) {\n const { cells, name, tables, space, compile, ...rest } = opts;\n this.#main = { where: \"the sheet\", tag: \"0\", space, columns, cells: cells ?? new Map(), warmed: new Map(), index: undefined, done: new Map() };\n this.#bySpace.set(space, this.#main);\n if (name !== undefined) this.#byName.set(name, this.#main);\n if (tables !== undefined) {\n let i = 0;\n for (const [n, t] of tables) {\n if (this.#byName.has(n)) continue;\n const other = tableState(`the table \"${n}\"`, ++i, t);\n this.#byName.set(n, other);\n // A table with the space of an earlier table does not take its cells: the first table keeps the space.\n if (!this.#bySpace.has(t.space)) this.#bySpace.set(t.space, other);\n }\n }\n // Stryker disable next-line all: the placeholder is not a cell, so the search reads none of its fields\n this.#top = { id: \"\", table: this.#main, column: \"\", key: \"\", index: -1, low: -1, reread: false, result: cycleError(\"\", \"\"), paused: false, need: undefined };\n // Stryker disable next-line all: the placeholder is not a cell, so the search reads none of its fields\n this.#filling = { id: \"\", table: this.#main, column: \"\", key: \"\", index: 0, low: 0, reread: false, result: cycleError(\"\", \"\"), paused: false, need: undefined };\n this.#budget = budget;\n this.#compile = compile;\n const spaces = Object.fromEntries([...this.#byName].map(([n, t]) => [n, t.space]));\n this.#opts = { ...rest, tables: spaces, extensions: { ...rest.extensions, [CELL_KIND]: this.#handler } };\n const outer = rest.extensions ?? NO_EXTENSIONS;\n let shared = SheetRun.#shared.get(outer);\n if (shared === undefined) {\n shared = { ...rest.extensions, [CELL_KIND]: SheetRun.#cellOfActive };\n SheetRun.#shared.set(outer, shared);\n }\n this.#compileOptions = { ...this.#opts, extensions: shared };\n }\n\n /** The cell handler of the compiled programs: it reads the cells of the active run. */\n static readonly #cellOfActive: ExtHandler = (data, ctx) => {\n const run = SheetRun.#active;\n return run === undefined ? fail(vexError(\"unbound\", \"a compiled formula reads cells only in the evaluation of a sheet run\")) : run.#handler(data, ctx);\n };\n\n /** This method gives the program of a cell: its own formula, or the formula of its column (SHEET.CELL.FORMULA). */\n #programOf(t: Table, column: string, key: string): Expr | undefined {\n // Stryker disable next-line ConditionalExpression: without formulas of cells, the lookup gives undefined anyway\n const own = t.cells.size === 0 ? undefined : t.cells.get(column)?.get(key);\n return own ?? t.columns.get(column);\n }\n\n /** This method gives the error of a cell without a program. */\n #unbound(t: Table, column: string, key: string): Result<never> {\n const message = t.cells.has(column) ? `the cell \"${column}\" at \"${key}\" has no formula` : `${t.where} has no column \"${column}\"`;\n return fail(vexError(\"unbound\", message, { origin: key, focus: key }));\n }\n\n /** This method gives the table of a name for a read from a host. Without a name, it is the main table. */\n #named(table: string | undefined, key: string): Table | Result<never> {\n if (table === undefined) return this.#main;\n return this.#byName.get(table) ?? fail(vexError(\"no-table\", `the run has no table \"${table}\"`, { origin: key, focus: key }));\n }\n\n readonly #handler: ExtHandler = (data, ctx) => {\n // The interpreter gives an error without an origin the path and the position of its node.\n if (!isCellRef(data)) return fail(vexError(\"bad-expression\", \"a cell reference needs a column name and an address of fixed moves\"));\n const where = resolveAddr(ctx.space, ctx.position, data.at);\n if (!where.ok) return fail({ ...where.error, path: ctx.path });\n // The evaluation of a cell has the space of its table, and the body of the axis table has the space of that table.\n /* v8 ignore next -- @preserve: each space of an evaluation of the run is the space of a table */\n return this.#read(this.#bySpace.get(ctx.space) ?? this.#main, data.column, where.value);\n };\n\n /**\n * This method gives the result of one cell: the column `column` at the key `key` of the main table, or of the table\n * `table`. A read from a host first evaluates the column at the keys before `key`, in key order. Thus a recurrence\n * over the keys reads finished cells.\n */\n cell(column: string, key: string, table?: string): Result<unknown> {\n const t = this.#named(table, key);\n if (!(\"space\" in t)) return t;\n // The placeholder at the top has the index -1. A read inside a formula has a cell at the top, so it does not warm.\n if (this.#top.index >= 0) return this.#read(t, column, key);\n // A finished cell needs no warm-up.\n const done = doneOf(t, column, key);\n if (done !== undefined) return done;\n this.#warmTo(t, column, key);\n return this.#drive(t, column, key);\n }\n\n /** This method evaluates the column `column` at each key before `key` that it did not evaluate before, in key order. */\n #warmTo(t: Table, column: string, key: string): void {\n if (!t.columns.has(column)) return;\n const keys = t.space.keys;\n t.index ??= new Map(keys.map((k, i) => [k, i]));\n const end = t.index.get(key) ?? 0;\n const start = t.warmed.get(column) ?? 0;\n for (let i = start; i < end; i++) this.#drive(t, column, keys[i] ?? key);\n if (end > start) t.warmed.set(column, end);\n }\n\n /** This method gives the estimated frames of the stack that one evaluation of the program `program` uses. */\n #costOf(program: Expr): number {\n let cost = this.#cost.get(program);\n if (cost === undefined) {\n cost = 3 * (shapeError(program) === undefined ? nestingOf(program) : 1) + 16;\n this.#cost.set(program, cost);\n }\n return cost;\n }\n\n /** This method puts a new cell on the stack of the search. */\n #start(t: Table, column: string, key: string): Visit {\n const n = this.#next++;\n const visit: Visit = { id: idOf(t, column, key), table: t, column, key, index: n, low: n, reread: false, result: cycleError(column, key), paused: false, need: undefined };\n this.#visits.set(visit.id, visit);\n this.#stack.push(visit);\n return visit;\n }\n\n /** This method evaluates the formula of a cell once. When the evaluation pauses, the result of the cell does not change. */\n #evaluate(visit: Visit, program: Expr): void {\n const caller = this.#top;\n const cost = this.#costOf(program);\n visit.paused = false;\n visit.need = undefined;\n this.#top = visit;\n this.#used += cost;\n const result = this.#run(visit.table, visit.column, visit.key, program);\n this.#used -= cost;\n this.#top = caller;\n if (!visit.paused) visit.result = result;\n }\n\n /** This method evaluates the formula `program` of a cell, with its compiled program or with the interpreter. */\n #run(t: Table, column: string, key: string, program: Expr): Result<unknown> {\n const options = { ...this.#opts, space: t.space, origin: key };\n const compiled = this.#compiled(t, column, program);\n if (compiled === undefined) return evaluate(program, options);\n const active = SheetRun.#active;\n SheetRun.#active = this;\n const result = compiled.run(options);\n SheetRun.#active = active;\n return result;\n }\n\n /**\n * This method gives the compiled program of the formula of a column, or `undefined` for the interpreter. A formula\n * compiles once for each compiler and options, also across runs.\n */\n #compiled(t: Table, column: string, program: Expr): Program | undefined {\n const compile = this.#compile;\n // The formula of a cell evaluates once in a run, so the run compiles only the formulas of the columns.\n if (compile === undefined || t.columns.get(column) !== program) return undefined;\n const { domains, fns, extensions } = this.#compileOptions;\n const hit = PROGRAMS.get(program);\n if (hit !== undefined && hit.compile === compile && hit.domains === domains && hit.fns === fns && hit.extensions === extensions) return hit.program;\n const compiled = compile(program, this.#compileOptions);\n PROGRAMS.set(program, { compile, domains, fns, extensions, program: compiled });\n return compiled;\n }\n\n /** This method ends a cell whose evaluation did not pause: it finishes its component, or it gives its low to the caller. */\n #end(visit: Visit, caller: Visit | undefined): void {\n if (visit.low === visit.index) this.#finish(visit);\n else if (caller !== undefined) caller.low = Math.min(caller.low, visit.low);\n }\n\n /** This method reads a cell from the formula of the cell at the top. */\n #read(t: Table, column: string, key: string): Result<unknown> {\n const done = doneOf(t, column, key);\n if (done !== undefined) return done;\n const caller = this.#top;\n // A paused evaluation reads no other cell, so it does not follow a path that its final evaluation does not follow.\n // In a fill, the cell goes to the search after the evaluation (SHEET.FILL).\n if (caller.paused) return cycleError(column, key);\n if (caller === this.#filling) {\n this.#missed = true;\n return cycleError(column, key);\n }\n const id = idOf(t, column, key);\n const seen = this.#visits.get(id);\n if (seen !== undefined) {\n // A read of a cell that is not finished: the caller and this cell are on one cycle. The cell is on the\n // stack of the search, so it is in the component of the caller. Thus a component with one cell is cyclic\n // only if that cell reads itself.\n caller.low = Math.min(caller.low, seen.index);\n seen.reread = true;\n return cycleError(column, key);\n }\n const program = this.#programOf(t, column, key);\n if (program === undefined) return this.#unbound(t, column, key);\n const visit = this.#start(t, column, key);\n if (this.#used + this.#costOf(program) > this.#budget) {\n // Over the budget: the caller pauses, and the run evaluates the new cell from its own list.\n caller.paused = true;\n caller.need = visit;\n return cycleError(column, key);\n }\n this.#evaluate(visit, program);\n if (visit.paused) {\n caller.paused = true;\n caller.need = visit;\n return cycleError(column, key);\n }\n this.#end(visit, caller);\n return doneOf(t, column, key) ?? cycleError(column, key);\n }\n\n /** This method evaluates a cell from the top level. The cells that pause go on a list, not on the call stack. */\n #drive(t: Table, column: string, key: string): Result<unknown> {\n const done = doneOf(t, column, key);\n if (done !== undefined) return done;\n if (this.#programOf(t, column, key) === undefined) return this.#unbound(t, column, key);\n const work: Visit[] = [this.#start(t, column, key)];\n for (let visit = work.at(-1); visit !== undefined; visit = work.at(-1)) {\n const program = this.#programOf(visit.table, visit.column, visit.key);\n /* v8 ignore next -- @preserve: a visit exists only for a cell with a program */\n if (program === undefined) break;\n this.#evaluate(visit, program);\n if (visit.paused) {\n // The cells that the evaluation waits for go on the list, the last one on the top.\n for (let need = visit.need; need !== undefined; need = need.need) work.push(need);\n continue;\n }\n work.pop();\n this.#end(visit, work.at(-1));\n }\n return doneOf(t, column, key) ?? cycleError(column, key);\n }\n\n /** This method takes the component of `root` from the stack, and sets the final result of each of its cells. */\n #finish(root: Visit): void {\n // The root is near the top of the stack, so the search starts at the top: a deep chain needs no long scan.\n const members = this.#stack.splice(this.#stack.lastIndexOf(root));\n // A component of two or more cells reads its root again, so root.reread alone decides. The length test is a guard.\n // Stryker disable next-line ConditionalExpression,LogicalOperator: members.length > 1 implies root.reread\n const cyclic = members.length > 1 || root.reread;\n for (const m of members) {\n // Stryker disable next-line CallExpression: a finished cell has a result, and a read looks for the result first\n this.#visits.delete(m.id);\n setDone(m.table, m.column, m.key, cyclic ? cycleError(m.column, m.key) : m.result);\n }\n }\n\n /** This method evaluates one cell with a trace of the nodes of its program. The result is the result of the cell. */\n explain(column: string, key: string, table?: string): Trace {\n const result = this.cell(column, key, table);\n const t = this.#named(table, key);\n const program = \"space\" in t ? this.#programOf(t, column, key) : undefined;\n if (program === undefined || !(\"space\" in t)) return { events: [], result };\n return { events: explain(program, { ...this.#opts, space: t.space, origin: key }).events, result };\n }\n\n /**\n * This method evaluates each cell of the table `table`, or of the main table (SHEET.FILL). Each column comes after\n * the columns that it reads, and the keys of a column come in the order of its reads from itself. Thus most reads\n * find a finished cell. An evaluation that reads a cell that is not finished has no effect, and the search then\n * evaluates its cell. A read of a cell gives the same result after a fill.\n */\n fill(table?: string): void {\n const t = table === undefined ? this.#main : this.#byName.get(table);\n // A read inside a formula has a cell at the top. A fill there has no effect.\n if (t === undefined || this.#top.index >= 0) return;\n const host = this.#top;\n for (const column of columnOrder(t)) {\n for (const key of keyOrder(t.space, readsOf(t, column).directions)) {\n const program = this.#programOf(t, column, key);\n if (program === undefined || doneOf(t, column, key) !== undefined) continue;\n this.#top = this.#filling;\n this.#missed = false;\n const result = this.#run(t, column, key, program);\n this.#top = host;\n if (this.#missed) this.#drive(t, column, key);\n else setDone(t, column, key, result);\n }\n }\n }\n\n /**\n * This method evaluates the column `column` at each key before `key`, in key order. A recurrence over the keys,\n * for example a running total, then reads finished cells.\n */\n warm(column: string, key: string, table?: string): void {\n const t = this.#named(table, key);\n // Stryker disable next-line all: a warm-up changes no result, only the depth of the recursion (SHEET.ORDER)\n if (\"space\" in t) this.#warmTo(t, column, key);\n }\n}\n","/**\n * The typed builder. Method calls make an expression of the IR. The builder has no other job: it does not\n * evaluate anything until a caller asks for a value.\n */\nimport type { AnyDomain, Domain, OpSpec } from \"./domain.ts\";\nimport type { VexError } from \"./errors.ts\";\nimport { evaluate, explain, type EvalOptions, type ExtHandler, type FreeFn } from \"./evaluate.ts\";\nimport { app, each, ext, fold as foldExpr, index as indexMove, iterate as iterateExpr, key as keyMove, let_, lit, offset as offsetMove, other as otherMove, origin as originMove, parent as parentMove, rec, ref, toPath, v, type Axis, type Expr, type ExprOf, type FixedMove, type Move } from \"./ir.ts\";\nimport { cell as cellRef, SheetRun, type CellFormulas } from \"./sheet.ts\";\nimport { toOptional, type Optional, type Result } from \"./result.ts\";\nimport type { Space } from \"./space.ts\";\nimport type { Trace } from \"./trace.ts\";\nimport type { VexList } from \"./list.ts\";\nimport { traversal, type Traversal } from \"./traversal.ts\";\n\n// ---------------------------------------------------------------- argument tokens\n\ndeclare const ARG_TYPE: unique symbol;\ndeclare const CHAIN_VALUE: unique symbol;\n\n/** An argument token: an expression with the static type `T` of its value. */\nexport interface Arg<T> {\n readonly kind: \"vex.arg\";\n readonly expr: Expr;\n /** This phantom member carries the type. It is not present at run time. */\n readonly [ARG_TYPE]?: T;\n}\n\nconst argToken = <T>(expr: Expr): Arg<T> => ({ kind: \"vex.arg\", expr });\n\n\n// ---------------------------------------------------------------- type helpers\n\n/** The keys of any member of a union of record types. */\ntype AllKeys<O> = O extends unknown ? keyof O : never;\n\n/** The type of field `P` in the members of `O` that have it. */\ntype FieldType<O, P extends PropertyKey> = O extends unknown ? (P extends keyof O ? O[P] : never) : never;\n\n/**\n * The merged view of a union of record types: each field of any member, with the union of its types. A record\n * without the field gives `#N/A` at run time.\n */\nexport type Merge<O> = { readonly [P in AllKeys<O>]: FieldType<O, P> };\n\n/** The keys of `O` whose values have the type `T`. */\nexport type KeysOfType<O, T> = { [P in keyof O]-?: [NonNullable<O[P]>] extends [never] ? never : NonNullable<O[P]> extends T ? P : never }[keyof O] & string;\n\n/** The method names of `D`. */\nexport type MethodKeys<D> = { [P in keyof D]-?: D[P] extends (...args: never[]) => unknown ? P : never }[keyof D] & string;\n\n/** The value type of a domain. */\nexport type DomainValue<Dm> = Dm extends Domain<string, infer D, infer _Ops> ? D : never;\n\ntype OpsOf<Dm> = Dm extends Domain<string, unknown, infer Ops> ? Ops : Dm extends { readonly ops: infer Ops } ? Ops : never;\n\n/** The op names that a chain over a value of domain `Dm` can use. */\nexport type OpNames<Dm> =\n | (keyof OpsOf<Dm> & string)\n | (Dm extends { readonly methods: \"all\" } ? MethodKeys<DomainValue<Dm>> : never);\n\ntype FnOf<Dm, M extends string> = M extends keyof OpsOf<Dm>\n ? OpsOf<Dm>[M] extends { readonly fn: (self: never, ...args: infer P) => infer R }\n ? (...args: P) => R\n : M extends keyof DomainValue<Dm>\n ? DomainValue<Dm>[M]\n : never\n : M extends keyof DomainValue<Dm>\n ? DomainValue<Dm>[M]\n : never;\n\n/** The parameters of op `M` after the receiver. */\nexport type OpParams<Dm, M extends string> = FnOf<Dm, M> extends (...args: infer P) => unknown ? P : never;\n\n/** The value type that op `M` gives. */\nexport type OpReturn<Dm, M extends string> = FnOf<Dm, M> extends (...args: never[]) => infer R ? R : never;\n\ntype Lifts<Dm, M extends string> = M extends keyof OpsOf<Dm> ? (OpsOf<Dm>[M] extends { readonly liftScalar: true } ? true : false) : false;\n\n/** The first domain of `Dms` whose values include `T`, or `never`. */\nexport type DomainFor<Dms extends readonly AnyDomain[], T> = Dms extends readonly [infer H, ...infer R extends readonly AnyDomain[]]\n ? [T] extends [never]\n ? never\n : [T] extends [DomainValue<H>]\n ? H\n : DomainFor<R, T>\n : never;\n\ntype UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;\ntype LastOf<U> = UnionToIntersection<U extends unknown ? () => U : never> extends () => infer R ? R : never;\n\n/** `true` if `other()` is permitted for the key type: a pair of keys, or keys that the compiler does not know. */\nexport type AllowsOther<K extends string> = string extends K\n ? true\n : `${number}` extends K\n ? true\n : [Exclude<K, LastOf<K>>] extends [never]\n ? false\n : [Exclude<Exclude<K, LastOf<K>>, LastOf<Exclude<K, LastOf<K>>>>] extends [never]\n ? true\n : false;\n\n/**\n * The inputs for an argument with the parameter type `P`. The input can be a literal of type `P`, but not a bare\n * string. It can be a field of the record with type `P`, an argument token, or a chain that gives `P`. If the op\n * lifts scalars, it can also be a number.\n */\nexport type ArgInput<P, Ctx extends ChainContext, Lift extends boolean> =\n | (P extends string ? never : P)\n | KeysOfType<Ctx[\"record\"], P>\n | Arg<P>\n | ChainOf<Ctx, P>\n | (Lift extends true ? ([P] extends [DomainValue<DomainFor<Ctx[\"domains\"], P>>] ? LiftedNumber<Ctx> : never) : never);\n\n/**\n * A number argument for a domain parameter of an op with `liftScalar` (TYPE.LIFT): a number, a field with numbers, an\n * argument or a chain. The interpreter lifts each of them with `fromScalar` (CALL.LIFT).\n */\ntype LiftedNumber<Ctx extends ChainContext> = number | KeysOfType<Ctx[\"record\"], number> | Arg<number> | ChainOf<Ctx, number>;\n\ntype MapArgs<P extends readonly unknown[], Ctx extends ChainContext, Lift extends boolean> = { [I in keyof P]: ArgInput<P[I], Ctx, Lift> };\n\n/** A table of free functions. The first parameter of a function gets the current value of the chain. */\nexport type FnTable = Readonly<Record<string, (...args: never[]) => unknown>>;\n\n/** The free functions of a builder without `withOptions`: none, so `call` accepts no name. */\n// oxlint-disable-next-line typescript/no-generated-empty-object-type -- an empty table is the intent.\nexport type NoFns = Record<never, never>;\n\n/** The static context of a chain: its domains, its key type, its record type and its free functions. */\nexport interface ChainContext {\n readonly domains: readonly AnyDomain[];\n readonly keys: string;\n readonly record: unknown;\n readonly fns?: FnTable;\n}\n\ntype FnsOf<Ctx extends ChainContext> = NonNullable<Ctx[\"fns\"]>;\ntype FnParams<F> = F extends (...args: infer P) => unknown ? P : never;\ntype FirstParam<P> = P extends readonly [infer A, ...unknown[]] ? A : unknown;\ntype RestParams<P> = P extends readonly [unknown, ...infer R] ? R : [];\n\n/** The names of the free functions whose first parameter accepts a value of type `T`. */\nexport type CallableFns<Ctx extends ChainContext, T> = {\n [K in keyof FnsOf<Ctx>]: [T] extends [FirstParam<FnParams<FnsOf<Ctx>[K]>>] ? K : never;\n}[keyof FnsOf<Ctx>] &\n string;\n\n/** The inputs for the parameters of the free function `N` after its first parameter. */\nexport type CallArgs<Ctx extends ChainContext, N extends keyof FnsOf<Ctx>> = MapArgs<RestParams<FnParams<FnsOf<Ctx>[N]>>, Ctx, false>;\n\n/** The return type of the free function `N`. */\nexport type CallReturn<Ctx extends ChainContext, N extends keyof FnsOf<Ctx>> = FnsOf<Ctx>[N] extends (...args: never[]) => infer R ? R : unknown;\n\n/** The ops section `._` of a chain whose value has domain `Dm`. */\nexport type OpsProxy<Ctx extends ChainContext, Dm> = {\n readonly [M in OpNames<Dm>]: (...args: MapArgs<OpParams<Dm, M>, Ctx, Lifts<Dm, M>>) => ChainOf<Ctx, OpReturn<Dm, M>>;\n};\n\n// ---------------------------------------------------------------- chain types\n\n/** The members of every chain. */\nexport interface ChainBase<Ctx extends ChainContext, T> {\n readonly kind: \"vex.chain\";\n /** This phantom member carries the value type. It is not present at run time. */\n readonly [CHAIN_VALUE]?: T;\n /** The expression of the chain, as plain data. */\n readonly program: Expr;\n /** This method evaluates the chain at a key. An error gives `none`. */\n at(k: Ctx[\"keys\"]): Optional<T>;\n /** This method is the same as `at`. The v0.9 spec calls it `value`. */\n value(k: Ctx[\"keys\"]): Optional<T>;\n /** This method evaluates the chain at a key, and gives the error if there is one. */\n result(k: Ctx[\"keys\"]): Result<T>;\n /** This method evaluates the chain at a key, with a trace of each node. */\n explain(k: Ctx[\"keys\"]): Trace;\n /** This method evaluates the chain at each key of the space (the start axis). */\n all(): Traversal<Ctx[\"keys\"], T>;\n /** This method gives a chain whose value is a field of the record at the current address. */\n from<P extends keyof Ctx[\"record\"] & string>(field: P): ChainOf<Ctx, NonNullable<Ctx[\"record\"][P]>>;\n /**\n * Navigation: later field references read at the key `k`. A chain of a text gives the key, and it evaluates at the\n * focus before the moves (NAV.COMPUTED).\n */\n to(k: Ctx[\"keys\"] | ChainBase<Ctx, string>): ChainOf<Ctx, T>;\n /**\n * Navigation: later field references read at the key with this position in the key order. A chain of a number gives\n * the position, and it evaluates at the focus before the moves (NAV.COMPUTED).\n */\n index(i: number | ChainBase<Ctx, number>): ChainOf<Ctx, T>;\n /** Navigation: later field references read at a relative position in an array or a grid. */\n offset(...d: readonly number[]): ChainOf<Ctx, T>;\n /** Navigation: later field references read at the origin again. */\n origin(): ChainOf<Ctx, T>;\n /** Navigation: later field references read at the parent of the focus, in a tree space. A root gives `#REF!`. */\n parent(): ChainOf<Ctx, T>;\n /** This method uses `fallback` when the chain gives an error. */\n ifError<U>(fallback: ArgInput<U, Ctx, false> | T): ChainOf<Ctx, T | U>;\n /**\n * This method gives `then` when the boolean value is true, and `otherwise` when it is false (the form `if`). Only\n * the selected branch evaluates.\n */\n if<U, V>(this: ChainBase<Ctx, boolean>, then: ArgInput<U, Ctx, false>, otherwise: ArgInput<V, Ctx, false>): ChainOf<Ctx, U | V>;\n /**\n * This method applies the free function `name` of `withOptions`. The function gets the current value as its first\n * argument, then `args`. The types accept only the functions whose first parameter accepts the current value.\n */\n call<N extends CallableFns<Ctx, T>>(name: N, ...args: CallArgs<Ctx, N>): ChainOf<Ctx, CallReturn<Ctx, N>>;\n /** This method evaluates each branch with the current value, and gives a record of the results. */\n fork<const B extends Readonly<Record<string, (c: ChainOf<Ctx, T>) => ChainBase<Ctx, unknown>>>>(branches: B): ChainOf<Ctx, { readonly [N in keyof B]: ValueOf<ReturnType<B[N]>> }>;\n /**\n * This method makes up to `limit` steps (ITERATE.LIMIT). `init` gives the names and their first values, and `step`\n * gives the next values. A true `until` stops the steps (ITERATE.UNTIL). `result` gives the value of the chain.\n */\n iterate<const I extends Readonly<Record<string, unknown>>, R>(\n limit: number,\n init: I,\n step: (vars: LoopVars<Ctx, I>) => NoInfer<LoopStep<Ctx, I>>,\n result: (vars: LoopVars<Ctx, I>) => ArgInput<R, Ctx, false>,\n opts?: { readonly until?: (vars: LoopVars<Ctx, I>) => ArgInput<boolean, Ctx, false> },\n ): ChainOf<Ctx, R>;\n /** This method binds names for the body. The body gets a variable token for each name. */\n with<const B extends Readonly<Record<string, unknown>>, U>(\n binds: B,\n body: (c: ChainOf<Ctx, T>, vars: { readonly [N in keyof B]: Arg<ArgValue<Ctx, B[N]>> }) => ChainBase<Ctx, U>,\n ): ChainOf<Ctx, U>;\n /** The others axis: the body evaluates at each key except the focus. Its start value is the current value. */\n others<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The neighbors axis of a grid. */\n neighbors<U>(n: 4 | 8, body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The all axis inside the expression: the body evaluates at each key, with the current value as start value. */\n each<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The children axis of a tree space: the body evaluates at each child of the focus. */\n children<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The ancestors axis of a tree space: the parent first, the root last. */\n ancestors<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The descendants axis of a tree space: depth first, each parent before its children. */\n descendants<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The siblings axis of a tree space: the other children of the parent, or the other roots for a root. */\n siblings<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /**\n * The window axis of an array space or a tree space: the keys at the offsets from `from` to `to` of the focus, in\n * order. The offset 0 is the focus. An offset outside the space has no target.\n */\n window<U>(from: number, to: number, body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /**\n * The table axis: the body evaluates at each key of the table `name` of the evaluation, in the space of that table.\n * The body reads the fields of that table, but the types of the chain are the types of this space.\n */\n table<U>(name: string, body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The successors axis of a graph space: the ends of the edges from the focus. In a tree space, the children. */\n successors<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The predecessors axis of a graph space: the keys with an edge to the focus. In a tree space, the parent. */\n predecessors<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The reachable axis of a graph space: each key that a path of edges reaches, in breadth-first order. */\n reachable<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n}\n\n/** The options of an axis. */\nexport interface AxisOpts<Ctx extends ChainContext, T> {\n /** A test at each target. The body evaluates only at the targets where the test gives `true`. */\n readonly where?: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, boolean>;\n}\n\n/** The members of a chain whose value has a domain. */\nexport interface DomainMembers<Ctx extends ChainContext, Dm> {\n /** The ops of the domain of the current value. */\n readonly _: OpsProxy<Ctx, Dm>;\n}\n\n/** The members of a chain over a space whose keys permit `other()`. */\nexport interface OtherMembers<Ctx extends ChainContext, T> {\n /** Navigation: later field references read at the other key of the pair. */\n other(): ChainOf<Ctx, T>;\n}\n\n/** A chain with the current value type `T`. */\nexport type ChainOf<Ctx extends ChainContext, T> = ChainBase<Ctx, T> &\n ([DomainFor<Ctx[\"domains\"], T>] extends [never] ? unknown : DomainMembers<Ctx, DomainFor<Ctx[\"domains\"], T>>) &\n (AllowsOther<Ctx[\"keys\"]> extends true ? OtherMembers<Ctx, T> : unknown);\n\n/** The value type of a chain. */\nexport type ValueOf<C> = C extends { readonly [CHAIN_VALUE]?: infer T } ? T : never;\n\n/** The value type of an argument input. */\nexport type ArgValue<Ctx extends ChainContext, A> = A extends Arg<infer T>\n ? T\n : A extends { readonly kind: \"vex.chain\" }\n ? ValueOf<A>\n : A extends keyof Ctx[\"record\"] & string\n ? NonNullable<Ctx[\"record\"][A]>\n : A;\n\n/** A chain whose value is a list: the result of an axis. */\n/** The type of a value of a name of a loop: a literal of `init` gives its primitive type. */\ntype LoopValue<Ctx extends ChainContext, A> = ArgValue<Ctx, A> extends infer T ? (T extends number ? number : T extends string ? string : T extends boolean ? boolean : T) : never;\n\n/** The names of a loop of the builder: a chain of the value of each name of `init` (LOOP.NAMES). */\nexport type LoopVars<Ctx extends ChainContext, I> = { readonly [N in keyof I]: ChainOf<Ctx, LoopValue<Ctx, I[N]>> };\n\n/** The next values of a step of a loop: a value for some of the names of `init`. */\nexport type LoopStep<Ctx extends ChainContext, I> = { readonly [N in keyof I]?: ArgInput<LoopValue<Ctx, I[N]>, Ctx, false> };\n\nexport interface ListChain<Ctx extends ChainContext, U> {\n readonly kind: \"vex.list-chain\";\n /** The expression of the chain, as plain data. */\n readonly program: Expr;\n /**\n * This method folds the items in the order of the axis (FOLD.ORDER). `init` gives the names and their first values.\n * `step` gives the next values from the names and the item, a chain at the target. `result` gives the value.\n */\n fold<const I extends Readonly<Record<string, unknown>>, R>(\n init: I,\n step: (vars: LoopVars<Ctx, I>, item: ChainOf<Ctx, U>) => NoInfer<LoopStep<Ctx, I>>,\n result: (vars: LoopVars<Ctx, I>) => ArgInput<R, Ctx, false>,\n ): ChainOf<Ctx, R>;\n count(opts?: ListOpts): ChainOf<Ctx, number>;\n sum(this: ListChain<Ctx, number>, opts?: ListOpts): ChainOf<Ctx, number>;\n mean(this: ListChain<Ctx, number>, opts?: ListOpts): ChainOf<Ctx, number>;\n min(this: ListChain<Ctx, number>, opts?: ListOpts): ChainOf<Ctx, number>;\n max(this: ListChain<Ctx, number>, opts?: ListOpts): ChainOf<Ctx, number>;\n any(this: ListChain<Ctx, boolean>, opts?: ListOpts): ChainOf<Ctx, boolean>;\n all(this: ListChain<Ctx, boolean>, opts?: ListOpts): ChainOf<Ctx, boolean>;\n none(this: ListChain<Ctx, boolean>, opts?: ListOpts): ChainOf<Ctx, boolean>;\n values(opts?: ListOpts): ChainOf<Ctx, readonly U[]>;\n /** The keys of the items with a value, in the order of the axis. */\n keys(opts?: ListOpts): ChainOf<Ctx, readonly Ctx[\"keys\"][]>;\n /** The error of each item that failed, in the order of the axis. */\n errors(): ChainOf<Ctx, readonly VexError[]>;\n first(opts?: ListOpts): ChainOf<Ctx, U>;\n reduce(op: OpNames<DomainFor<Ctx[\"domains\"], U>>, opts?: ReduceOpts<Ctx>): ChainOf<Ctx, U>;\n /** The list at the origin `k`: one item for each target of the axis, with its key and its result. */\n result(k: Ctx[\"keys\"]): Result<VexList<U>>;\n /** The list at the origin `k`, as an `Optional`. */\n at(k: Ctx[\"keys\"]): Optional<VexList<U>>;\n /** The trace of the evaluation of the list at the origin `k`. */\n explain(k: Ctx[\"keys\"]): Trace;\n}\n\n/** The options of a list reduction. */\nexport interface ListOpts {\n /** With `true`, an error item makes the result that error. The default skips error items. */\n readonly strict?: boolean;\n}\n\n/** The options of `reduce`. `domain` names the domain whose identity an empty list gives (LIST.EMPTY). */\nexport interface ReduceOpts<Ctx extends ChainContext> extends ListOpts {\n readonly domain?: Ctx[\"domains\"][number][\"name\"];\n}\n\n/** The root of the builder for one space. */\nexport interface Root<Ctx extends ChainContext> {\n /** This method starts a chain with a field of the record at the focus. */\n from<P extends keyof Ctx[\"record\"] & string>(field: P): ChainOf<Ctx, NonNullable<Ctx[\"record\"][P]>>;\n /** This method starts a chain with a value. A string is a field reference, as in an argument. */\n start<const T>(value: T): ChainOf<Ctx, ArgValue<Ctx, T>>;\n /** This method makes an absolute reference: the field of the record at key `k`. */\n of<P extends keyof Ctx[\"record\"] & string>(k: Ctx[\"keys\"], field: P): Arg<NonNullable<Ctx[\"record\"][P]>>;\n /** This method makes a reference to a dotted path at the focus, with the type that the caller gives. */\n field<T>(path: string): Arg<T>;\n /** This method makes a literal argument. Use it for a string or an array: a bare string is a field reference. */\n lit<const T>(value: T): Arg<T>;\n /** This method makes an absolute reference to a dotted path at key `k`, with the type that the caller gives. */\n ofPath<T>(k: Ctx[\"keys\"], path: string): Arg<T>;\n /** This method makes a record argument from field arguments. */\n rec<const F extends Readonly<Record<string, unknown>>>(fields: F): Arg<{ readonly [N in keyof F]: ArgValue<Ctx, F[N]> }>;\n /**\n * This method makes an extension argument: the node `ext(kind, data)`. The handler of `kind` in the options of\n * `withOptions` gives its value. The caller gives the type `T` of that value.\n */\n ext<T>(kind: string, data?: unknown): Arg<T>;\n /** This method starts a sheet over the space: named columns of formulas. Refer to `Sheet`. */\n sheet(): Sheet<Ctx, object>;\n /** The space of the root. */\n readonly space: Space<Ctx[\"keys\"], Ctx[\"record\"]>;\n}\n\n/** The root of a column formula: the root of the builder, and references to the cells of the sheet. */\nexport interface SheetRoot<Ctx extends ChainContext, Cols> extends Root<Ctx> {\n /**\n * This method makes a cell reference: the column `column` at the key `at`, or at the address `at` from the focus.\n * The address has only fixed moves. Without `at`, it reads at the focus. The type is the type of a column before\n * this one.\n */\n cell<N extends keyof Cols & string>(column: N, at?: Ctx[\"keys\"] | readonly FixedMove[]): Arg<Cols[N]>;\n /** This method makes a cell reference to any column, also this column or a later one. The caller gives the type. */\n cell<T>(column: string, at?: Ctx[\"keys\"] | readonly FixedMove[]): Arg<T>;\n}\n\n/** One row of a sheet: the key and the result of each column. */\nexport interface SheetRow<K extends string, Cols> {\n readonly key: K;\n readonly cells: { readonly [N in keyof Cols]: Result<Cols[N]> };\n}\n\n/**\n * A sheet: named columns of formulas over a space, like the computed columns of a spreadsheet. A formula reads the\n * other columns with `cell`. Each evaluation evaluates a cell once, and each cell on a cycle of references gives\n * `#CYCLE!`. A sheet is immutable: `column` gives a new sheet.\n */\nexport interface Sheet<Ctx extends ChainContext, Cols, Decl = object> {\n /**\n * This method gives a new sheet with one more column. The formula gets a root with `cell`. If `declare` gave the\n * column a type, the formula must give a value of that type.\n */\n column<const N extends string, C extends ChainBase<Ctx, DeclaredType<Decl, N>>>(\n name: N,\n formula: (r: SheetRoot<Ctx, Cols & Decl>) => C,\n ): Sheet<Ctx, Cols & { readonly [P in N]: ValueOf<C> }, Decl>;\n /**\n * This method gives the types of columns before their formulas. A formula can then read a declared column with\n * `cell` and its type: the column itself (a recurrence) or a later column. It has no effect at run time.\n */\n declare<D extends Readonly<Record<string, unknown>>>(): Sheet<Ctx, Cols, Decl & D>;\n /**\n * This method gives a new sheet in which the cell of the column `column` at the key `k` has its own formula. That\n * formula replaces the formula of the column at the key `k`. It must give a value of the type of the column.\n */\n cellFormula<const N extends keyof (Cols & Decl) & string>(\n k: Ctx[\"keys\"],\n column: N,\n formula: (r: SheetRoot<Ctx, Cols & Decl>) => ChainBase<Ctx, (Cols & Decl)[N]>,\n ): Sheet<Ctx, Cols, Decl>;\n /** The program of each column. */\n readonly columns: Readonly<Record<string, Expr>>;\n /** The program of each cell with its own formula, by column and then by key. */\n readonly cellFormulas: Readonly<Record<string, Readonly<Record<string, Expr>>>>;\n /** This method evaluates one cell, and gives the error if there is one. */\n result<N extends keyof Cols & string>(k: Ctx[\"keys\"], column: N): Result<Cols[N]>;\n /** This method evaluates one cell. An error gives `none`. */\n at<N extends keyof Cols & string>(k: Ctx[\"keys\"], column: N): Optional<Cols[N]>;\n /** This method evaluates one cell, with a trace of the nodes of its column. */\n explain(k: Ctx[\"keys\"], column: keyof Cols & string): Trace;\n /** This method evaluates each cell, in key order, with one result for each cell. */\n table(): readonly SheetRow<Ctx[\"keys\"], Cols>[];\n}\n\n/** The declared type of the column `N`, or `unknown` for a column without a declaration. */\nexport type DeclaredType<Decl, N extends string> = N extends keyof Decl ? Decl[N] : unknown;\n\n/** The options of the builder. */\nexport interface VexOptions<F extends FnTable = FnTable> {\n /** Free function ops. A chain applies them with `call`. */\n readonly fns?: F;\n /** Handlers of extension expression kinds. */\n readonly extensions?: Readonly<Record<string, ExtHandler>>;\n}\n\n/** The entry point for a list of domains. */\nexport interface VexEntry<Dms extends readonly AnyDomain[], F extends FnTable = NoFns> {\n /** This method gives the root of the builder for a space. */\n over<K extends string, O>(s: Space<K, O>): Root<{ readonly domains: Dms; readonly keys: K; readonly record: Merge<O>; readonly fns: F }>;\n /** The domains. */\n readonly domains: Dms;\n}\n\n// ---------------------------------------------------------------- run time\n\n/** The options as the interpreter takes them: free functions get untyped arguments at run time. */\ninterface RuntimeOptions {\n readonly fns?: Readonly<Record<string, FreeFn>>;\n readonly extensions?: Readonly<Record<string, ExtHandler>>;\n}\n\n/** This function gives the run-time form of the options. A typed free function gets the values that the types promise. */\nconst runtimeOptions = (options: VexOptions): RuntimeOptions => ({\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(options.fns === undefined ? {} : { fns: options.fns as Readonly<Record<string, FreeFn>> }),\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(options.extensions === undefined ? {} : { extensions: options.extensions }),\n});\n\ninterface Env {\n readonly space: Space;\n readonly domains: readonly AnyDomain[];\n readonly options: RuntimeOptions;\n}\n\ninterface State {\n readonly env: Env;\n /** The current value. */\n readonly expr: Expr;\n /** The address where later field references read. */\n readonly addr: readonly Move[];\n /** The depth of nested axis and binding bodies, for unique variable names. */\n readonly depth: number;\n}\n\nconst kindOf = (u: unknown): unknown => (u as { kind?: unknown } | null | undefined)?.kind;\nconst isArg = (u: unknown): u is Arg<unknown> => kindOf(u) === \"vex.arg\";\nconst isChainLike = (u: unknown): u is { readonly program: Expr } => kindOf(u) === \"vex.chain\" || kindOf(u) === \"vex.list-chain\";\n\n/** This function turns a builder argument into an expression. A bare string is a field reference at `addr`. */\nfunction toExpr(a: unknown, addr: readonly Move[]): Expr {\n if (typeof a === \"string\") return ref(toPath(a), addr);\n if (isArg(a)) return a.expr;\n if (isChainLike(a)) return a.program;\n return lit(a);\n}\n\n/** This function gives the expressions of a step of a loop, with the unique names of the loop. */\nfunction stepExprs(step: Readonly<Record<string, unknown>>, unique: ReadonlyMap<string, string>, addr: readonly Move[]): Readonly<Record<string, Expr>> {\n const out: Record<string, Expr> = {};\n for (const [n, a] of Object.entries(step)) {\n const name = unique.get(n);\n if (name === undefined) throw new TypeError(`the name \"${n}\" of the step is not a name of init`);\n out[name] = toExpr(a, addr);\n }\n return out;\n}\n\nconst PROXY_RESERVED = new Set([\"then\", \"catch\", \"finally\", \"toJSON\", \"valueOf\", \"toString\", \"constructor\", \"inspect\", \"asymmetricMatch\", \"$$typeof\", \"nodeType\"]);\n\nclass ChainImpl {\n readonly kind = \"vex.chain\" as const;\n readonly #s: State;\n\n constructor(s: State) {\n this.#s = s;\n }\n\n get program(): Expr {\n return this.#s.expr;\n }\n\n get _(): Readonly<Record<string, (...args: readonly unknown[]) => ChainImpl>> {\n const s = this.#s;\n return new Proxy(Object.create(null) as Record<string, never>, {\n get: (_t, prop): unknown => {\n if (typeof prop !== \"string\" || PROXY_RESERVED.has(prop)) return undefined;\n return (...args: readonly unknown[]): ChainImpl => new ChainImpl({ ...s, expr: app(prop, s.expr, ...args.map((a) => toExpr(a, s.addr))) });\n },\n });\n }\n\n #opts(k: string): EvalOptions {\n return evalOptions(this.#s, k);\n }\n\n result(k: string): Result<unknown> {\n return evaluate(this.#s.expr, this.#opts(k));\n }\n at(k: string): Optional<unknown> {\n return toOptional(this.result(k));\n }\n value(k: string): Optional<unknown> {\n return this.at(k);\n }\n explain(k: string): Trace {\n return explain(this.#s.expr, this.#opts(k));\n }\n all(): Traversal<string, unknown> {\n const { env } = this.#s;\n const items = env.space.keys.map((k) => ({ key: k, result: this.result(k) }));\n return traversal(items, env);\n }\n\n from(field: string): ChainImpl {\n return new ChainImpl({ ...this.#s, expr: ref(toPath(field), this.#s.addr) });\n }\n\n #move(m: Move): ChainImpl {\n return new ChainImpl({ ...this.#s, addr: [...this.#s.addr, m] });\n }\n to(k: string | { readonly program: Expr }): ChainImpl {\n return this.#move(keyMove(typeof k === \"string\" ? k : k.program));\n }\n index(i: number | { readonly program: Expr }): ChainImpl {\n return this.#move(indexMove(typeof i === \"number\" ? i : i.program));\n }\n offset(...d: readonly number[]): ChainImpl {\n return this.#move(offsetMove(...d));\n }\n other(): ChainImpl {\n return this.#move(otherMove);\n }\n origin(): ChainImpl {\n return this.#move(originMove);\n }\n parent(): ChainImpl {\n return this.#move(parentMove);\n }\n\n call(name: string, ...args: readonly unknown[]): ChainImpl {\n return new ChainImpl({ ...this.#s, expr: app(name, this.#s.expr, ...args.map((a) => toExpr(a, this.#s.addr))) });\n }\n if(then: unknown, otherwise: unknown): ChainImpl {\n return new ChainImpl({ ...this.#s, expr: app(\"if\", this.#s.expr, toExpr(then, this.#s.addr), toExpr(otherwise, this.#s.addr)) });\n }\n ifError(fallback: unknown): ChainImpl {\n return new ChainImpl({ ...this.#s, expr: app(\"ifError\", this.#s.expr, toExpr(fallback, this.#s.addr)) });\n }\n\n /** This method binds the current value to a fresh name, and gives a chain that starts from that name. */\n #bound(): { readonly name: string; readonly start: ChainImpl } {\n const name = `$${this.#s.depth}`;\n return { name, start: new ChainImpl({ ...this.#s, expr: v(name), depth: this.#s.depth + 1 }) };\n }\n\n fork(branches: Readonly<Record<string, (c: ChainImpl) => { readonly program: Expr }>>): ChainImpl {\n const { name, start } = this.#bound();\n const fields: Record<string, Expr> = {};\n for (const [n, f] of Object.entries(branches)) fields[n] = f(start).program;\n return new ChainImpl({ ...this.#s, expr: let_({ [name]: this.#s.expr }, rec(fields)) });\n }\n\n with(binds: Readonly<Record<string, unknown>>, body: (c: ChainImpl, vars: Readonly<Record<string, Arg<unknown>>>) => { readonly program: Expr }): ChainImpl {\n const depth = this.#s.depth;\n const bindExprs: Record<string, Expr> = {};\n const vars: Record<string, Arg<unknown>> = {};\n for (const [n, a] of Object.entries(binds)) {\n const unique = `${n}$${depth}`;\n bindExprs[unique] = toExpr(a, this.#s.addr);\n vars[n] = argToken(v(unique));\n }\n const inner = body(new ChainImpl({ ...this.#s, depth: depth + 1 }), vars);\n return new ChainImpl({ ...this.#s, expr: let_(bindExprs, inner.program) });\n }\n\n /**\n * This method gives the names of a loop. Each name of `init` gets a name that is unique at the depth of the chain.\n * It also gets its first value at the address of the chain, and a chain of its value.\n */\n loopNames(init: Readonly<Record<string, unknown>>): { readonly unique: ReadonlyMap<string, string>; readonly first: Readonly<Record<string, Expr>>; readonly vars: Readonly<Record<string, ChainImpl>> } {\n const depth = this.#s.depth;\n const unique = new Map<string, string>();\n const first: Record<string, Expr> = {};\n const vars: Record<string, ChainImpl> = {};\n for (const [n, a] of Object.entries(init)) {\n const name = `${n}$${depth}`;\n unique.set(n, name);\n first[name] = toExpr(a, this.#s.addr);\n vars[n] = new ChainImpl({ ...this.#s, expr: v(name), addr: [], depth: depth + 1 });\n }\n return { unique, first, vars };\n }\n\n iterate(\n limit: number,\n init: Readonly<Record<string, unknown>>,\n step: (vars: Readonly<Record<string, ChainImpl>>) => Readonly<Record<string, unknown>>,\n result: (vars: Readonly<Record<string, ChainImpl>>) => unknown,\n opts?: { readonly until?: (vars: Readonly<Record<string, ChainImpl>>) => unknown },\n ): ChainImpl {\n const { unique, first, vars } = this.loopNames(init);\n const next = stepExprs(step(vars), unique, this.#s.addr);\n const until = opts?.until === undefined ? undefined : toExpr(opts.until(vars), this.#s.addr);\n return new ChainImpl({ ...this.#s, expr: iterateExpr(limit, first, next, toExpr(result(vars), this.#s.addr), until) });\n }\n\n #axis(a: Axis, body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n const { name, start } = this.#bound();\n // Inside the axis, the focus is the target, so the address of the body starts empty.\n const inTarget = new ChainImpl({ ...start.#s, addr: [] });\n const inner = body(inTarget);\n const axis: Axis = opts?.where === undefined ? a : { t: \"where\", axis: a, test: opts.where(inTarget).program };\n // The moves before the axis are its address: parent().children(f) gives f at each child of the parent.\n return new ListChainImpl({ ...this.#s, expr: let_({ [name]: this.#s.expr }, each(axis, inner.program, this.#s.addr)) });\n }\n others(body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"others\" }, body, opts);\n }\n neighbors(n: 4 | 8, body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"neighbors\", n }, body, opts);\n }\n each(body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"all\" }, body, opts);\n }\n children(body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"children\" }, body, opts);\n }\n ancestors(body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"ancestors\" }, body, opts);\n }\n descendants(body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"descendants\" }, body, opts);\n }\n siblings(body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"siblings\" }, body, opts);\n }\n window(from: number, to: number, body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"window\", from, to }, body, opts);\n }\n table(name: string, body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"table\", name }, body, opts);\n }\n successors(body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"successors\" }, body, opts);\n }\n predecessors(body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"predecessors\" }, body, opts);\n }\n reachable(body: (c: ChainImpl) => { readonly program: Expr }, opts?: { readonly where?: (c: ChainImpl) => { readonly program: Expr } }): ListChainImpl {\n return this.#axis({ t: \"reachable\" }, body, opts);\n }\n}\n\n/** This function gives the options of an evaluation of a chain or a list chain at the origin `k`. */\nfunction evalOptions(s: State, k: string): EvalOptions {\n const { env } = s;\n return {\n space: env.space,\n origin: k,\n domains: env.domains,\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(env.options.fns === undefined ? {} : { fns: env.options.fns }),\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(env.options.extensions === undefined ? {} : { extensions: env.options.extensions }),\n };\n}\n\nclass ListChainImpl {\n readonly kind = \"vex.list-chain\" as const;\n readonly #s: State;\n constructor(s: State) {\n this.#s = s;\n }\n get program(): Expr {\n return this.#s.expr;\n }\n fold(\n init: Readonly<Record<string, unknown>>,\n step: (vars: Readonly<Record<string, ChainImpl>>, item: ChainImpl) => Readonly<Record<string, unknown>>,\n result: (vars: Readonly<Record<string, ChainImpl>>) => unknown,\n ): ChainImpl {\n // The list of an axis is a let of the start value around the axis. The fold keeps the let, and the body of the\n // axis is the item of each step.\n const { bind, body: loop } = this.#s.expr as ExprOf<\"let\"> & { readonly body: ExprOf<\"each\"> };\n const names = new ChainImpl({ ...this.#s, expr: lit(null) }).loopNames(init);\n const item = new ChainImpl({ ...this.#s, expr: loop.body, addr: [] });\n const next = stepExprs(step(names.vars, item), names.unique, []);\n return new ChainImpl({ ...this.#s, expr: let_(bind, foldExpr(loop.axis, names.first, next, toExpr(result(names.vars), this.#s.addr), loop.at)) });\n }\n\n #op(op: string, extra: readonly Expr[], opts?: ListOpts & { readonly domain?: string }): ChainImpl {\n const options = { ...(opts?.strict === true ? { strict: true } : {}), ...(opts?.domain === undefined ? {} : { domain: opts.domain }) };\n const args = Object.keys(options).length > 0 ? [...extra, lit(options)] : extra;\n return new ChainImpl({ ...this.#s, expr: app(op, this.#s.expr, ...args) });\n }\n count(opts?: ListOpts): ChainImpl {\n return this.#op(\"count\", [], opts);\n }\n sum(opts?: ListOpts): ChainImpl {\n return this.#op(\"sum\", [], opts);\n }\n mean(opts?: ListOpts): ChainImpl {\n return this.#op(\"mean\", [], opts);\n }\n min(opts?: ListOpts): ChainImpl {\n return this.#op(\"min\", [], opts);\n }\n max(opts?: ListOpts): ChainImpl {\n return this.#op(\"max\", [], opts);\n }\n any(opts?: ListOpts): ChainImpl {\n return this.#op(\"any\", [], opts);\n }\n all(opts?: ListOpts): ChainImpl {\n return this.#op(\"all\", [], opts);\n }\n none(opts?: ListOpts): ChainImpl {\n return this.#op(\"none\", [], opts);\n }\n values(opts?: ListOpts): ChainImpl {\n return this.#op(\"values\", [], opts);\n }\n keys(opts?: ListOpts): ChainImpl {\n return this.#op(\"keys\", [], opts);\n }\n errors(): ChainImpl {\n return this.#op(\"errors\", []);\n }\n first(opts?: ListOpts): ChainImpl {\n return this.#op(\"first\", [], opts);\n }\n reduce(op: string, opts?: ListOpts & { readonly domain?: string }): ChainImpl {\n return this.#op(\"reduce\", [lit(op)], opts);\n }\n result(k: string): Result<unknown> {\n return evaluate(this.#s.expr, evalOptions(this.#s, k));\n }\n at(k: string): Optional<unknown> {\n return toOptional(this.result(k));\n }\n explain(k: string): Trace {\n return explain(this.#s.expr, evalOptions(this.#s, k));\n }\n}\n\nclass RootImpl {\n readonly #env: Env;\n constructor(env: Env) {\n this.#env = env;\n }\n get space(): Space {\n return this.#env.space;\n }\n #chain(expr: Expr): ChainImpl {\n return new ChainImpl({ env: this.#env, expr, addr: [], depth: 0 });\n }\n from(field: string): ChainImpl {\n return this.#chain(ref(toPath(field)));\n }\n start(value: unknown): ChainImpl {\n return this.#chain(toExpr(value, []));\n }\n of(k: string, field: string): Arg<unknown> {\n return argToken(ref(toPath(field), [keyMove(k)]));\n }\n field(path: string): Arg<unknown> {\n return argToken(ref(toPath(path)));\n }\n lit(value: unknown): Arg<unknown> {\n return argToken(lit(value));\n }\n ofPath(k: string, path: string): Arg<unknown> {\n return argToken(ref(toPath(path), [keyMove(k)]));\n }\n ext(kind: string, data: unknown = null): Arg<unknown> {\n return argToken(ext(kind, data));\n }\n sheet(): SheetImpl {\n return new SheetImpl(this.#env, new Map());\n }\n rec(fields: Readonly<Record<string, unknown>>): Arg<unknown> {\n const out: Record<string, Expr> = {};\n for (const [n, a] of Object.entries(fields)) out[n] = toExpr(a, []);\n return argToken(rec(out));\n }\n}\n\nclass SheetRootImpl extends RootImpl {\n cell(column: string, at?: string | readonly FixedMove[]): Arg<unknown> {\n return argToken(cellRef(column, typeof at === \"string\" ? [keyMove(at)] : at));\n }\n}\n\nclass SheetImpl {\n readonly #env: Env;\n readonly #columns: ReadonlyMap<string, Expr>;\n readonly #cells: CellFormulas;\n constructor(env: Env, columns: ReadonlyMap<string, Expr>, cells: CellFormulas = new Map()) {\n this.#env = env;\n this.#columns = columns;\n this.#cells = cells;\n }\n get columns(): Readonly<Record<string, Expr>> {\n return Object.freeze(Object.fromEntries(this.#columns));\n }\n get cellFormulas(): Readonly<Record<string, Readonly<Record<string, Expr>>>> {\n return Object.freeze(Object.fromEntries([...this.#cells].map(([c, keys]) => [c, Object.freeze(Object.fromEntries(keys))])));\n }\n declare(): SheetImpl {\n return this;\n }\n column(name: string, formula: (r: SheetRootImpl) => { readonly program: Expr }): SheetImpl {\n const program = formula(new SheetRootImpl(this.#env)).program;\n return new SheetImpl(this.#env, new Map([...this.#columns, [name, program]]), this.#cells);\n }\n cellFormula(k: string, column: string, formula: (r: SheetRootImpl) => { readonly program: Expr }): SheetImpl {\n const program = formula(new SheetRootImpl(this.#env)).program;\n const keys = new Map([...(this.#cells.get(column) ?? []), [k, program]]);\n return new SheetImpl(this.#env, this.#columns, new Map([...this.#cells, [column, keys]]));\n }\n #run(): SheetRun {\n const { space: s, domains, options } = this.#env;\n return new SheetRun(this.#columns, {\n space: s,\n domains,\n cells: this.#cells,\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(options.fns === undefined ? {} : { fns: options.fns }),\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(options.extensions === undefined ? {} : { extensions: options.extensions }),\n });\n }\n result(k: string, column: string): Result<unknown> {\n const run = this.#run();\n run.warm(column, k);\n return run.cell(column, k);\n }\n at(k: string, column: string): Optional<unknown> {\n return toOptional(this.result(k, column));\n }\n explain(k: string, column: string): Trace {\n const run = this.#run();\n run.warm(column, k);\n return run.explain(column, k);\n }\n table(): readonly SheetRow<string, Record<string, unknown>>[] {\n const run = this.#run();\n // The table reads each cell, so a fill evaluates them in the order of their reads first (SHEET.FILL).\n run.fill();\n const names = [...this.#columns.keys()];\n return this.#env.space.keys.map((key) => ({ key, cells: Object.fromEntries(names.map((c) => [c, run.cell(c, key)])) }));\n }\n}\n\n/**\n * This function gives the entry point of the builder for a list of domains. The interpreter finds the op of a\n * value in the first domain that accepts the value.\n */\nexport function vex<const Dms extends readonly AnyDomain[]>(\n ...domains: Dms\n): VexEntry<Dms> & { withOptions<const F extends FnTable = NoFns>(options: VexOptions<F>): VexEntry<Dms, F> } {\n const make = <F extends FnTable>(options: VexOptions<F>): VexEntry<Dms, F> => ({\n domains,\n over: <K extends string, O>(s: Space<K, O>): Root<{ readonly domains: Dms; readonly keys: K; readonly record: Merge<O>; readonly fns: F }> =>\n new RootImpl({ space: s, domains, options: runtimeOptions(options) }) as unknown as Root<{\n readonly domains: Dms;\n readonly keys: K;\n readonly record: Merge<O>;\n readonly fns: F;\n }>,\n });\n return { ...make<NoFns>({}), withOptions: make };\n}\n\n/** The type of a domain value, from the domain object. */\nexport type ValueOfDomain<Dm> = DomainValue<Dm>;\n\n/** An op specification type, for domain authors. */\nexport type { OpSpec };\n"],"mappings":";AAaA,MAAM,OAAwB,OAAO,OAAO,EAAE,KAAK,OAAO,CAAC;;AAG3D,MAAa,QAAW,WAA2B;CAAE,KAAK;CAAQ;AAAM;;AAGxE,MAAa,aAAqC;;AAGlD,MAAa,MAAS,WAAyB;CAAE,IAAI;CAAM;AAAM;;AAGjE,MAAa,QAAmB,WAAgC;CAAE,IAAI;CAAO;AAAM;;AAGnF,MAAa,UAAa,MAAqE,EAAE,QAAQ;;AAGzG,MAAa,UAAa,MAAkD,EAAE,QAAQ;;AAGtF,MAAa,cAAiB,MAA+B,EAAE,KAAK,KAAK,EAAE,KAAK,IAAI,KAAK;;AAGzF,MAAa,SAAe,GAAgB,aAAwB,EAAE,QAAQ,SAAS,EAAE,QAAQ;;AAGjG,MAAa,aAAmB,GAAc,MAAmC,EAAE,KAAK,GAAG,EAAE,EAAE,KAAK,CAAC,IAAI;;AAGzG,MAAa,eAAqB,GAAc,MAA2C,EAAE,KAAK,EAAE,EAAE,KAAK,IAAI;;;ACX/G,MAAM,UAAkD;CACtD,eAAe;CACf,cAAc;CACd,iBAAiB;CACjB,aAAa;CACb,WAAW;CACX,WAAW;CACX,YAAY;CACZ,YAAY;CACZ,iBAAiB;CACjB,OAAO;CACP,gBAAgB;CAChB,iBAAiB;CACjB,kBAAkB;CAClB,cAAc;C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AAS,KAAK,CAAC;EACtC,OAAO,KAAK,KAAK,MAAM,KAAK,KAAK,SAAS;GAAE;GAAK,OAAO,OAAO,YAAY,MAAM,KAAK,MAAM,CAAC,GAAG,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC;EAAE,EAAE;CACxH;AACF;;;;;AAMA,SAAgB,IACd,GAAG,SACyG;CAC5G,MAAM,QAA2B,aAA8C;EAC7E;EACA,OAA4B,MAC1B,IAAI,SAAS;GAAE,OAAO;GAAG;GAAS,SAAS,eAAe,OAAO;EAAE,CAAC;CAMxE;CACA,OAAO;EAAE,GAAG,KAAY,CAAC,CAAC;EAAG,aAAa;CAAK;AACjD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["spaces","keyMove","indexMove","offsetMove","otherMove","originMove","parentMove","fnExpr","callExpr","iterateExpr","foldExpr","cellRef"],"sources":["../src/result.ts","../src/errors.ts","../src/ir.ts","../src/space.ts","../src/domain.ts","../src/list.ts","../src/evaluate.ts","../src/deps.ts","../src/json.ts","../src/traversal.ts","../src/sheet.ts","../src/builder.ts"],"sourcesContent":["import type { Optional as FamilyOptional } from \"@mark1russell7/optional\";\nimport type { VexError } from \"./errors.ts\";\n\n/**\n * A value that is there, or not there. This is the public result of a Vex program. It is the Optional of the\n * family (`@mark1russell7/optional`), so render and Vex give and take the same values. The import is a type import\n * only: the build copies the type into the declarations, so the package has no runtime dependency.\n */\nexport type Optional<T> = FamilyOptional<T>;\n\n/** A value, or the error that tells why there is no value. The interpreter uses this type. */\nexport type Result<T> = { readonly ok: true; readonly value: T } | { readonly ok: false; readonly error: VexError };\n\nconst NONE: Optional<never> = Object.freeze({ tag: \"none\" });\n\n/** This function makes an `Optional` that holds `value`. */\nexport const some = <T>(value: T): Optional<T> => ({ tag: \"some\", value });\n\n/** This function gives the shared empty `Optional`. */\nexport const none = <T = never>(): Optional<T> => NONE;\n\n/** This function makes a successful `Result`. */\nexport const ok = <T>(value: T): Result<T> => ({ ok: true, value });\n\n/** This function makes a failed `Result`. */\nexport const fail = <T = never>(error: VexError): Result<T> => ({ ok: false, error });\n\n/** This function tells if an `Optional` holds a value. */\nexport const isSome = <T>(o: Optional<T>): o is { readonly tag: \"some\"; readonly value: T } => o.tag === \"some\";\n\n/** This function tells if an `Optional` is empty. */\nexport const isNone = <T>(o: Optional<T>): o is { readonly tag: \"none\" } => o.tag === \"none\";\n\n/** This function changes a `Result` into an `Optional`. The error is lost. */\nexport const toOptional = <T>(r: Result<T>): Optional<T> => (r.ok ? some(r.value) : none());\n\n/** This function gives the value of an `Optional`, or `fallback` if it is empty. */\nexport const getOr = <T, U>(o: Optional<T>, fallback: U): T | U => (o.tag === \"some\" ? o.value : fallback);\n\n/** This function applies `f` to the value of a `Result`. An error stays the same. */\nexport const mapResult = <T, U>(r: Result<T>, f: (value: T) => U): Result<U> => (r.ok ? ok(f(r.value)) : r);\n\n/** This function applies `f` to the value of a `Result`, and `f` gives a `Result`. An error stays the same. */\nexport const chainResult = <T, U>(r: Result<T>, f: (value: T) => Result<U>): Result<U> => (r.ok ? f(r.value) : r);\n","/**\n * The error codes of Vex. The names come from the spreadsheet error values, because a Vex program is a\n * spreadsheet formula over records.\n */\nexport type ErrorCode = \"#REF!\" | \"#N/A\" | \"#VALUE!\" | \"#NAME?\" | \"#NUM!\" | \"#CALC!\" | \"#ARGS\" | \"#CYCLE!\" | \"#DEPTH!\";\n\n/** The cause of an error, in more detail than the code. */\nexport type ErrorKind =\n | \"unknown-key\"\n | \"not-a-pair\"\n | \"out-of-bounds\"\n | \"no-offset\"\n | \"no-grid\"\n | \"no-tree\"\n | \"no-table\"\n | \"no-graph\"\n | \"missing-field\"\n | \"empty\"\n | \"not-instance\"\n | \"kind-mismatch\"\n | \"unknown-op\"\n | \"unbound\"\n | \"not-finite\"\n | \"invalid-value\"\n | \"threw\"\n | \"undefined-result\"\n | \"args\"\n | \"cycle\"\n | \"depth\"\n | \"bad-expression\"\n | \"limit\";\n\nconst CODE_OF: Readonly<Record<ErrorKind, ErrorCode>> = {\n \"unknown-key\": \"#REF!\",\n \"not-a-pair\": \"#REF!\",\n \"out-of-bounds\": \"#REF!\",\n \"no-offset\": \"#REF!\",\n \"no-grid\": \"#REF!\",\n \"no-tree\": \"#REF!\",\n \"no-table\": \"#REF!\",\n \"no-graph\": \"#REF!\",\n \"missing-field\": \"#N/A\",\n empty: \"#N/A\",\n \"not-instance\": \"#VALUE!\",\n \"kind-mismatch\": \"#VALUE!\",\n \"bad-expression\": \"#VALUE!\",\n \"unknown-op\": \"#NAME?\",\n unbound: \"#NAME?\",\n \"not-finite\": \"#NUM!\",\n \"invalid-value\": \"#NUM!\",\n limit: \"#NUM!\",\n threw: \"#CALC!\",\n \"undefined-result\": \"#CALC!\",\n args: \"#ARGS\",\n cycle: \"#CYCLE!\",\n depth: \"#DEPTH!\",\n};\n\n/**\n * This function tells if an exception is the report of the engine that the call stack is full. V8 and JavaScriptCore\n * throw a `RangeError`. SpiderMonkey throws an `InternalError` (\"too much recursion\").\n */\nexport function isStackOverflow(thrown: unknown): boolean {\n if (!(thrown instanceof Error)) return false;\n return (thrown instanceof RangeError && /call stack/i.test(thrown.message)) || (thrown.name === \"InternalError\" && /recursion/i.test(thrown.message));\n}\n\n/** This function tells if an error is `#DEPTH!`. `ifError` and the reductions that skip errors do not hide it (EVAL.DEPTH). */\nexport const isDepthError = (e: VexError): boolean => e.kind === \"depth\";\n\n/** A Vex error. It is a value: a program can catch it with `ifError`, except `#DEPTH!`. */\nexport interface VexError {\n /** The spreadsheet-style code, for example `#REF!`. */\n readonly code: ErrorCode;\n /** The cause in more detail. */\n readonly kind: ErrorKind;\n /** A sentence that tells what went wrong. */\n readonly message: string;\n /** The position of the failed node in the expression tree. The root is `[]`. */\n readonly path: readonly number[];\n /** The key where the evaluation started. */\n readonly origin?: string;\n /** The key where relative references read when the error occurred. */\n readonly focus?: string;\n /** The op name, for errors of an op. */\n readonly op?: string;\n /** The errors of the arguments, for the code `#ARGS`. */\n readonly causes?: readonly VexError[];\n /** The value that an op threw, for the kind `threw`. */\n readonly thrown?: unknown;\n}\n\n/** The details that a caller can give to `vexError`. */\nexport interface ErrorDetails {\n readonly path?: readonly number[];\n readonly origin?: string;\n readonly focus?: string;\n readonly op?: string;\n readonly causes?: readonly VexError[];\n readonly thrown?: unknown;\n}\n\n/** This function gives the code of an error kind. */\nexport const codeOf = (kind: ErrorKind): ErrorCode => CODE_OF[kind];\n\n/** This function makes a `VexError`. */\nexport function vexError(kind: ErrorKind, message: string, details: ErrorDetails = {}): VexError {\n return {\n code: CODE_OF[kind],\n kind,\n message,\n path: details.path ?? [],\n ...(details.origin === undefined ? {} : { origin: details.origin }),\n ...(details.focus === undefined ? {} : { focus: details.focus }),\n ...(details.op === undefined ? {} : { op: details.op }),\n ...(details.causes === undefined ? {} : { causes: details.causes }),\n ...(details.thrown === undefined ? {} : { thrown: details.thrown }),\n };\n}\n\n/** This function gives a short text for an error, for example `#REF! unknown-key: there is no key \"Z\"`. */\nexport const formatError = (e: VexError): string => `${e.code} ${e.kind}: ${e.message}`;\n","/**\n * The expression IR of Vex. It is plain JSON data. Its first three kinds (`lit`, `ref`, `app`) have the same\n * shape as the expressions of `render`.\n */\n\n/**\n * One move of an address. The moves of an address apply in order, from the focus of the evaluation. The key of `key`\n * and the position of `index` can be an expression, which evaluates before the moves (NAV.COMPUTED).\n */\nexport type Move =\n | { readonly t: \"key\"; readonly key: string | Expr }\n | { readonly t: \"index\"; readonly i: number | Expr }\n | { readonly t: \"other\" }\n | { readonly t: \"offset\"; readonly d: readonly number[] }\n | { readonly t: \"origin\" }\n | { readonly t: \"parent\" };\n\n/** A move with a fixed key or position: a move with no expression. */\nexport type FixedMove = Exclude<Move, { readonly t: \"key\" | \"index\" }> | { readonly t: \"key\"; readonly key: string } | { readonly t: \"index\"; readonly i: number };\n\n/** An address: a list of moves. The empty list is the focus. */\nexport type Addr = readonly Move[];\n\n/** An axis: the relation between a position and the targets that a body reads. */\nexport type Axis =\n | { readonly t: \"all\" }\n | { readonly t: \"others\" }\n | { readonly t: \"other\" }\n | { readonly t: \"neighbors\"; readonly n: 4 | 8 }\n | { readonly t: \"children\" }\n | { readonly t: \"ancestors\" }\n | { readonly t: \"descendants\" }\n | { readonly t: \"siblings\" }\n | { readonly t: \"window\"; readonly from: number; readonly to: number }\n | { readonly t: \"table\"; readonly name: string }\n | { readonly t: \"successors\" }\n | { readonly t: \"predecessors\" }\n | { readonly t: \"reachable\" }\n | { readonly t: \"list\"; readonly list: Expr }\n | { readonly t: \"reverse\"; readonly axis: Axis }\n | { readonly t: \"where\"; readonly axis: Axis; readonly test: Expr };\n\n/** A Vex expression. */\nexport type Expr =\n | { readonly tag: \"lit\"; readonly value: unknown }\n | { readonly tag: \"ref\"; readonly path: readonly string[]; readonly at?: Addr }\n | { readonly tag: \"app\"; readonly op: string; readonly args: readonly Expr[] }\n | { readonly tag: \"let\"; readonly bind: Readonly<Record<string, Expr>>; readonly body: Expr }\n | { readonly tag: \"var\"; readonly name: string }\n | { readonly tag: \"rec\"; readonly fields: Readonly<Record<string, Expr>> }\n | { readonly tag: \"each\"; readonly axis: Axis; readonly body: Expr; readonly at?: Addr }\n | { readonly tag: \"fold\"; readonly axis: Axis; readonly init: Names; readonly step: Names; readonly result: Expr; readonly at?: Addr }\n | { readonly tag: \"iterate\"; readonly limit: number; readonly init: Names; readonly step: Names; readonly until?: Expr; readonly result: Expr }\n | { readonly tag: \"fn\"; readonly params: readonly string[]; readonly body: Expr }\n | { readonly tag: \"call\"; readonly fn: string; readonly args: readonly Expr[] }\n | { readonly tag: \"ext\"; readonly kind: string; readonly data: unknown };\n\n/** The names of a loop and an expression for each (LOOP.NAMES). */\nexport type Names = Readonly<Record<string, Expr>>;\n\n/** The largest number of steps of `iterate` (ITERATE.LIMIT). */\nexport const MAX_ITERATIONS = 100_000;\n\n/** The tag of an expression kind. */\nexport type ExprTag = Expr[\"tag\"];\n\n/** An expression of one kind. */\nexport type ExprOf<T extends ExprTag> = Extract<Expr, { readonly tag: T }>;\n\n// ---------------------------------------------------------------- constructors\n\n/** This function makes a literal. */\nexport const lit = (value: unknown): ExprOf<\"lit\"> => ({ tag: \"lit\", value });\n\n/** This function splits a dotted path, for example `\"pos.x\"`, into its segments. */\nexport const toPath = (path: string | readonly string[]): readonly string[] =>\n typeof path === \"string\" ? path.split(\".\").filter((s) => s.length > 0) : path;\n\n/** This function makes a reference to a field path. With `at`, the reference reads at that address. */\nexport function ref(path: string | readonly string[], at?: Addr): ExprOf<\"ref\"> {\n const segments = toPath(path);\n return at === undefined || at.length === 0 ? { tag: \"ref\", path: segments } : { tag: \"ref\", path: segments, at };\n}\n\n/** This function makes the application of an op to arguments. For a method op, the first argument is the receiver. */\nexport const app = (op: string, ...args: readonly Expr[]): ExprOf<\"app\"> => ({ tag: \"app\", op, args });\n\n/** This function binds names to expressions for the body. */\nexport const let_ = (bind: Readonly<Record<string, Expr>>, body: Expr): ExprOf<\"let\"> => ({ tag: \"let\", bind, body });\n\n/** This function makes a reference to a bound name. */\nexport const v = (name: string): ExprOf<\"var\"> => ({ tag: \"var\", name });\n\n/** This function makes a record from field expressions. */\nexport const rec = (fields: Readonly<Record<string, Expr>>): ExprOf<\"rec\"> => ({ tag: \"rec\", fields });\n\n/**\n * This function evaluates `body` once for each target of `axis`. The result is a list. With `at`, the axis finds its\n * targets from the key of that address, not from the focus.\n */\nexport function each(axis: Axis, body: Expr, at?: Addr): ExprOf<\"each\"> {\n return at === undefined || at.length === 0 ? { tag: \"each\", axis, body } : { tag: \"each\", axis, body, at };\n}\n\n/**\n * This function makes a fold: a step at each target of `axis`, in order. `init` gives the names and their first\n * values, and `step` gives the next values. `result` gives the value from the last values (LOOP.NAMES, FOLD.ORDER).\n */\nexport function fold(axis: Axis, init: Names, step: Names, result: Expr, at?: Addr): ExprOf<\"fold\"> {\n return at === undefined || at.length === 0 ? { tag: \"fold\", axis, init, step, result } : { tag: \"fold\", axis, init, step, result, at };\n}\n\n/**\n * This function makes an iteration: up to `limit` steps. `init` gives the names and their first values, and `step`\n * gives the next values. A true `until` stops it, and `result` gives the value (ITERATE.LIMIT, ITERATE.UNTIL).\n */\nexport function iterate(limit: number, init: Names, step: Names, result: Expr, until?: Expr): ExprOf<\"iterate\"> {\n return until === undefined ? { tag: \"iterate\", limit, init, step, result } : { tag: \"iterate\", limit, init, step, until, result };\n}\n\n/**\n * This function makes a function (FN.BIND): the names of its parameters and its body. A function is only the value of\n * a binding of `let`. The body sees the names of the place of that `let`, so a function cannot call itself.\n */\nexport const fn = (params: readonly string[], body: Expr): ExprOf<\"fn\"> => ({ tag: \"fn\", params, body });\n\n/** This function makes a call of a bound function (FN.CALL). The body evaluates at the position of the call. */\nexport const call = (name: string, ...args: Expr[]): ExprOf<\"call\"> => ({ tag: \"call\", fn: name, args });\n\n/** This function makes an expression of an extension kind. */\nexport const ext = (kind: string, data: unknown): ExprOf<\"ext\"> => ({ tag: \"ext\", kind, data });\n\n// ---------------------------------------------------------------- moves and axes\n\n/** The move to an absolute key. The key can be an expression that gives a text. */\nexport function key(k: string): FixedMove;\nexport function key(k: string | Expr): Move;\nexport function key(k: string | Expr): Move {\n return { t: \"key\", key: k };\n}\n/** The move to a position in the key order. The position can be an expression that gives a number. */\nexport function index(i: number): FixedMove;\nexport function index(i: number | Expr): Move;\nexport function index(i: number | Expr): Move {\n return { t: \"index\", i };\n}\n\n/** This function gives the expression of a move with a computed key or position, or `undefined`. */\nexport function moveExpr(m: Move): Expr | undefined {\n if (m.t === \"key\") return typeof m.key === \"string\" ? undefined : m.key;\n return m.t === \"index\" && typeof m.i !== \"number\" ? m.i : undefined;\n}\n\n/** This function gives the expressions of the computed moves of an address, in the order of the moves. */\nexport const addrExprs = (at: Addr | undefined): readonly Expr[] => (at ?? []).flatMap((m) => moveExpr(m) ?? []);\n\n/** This function tells if each move of an address is fixed. */\nexport const isFixedAddr = (at: Addr | undefined): at is readonly FixedMove[] => addrExprs(at).length === 0;\n/** The move to the other key of a space with two keys. */\nexport const other: FixedMove = Object.freeze({ t: \"other\" });\n/** The relative move in an array (one number) or a grid (two numbers). */\nexport const offset = (...d: readonly number[]): FixedMove => ({ t: \"offset\", d });\n/** The move back to the origin of the evaluation. */\nexport const origin: FixedMove = Object.freeze({ t: \"origin\" });\n/** The move to the parent of the focus in a tree space. */\nexport const parent: FixedMove = Object.freeze({ t: \"parent\" });\n\n/** The axes. */\nexport const axes = {\n /** Each key of the space. */\n all: Object.freeze({ t: \"all\" }) as Axis,\n /** Each key except the focus. */\n others: Object.freeze({ t: \"others\" }) as Axis,\n /** The other key of a pair. */\n other: Object.freeze({ t: \"other\" }) as Axis,\n /** The neighbors of the focus in a grid. */\n neighbors: (n: 4 | 8 = 8): Axis => ({ t: \"neighbors\", n }),\n /** The children of the focus in a tree, in key order. */\n children: Object.freeze({ t: \"children\" }) as Axis,\n /** The ancestors of the focus in a tree: the parent first, the root last. */\n ancestors: Object.freeze({ t: \"ancestors\" }) as Axis,\n /** The descendants of the focus in a tree, depth first, each parent before its children. */\n descendants: Object.freeze({ t: \"descendants\" }) as Axis,\n /** The other children of the parent of the focus. For a root, the other roots. */\n siblings: Object.freeze({ t: \"siblings\" }) as Axis,\n /**\n * 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\n * a tree space, the offsets go among the siblings. An offset outside the space has no target.\n */\n window: (from: number, to: number): Axis => ({ t: \"window\", from, to }),\n /**\n * Each key of the table `name` of the evaluation, in key order. The body evaluates in the space of that table, and\n * there the origin is the target.\n */\n table: (name: string): Axis => ({ t: \"table\", name }),\n /** The keys at the ends of the edges from the focus, in a graph space. In a tree space, the children. */\n successors: Object.freeze({ t: \"successors\" }) as Axis,\n /** The keys with an edge to the focus, in key order. In a tree space, the parent. */\n predecessors: Object.freeze({ t: \"predecessors\" }) as Axis,\n /** Each key that a path of edges reaches from the focus, in breadth-first order, without the focus. */\n reachable: Object.freeze({ t: \"reachable\" }) as Axis,\n /**\n * The targets of `axis` in the reverse order (AXIS.REVERSE). The inner axis is a base axis: not `where`, `reverse` or\n * `table`. A test goes outside: `where(reverse(axis), test)`.\n */\n reverse: (axis: Axis): Axis => ({ t: \"reverse\", axis }),\n /**\n * The keys of the items of the list that `list` gives, in the order of the list (AXIS.LIST). The expression evaluates\n * before the targets. An error item gives an error item for its target.\n */\n list: (list: Expr): Axis => ({ t: \"list\", list }),\n /** The targets of `axis` where `test` gives `true`. */\n where: (axis: Axis, test: Expr): Axis => ({ t: \"where\", axis, test }),\n} as const;\n\n// ---------------------------------------------------------------- validation\n\nconst isObject = (u: unknown): u is Readonly<Record<string, unknown>> => typeof u === \"object\" && u !== null;\n\nconst isStringArray = (u: unknown): u is readonly string[] => Array.isArray(u) && u.every((s) => typeof s === \"string\");\n\n/** This function tells if a value is a valid move. The expression of a computed move must be valid too. */\nexport function isMove(u: unknown): u is Move {\n const exprs = moveParts(u);\n return exprs !== undefined && exprs.every(isExpr);\n}\n\n/**\n * A test of the numbers of a move or of a window. The JSON form needs whole numbers. An expression in code can have any\n * number, and a number that is not whole has a meaning at run time (EVAL.SHAPE).\n */\ntype NumberTest = (x: unknown) => boolean;\n\nconst anyNumber: NumberTest = (x) => typeof x === \"number\";\n\n/** This function checks the fixed parts of a move. It gives the expressions of the move, or `undefined` for a bad move. */\nfunction moveParts(u: unknown, isNumber: NumberTest = Number.isInteger): readonly unknown[] | undefined {\n if (!isObject(u)) return undefined;\n switch (u[\"t\"]) {\n case \"key\":\n return typeof u[\"key\"] === \"string\" ? [] : isObject(u[\"key\"]) ? [u[\"key\"]] : undefined;\n case \"index\":\n return isNumber(u[\"i\"]) ? [] : isObject(u[\"i\"]) ? [u[\"i\"]] : undefined;\n case \"offset\":\n return Array.isArray(u[\"d\"]) && u[\"d\"].every((n) => isNumber(n)) ? [] : undefined;\n case \"other\":\n case \"origin\":\n case \"parent\":\n return [];\n default:\n return undefined;\n }\n}\n\n/** This function tells if a value is a valid axis. It checks the tests of `where` too. */\nexport function isAxis(u: unknown): u is Axis {\n return badPart([{ axis: true, u }], true) === undefined;\n}\n\n/** This function tells if a value is a valid expression. It checks the whole tree. */\nexport function isExpr(u: unknown): u is Expr {\n return badPart([{ axis: false, u }], true) === undefined;\n}\n\n/** The tags of the expressions of this version of Vex. */\nconst TAGS: ReadonlySet<unknown> = new Set([\"lit\", \"ref\", \"app\", \"let\", \"var\", \"rec\", \"each\", \"fold\", \"iterate\", \"fn\", \"call\", \"ext\"]);\n\n/**\n * This function gives the reason that a value is not a valid expression, or `undefined` for a valid expression\n * (EVAL.SHAPE). An expression from a newer version of Vex can have a tag that this version does not know. Unlike\n * `isExpr`, it accepts a number that is not whole in a move or in a window, because it has a meaning at run time.\n */\nexport function shapeError(u: unknown): string | undefined {\n const bad = badPart([{ axis: false, u }], false);\n if (bad === undefined) return undefined;\n const tag = isObject(bad.u) ? bad.u[\"tag\"] : undefined;\n if (bad.axis) return \"the expression has an axis that is not valid\";\n if (typeof tag === \"string\" && !TAGS.has(tag)) return `the expression has a node with the tag \"${tag}\", and this version of Vex does not know it`;\n if (tag === \"fn\") return \"the expression has a function outside the bindings of a let, or a function with parameters that are not distinct names\";\n return typeof tag === \"string\" ? `the expression has a node \"${tag}\" with parts that are not valid` : \"the expression has a part that is not a node\";\n}\n\n/**\n * This function checks the names of a loop: `init` and `step` are records, and each name of `step` is a name of `init`.\n * It gives the expressions of `init`, of `step` and `result`, or `undefined` (LOOP.NAMES).\n */\nfunction loopParts(u: Readonly<Record<string, unknown>>): readonly unknown[] | undefined {\n const { init, step } = u;\n if (!isObject(init) || Array.isArray(init) || !isObject(step) || Array.isArray(step)) return undefined;\n if (!Object.keys(step).every((n) => Object.hasOwn(init, n))) return undefined;\n return [...Object.values(init), ...Object.values(step), u[\"result\"]];\n}\n\n/** This function checks the fixed parts of an address. It gives the expressions of its moves, or `undefined`. */\nfunction addrParts(u: unknown, isNumber: NumberTest): readonly unknown[] | undefined {\n if (u === undefined) return [];\n if (!Array.isArray(u)) return undefined;\n const out: unknown[] = [];\n for (const m of u) {\n const parts = moveParts(m, isNumber);\n if (parts === undefined) return undefined;\n out.push(...parts);\n }\n return out;\n}\n\n/**\n * This function checks a tree of expressions and axes, and it gives the first part that is not valid. It uses a stack,\n * not recursion, so the input can be deep. For example, a deep JSON file from a stranger does not need a deep call\n * stack (EVAL.NESTING). With `whole`, the numbers of the moves and of the windows must be whole, as the JSON form needs.\n */\nfunction badPart(todo: { readonly axis: boolean; readonly u: unknown }[], whole: boolean): { readonly axis: boolean; readonly u: unknown } | undefined {\n const moveNumber = whole ? Number.isInteger : anyNumber;\n const windowNumber = whole ? Number.isSafeInteger : anyNumber;\n const push = (axis: boolean, values: readonly unknown[]): void => {\n for (const u of values) todo.push({ axis, u });\n };\n for (let item = todo.pop(); item !== undefined; item = todo.pop()) {\n const { u } = item;\n if (!isObject(u)) return item;\n if (item.axis) {\n const t = u[\"t\"];\n if (t === \"neighbors\") {\n if (u[\"n\"] !== 4 && u[\"n\"] !== 8) return item;\n } else if (t === \"window\") {\n if (!windowNumber(u[\"from\"]) || !windowNumber(u[\"to\"])) return item;\n } else if (t === \"table\") {\n if (typeof u[\"name\"] !== \"string\") return item;\n } else if (t === \"where\") {\n push(true, [u[\"axis\"]]);\n push(false, [u[\"test\"]]);\n } else if (t === \"list\") {\n push(false, [u[\"list\"]]);\n } else if (t === \"reverse\") {\n // The inner axis of reverse is a base axis.\n const inner = u[\"axis\"];\n if (!isObject(inner) || [\"where\", \"reverse\", \"table\"].includes(inner[\"t\"] as string)) return item;\n push(true, [inner]);\n } else if (![\"all\", \"others\", \"other\", \"children\", \"ancestors\", \"descendants\", \"siblings\", \"successors\", \"predecessors\", \"reachable\"].includes(t as string)) {\n return item;\n }\n continue;\n }\n switch (u[\"tag\"]) {\n case \"lit\":\n if (!(\"value\" in u)) return item;\n break;\n case \"ref\": {\n const at = addrParts(u[\"at\"], moveNumber);\n if (!isStringArray(u[\"path\"]) || at === undefined) return item;\n push(false, at);\n break;\n }\n case \"app\":\n if (typeof u[\"op\"] !== \"string\" || !Array.isArray(u[\"args\"])) return item;\n push(false, u[\"args\"]);\n break;\n case \"let\": {\n if (!isObject(u[\"bind\"]) || Array.isArray(u[\"bind\"])) return item;\n // A binding can be a function (FN.BIND): its parameters are distinct names, and its body is an expression.\n const values = Object.values(u[\"bind\"]).map((b) => (isObject(b) && b[\"tag\"] === \"fn\" && isStringArray(b[\"params\"]) && new Set(b[\"params\"]).size === b[\"params\"].length ? b[\"body\"] : b));\n push(false, [...values, u[\"body\"]]);\n break;\n }\n case \"call\":\n if (typeof u[\"fn\"] !== \"string\" || !Array.isArray(u[\"args\"])) return item;\n push(false, u[\"args\"]);\n break;\n case \"var\":\n if (typeof u[\"name\"] !== \"string\") return item;\n break;\n case \"rec\":\n if (!isObject(u[\"fields\"]) || Array.isArray(u[\"fields\"])) return item;\n push(false, Object.values(u[\"fields\"]));\n break;\n case \"each\": {\n const at = addrParts(u[\"at\"], moveNumber);\n if (at === undefined) return item;\n push(true, [u[\"axis\"]]);\n push(false, [u[\"body\"], ...at]);\n break;\n }\n case \"fold\": {\n const at = addrParts(u[\"at\"], moveNumber);\n const names = loopParts(u);\n if (at === undefined || names === undefined) return item;\n push(true, [u[\"axis\"]]);\n push(false, [...names, ...at]);\n break;\n }\n case \"iterate\": {\n const limit = u[\"limit\"];\n const names = loopParts(u);\n if (typeof limit !== \"number\" || !Number.isInteger(limit) || limit < 0 || limit > MAX_ITERATIONS || names === undefined) return item;\n push(false, [...names, ...(u[\"until\"] === undefined ? [] : [u[\"until\"]])]);\n break;\n }\n case \"ext\":\n if (typeof u[\"kind\"] !== \"string\" || !(\"data\" in u)) return item;\n break;\n default:\n return item;\n }\n }\n return undefined;\n}\n\n/**\n * This function gives the child expressions of an expression, in the order of their child index. The expressions of\n * the computed moves of an address come last. They evaluate at the position of their node, also for an axis.\n */\nexport function children(e: Expr): readonly Expr[] {\n switch (e.tag) {\n case \"app\":\n case \"call\":\n return e.args;\n case \"fn\":\n return [e.body];\n case \"let\":\n return [...Object.values(e.bind), e.body];\n case \"rec\":\n return Object.values(e.fields);\n case \"each\":\n return [e.body, ...axisExprs(e.axis), ...addrExprs(e.at)];\n case \"fold\":\n return [...Object.values(e.init), ...Object.values(e.step), ...axisExprs(e.axis), ...addrExprs(e.at), e.result];\n case \"iterate\":\n return [...Object.values(e.init), ...Object.values(e.step), ...(e.until === undefined ? [] : [e.until]), e.result];\n case \"ref\":\n return addrExprs(e.at);\n case \"lit\":\n case \"var\":\n case \"ext\":\n return [];\n }\n}\n\n/**\n * This function gives the expressions of an axis, in the order of their child indexes. The expression of the axis\n * `list` comes first, and then the tests of the `where` axes from the inside out. It uses a loop, not recursion.\n */\nexport function axisExprs(a: Axis): readonly Expr[] {\n const out: Expr[] = [];\n for (let x = a; x.t === \"where\"; x = x.axis) out.unshift(x.test);\n const list = listOf(a);\n return list === undefined ? out : [list, ...out];\n}\n\n/** This function gives the expression of the axis `list` inside an axis, through `where` and `reverse`, if it has one. */\nexport function listOf(a: Axis): Expr | undefined {\n let x = a;\n while (x.t === \"where\") x = x.axis;\n const base = x.t === \"reverse\" ? x.axis : x;\n return base.t === \"list\" ? base.list : undefined;\n}\n","import { vexError } from \"./errors.ts\";\nimport { moveExpr, type Addr, type Axis, type FixedMove } from \"./ir.ts\";\nimport { fail, ok, type Result } from \"./result.ts\";\n\n/** The kind of a space. The kind sets which moves and axes are valid. */\nexport type SpaceKind = \"record\" | \"array\" | \"grid\" | \"tree\" | \"graph\";\n\n/**\n * A space: an immutable collection of records with keys. A Vex program evaluates at one key of a space.\n * Nothing changes a space after it is made.\n */\nexport interface Space<K extends string = string, O = unknown> {\n readonly kind: SpaceKind;\n /** The keys, in their order. */\n readonly keys: readonly K[];\n /**\n * The record of each key, in the order of `keys` (SPACE.RECORDS). A compiler reads a record by its index with it.\n * A space without it gives each record with `get` only.\n */\n readonly records?: readonly (O | undefined)[];\n /** This function tells if the space has the key `k`. */\n has(k: string): k is K;\n /** This function gives the record at the key `k`, or `undefined`. */\n get(k: string): O | undefined;\n /** The position of each key, for array and grid spaces. An array key has one number, a grid key has two. */\n coords(k: string): readonly number[] | undefined;\n /** The key at a position, or `undefined`. */\n keyAt(coords: readonly number[]): K | undefined;\n /** The parent of the key `k` in a tree space, or `undefined` for a root. Other spaces do not have it. */\n parentOf?(k: string): K | undefined;\n /** The children of the key `k` in a tree space, in key order. Other spaces do not have it. */\n childrenOf?(k: string): readonly K[];\n /** The keys at the ends of the edges from `k`, in a graph space or a tree space. Other spaces do not have it. */\n successorsOf?(k: string): readonly K[];\n /** The keys with an edge to `k`, in key order, in a graph space or a tree space. Other spaces do not have it. */\n predecessorsOf?(k: string): readonly K[];\n}\n\n/** The key type of a grid space. */\nexport type GridKey = `${number},${number}`;\n\n/** The key type of an array space. */\nexport type ArrayKey = `${number}`;\n\nclass RecordSpace<K extends string, O> implements Space<K, O> {\n readonly kind: SpaceKind = \"record\";\n readonly keys: readonly K[];\n readonly records: readonly O[];\n readonly #records: ReadonlyMap<string, O>;\n\n constructor(records: Readonly<Record<K, O>>) {\n const entries = Object.entries(records) as [K, O][];\n this.keys = Object.freeze(entries.map(([k]) => k));\n this.records = Object.freeze(entries.map(([, o]) => o));\n this.#records = new Map(entries);\n }\n\n has(k: string): k is K {\n return this.#records.has(k);\n }\n get(k: string): O | undefined {\n return this.#records.get(k);\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n coords(): readonly number[] | undefined {\n return undefined;\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n keyAt(): K | undefined {\n return undefined;\n }\n}\n\nclass ArraySpace<O> implements Space<ArrayKey, O> {\n readonly kind: SpaceKind = \"array\";\n readonly keys: readonly ArrayKey[];\n readonly records: readonly O[];\n\n constructor(items: readonly O[]) {\n this.keys = Object.freeze(Array.from(items, (_item, i): ArrayKey => `${i}`));\n this.records = Object.freeze(Array.from(items));\n }\n\n // The key at the position i is the text of i, so the position of a key finds it. A text that is not a key of the\n // space, for example \"01\" or \"1.0\", has no key at its position.\n has(k: string): k is ArrayKey {\n return this.keys[Number(k)] === k;\n }\n get(k: string): O | undefined {\n return this.has(k) ? this.records[Number(k)] : undefined;\n }\n coords(k: string): readonly number[] | undefined {\n return this.has(k) ? [Number(k)] : undefined;\n }\n keyAt(coords: readonly number[]): ArrayKey | undefined {\n return coords.length === 1 ? this.keys[Number(coords[0])] : undefined;\n }\n}\n\nclass GridSpace<O> implements Space<GridKey, O> {\n readonly kind: SpaceKind = \"grid\";\n readonly keys: readonly GridKey[];\n readonly records: readonly O[];\n readonly #cells: ReadonlyMap<string, O>;\n readonly #coords: ReadonlyMap<string, readonly number[]>;\n\n constructor(rows: readonly (readonly O[])[]) {\n const entries = rows.flatMap((row, i) => row.map((cell, j): [GridKey, O, readonly number[]] => [`${i},${j}`, cell, Object.freeze([i, j])]));\n this.keys = Object.freeze(entries.map(([k]) => k));\n this.records = Object.freeze(entries.map(([, o]) => o));\n this.#cells = new Map(entries.map(([k, cell]) => [k, cell]));\n this.#coords = new Map(entries.map(([k, , c]) => [k, c]));\n }\n\n has(k: string): k is GridKey {\n return this.#cells.has(k);\n }\n get(k: string): O | undefined {\n return this.#cells.get(k);\n }\n coords(k: string): readonly number[] | undefined {\n return this.#coords.get(k);\n }\n keyAt(coords: readonly number[]): GridKey | undefined {\n // Each key has two coordinates, so a list with more or fewer coordinates gives no key.\n const k = coords.join(\",\");\n return this.has(k) ? k : undefined;\n }\n}\n\nclass TreeSpace<K extends string, O> implements Space<K, O> {\n readonly kind: SpaceKind = \"tree\";\n readonly keys: readonly K[];\n readonly records: readonly O[];\n readonly #records: ReadonlyMap<string, O>;\n readonly #parents: ReadonlyMap<string, K>;\n readonly #children: ReadonlyMap<string, readonly K[]>;\n\n constructor(records: Readonly<Record<K, O>>, parents: Readonly<Partial<Record<K, K | null>>>) {\n const entries = Object.entries(records) as [K, O][];\n this.keys = Object.freeze(entries.map(([k]) => k));\n this.records = Object.freeze(entries.map(([, o]) => o));\n this.#records = new Map(entries);\n const parentOf = new Map<string, K>();\n for (const [k, p] of Object.entries(parents) as [K, K | null | undefined][]) {\n if (!this.#records.has(k)) throw new TypeError(`the tree has no key \"${k}\", but the parents name it`);\n if (p === null || p === undefined) continue;\n if (!this.#records.has(p)) throw new TypeError(`the parent \"${p}\" of \"${k}\" is not a key of the tree`);\n parentOf.set(k, p);\n }\n // A parent chain that comes back to a key of the same walk is a cycle, not a tree. Each key is in one walk\n // only: a walk stops at a key that an earlier walk proved to reach a root. Thus the check is linear.\n const reachesRoot = new Set<string>();\n for (const k of this.keys) {\n const walk = new Set<string>();\n for (let p: string | undefined = k; p !== undefined && !reachesRoot.has(p); p = parentOf.get(p)) {\n if (walk.has(p)) throw new TypeError(`the parents of \"${k}\" make a cycle, so the space is not a tree`);\n walk.add(p);\n }\n for (const w of walk) reachesRoot.add(w);\n }\n this.#parents = parentOf;\n const children = new Map<string, K[]>(this.keys.map((k) => [k, []]));\n for (const k of this.keys) {\n const p = parentOf.get(k);\n // Each parent is a key, so its list exists, and the test of p only skips the roots.\n // Stryker disable next-line ConditionalExpression,OptionalChaining: a root has no list to push to\n if (p !== undefined) children.get(p)?.push(k);\n }\n this.#children = new Map([...children].map(([k, c]) => [k, Object.freeze(c)]));\n }\n\n has(k: string): k is K {\n return this.#records.has(k);\n }\n get(k: string): O | undefined {\n return this.#records.get(k);\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n coords(): readonly number[] | undefined {\n return undefined;\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n keyAt(): K | undefined {\n return undefined;\n }\n // In a tree, the edges go from a parent to its children.\n successorsOf(k: string): readonly K[] {\n return this.childrenOf(k);\n }\n predecessorsOf(k: string): readonly K[] {\n const p = this.#parents.get(k);\n return p === undefined ? [] : [p];\n }\n parentOf(k: string): K | undefined {\n return this.#parents.get(k);\n }\n childrenOf(k: string): readonly K[] {\n return this.#children.get(k) ?? [];\n }\n}\n\n/** The constructors of spaces. */\n/** The empty list of keys. */\nconst NO_KEYS: readonly never[] = Object.freeze([]);\n\nclass GraphSpace<K extends string, O> implements Space<K, O> {\n readonly kind: SpaceKind = \"graph\";\n readonly keys: readonly K[];\n readonly records: readonly O[];\n readonly #records: ReadonlyMap<string, O>;\n readonly #out: ReadonlyMap<string, readonly K[]>;\n readonly #in: ReadonlyMap<string, readonly K[]>;\n\n constructor(records: Readonly<Record<K, O>>, edges: Readonly<Partial<Record<K, readonly K[]>>>) {\n const entries = Object.entries(records) as [K, O][];\n this.keys = Object.freeze(entries.map(([k]) => k));\n this.records = Object.freeze(entries.map(([, o]) => o));\n this.#records = new Map(entries);\n const out = new Map<string, readonly K[]>();\n for (const [k, to] of Object.entries(edges) as [K, readonly K[] | undefined][]) {\n if (!this.#records.has(k)) throw new TypeError(`the graph has no key \"${k}\", but the edges name it`);\n // A second edge to the same key is the same edge.\n const ends = [...new Set(to ?? NO_KEYS)];\n for (const t of ends) if (!this.#records.has(t)) throw new TypeError(`the edge from \"${k}\" goes to \"${t}\", which is not a key of the graph`);\n out.set(k, Object.freeze(ends));\n }\n this.#out = out;\n // The predecessors in key order: the keys in key order, and the ends of the edges of each key.\n const into = new Map<string, K[]>();\n for (const k of this.keys) {\n for (const t of out.get(k) ?? NO_KEYS) {\n const from = into.get(t);\n if (from === undefined) into.set(t, [k]);\n else from.push(k);\n }\n }\n this.#in = new Map([...into].map(([k, from]) => [k, Object.freeze(from)]));\n }\n\n has(k: string): k is K {\n return this.#records.has(k);\n }\n get(k: string): O | undefined {\n return this.#records.get(k);\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n coords(): readonly number[] | undefined {\n return undefined;\n }\n // Stryker disable next-line BlockStatement: the body gives undefined, and an empty body gives undefined too\n keyAt(): K | undefined {\n return undefined;\n }\n successorsOf(k: string): readonly K[] {\n return this.#out.get(k) ?? NO_KEYS;\n }\n predecessorsOf(k: string): readonly K[] {\n return this.#in.get(k) ?? NO_KEYS;\n }\n}\n\nexport const space = {\n /** This function makes a space from the entries of an object. The keys are the property names. */\n record<const R extends Readonly<Record<string, unknown>>>(records: R): Space<keyof R & string, R[keyof R]> {\n return new RecordSpace<keyof R & string, R[keyof R]>(records);\n },\n /** This function makes a space from an array. The keys are `\"0\"`, `\"1\"` and so on. */\n array<O>(items: readonly O[]): Space<ArrayKey, O> {\n return new ArraySpace(items);\n },\n /** This function makes a space from rows of cells. The key of a cell is `\"row,column\"`. */\n grid<O>(rows: readonly (readonly O[])[]): Space<GridKey, O> {\n return new GridSpace(rows);\n },\n /**\n * This function makes a tree space: the records by key, and the parent of each key. A key without a parent, or\n * with the parent `null`, is a root. A parent that is not a key, or a cycle of parents, throws a `TypeError`.\n */\n tree<const R extends Readonly<Record<string, unknown>>>(records: R, parents: Readonly<Partial<Record<keyof R & string, (keyof R & string) | null>>>): Space<keyof R & string, R[keyof R]> {\n return new TreeSpace<keyof R & string, R[keyof R]>(records, parents);\n },\n /**\n * This function makes a graph space: the records by key, and the edges from each key, in order. An edge to a key\n * that is not in the graph throws a `TypeError`. A graph can have cycles, and an edge can go from a key to itself.\n */\n graph<const R extends Readonly<Record<string, unknown>>>(records: R, edges: Readonly<Partial<Record<keyof R & string, readonly (keyof R & string)[]>>>): Space<keyof R & string, R[keyof R]> {\n return new GraphSpace<keyof R & string, R[keyof R]>(records, edges);\n },\n} as const;\n\n/** The position of an evaluation: the key where it started, and the key where relative references read. */\nexport interface Position {\n readonly origin: string;\n readonly focus: string;\n}\n\n/** This function applies one move to the focus. It gives the new focus, or a `#REF!` error. */\nexport function applyMove(s: Space, at: Position, m: FixedMove): Result<string> {\n const refError = (kind: \"unknown-key\" | \"not-a-pair\" | \"out-of-bounds\" | \"no-offset\" | \"no-tree\", message: string): Result<string> =>\n fail(vexError(kind, message, { origin: at.origin, focus: at.focus }));\n switch (m.t) {\n case \"key\":\n return s.has(m.key) ? ok(m.key) : refError(\"unknown-key\", `the space has no key \"${m.key}\"`);\n case \"index\": {\n const k = s.keys[m.i];\n return k !== undefined ? ok(k) : refError(\"out-of-bounds\", `the space has no key at index ${m.i}`);\n }\n case \"other\": {\n if (s.keys.length !== 2) return refError(\"not-a-pair\", `\"other\" needs a space with 2 keys, but this space has ${s.keys.length}`);\n const [a, b] = s.keys;\n // A pair has two keys, so `a` and `b` are defined.\n /* v8 ignore next -- @preserve */\n return ok(at.focus === a ? (b ?? at.focus) : (a ?? at.focus));\n }\n case \"offset\": {\n // In a tree space, an offset with one number moves among the siblings in key order. The roots are siblings.\n const parentOf = s.parentOf?.bind(s);\n const childrenOf = s.childrenOf?.bind(s);\n if (parentOf !== undefined && childrenOf !== undefined && m.d.length === 1) {\n const p = parentOf(at.focus);\n const group = p === undefined ? s.keys.filter((k) => parentOf(k) === undefined) : childrenOf(p);\n const i = group.indexOf(at.focus);\n const k = i < 0 ? undefined : group[i + (m.d[0] ?? 0)];\n return k === undefined ? refError(\"out-of-bounds\", `the offset [${m.d.join(\",\")}] from \"${at.focus}\" is outside its siblings`) : ok(k);\n }\n const c = s.coords(at.focus);\n if (c === undefined || c.length !== m.d.length) {\n return refError(\"no-offset\", `an offset of length ${m.d.length} is not valid in a ${s.kind} space`);\n }\n // The lengths are equal, so each index of `c` is also an index of `m.d`.\n /* v8 ignore next -- @preserve */\n const target = c.map((x, i) => x + (m.d[i] ?? 0));\n const k = s.keyAt(target);\n return k === undefined ? refError(\"out-of-bounds\", `the offset [${m.d.join(\",\")}] from \"${at.focus}\" is outside the space`) : ok(k);\n }\n case \"origin\":\n return ok(at.origin);\n case \"parent\": {\n if (s.parentOf === undefined) return refError(\"no-tree\", `\"parent\" needs a tree space, but this space is a ${s.kind}`);\n const p = s.parentOf(at.focus);\n return p === undefined ? refError(\"out-of-bounds\", `the key \"${at.focus}\" is a root, so it has no parent`) : ok(p);\n }\n }\n}\n\n/**\n * This function gives the fixed moves of an address. `values` has the value of the expression of each computed move,\n * in order (NAV.COMPUTED). A key that is not a text, or a position that is not a number, gives `#VALUE!`.\n */\nexport function fixAddr(addr: Addr, values: readonly unknown[], at: Position): Result<readonly FixedMove[]> {\n const out: FixedMove[] = [];\n let next = 0;\n for (const m of addr) {\n if (moveExpr(m) === undefined) {\n out.push(m as FixedMove);\n continue;\n }\n const u = values[next++];\n if (m.t === \"key\" && typeof u === \"string\") out.push({ t: \"key\", key: u });\n else if (m.t === \"index\" && typeof u === \"number\") out.push({ t: \"index\", i: u });\n else return fail(vexError(\"kind-mismatch\", m.t === \"key\" ? `the key of a move is a ${typeof u}, not a text` : `the position of a move is a ${typeof u}, not a number`, at));\n }\n return ok(out);\n}\n\n/** This function applies the moves of an address in order. It gives the key where the address points. */\nexport function resolveAddr(s: Space, at: Position, addr: readonly FixedMove[] | undefined): Result<string> {\n let focus = at.focus;\n for (const m of addr ?? []) {\n const r = applyMove(s, { origin: at.origin, focus }, m);\n if (!r.ok) return r;\n focus = r.value;\n }\n return ok(focus);\n}\n\nconst NEIGHBORS_4: readonly (readonly [number, number])[] = [[-1, 0], [0, -1], [0, 1], [1, 0]];\nconst NEIGHBORS_8: readonly (readonly [number, number])[] = [\n [-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1],\n];\n\n/** The axes of a tree space. */\ntype TreeAxis = \"children\" | \"ancestors\" | \"descendants\" | \"siblings\";\n\nfunction treeTargets(s: Space, at: Position, t: TreeAxis): Result<readonly string[]> {\n const parentOf = s.parentOf?.bind(s);\n const childrenOf = s.childrenOf?.bind(s);\n if (parentOf === undefined || childrenOf === undefined) {\n return fail(vexError(\"no-tree\", `\"${t}\" needs a tree space, but this space is a ${s.kind}`, at));\n }\n switch (t) {\n case \"children\":\n return ok(childrenOf(at.focus));\n case \"ancestors\": {\n const out: string[] = [];\n for (let p = parentOf(at.focus); p !== undefined; p = parentOf(p)) out.push(p);\n return ok(out);\n }\n case \"descendants\": {\n // A depth-first walk with a stack, so a deep tree does not need a deep call stack.\n const out: string[] = [];\n const stack = childrenOf(at.focus).toReversed();\n for (let k = stack.pop(); k !== undefined; k = stack.pop()) {\n out.push(k);\n stack.push(...childrenOf(k).toReversed());\n }\n return ok(out);\n }\n case \"siblings\": {\n const p = parentOf(at.focus);\n const group = p === undefined ? s.keys.filter((k) => parentOf(k) === undefined) : childrenOf(p);\n return ok(group.filter((k) => k !== at.focus));\n }\n }\n}\n\n/**\n * This function gives the targets of a base axis at a focus. It does not handle `where`, because the\n * interpreter must evaluate the test.\n */\nexport function axisTargets(s: Space, at: Position, a: Exclude<Axis, { readonly t: \"where\" }>): Result<readonly string[]> {\n switch (a.t) {\n case \"all\":\n return ok(s.keys);\n case \"others\":\n return ok(s.keys.filter((k) => k !== at.focus));\n case \"other\": {\n const r = applyMove(s, at, { t: \"other\" });\n return r.ok ? ok([r.value]) : r;\n }\n case \"neighbors\": {\n if (s.kind !== \"grid\") return fail(vexError(\"no-grid\", `\"neighbors\" needs a grid space, but this space is a ${s.kind}`, at));\n const deltas = a.n === 4 ? NEIGHBORS_4 : NEIGHBORS_8;\n return ok(\n deltas.flatMap((d) => {\n const r = applyMove(s, at, { t: \"offset\", d });\n return r.ok ? [r.value] : [];\n }),\n );\n }\n case \"children\":\n case \"ancestors\":\n case \"descendants\":\n case \"siblings\":\n return treeTargets(s, at, a.t);\n case \"window\":\n return windowTargets(s, at, a.from, a.to);\n case \"successors\":\n case \"predecessors\":\n case \"reachable\":\n return graphTargets(s, at, a.t);\n case \"reverse\": {\n // The validation of the IR keeps a base axis inside reverse: not where, reverse or table.\n const r = axisTargets(s, at, a.axis as Exclude<Axis, { readonly t: \"where\" }>);\n return r.ok ? ok(r.value.toReversed()) : r;\n }\n case \"table\":\n // The evaluator gives the axis table the space of its table. Here, without the tables, it has no targets.\n return fail(vexError(\"no-table\", `the axis \"table\" needs the tables of the evaluation, and \"${a.name}\" is not one of them`, at));\n case \"list\":\n // The evaluator gives the targets of the axis list from the value of its expression. A space alone has no list.\n return fail(vexError(\"bad-expression\", 'the axis \"list\" needs the evaluator, which gives the value of its list', at));\n }\n}\n\n/**\n * This function gives the targets of an axis of a graph. `reachable` has each key that a path of one or more edges\n * reaches from the focus, once, in the order of a breadth-first search. The focus is not a target of `reachable`.\n */\nfunction graphTargets(s: Space, at: Position, t: \"successors\" | \"predecessors\" | \"reachable\"): Result<readonly string[]> {\n const successorsOf = s.successorsOf?.bind(s);\n const predecessorsOf = s.predecessorsOf?.bind(s);\n if (successorsOf === undefined || predecessorsOf === undefined) {\n return fail(vexError(\"no-graph\", `\"${t}\" needs a graph space or a tree space, but this space is a ${s.kind}`, at));\n }\n if (t === \"successors\") return ok(successorsOf(at.focus));\n if (t === \"predecessors\") return ok(predecessorsOf(at.focus));\n // A queue, not recursion, so a long path does not need a deep call stack. A loop over an array also reads the\n // keys that the loop adds to it.\n const seen = new Set<string>([at.focus]);\n const queue: string[] = [at.focus];\n for (const k of queue) {\n for (const next of successorsOf(k)) {\n if (seen.has(next)) continue;\n seen.add(next);\n queue.push(next);\n }\n }\n return ok(queue.slice(1));\n}\n\n/**\n * This function gives the targets of the axis `window(from, to)`: the keys of the moves `offset(d)` for each `d`\n * from `from` to `to`, in order. An offset outside the space has no target. The axis needs an array space or a tree\n * space, where an offset has one number.\n */\nfunction windowTargets(s: Space, at: Position, from: number, to: number): Result<readonly string[]> {\n const tree = s.parentOf !== undefined && s.childrenOf !== undefined;\n if (!tree && s.coords(at.focus)?.length !== 1) {\n return fail(vexError(\"no-offset\", `\"window\" needs an array space or a tree space, but this space is a ${s.kind}`, at));\n }\n // An offset larger than the number of keys has no target, so the loop stays in the size of the space.\n const out: string[] = [];\n for (let d = Math.max(from, -s.keys.length); d <= Math.min(to, s.keys.length); d++) {\n const r = applyMove(s, at, { t: \"offset\", d: [d] });\n if (r.ok) out.push(r.value);\n }\n return ok(out);\n}\n","/**\n * Domains. A domain tells which values belong to it and which ops it has. The domain object owns this data.\n * Vex does not write to the prototypes of domain classes, and an import has no side effects.\n */\n\n/** An algebraic law that an op claims. `@mark1russell7/vex-testkit` checks each claim with property tests. */\nexport type Law = \"commutative\" | \"associative\" | \"idempotent\";\n\n/** The kind of a parameter. The interpreter checks the arguments of an op that declares its parameters. */\nexport type ParamKind = \"domain\" | \"number\" | \"boolean\" | \"string\" | \"any\";\n\n/** The kind of the result of an op: a kind of a parameter, or `domain:Name` for a value of the domain `Name`. */\nexport type ReturnKind = ParamKind | `domain:${string}`;\n\n/** The description of one op of a domain. */\nexport interface OpSpec<D = never> {\n /**\n * The implementation, for an op that is not a method of the value (static-land style). The first argument\n * is the receiver. Without `fn`, the interpreter calls the method of the receiver with the same name.\n */\n readonly fn?: (self: D, ...args: never[]) => unknown;\n /** The laws that the op claims. */\n readonly laws?: readonly Law[];\n /** The identity element of the op, for reductions over an empty list. */\n readonly identity?: () => D;\n /** Scalar lifting: `true` lifts each number argument with `fromScalar`. An array sets it for each argument. */\n readonly liftScalar?: boolean | readonly boolean[];\n /** The kinds of the parameters after the receiver. When set, the interpreter checks the arguments. */\n readonly params?: readonly ParamKind[];\n /**\n * The kind of the result: `domain` for a value of this domain, and `domain:Name` for a value of the domain `Name`. A\n * compiler reads it to know the kinds of the values of a program (KIND.RETURNS). The interpreter does not check it,\n * and the law checker of the test kit does.\n */\n readonly returns?: ReturnKind;\n}\n\n/** A JavaScript type of primitive values that a domain can accept. */\nexport type PrimitiveKind = \"number\" | \"string\" | \"boolean\";\n\n/** The type of an op that lifts number arguments. Use it to type the ops of a domain under `isolatedDeclarations`. */\nexport type LiftedOp<D> = OpSpec<D> & { readonly liftScalar: true };\n\n/** The type of an op with an implementation function `F`. */\nexport type FnOp<D, F extends (self: D, ...args: never[]) => unknown> = OpSpec<D> & { readonly fn: F };\n\n/**\n * The type of an op table: each name in `Names` is an op, and each name in `Lifted` lifts number arguments.\n * Use it to type the ops of a domain under `isolatedDeclarations`.\n */\nexport type OpTable<D, Names extends string, Lifted extends string = never> = {\n readonly [N in Names]: N extends Lifted ? LiftedOp<D> : OpSpec<D>;\n};\n\n/** The description of a domain, as a caller gives it to `defineDomain`. */\nexport interface DomainSpec<Name extends string, D, Ops extends Readonly<Record<string, OpSpec<D>>>> {\n /** The name of the domain. */\n readonly name: Name;\n /** The runtime test for the values of the domain. It must not give false positives. */\n readonly is: (u: unknown) => u is D;\n /**\n * The JavaScript type of the values of the domain, if `is` accepts each value of that type and no other value\n * (KIND.PRIMITIVE). A compiler then finds the op of such a value before a run.\n */\n readonly primitive?: PrimitiveKind;\n /** The ops of the domain, with their metadata. */\n readonly ops: Ops;\n /** With `\"all\"`, each method of a value is an op, also without an entry in `ops`. The default is `\"declared\"`. */\n readonly methods?: \"declared\" | \"all\";\n /** The scalar lift: it makes a domain value from a number. */\n readonly fromScalar?: (n: number) => D;\n /** A check of the values that ops give. A value that fails the check gives the error `#NUM!`. */\n readonly valid?: (d: D) => boolean;\n /** A short text for a value, for traces and the site. */\n readonly show?: (d: D) => string;\n /** The JSON form of a value, for literals in serialized programs. */\n readonly encode?: (d: D) => unknown;\n /** The value of a JSON form that `encode` made. */\n readonly decode?: (json: unknown) => D;\n /**\n * 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\n * results (KIND.DOMAIN).\n */\n readonly samples?: () => readonly D[];\n}\n\n/** A domain. Make one with `defineDomain`. */\nexport interface Domain<Name extends string = string, D = unknown, Ops extends Readonly<Record<string, OpSpec<D>>> = Readonly<Record<string, OpSpec<D>>>>\n extends DomainSpec<Name, D, Ops> {\n readonly kind: \"vex.domain\";\n}\n\n/** A domain with any value type. The interpreter uses this type. */\n// oxlint-disable-next-line typescript/no-explicit-any -- a list of domains with different value types needs `any`: `fn` is contravariant in the value type.\nexport type AnyDomain = Domain<string, any, Readonly<Record<string, OpSpec<any>>>>;\n\n/** This function makes a domain. The result is frozen. */\nexport function defineDomain<const Name extends string, D, const Ops extends Readonly<Record<string, OpSpec<D>>>>(\n spec: DomainSpec<Name, D, Ops>,\n): Domain<Name, D, Ops> {\n return Object.freeze({ ...spec, kind: \"vex.domain\" as const });\n}\n\nconst FORBIDDEN = new Set([\"constructor\", \"__proto__\", \"prototype\", \"__defineGetter__\", \"__defineSetter__\", \"__lookupGetter__\", \"__lookupSetter__\"]);\n\n/** This function tells if a name can be an op name. */\nexport const isOpName = (name: string): boolean => name.length > 0 && !FORBIDDEN.has(name);\n\n/**\n * This function finds a method on a value: an own function property, or a function on the prototype chain.\n * It stops at `Object.prototype` and `Function.prototype`, so inherited members (for example `toString`) are not ops.\n */\nexport function findMethod(self: unknown, name: string): ((...args: unknown[]) => unknown) | undefined {\n if (!isOpName(name)) return undefined;\n // A primitive has no own methods. The loop below stops at null, so null needs no test here.\n if (typeof self !== \"object\" && typeof self !== \"function\") return undefined;\n let o: object | null = self;\n while (o !== null && o !== Object.prototype && o !== Function.prototype) {\n const d = Object.getOwnPropertyDescriptor(o, name);\n if (d !== undefined) {\n return typeof d.value === \"function\" ? (d.value as (...args: unknown[]) => unknown) : undefined;\n }\n o = Object.getPrototypeOf(o) as object | null;\n }\n return undefined;\n}\n\n/** An op that the interpreter found for a receiver. */\nexport interface ResolvedOp {\n readonly domain: AnyDomain;\n readonly spec: OpSpec<unknown>;\n readonly call: (args: readonly unknown[]) => unknown;\n}\n\nconst EMPTY_SPEC: OpSpec<unknown> = Object.freeze({});\n\n/** This function finds the op `name` for `self` in one domain. It gives `undefined` if the domain does not have it. */\nexport function resolveOp(domain: AnyDomain, self: unknown, name: string): ResolvedOp | undefined {\n if (!isOpName(name)) return undefined;\n const declared = Object.hasOwn(domain.ops, name) ? (domain.ops[name] as OpSpec<unknown>) : undefined;\n if (declared?.fn !== undefined) {\n const fn = declared.fn as (self: unknown, ...args: unknown[]) => unknown;\n return { domain, spec: declared, call: (args) => fn(self, ...args) };\n }\n if (declared === undefined && domain.methods !== \"all\") return undefined;\n const method = findMethod(self, name);\n if (method === undefined) return undefined;\n return { domain, spec: declared ?? EMPTY_SPEC, call: (args) => method.apply(self, [...args]) };\n}\n\n/** This function gives the domain of a value: the first domain whose `is` accepts it. */\nexport function domainOf(domains: readonly AnyDomain[], value: unknown): AnyDomain | undefined {\n return domains.find((d) => d.is(value));\n}\n\n/** This function tells if the `liftScalar` setting lifts the argument at `index`. */\nexport const liftsAt = (lift: OpSpec<unknown>[\"liftScalar\"], index: number): boolean =>\n lift === true || (Array.isArray(lift) && lift[index] === true);\n","import type { Result } from \"./result.ts\";\n\n/** One item of a list: the key of the target and the result of the body there. */\nexport interface ListItem<T = unknown> {\n readonly key: string;\n readonly result: Result<T>;\n}\n\n/** The value of an `each` expression: one item for each target of the axis. */\nexport interface VexList<T = unknown> {\n readonly kind: \"vex.list\";\n readonly items: readonly ListItem<T>[];\n}\n\n/** This function makes a list. */\nexport const vexList = <T>(items: readonly ListItem<T>[]): VexList<T> => Object.freeze({ kind: \"vex.list\", items: Object.freeze([...items]) });\n\n/** This function tells if a value is a Vex list. */\nexport const isVexList = (u: unknown): u is VexList =>\n (u as { kind?: unknown } | null | undefined)?.kind === \"vex.list\" && Array.isArray((u as { items?: unknown }).items);\n\n/** The name of a core list op. `sortBy` and `take` give a list, and the other ops give a value. */\nexport type ListOp = \"count\" | \"sum\" | \"min\" | \"max\" | \"mean\" | \"any\" | \"all\" | \"none\" | \"values\" | \"keys\" | \"reduce\" | \"first\" | \"errors\" | \"sortBy\" | \"take\" | \"nth\";\n\n/** The names of the core list ops. They apply when the first argument is a list. */\nexport const LIST_OPS: ReadonlySet<string> = new Set<ListOp>([\"count\", \"sum\", \"min\", \"max\", \"mean\", \"any\", \"all\", \"none\", \"values\", \"keys\", \"reduce\", \"first\", \"errors\", \"sortBy\", \"take\", \"nth\"]);\n\n/** This function tells if a name is the name of a core list op. */\nexport const isListOp = (op: string): op is ListOp => LIST_OPS.has(op);\n\n/** The options of a list op. */\nexport interface ListOptions {\n /** With `true`, any error item makes the result that error. The default skips error items. */\n readonly strict?: boolean;\n}\n","import { liftsAt, resolveOp, type AnyDomain, type ParamKind, type ResolvedOp } from \"./domain.ts\";\nimport { formatError, isDepthError, isStackOverflow, vexError, type ErrorKind, type VexError } from \"./errors.ts\";\nimport { addrExprs, children, shapeError, type Addr, type Axis, type Expr, type ExprOf, type FixedMove, type Move } from \"./ir.ts\";\nimport { isListOp, isVexList, vexList, type ListItem, type ListOp, type ListOptions, type VexList } from \"./list.ts\";\nimport { fail, ok, type Result } from \"./result.ts\";\nimport { axisTargets, fixAddr, resolveAddr, type Position, type Space } from \"./space.ts\";\nimport type { Read, Trace, TraceEvent, TraceSink } from \"./trace.ts\";\n\n/** A free function op. The interpreter gives it the values of all arguments. */\nexport type FreeFn = (...args: readonly unknown[]) => unknown;\n\n/** The context of an extension handler. */\nexport interface ExtContext {\n readonly space: Space;\n readonly position: Position;\n readonly path: readonly number[];\n}\n\n/** The handler of an extension expression kind. */\nexport type ExtHandler = (data: unknown, ctx: ExtContext) => Result<unknown>;\n\n/** The options of an evaluation. */\nexport interface EvalOptions {\n /** The space that the program reads. */\n readonly space: Space;\n /** The key where the evaluation starts. Relative references read here. */\n readonly origin: string;\n /** The domains. The interpreter finds the op of a value in the first domain that accepts the value. */\n readonly domains?: readonly AnyDomain[];\n /** Free function ops, for ops that are not domain ops. */\n readonly fns?: Readonly<Record<string, FreeFn>>;\n /** The handlers of extension expression kinds. */\n readonly extensions?: Readonly<Record<string, ExtHandler>>;\n /** Variables that the program can read with `v(name)`. */\n readonly vars?: Readonly<Record<string, unknown>>;\n /** The other spaces of the evaluation, by name. The axis `table(name)` reads them. */\n readonly tables?: Readonly<Record<string, Space>>;\n /** A receiver of trace events. */\n readonly trace?: TraceSink;\n}\n\ntype Env = ReadonlyMap<string, Result<unknown>>;\n\ninterface Frame {\n readonly pos: Position;\n readonly env: Env;\n}\n\n/** The name of a special form. */\nexport type SpecialForm = \"if\" | \"and\" | \"or\" | \"ifError\";\n\n/** The names of the special forms. Their arguments are not evaluated before the call. */\nexport const SPECIAL_FORMS: ReadonlySet<string> = new Set<SpecialForm>([\"if\", \"and\", \"or\", \"ifError\"]);\n\nconst isSpecialForm = (op: string): op is SpecialForm => SPECIAL_FORMS.has(op);\n\n/** The options that a compiled program keeps: the domains, the free functions and the extension handlers. */\nexport type CompileOptions = Pick<EvalOptions, \"domains\" | \"fns\" | \"extensions\">;\n\n/** The options of one run of a compiled program. */\nexport type RunOptions = Pick<EvalOptions, \"space\" | \"origin\" | \"vars\" | \"trace\" | \"tables\">;\n\n/**\n * A compiled program: the expression as a tree of functions. A program evaluates many times at different origins,\n * and over different spaces, without a new walk of the expression.\n */\nexport interface Program {\n /** The expression of the program. */\n readonly expr: Expr;\n /** This method evaluates the program at an origin. It does not throw. */\n run(opts: RunOptions): Result<unknown>;\n /** This method evaluates the program at an origin, with a trace of each node. */\n explain(opts: Omit<RunOptions, \"trace\">): Trace;\n}\n\n/**\n * This function compiles an expression. The result gives the same results and the same traces as `evaluate`,\n * because `evaluate` uses it too.\n */\n/** A bound function (FN.BIND): its parameters, its compiled body and the names of the place of its binding. */\nclass Closure {\n readonly params: readonly string[];\n readonly body: Node;\n readonly env: ReadonlyMap<string, Result<unknown>>;\n\n constructor(params: readonly string[], body: Node, env: ReadonlyMap<string, Result<unknown>>) {\n this.params = params;\n this.body = body;\n this.env = env;\n }\n}\n\n/** The deepest nesting of an expression that `compile` accepts (EVAL.NESTING). */\nexport const MAX_NESTING = 500;\n\nconst DEPTH_MESSAGE = \"the evaluation is too deep for the call stack of the engine\";\n\n/** This function gives the number of nodes on the longest path from the root of `e`. It uses a stack, not recursion. */\nexport function nestingOf(e: Expr): number {\n let deepest = 0;\n const todo: [Expr, number][] = [[e, 1]];\n for (let item = todo.pop(); item !== undefined; item = todo.pop()) {\n const [x, d] = item;\n if (d > deepest) deepest = d;\n for (const child of children(x)) todo.push([child, d + 1]);\n }\n return deepest;\n}\n\nexport function compile(expr: Expr, opts: CompileOptions = {}): Program {\n // EVAL.SHAPE: an expression that is not valid, for example from a newer version of Vex, gives an error before a walk.\n // EVAL.NESTING: a program nested too deep gives an error before the compiler walks it with recursion.\n const shape = shapeError(expr);\n const nesting = shape === undefined ? nestingOf(expr) : 0;\n const bad = shape ?? (nesting > MAX_NESTING ? `the expression is nested ${nesting} levels deep, and the limit is ${MAX_NESTING}` : undefined);\n const root: Node = bad === undefined ? new Compiler(opts).node(expr, []) : (f) => fail(vexError(\"bad-expression\", bad, { path: [], origin: f.pos.origin, focus: f.pos.focus }));\n const run = (r: RunOptions): Result<unknown> => {\n const { space, origin } = r;\n if (!space.has(origin)) return fail(vexError(\"unknown-key\", `the space has no key \"${origin}\"`, { origin, focus: origin }));\n const env = new Map<string, Result<unknown>>(Object.entries(r.vars ?? {}).map(([k, val]) => [k, ok(val)]));\n try {\n return root({ pos: { origin, focus: origin }, env }, { space, trace: r.trace, tables: r.tables });\n } catch (thrown) {\n // A defect in an extension handler or in a test of the interpreter itself. Totality still holds.\n if (isStackOverflow(thrown)) return fail(vexError(\"depth\", DEPTH_MESSAGE, { origin, focus: origin, thrown }));\n return fail(vexError(\"threw\", \"the evaluation threw an exception\", { origin, focus: origin, thrown }));\n }\n };\n return {\n expr,\n run,\n explain: (r) => {\n const sink: TraceSink = { events: [] };\n const result = run({ ...r, trace: sink });\n return { events: sink.events, result };\n },\n };\n}\n\n// The cache of compiled programs: one entry for each expression object, for the last options.\nconst CACHE = new WeakMap<Expr, { readonly domains: unknown; readonly fns: unknown; readonly extensions: unknown; readonly program: Program }>();\n\nfunction compiled(expr: Expr, opts: CompileOptions): Program {\n const hit = CACHE.get(expr);\n // Without the cache, each evaluation compiles again: the result is the same, so a mutant that removes a hit is\n // equivalent. A false hit changes results, and the tests find it.\n // Stryker disable next-line ConditionalExpression: a missed hit only compiles again\n if (hit !== undefined && hit.domains === opts.domains && hit.fns === opts.fns && hit.extensions === opts.extensions) return hit.program;\n const program = compile(expr, opts);\n CACHE.set(expr, { domains: opts.domains, fns: opts.fns, extensions: opts.extensions, program });\n return program;\n}\n\n/** This function evaluates an expression at the origin of a space. It does not throw. */\nexport function evaluate(expr: Expr, opts: EvalOptions): Result<unknown> {\n return compiled(expr, opts).run(opts);\n}\n\n/** This function evaluates an expression and records a trace of each node. */\nexport function explain(expr: Expr, opts: Omit<EvalOptions, \"trace\">): Trace {\n return compiled(expr, opts).explain(opts);\n}\n\n/** The state of one run that the nodes read: the space, the trace sink and the other spaces. */\ninterface Ctx {\n readonly space: Space;\n readonly trace: TraceSink | undefined;\n readonly tables: Readonly<Record<string, Space>> | undefined;\n}\n\n/** This function gives the axis inside the `where` axes of an axis. */\nconst baseAxis = (a: Axis): Exclude<Axis, { readonly t: \"where\" }> => (a.t === \"where\" ? baseAxis(a.axis) : a);\n\n/** A compiled node: it evaluates in a frame of a run. */\ntype Node = (f: Frame, c: Ctx) => Result<unknown>;\n\n/** The static facts of a node for its trace events. */\ninterface Info {\n readonly path: readonly number[];\n readonly tag: Expr[\"tag\"];\n readonly label: string;\n}\n\nclass Compiler {\n readonly #domains: readonly AnyDomain[];\n readonly #fns: Readonly<Record<string, FreeFn>> | undefined;\n readonly #extensions: Readonly<Record<string, ExtHandler>> | undefined;\n\n constructor(opts: CompileOptions) {\n // Stryker disable next-line ArrayDeclaration: a list with a value that is not a domain matches no value\n this.#domains = opts.domains ?? [];\n this.#fns = opts.fns;\n this.#extensions = opts.extensions;\n }\n\n #err(kind: ErrorKind, message: string, f: Frame, path: readonly number[], extra: { op?: string; causes?: readonly VexError[]; thrown?: unknown } = {}): Result<never> {\n return fail(vexError(kind, message, { path, origin: f.pos.origin, focus: f.pos.focus, ...extra }));\n }\n\n #emit(c: Ctx, info: Info, f: Frame, result: Result<unknown>, reads?: readonly Read[]): Result<unknown> {\n if (c.trace !== undefined) {\n const event: TraceEvent = {\n path: info.path,\n tag: info.tag,\n label: info.label,\n origin: f.pos.origin,\n focus: f.pos.focus,\n ...(reads === undefined ? {} : { reads }),\n result,\n };\n c.trace.events.push(event);\n }\n return result;\n }\n\n /** This method compiles the expression `e` at the position `path` of the tree. */\n node(e: Expr, path: readonly number[]): Node {\n const info: Info = { path, tag: e.tag, label: labelOf(e) };\n switch (e.tag) {\n case \"lit\": {\n const r = ok(e.value);\n return (f, c) => this.#emit(c, info, f, r);\n }\n case \"ref\":\n return this.#ref(e, info);\n case \"var\": {\n const name = e.name;\n return (f, c) => {\n const bound = f.env.get(name);\n // A function is not a value (FN.VALUE).\n if (bound?.ok === true && bound.value instanceof Closure) return this.#emit(c, info, f, this.#err(\"kind-mismatch\", `the name \"${name}\" is a function, not a value`, f, path));\n return this.#emit(c, info, f, bound ?? this.#err(\"unbound\", `the name \"${name}\" has no binding`, f, path));\n };\n }\n case \"fn\":\n return this.#fn(e, path);\n case \"call\":\n return this.#callFn(e, info);\n case \"let\": {\n const binds = Object.entries(e.bind).map(([name, be], i): readonly [string, Node] => [name, this.node(be, [...path, i])]);\n const body = this.node(e.body, [...path, binds.length]);\n return (f, c) => {\n const env = new Map(f.env);\n for (const [name, n] of binds) env.set(name, n(f, c));\n return this.#emit(c, info, f, body({ pos: f.pos, env }, c));\n };\n }\n case \"rec\": {\n const names = Object.keys(e.fields);\n const fields = this.#nodes(Object.values(e.fields), path);\n return (f, c) => {\n const values = this.#all(fields, f, c, path, \"fields\");\n if (!values.ok) return this.#emit(c, info, f, values);\n const out: Record<string, unknown> = {};\n names.forEach((n, i) => {\n out[n] = values.value[i];\n });\n return this.#emit(c, info, f, ok(Object.freeze(out)));\n };\n }\n case \"app\":\n return isSpecialForm(e.op) ? this.#special(e.op, this.#nodes(e.args, path), info) : this.#app(e.op, this.#nodes(e.args, path), info);\n case \"each\":\n return this.#each(e, info);\n case \"fold\":\n return this.#fold(e, info);\n case \"iterate\":\n return this.#iterate(e, info);\n case \"ext\": {\n const extensions = this.#extensions ?? {};\n const handler = Object.hasOwn(extensions, e.kind) ? extensions[e.kind] : undefined;\n const { kind, data } = e;\n if (handler === undefined) return (f, c) => this.#emit(c, info, f, this.#err(\"unknown-op\", `no handler for the extension kind \"${kind}\"`, f, path));\n return (f, c) =>\n this.#emit(c, info, f, this.#locate(this.#guard(() => handler(data, { space: c.space, position: f.pos, path }), f, path, kind), f, path));\n }\n }\n }\n\n #nodes(es: readonly Expr[], path: readonly number[]): readonly Node[] {\n return es.map((x, i) => this.node(x, [...path, i]));\n }\n\n /**\n * This method compiles a function (FN.BIND). Its value is a closure: the parameters, the body, and the names of the\n * place of its binding. A binding of `let` does not see the other bindings, so a function cannot call itself.\n */\n #fn(e: ExprOf<\"fn\">, path: readonly number[]): Node {\n const body = this.node(e.body, [...path, 0]);\n return (f) => ok(new Closure(e.params, body, f.env));\n }\n\n /**\n * This method compiles a call (FN.CALL, FN.ARGS). Each parameter gets the result of its argument at the call, so an\n * argument that fails has an effect only where the body reads it. The body evaluates at the position of the call.\n */\n #callFn(e: ExprOf<\"call\">, info: Info): Node {\n const { path } = info;\n const args = this.#nodes(e.args, path);\n return (f, c) => {\n const bound = f.env.get(e.fn);\n if (bound === undefined) return this.#emit(c, info, f, this.#err(\"unbound\", `the function \"${e.fn}\" has no binding`, f, path));\n if (!bound.ok) return this.#emit(c, info, f, bound);\n const callee = bound.value;\n if (!(callee instanceof Closure)) return this.#emit(c, info, f, this.#err(\"kind-mismatch\", `the name \"${e.fn}\" is a value, not a function`, f, path));\n if (callee.params.length !== args.length) return this.#emit(c, info, f, this.#err(\"bad-expression\", `the function \"${e.fn}\" takes ${String(callee.params.length)} arguments, not ${String(args.length)}`, f, path));\n const env = new Map(callee.env);\n callee.params.forEach((p, i) => env.set(p, (args[i] as Node)(f, c)));\n return this.#emit(c, info, f, callee.body({ pos: f.pos, env }, c));\n };\n }\n\n /** This method gives an error of a handler the path, the origin and the focus of its node, if it has no origin. */\n #locate(r: Result<unknown>, f: Frame, path: readonly number[]): Result<unknown> {\n if (r.ok || r.error.origin !== undefined) return r;\n return fail({ ...r.error, path, origin: f.pos.origin, focus: f.pos.focus });\n }\n\n #guard(run: () => Result<unknown>, f: Frame, path: readonly number[], op: string): Result<unknown> {\n try {\n return run();\n } catch (thrown) {\n return this.#threw(thrown, `\"${op}\" threw an exception`, f, path, { op });\n }\n }\n\n /** This method gives the error of an exception: `#DEPTH!` for a full call stack, and `#CALC!` for each other exception. */\n #threw(thrown: unknown, message: string, f: Frame, path: readonly number[], extra: Partial<VexError> = {}): Result<never> {\n return isStackOverflow(thrown) ? this.#err(\"depth\", DEPTH_MESSAGE, f, path, { ...extra, thrown }) : this.#err(\"threw\", message, f, path, { ...extra, thrown });\n }\n\n /**\n * This method compiles an address. Its function gives the key where the address points. The expressions of the\n * computed moves evaluate first, at the position of the node, and their child indexes start at `first`. An error of\n * an expression keeps its path, and an error of a move gets the path of the node.\n */\n #address(at: Addr, path: readonly number[], first: number): (f: Frame, c: Ctx) => Result<string> {\n const nodes = addrExprs(at).map((x, i) => this.node(x, [...path, first + i]));\n const moved = (r: Result<string>): Result<string> => (r.ok ? r : fail({ ...r.error, path }));\n if (nodes.length === 0) return (f, c) => moved(resolveAddr(c.space, f.pos, at as readonly FixedMove[]));\n return (f, c) => {\n const values: unknown[] = [];\n for (const n of nodes) {\n const r = n(f, c);\n if (!r.ok) return r;\n values.push(r.value);\n }\n const fixed = fixAddr(at, values, f.pos);\n return fixed.ok ? moved(resolveAddr(c.space, f.pos, fixed.value)) : moved(fixed);\n };\n }\n\n #ref(e: ExprOf<\"ref\">, info: Info): Node {\n const { path } = info;\n const segs = e.path;\n const at = e.at ?? [];\n const address = this.#address(at, path, 0);\n const label = segs.join(\".\");\n const steps = segs.map((seg, i) => ({ seg, where: segs.slice(0, i + 1).join(\".\"), valid: isFieldName(seg) }));\n return (f, c) => {\n let key = f.pos.focus;\n // The empty address resolves to the focus, so this fast path changes no result.\n // Stryker disable next-line ConditionalExpression,EqualityOperator: resolveAddr of [] gives the focus too\n if (at.length > 0) {\n const where = address(f, c);\n if (!where.ok) return this.#emit(c, info, f, where);\n key = where.value;\n }\n const failed = (r: Result<unknown>): Result<unknown> => this.#emit(c, info, f, r, [{ key, path: segs, ok: false }]);\n const missing = (where: string): Result<unknown> => failed(this.#err(\"missing-field\", `the record at \"${key}\" has no value at \"${where}\"`, f, path));\n let value: unknown = c.space.get(key);\n if (value === undefined || value === null) return missing(label === \"\" ? \"(record)\" : label);\n for (const { seg, where, valid } of steps) {\n if ((typeof value !== \"object\" && typeof value !== \"function\") || !valid) return missing(where);\n try {\n value = Reflect.get(value, seg);\n } catch (thrown) {\n return failed(this.#threw(thrown, `reading \"${where}\" at \"${key}\" threw an exception`, f, path));\n }\n if (value === undefined || value === null) return missing(where);\n }\n return this.#emit(c, info, f, ok(value), [{ key, path: segs, ok: true }]);\n };\n }\n\n /** This method evaluates nodes applicatively. One failure stays as it is. Two or more give `#ARGS`. */\n #all(nodes: readonly Node[], f: Frame, c: Ctx, path: readonly number[], what: string): Result<readonly unknown[]> {\n const values: unknown[] = [];\n let first: VexError | undefined;\n let errors: VexError[] | undefined;\n for (const n of nodes) {\n const r = n(f, c);\n if (r.ok) values.push(r.value);\n else if (first === undefined) first = r.error;\n else (errors ??= [first]).push(r.error);\n }\n if (first === undefined) return ok(values);\n // A #DEPTH! argument is the result, so #ARGS does not wrap it, and ifError cannot hide it.\n const depth = [first, ...(errors ?? [])].find(isDepthError);\n if (depth !== undefined) return fail(depth);\n return errors === undefined ? fail(first) : this.#err(\"args\", `${errors.length} ${what} failed`, f, path, { causes: errors });\n }\n\n #each(e: ExprOf<\"each\">, info: Info): Node {\n const { path } = info;\n const at = e.at ?? [];\n const counter = { next: 1 };\n const targets = this.#targets(e.axis, path, counter);\n const body = this.node(e.body, [...path, 0]);\n const address = this.#address(at, path, counter.next);\n return (f, c) => {\n // An axis with an address finds its targets from the key of the address. The origin does not change.\n let from = f;\n // Stryker disable next-line ConditionalExpression,EqualityOperator: resolveAddr of [] gives the focus too\n if (at.length > 0) {\n const where = address(f, c);\n if (!where.ok) return this.#emit(c, info, f, where);\n from = { pos: { origin: f.pos.origin, focus: where.value }, env: f.env };\n }\n // The axis table moves the evaluation to the space of its table, where the origin of this space is not a key.\n // Thus there the origin is the target, and a value of this space goes in through a variable.\n const base = baseAxis(e.axis);\n let inner = c;\n if (base.t === \"table\") {\n const space = c.tables !== undefined && Object.hasOwn(c.tables, base.name) ? c.tables[base.name] : undefined;\n if (space === undefined) return this.#emit(c, info, f, this.#err(\"no-table\", `the evaluation has no table \"${base.name}\"`, f, path));\n inner = { ...c, space };\n }\n const ts = targets(from, inner);\n if (!ts.ok) return this.#emit(c, info, f, ts);\n const items: ListItem[] = ts.value.map(({ key, test }) => {\n if (test !== undefined && !test.ok) return { key, result: test };\n return { key, result: body({ pos: { origin: base.t === \"table\" ? key : f.pos.origin, focus: key }, env: f.env }, inner) };\n });\n return this.#emit(c, info, f, ok(vexList(items)));\n };\n }\n\n /**\n * This method compiles the names of a loop: `init` at the indexes from 0, and `step` after them (LOOP.NAMES). Its\n * functions give the first values, and the values after one step. The first error stops each of them.\n */\n #names(e: ExprOf<\"fold\"> | ExprOf<\"iterate\">, path: readonly number[]): {\n readonly first: (f: Frame, c: Ctx) => Result<Map<string, Result<unknown>>>;\n readonly next: (f: Frame, c: Ctx) => Result<Map<string, Result<unknown>>>;\n } {\n const inits = Object.entries(e.init).map(([name, x], i) => [name, this.node(x, [...path, i])] as const);\n const steps = Object.entries(e.step).map(([name, x], i) => [name, this.node(x, [...path, inits.length + i])] as const);\n return {\n first: (f, c) => {\n const env = new Map(f.env);\n for (const [name, n] of inits) {\n const r = n(f, c);\n if (!r.ok) return r;\n env.set(name, r);\n }\n return ok(env);\n },\n // Each value of a step reads the values before the step, so the names change only after all the values.\n next: (f, c) => {\n const values: (readonly [string, Result<unknown>])[] = [];\n for (const [name, n] of steps) {\n const r = n(f, c);\n if (!r.ok) return r;\n values.push([name, r]);\n }\n const env = new Map(f.env);\n for (const [name, r] of values) env.set(name, r);\n return ok(env);\n },\n };\n }\n\n /**\n * This method compiles a fold (FOLD.ORDER, FOLD.ERROR). `init` evaluates at the node, then the address and the\n * targets. A step evaluates at each target in order. `result` evaluates at the node with the last values.\n */\n #fold(e: ExprOf<\"fold\">, info: Info): Node {\n const { path } = info;\n const at = e.at ?? [];\n const names = this.#names(e, path);\n const counter = { next: Object.keys(e.init).length + Object.keys(e.step).length };\n const targets = this.#targets(e.axis, path, counter);\n const address = this.#address(at, path, counter.next);\n const result = this.node(e.result, [...path, counter.next + addrExprs(at).length]);\n const base = baseAxis(e.axis);\n return (f, c) => {\n const first = names.first(f, c);\n if (!first.ok) return this.#emit(c, info, f, first);\n let env = first.value;\n let from = f;\n // Stryker disable next-line ConditionalExpression,EqualityOperator: resolveAddr of [] gives the focus too\n if (at.length > 0) {\n const where = address(f, c);\n if (!where.ok) return this.#emit(c, info, f, where);\n from = { pos: { origin: f.pos.origin, focus: where.value }, env: f.env };\n }\n let inner = c;\n if (base.t === \"table\") {\n const space = c.tables !== undefined && Object.hasOwn(c.tables, base.name) ? c.tables[base.name] : undefined;\n if (space === undefined) return this.#emit(c, info, f, this.#err(\"no-table\", `the evaluation has no table \"${base.name}\"`, f, path));\n inner = { ...c, space };\n }\n const ts = targets(from, inner);\n if (!ts.ok) return this.#emit(c, info, f, ts);\n for (const { key, test } of ts.value) {\n if (test !== undefined && !test.ok) return this.#emit(c, info, f, test);\n const after = names.next({ pos: { origin: base.t === \"table\" ? key : f.pos.origin, focus: key }, env }, inner);\n if (!after.ok) return this.#emit(c, info, f, after);\n env = after.value;\n }\n return this.#emit(c, info, f, result({ pos: f.pos, env }, c));\n };\n }\n\n /**\n * This method compiles an iteration (ITERATE.LIMIT, ITERATE.UNTIL, ITERATE.ERROR). The test `until` evaluates before\n * each step and after the last step. `result` evaluates with the last values.\n */\n #iterate(e: ExprOf<\"iterate\">, info: Info): Node {\n const { path } = info;\n const names = this.#names(e, path);\n const untilAt = Object.keys(e.init).length + Object.keys(e.step).length;\n const untilPath = [...path, untilAt];\n const until = e.until === undefined ? undefined : this.node(e.until, untilPath);\n const result = this.node(e.result, [...path, untilAt + (until === undefined ? 0 : 1)]);\n const { limit } = e;\n return (f, c) => {\n const first = names.first(f, c);\n if (!first.ok) return this.#emit(c, info, f, first);\n let env = first.value;\n for (let k = 0; ; k++) {\n const frame: Frame = { pos: f.pos, env };\n if (until !== undefined) {\n const t = until(frame, c);\n if (!t.ok) return this.#emit(c, info, f, t);\n if (t.value === true) break;\n if (t.value !== false) return this.#emit(c, info, f, this.#err(\"kind-mismatch\", `the test \"until\" of \"iterate\" gave a ${typeof t.value}, not a boolean`, f, untilPath));\n }\n if (k === limit) {\n if (until !== undefined) return this.#emit(c, info, f, this.#err(\"limit\", `\"iterate\" made its ${String(limit)} steps, and its test \"until\" is not true`, f, path));\n break;\n }\n const after = names.next(frame, c);\n if (!after.ok) return this.#emit(c, info, f, after);\n env = after.value;\n }\n return this.#emit(c, info, f, result({ pos: f.pos, env }, c));\n };\n }\n\n /** This method compiles the targets of an axis. For `where`, a failed test keeps the target with its error. */\n #targets(a: Axis, path: readonly number[], counter: { next: number }): (f: Frame, c: Ctx) => Result<readonly { readonly key: string; readonly test?: Result<unknown> }[]> {\n if (a.t === \"table\") return (_f, c) => ok(c.space.keys.map((key) => ({ key })));\n const base = a.t === \"reverse\" ? a.axis : a;\n if (base.t === \"list\") return this.#listTargets(base.list, a.t === \"reverse\", path, counter);\n if (a.t !== \"where\") {\n return (f, c) => {\n const keys = axisTargets(c.space, f.pos, a);\n return keys.ok ? ok(keys.value.map((key) => ({ key }))) : fail({ ...keys.error, path });\n };\n }\n const inner = this.#targets(a.axis, path, counter);\n const testPath = [...path, counter.next++];\n const test = this.node(a.test, testPath);\n // In the space of the axis table, the origin of the test is the target, as for the body.\n const sameOrigin = baseAxis(a).t === \"table\";\n return (f, c) => {\n const ts = inner(f, c);\n if (!ts.ok) return ts;\n const out: { key: string; test?: Result<unknown> }[] = [];\n for (const t of ts.value) {\n if (t.test !== undefined && !t.test.ok) {\n out.push(t);\n continue;\n }\n const at: Frame = { pos: { origin: sameOrigin ? t.key : f.pos.origin, focus: t.key }, env: f.env };\n const r = test(at, c);\n if (!r.ok) out.push({ key: t.key, test: r });\n else if (r.value === true) out.push({ key: t.key });\n else if (r.value !== false) {\n out.push({ key: t.key, test: this.#err(\"kind-mismatch\", `the test of \"where\" gave a ${typeof r.value}, not a boolean`, at, testPath) });\n }\n }\n return ok(out);\n };\n }\n\n /**\n * This method compiles the targets of the axis list (AXIS.LIST): the keys of the items of a list, in its order. The\n * expression evaluates at the key of the address. An error item keeps its target with its error.\n */\n #listTargets(list: Expr, reverse: boolean, path: readonly number[], counter: { next: number }): (f: Frame, c: Ctx) => Result<readonly { readonly key: string; readonly test?: Result<unknown> }[]> {\n const node = this.node(list, [...path, counter.next++]);\n return (f, c) => {\n const r = node(f, c);\n if (!r.ok) return r;\n if (!isVexList(r.value)) return this.#err(\"kind-mismatch\", `the axis \"list\" needs a list, not a ${describeType(r.value)}`, f, path);\n const items = r.value.items.map(({ key, result }) => (result.ok ? { key } : { key, test: result }));\n return ok(reverse ? items.toReversed() : items);\n };\n }\n\n #app(op: string, args: readonly Node[], info: Info): Node {\n const { path } = info;\n const listOp = isListOp(op) ? op : undefined;\n const fn = this.#fns !== undefined && Object.hasOwn(this.#fns, op) ? this.#fns[op] : undefined;\n return (f, c) => {\n const all = this.#all(args, f, c, path, \"arguments\");\n if (!all.ok) return this.#emit(c, info, f, all);\n const values = all.value;\n const self = values[0];\n if (listOp !== undefined && isVexList(self)) return this.#emit(c, info, f, this.#listOp(listOp, self, values.slice(1), f, path));\n let accepted: AnyDomain | undefined;\n // Without arguments, the receiver is undefined, and no domain of a test accepts it.\n // Stryker disable next-line ConditionalExpression,EqualityOperator: the loop finds no domain for undefined\n if (values.length > 0) {\n for (const d of this.#domains) {\n if (!safeIs(d, self)) continue;\n accepted ??= d;\n const resolved = resolveOp(d, self, op);\n if (resolved !== undefined) return this.#emit(c, info, f, this.#call(resolved, op, values.slice(1), f, path));\n }\n }\n if (fn !== undefined) return this.#emit(c, info, f, this.#checkResult(this.#invoke(() => fn(...values), op, f, path), f, path, op));\n if (accepted !== undefined) return this.#emit(c, info, f, this.#err(\"unknown-op\", `the domain \"${accepted.name}\" has no op \"${op}\"`, f, path, { op }));\n if (values.length === 0) return this.#emit(c, info, f, this.#err(\"unknown-op\", `there is no function \"${op}\"`, f, path, { op }));\n return this.#emit(c, info, f, this.#err(\"not-instance\", `no domain accepts the receiver of \"${op}\" (${describeType(self)})`, f, path, { op }));\n };\n }\n\n #special(op: SpecialForm, args: readonly Node[], info: Info): Node {\n const { path } = info;\n const arg = (i: number, f: Frame, c: Ctx): Result<unknown> => {\n const n = args[i];\n return n === undefined ? this.#err(\"bad-expression\", `\"${op}\" needs argument ${i + 1}`, f, path, { op }) : n(f, c);\n };\n const bool = (i: number, f: Frame, c: Ctx): Result<boolean> => {\n const r = arg(i, f, c);\n if (!r.ok) return r;\n return typeof r.value === \"boolean\" ? ok(r.value) : this.#err(\"kind-mismatch\", `argument ${i + 1} of \"${op}\" is a ${describeType(r.value)}, not a boolean`, f, path, { op });\n };\n switch (op) {\n case \"if\":\n return (f, c) => {\n const cond = bool(0, f, c);\n return this.#emit(c, info, f, cond.ok ? arg(cond.value ? 1 : 2, f, c) : cond);\n };\n case \"and\":\n case \"or\": {\n const stop = op === \"or\";\n return (f, c) => {\n if (args.length === 0) return this.#emit(c, info, f, this.#err(\"bad-expression\", `\"${op}\" needs at least 1 argument`, f, path, { op }));\n for (let i = 0; i < args.length; i++) {\n const b = bool(i, f, c);\n if (!b.ok) return this.#emit(c, info, f, b);\n if (b.value === stop) return this.#emit(c, info, f, ok(b.value));\n }\n return this.#emit(c, info, f, ok(!stop));\n };\n }\n case \"ifError\":\n return (f, c) => {\n const first = arg(0, f, c);\n // EVAL.DEPTH: ifError does not hide #DEPTH!, because the engine, not the data, failed.\n return this.#emit(c, info, f, first.ok || isDepthError(first.error) ? first : arg(1, f, c));\n };\n }\n }\n\n #call(op: ResolvedOp, name: string, rest: readonly unknown[], f: Frame, path: readonly number[]): Result<unknown> {\n const { domain, spec } = op;\n const lift = spec.liftScalar;\n const from = domain.fromScalar;\n let callArgs: readonly unknown[] = rest;\n if (lift && from !== undefined) {\n const lifted = this.#invoke(() => rest.map((a, i): unknown => (typeof a === \"number\" && liftsAt(lift, i) ? from(a) : a)), `${domain.name}.fromScalar`, f, path);\n if (!lifted.ok) return lifted;\n callArgs = lifted.value as readonly unknown[];\n }\n if (spec.params !== undefined) {\n for (let i = 0; i < callArgs.length; i++) {\n const kind = spec.params[i] ?? \"any\";\n if (!matchesKind(kind, callArgs[i], domain)) {\n const k: ErrorKind = kind === \"domain\" ? \"not-instance\" : \"kind-mismatch\";\n return this.#err(k, `argument ${i + 1} of \"${name}\" is a ${describeType(callArgs[i])}, not a ${kind === \"domain\" ? domain.name : kind}`, f, path, { op: name });\n }\n }\n }\n return this.#checkResult(this.#invoke(() => op.call(callArgs), name, f, path), f, path, name);\n }\n\n #invoke(run: () => unknown, op: string, f: Frame, path: readonly number[]): Result<unknown> {\n try {\n return ok(run());\n } catch (thrown) {\n return this.#threw(thrown, `\"${op}\" threw an exception`, f, path, { op });\n }\n }\n\n /** This method checks the value that an op gave: no `undefined`, finite numbers, and valid domain values. */\n #checkResult(r: Result<unknown>, f: Frame, path: readonly number[], op: string): Result<unknown> {\n if (!r.ok) return r;\n const value = r.value;\n const extra = { op };\n if (value === undefined || value === null) return this.#err(\"undefined-result\", `\"${op}\" gave no value`, f, path, extra);\n if (typeof value === \"number\" && !Number.isFinite(value)) return this.#err(\"not-finite\", `\"${op}\" gave ${value}`, f, path, extra);\n const d = this.#domains.find((dom) => safeIs(dom, value));\n if (d?.valid !== undefined) {\n let valid: boolean;\n try {\n valid = d.valid(value);\n } catch (thrown) {\n return this.#threw(thrown, `the \"valid\" check of \"${d.name}\" threw an exception`, f, path, extra);\n }\n if (!valid) return this.#err(\"invalid-value\", `\"${op}\" gave a value that is not a valid ${d.name}`, f, path, extra);\n }\n return r;\n }\n\n #listOp(op: ListOp, list: VexList, rest: readonly unknown[], f: Frame, path: readonly number[]): Result<unknown> {\n // The options come after the first argument of reduce, take and nth.\n const optsArg = op === \"reduce\" || op === \"take\" || op === \"nth\" ? rest[1] : rest[0];\n // A reduction that skips error items does not skip #DEPTH! (EVAL.DEPTH).\n const depth = list.items.find((it) => !it.result.ok && isDepthError(it.result.error))?.result;\n if (depth !== undefined && !depth.ok) return fail(depth.error);\n const strict = (optsArg as ListOptions | null | undefined)?.strict === true;\n const firstError = list.items.find((it) => !it.result.ok)?.result;\n if (strict && firstError !== undefined && !firstError.ok) return fail(firstError.error);\n const okValues = list.items.flatMap((it) => (it.result.ok ? [it.result.value] : []));\n const numbers = (): Result<readonly number[]> => {\n const bad = okValues.find((x) => typeof x !== \"number\");\n return bad === undefined ? ok(okValues as readonly number[]) : this.#err(\"kind-mismatch\", `\"${op}\" needs numbers, but an item is a ${describeType(bad)}`, f, path, { op });\n };\n const booleans = (): Result<readonly boolean[]> => {\n const bad = okValues.find((x) => typeof x !== \"boolean\");\n return bad === undefined ? ok(okValues as readonly boolean[]) : this.#err(\"kind-mismatch\", `\"${op}\" needs booleans, but an item is a ${describeType(bad)}`, f, path, { op });\n };\n const empty = (): Result<never> => this.#err(\"empty\", `\"${op}\" has no values to work with`, f, path, { op });\n // A count or a position of take and nth is a whole number from 0.\n const whole = (): Result<number> => {\n const n = rest[0] as number;\n return Number.isSafeInteger(n) && n >= 0 ? ok(n) : this.#err(\"kind-mismatch\", `\"${op}\" needs a whole number from 0, not ${describeType(n)}`, f, path, { op });\n };\n const okItems = list.items.filter((it) => it.result.ok);\n switch (op) {\n case \"sortBy\":\n return this.#sortBy(okItems, okValues, f, path);\n case \"take\": {\n const n = whole();\n return n.ok ? ok(vexList(okItems.slice(0, n.value))) : n;\n }\n case \"nth\": {\n const i = whole();\n if (!i.ok) return i;\n return i.value < okValues.length ? ok(okValues[i.value]) : this.#err(\"empty\", `\"nth\" has no item at the position ${String(i.value)}, and the list has ${String(okValues.length)} items`, f, path, { op });\n }\n case \"count\":\n return ok(okValues.length);\n case \"values\":\n return ok(Object.freeze([...okValues]));\n case \"keys\":\n return ok(Object.freeze(list.items.filter((it) => it.result.ok).map((it) => it.key)));\n case \"errors\":\n return ok(Object.freeze(list.items.flatMap((it) => (it.result.ok ? [] : [it.result.error]))));\n case \"first\":\n return okValues.length > 0 ? ok(okValues[0]) : empty();\n case \"sum\": {\n const n = numbers();\n return n.ok ? this.#checkResult(ok(n.value.reduce((s, x) => s + x, 0)), f, path, op) : n;\n }\n case \"mean\": {\n const n = numbers();\n if (!n.ok) return n;\n return n.value.length === 0 ? empty() : this.#checkResult(ok(n.value.reduce((s, x) => s + x, 0) / n.value.length), f, path, op);\n }\n case \"min\":\n case \"max\": {\n const n = numbers();\n if (!n.ok) return n;\n if (n.value.length === 0) return empty();\n return ok(n.value.reduce((best, x) => (op === \"min\" ? Math.min(best, x) : Math.max(best, x))));\n }\n case \"any\":\n case \"all\":\n case \"none\": {\n const b = booleans();\n if (!b.ok) return b;\n if (op === \"any\") return ok(b.value.some((x) => x));\n if (op === \"all\") return ok(b.value.every((x) => x));\n return ok(!b.value.some((x) => x));\n }\n case \"reduce\":\n return this.#reduce(rest[0], okValues, f, path, optsArg);\n }\n }\n\n /**\n * This method sorts the items of a list by their values, from the smallest (LIST.SORT). The sort is stable. The values\n * are all numbers without NaN, or all texts. Texts compare by their UTF-16 code units.\n */\n #sortBy(items: readonly ListItem[], values: readonly unknown[], f: Frame, path: readonly number[]): Result<VexList> {\n const kind = typeof values[0];\n const bad = values.findIndex((x) => typeof x !== kind || (kind !== \"number\" && kind !== \"string\") || Number.isNaN(x));\n if (bad >= 0) return this.#err(\"kind-mismatch\", `\"sortBy\" needs numbers without NaN or texts, all of one kind, but an item is ${Number.isNaN(values[bad]) ? \"NaN\" : `a ${describeType(values[bad])}`}`, f, path, { op: \"sortBy\" });\n const order = values.map((_x, i) => i).toSorted((i, j) => {\n const a = values[i] as number | string;\n const b = values[j] as number | string;\n // The sort of Node reads only a negative result, and the sort of another engine needs the whole comparison.\n // Stryker disable next-line ConditionalExpression,EqualityOperator: see the comment above\n return a < b ? -1 : a > b ? 1 : 0;\n });\n return ok(vexList(order.map((i) => items[i] as ListItem)));\n }\n\n /**\n * This method folds the values with a domain op, from the left. An empty list gives the identity of the op, if one\n * domain has an identity for the op (LIST.EMPTY). The option `domain` names that domain when more domains have one.\n */\n #reduce(opName: unknown, values: readonly unknown[], f: Frame, path: readonly number[], opts: unknown): Result<unknown> {\n if (typeof opName !== \"string\") return this.#err(\"kind-mismatch\", `\"reduce\" needs an op name, but got a ${describeType(opName)}`, f, path, { op: \"reduce\" });\n if (values.length === 0) {\n const named = (opts as { domain?: unknown } | null | undefined)?.domain;\n const candidates = this.#domains.filter((d) => Object.hasOwn(d.ops, opName) && (d.ops[opName] as { identity?: () => unknown }).identity !== undefined && (named === undefined || d.name === named));\n if (named !== undefined && !this.#domains.some((d) => d.name === named)) {\n return this.#err(\"unknown-op\", `\"reduce\" names the domain ${JSON.stringify(named)}, but the program has no such domain`, f, path, { op: opName });\n }\n const [only, second] = candidates;\n if (only === undefined) return this.#err(\"empty\", `\"reduce\" with \"${opName}\" has no values and the op has no identity`, f, path, { op: opName });\n if (second !== undefined) {\n const names = candidates.map((d) => d.name).join(\", \");\n return this.#err(\"empty\", `\"reduce\" with \"${opName}\" has no values, and more domains have an identity for it (${names}). Name one with { domain }`, f, path, { op: opName });\n }\n return this.#invoke((only.ops[opName] as { identity: () => unknown }).identity, opName, f, path);\n }\n let acc: unknown = values[0];\n for (let i = 1; i < values.length; i++) {\n const d = this.#domains.find((dom) => safeIs(dom, acc) && resolveOp(dom, acc, opName) !== undefined);\n const op = d === undefined ? undefined : resolveOp(d, acc, opName);\n if (op === undefined) return this.#err(\"unknown-op\", `no domain gives \"${opName}\" for a ${describeType(acc)}`, f, path, { op: opName });\n const r = this.#call(op, opName, [values[i]], f, path);\n if (!r.ok) return r;\n acc = r.value;\n }\n return ok(acc);\n }\n}\n\nconst FORBIDDEN_FIELDS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n/** This function tells if a segment of a path can name a field. A compiler uses the same rule as the interpreter. */\nexport const isFieldName = (seg: string): boolean => seg.length > 0 && !FORBIDDEN_FIELDS.has(seg);\n\n/** This function runs the `is` test of a domain. A test that throws counts as `false`. */\n// Stryker disable BlockStatement: an empty catch gives undefined, which also counts as false\nexport function safeIs(d: AnyDomain, value: unknown): boolean {\n try {\n return d.is(value);\n } catch {\n return false;\n }\n}\n// Stryker restore BlockStatement\n\n\n/** This function tells if an argument has the kind of a parameter of an op of the domain `domain`. */\nexport function matchesKind(kind: ParamKind, value: unknown, domain: AnyDomain): boolean {\n switch (kind) {\n case \"domain\":\n return safeIs(domain, value);\n case \"number\":\n return typeof value === \"number\";\n case \"boolean\":\n return typeof value === \"boolean\";\n case \"string\":\n return typeof value === \"string\";\n case \"any\":\n return true;\n }\n}\n\n/** This function gives a short name for the type of a value, for error messages. */\nexport function describeType(u: unknown): string {\n if (u === null) return \"null\";\n if (Array.isArray(u)) return \"array\";\n if (isVexList(u)) return \"list\";\n if (typeof u === \"object\") {\n const name = (Object.getPrototypeOf(u) as { constructor?: { name?: unknown } } | null)?.constructor?.name;\n return typeof name === \"string\" && name !== \"Object\" ? name : \"object\";\n }\n return typeof u;\n}\n\n/** This function gives the label of a node, for traces. */\nexport function labelOf(e: Expr): string {\n switch (e.tag) {\n case \"lit\":\n return previewValue(e.value);\n case \"ref\":\n return e.path.length === 0 ? \"(record)\" : e.path.join(\".\");\n case \"app\":\n return e.op;\n case \"let\":\n return `let ${Object.keys(e.bind).join(\", \")}`;\n // A function makes no event of the trace, so its label only completes the switch.\n // Stryker disable next-line all: see the comment above\n case \"fn\": return `fn (${e.params.join(\", \")})`;\n case \"call\":\n return `call ${e.fn}`;\n case \"var\":\n return e.name;\n case \"rec\":\n return `{ ${Object.keys(e.fields).join(\", \")} }`;\n case \"each\":\n case \"fold\":\n return e.at === undefined ? `${e.tag} ${e.axis.t}` : `${e.tag} ${e.axis.t} from ${e.at.map(moveText).join(\".\")}`;\n case \"iterate\":\n return `iterate ${String(e.limit)}`;\n case \"ext\":\n return e.kind;\n }\n}\n\n/** This function gives a short text for a move, for the label of an axis with an address. */\nfunction moveText(m: Move): string {\n switch (m.t) {\n case \"key\":\n return `key(${typeof m.key === \"string\" ? m.key : labelOf(m.key)})`;\n case \"index\":\n return `index(${typeof m.i === \"number\" ? String(m.i) : labelOf(m.i)})`;\n case \"offset\":\n return `offset(${m.d.join(\", \")})`;\n case \"other\":\n case \"origin\":\n case \"parent\":\n return m.t;\n }\n}\n\n/** This function gives a short text for a value. */\nexport function previewValue(u: unknown): string {\n // JSON has no NaN and no Infinity, so a number gets its own text. JSON gives the text of the other primitives.\n if (typeof u === \"number\") return String(u);\n if (isVexList(u)) return `list(${u.items.length})`;\n try {\n const json = JSON.stringify(u);\n // A function, a symbol and undefined have no JSON form.\n // Stryker disable next-line ConditionalExpression: without the test, undefined.length throws, and the catch gives the same text\n if (json !== undefined) return json.length > 60 ? `${json.slice(0, 57)}...` : json;\n } catch {\n // A value with cycles has no JSON form.\n }\n return describeType(u);\n}\n\n// The reads of a reference show the key and the path, for example \"read B.position\" or \"no value at A.mass\".\nconst formatRead = (r: Read): string => `${r.ok ? \"read\" : \"no value at\"} ${r.key}.${r.path.length === 0 ? \"(record)\" : r.path.join(\".\")}`;\n\n/**\n * This function gives a text form of a trace. Each event has one line, in finish order. The indent of a line\n * shows the depth of the node. A domain with `show` gives the text of its values. The golden tests compare this text.\n */\n// Stryker disable next-line ArrayDeclaration: a list with a value that is not a domain shows no value\nexport function formatTrace(trace: Trace, domains: readonly AnyDomain[] = []): string {\n const show = (u: unknown): string => {\n if (isVexList(u)) return `[${u.items.map((it) => `${it.key}: ${result(it.result)}`).join(\", \")}]`;\n const d = domains.find((dom) => dom.show !== undefined && safeIs(dom, u));\n try {\n // Stryker disable next-line ConditionalExpression,OptionalChaining: without a domain, d.show throws, and the catch gives the same text\n if (d?.show !== undefined) return d.show(u);\n } catch {\n // A show function that throws gives the default text.\n }\n return previewValue(u);\n };\n const result = (r: Result<unknown>): string => (r.ok ? show(r.value) : formatError(r.error));\n const line = (e: TraceEvent): string => {\n const reads = e.reads === undefined ? \"\" : ` [${e.reads.map(formatRead).join(\", \")}]`;\n return `${\" \".repeat(e.path.length)}${e.label} @${e.focus}${reads} = ${result(e.result)}`;\n };\n const lines = trace.events.map(line);\n return [...lines, `result = ${result(trace.result)}`, \"\"].join(\"\\n\");\n}\n\n/** This function gives the number of nodes of an expression. */\nexport const sizeOf = (e: Expr): number => 1 + children(e).reduce((s, c) => s + sizeOf(c), 0);\n","import { addrExprs, children, listOf, type Addr, type Axis, type Expr, type ExprOf } from \"./ir.ts\";\n\n/** A bound function: its node, and the functions of the place of its binding. */\ninterface Bound {\n readonly fn: ExprOf<\"fn\">;\n readonly fns: ReadonlyMap<string, Bound>;\n}\n\n/** This function gives the functions of a scope without some names: a parameter or a binding hides a function. */\nconst without = (fns: ReadonlyMap<string, Bound>, names: readonly string[]): ReadonlyMap<string, Bound> => new Map([...fns].filter(([n]) => !names.includes(n)));\n\n/**\n * This function gives the functions that each child of a node sees. The names of a loop hide the functions with those\n * names in its steps, its test of until and its result. The values of init, the tests of where and an address see the\n * functions outside.\n */\nfunction childFns(x: Expr, fns: ReadonlyMap<string, Bound>, count: number): (i: number) => ReadonlyMap<string, Bound> {\n if (x.tag !== \"fold\" && x.tag !== \"iterate\") return () => fns;\n const hidden = without(fns, Object.keys(x.init));\n const first = Object.keys(x.init).length;\n const steps = first + Object.keys(x.step).length;\n // The children of a fold have the tests of where and the address between the steps and the result.\n return (i) => (i >= first && (i < steps || i === count - 1 || x.tag === \"iterate\") ? hidden : fns);\n}\n\n/** One static read of a program: a field path at an address, inside zero or more axes. */\nexport interface Dependency {\n /** The address of the read. The empty address is the focus. */\n readonly at: Addr;\n /** The field path of the read. */\n readonly path: readonly string[];\n /** The axes around the read, from the outside to the inside. Inside an axis, the focus is the target. */\n readonly axes: readonly Axis[\"t\"][];\n /** The address of each axis in `axes`, in the same order. The empty address is the focus. */\n readonly axisAt: readonly Addr[];\n}\n\n/**\n * This function gives the static reads of an expression. A host can use them to recompute a program only\n * when a field that it reads changes. A computed move reads a key that only a run knows. Its address keeps the\n * expression, and the reads of that expression are in the list too (NAV.COMPUTED).\n */\nexport function deps(e: Expr): readonly Dependency[] {\n const out: Dependency[] = [];\n // A stack, not recursion, so a deep expression needs no deep call stack. The children go on the stack in reverse\n // order, so the reads come out in the order of a depth-first walk.\n type Item = { readonly x: Expr; readonly axes: readonly Axis[\"t\"][]; readonly axisAt: readonly Addr[]; readonly fns: ReadonlyMap<string, Bound> };\n const todo: Item[] = [{ x: e, axes: [], axisAt: [], fns: new Map() }];\n for (let item = todo.pop(); item !== undefined; item = todo.pop()) {\n const { x } = item;\n if (x.tag === \"ref\") out.push({ at: x.at ?? [], path: x.path, axes: item.axes, axisAt: item.axisAt });\n // A function reads at each call, inside the axes of the call (FN.CALL). Its body does not read where it is bound.\n if (x.tag === \"let\") {\n const names = Object.keys(x.bind);\n const inner = new Map(without(item.fns, names));\n for (const [name, b] of Object.entries(x.bind)) if (b.tag === \"fn\") inner.set(name, { fn: b, fns: item.fns });\n todo.push({ ...item, x: x.body, fns: inner });\n for (const b of Object.values(x.bind).toReversed()) if (b.tag !== \"fn\") todo.push({ ...item, x: b });\n continue;\n }\n if (x.tag === \"call\") {\n const bound = item.fns.get(x.fn);\n if (bound !== undefined) todo.push({ ...item, x: bound.fn.body, fns: without(bound.fns, bound.fn.params) });\n for (const a of x.args.toReversed()) todo.push({ ...item, x: a });\n continue;\n }\n const all = children(x);\n const fnsOf = childFns(x, item.fns, all.length);\n const axial = x.tag === \"each\" || x.tag === \"fold\";\n // Inside the axis: the body or the values of the step, and the tests of where. The values of init, the result of a\n // fold, the list of the axis list and the expressions of an address evaluate at the node, outside the axis.\n const first = x.tag === \"fold\" ? Object.keys(x.init).length : 0;\n const last = axial ? all.length - addrExprs(x.at).length - (x.tag === \"fold\" ? 1 : 0) : 0;\n // The list of the axis list comes after the body or the values of the step, before the tests of where.\n const listAt = axial && listOf(x.axis) !== undefined ? (x.tag === \"fold\" ? first + Object.keys(x.step).length : 1) : -1;\n const axes = axial ? [...item.axes, x.axis.t] : item.axes;\n const axisAt = axial ? [...item.axisAt, x.at ?? []] : item.axisAt;\n for (let i = all.length - 1; i >= 0; i--) {\n const inside = i >= first && i < last && i !== listAt;\n todo.push({ x: all[i] as Expr, axes: inside ? axes : item.axes, axisAt: inside ? axisAt : item.axisAt, fns: fnsOf(i) });\n }\n }\n return out;\n}\n","import type { AnyDomain } from \"./domain.ts\";\nimport { isStackOverflow, vexError } from \"./errors.ts\";\nimport { isExpr, type Expr } from \"./ir.ts\";\nimport { fail, ok, type Result } from \"./result.ts\";\n\n/**\n * The JSON form of the values in a literal. JSON data stays as it is, with three exceptions. Each exception is a record\n * with the key `$vex`:\n *\n * - `{ \"$vex\": \"domain\", \"domain\": name, \"value\": v }`: a value of a domain, with the `encode` of the domain.\n * - `{ \"$vex\": \"number\", \"value\": \"-0\" }`: a number that JSON has no text for: `-0`, `NaN`, `Infinity` or `-Infinity`.\n * - `{ \"$vex\": \"escape\", \"value\": record }`: a record of the data that has the key `$vex` itself (IR.JSON.ESCAPE).\n *\n * A record with the key `$vex` and another form stays data, so a file from an older version reads as before.\n *\n * The functions walk the tree of the expression, so only the value of a literal gets this form. A field of a literal\n * that looks like an expression stays data. The data of an extension is plain JSON, as before.\n */\ntype Encoded =\n | { readonly $vex: \"domain\"; readonly domain: string; readonly value: unknown }\n | { readonly $vex: \"number\"; readonly value: \"-0\" | \"NaN\" | \"Infinity\" | \"-Infinity\" }\n | { readonly $vex: \"escape\"; readonly value: Readonly<Record<string, unknown>> };\n\nconst isRecord = (u: unknown): u is Readonly<Record<string, unknown>> => typeof u === \"object\" && u !== null && !Array.isArray(u);\n\nconst isPlainRecord = (u: unknown): u is Readonly<Record<string, unknown>> => {\n if (!isRecord(u)) return false;\n const proto: unknown = Object.getPrototypeOf(u);\n return proto === Object.prototype || proto === null;\n};\n\n/** This function gives the JSON form of a value, or the reason why the value has no JSON form. */\nfunction encodeValue(u: unknown, domains: readonly AnyDomain[]): Result<unknown> {\n if (u === null || typeof u === \"string\" || typeof u === \"boolean\") return ok(u);\n if (typeof u === \"number\") {\n if (Object.is(u, -0)) return ok({ $vex: \"number\", value: \"-0\" } satisfies Encoded);\n // Stryker disable next-line EqualityOperator: here u is an infinity, so u > 0 and u >= 0 are the same test\n return Number.isFinite(u) ? ok(u) : ok({ $vex: \"number\", value: Number.isNaN(u) ? \"NaN\" : u > 0 ? \"Infinity\" : \"-Infinity\" } satisfies Encoded);\n }\n if (Array.isArray(u)) {\n const out: unknown[] = [];\n for (const x of u) {\n const r = encodeValue(x, domains);\n if (!r.ok) return r;\n out.push(r.value);\n }\n return ok(out);\n }\n if (isPlainRecord(u)) {\n const out: Record<string, unknown> = {};\n for (const [k, x] of Object.entries(u)) {\n const r = encodeValue(x, domains);\n if (!r.ok) return r;\n out[k] = r.value;\n }\n return ok(Object.hasOwn(u, \"$vex\") ? ({ $vex: \"escape\", value: out } satisfies Encoded) : out);\n }\n // A plain array or record stays data. Another object is a value of a domain, or it has no JSON form.\n const d = domains.find((dom) => dom.encode !== undefined && dom.is(u));\n if (d?.encode !== undefined) return ok({ $vex: \"domain\", domain: d.name, value: d.encode(u) } satisfies Encoded);\n return fail(vexError(\"bad-expression\", \"a literal value is not JSON data and no domain encodes it\"));\n}\n\nconst NUMBERS: Readonly<Record<string, number>> = { \"-0\": -0, NaN: Number.NaN, Infinity: Number.POSITIVE_INFINITY, \"-Infinity\": Number.NEGATIVE_INFINITY };\n\n/** This function reads a value from its JSON form. */\nfunction decodeValue(u: unknown, domains: readonly AnyDomain[]): Result<unknown> {\n if (Array.isArray(u)) {\n const out: unknown[] = [];\n for (const x of u) {\n const r = decodeValue(x, domains);\n if (!r.ok) return r;\n out.push(r.value);\n }\n return ok(out);\n }\n if (!isRecord(u)) return ok(u);\n const fields = (record: Readonly<Record<string, unknown>>): Result<unknown> => {\n const out: Record<string, unknown> = {};\n for (const [k, x] of Object.entries(record)) {\n const r = decodeValue(x, domains);\n if (!r.ok) return r;\n out[k] = r.value;\n }\n return ok(out);\n };\n // A record without the key $vex matches none of the forms below, so it stays data too.\n const kind = u[\"$vex\"];\n if (kind === \"escape\" && isRecord(u[\"value\"])) return fields(u[\"value\"]);\n if (kind === \"number\" && typeof u[\"value\"] === \"string\" && Object.hasOwn(NUMBERS, u[\"value\"])) return ok(NUMBERS[u[\"value\"]]);\n if (kind === \"domain\" && typeof u[\"domain\"] === \"string\") {\n const name = u[\"domain\"];\n const d = domains.find((dom) => dom.name === name);\n if (d?.decode === undefined) return fail(vexError(\"bad-expression\", `no domain \"${name}\" decodes a literal`));\n return ok(d.decode(u[\"value\"]));\n }\n // A form that this version does not know stays data, so a file from an older version reads as before.\n return fields(u);\n}\n\n/** This function applies `f` to each literal value of a JSON tree of an expression. */\nfunction mapValues(u: unknown, f: (value: unknown) => Result<unknown>): Result<unknown> {\n if (!isRecord(u)) return ok(u);\n const out: Record<string, unknown> = { ...u };\n const child = (key: string): Result<unknown> | undefined => {\n const r = mapValues(u[key], f);\n if (r.ok) out[key] = r.value;\n return r.ok ? undefined : r;\n };\n const each = (key: string): Result<unknown> | undefined => {\n const list = u[key];\n if (Array.isArray(list)) {\n const items: unknown[] = [];\n for (const x of list) {\n const r = mapValues(x, f);\n if (!r.ok) return r;\n items.push(r.value);\n }\n out[key] = items;\n } else if (isRecord(list)) {\n const rec: Record<string, unknown> = {};\n for (const [k, x] of Object.entries(list)) {\n const r = mapValues(x, f);\n if (!r.ok) return r;\n rec[k] = r.value;\n }\n out[key] = rec;\n }\n return undefined;\n };\n // The expression of a computed move is a tree of the expression too (NAV.COMPUTED).\n const address = (): Result<unknown> | undefined => {\n const at = u[\"at\"];\n if (!Array.isArray(at)) return undefined;\n const moves: unknown[] = [];\n for (const m of at) {\n const field = isRecord(m) ? (m[\"t\"] === \"key\" ? \"key\" : m[\"t\"] === \"index\" ? \"i\" : undefined) : undefined;\n if (field === undefined || !isRecord(m) || !isRecord(m[field])) {\n moves.push(m);\n continue;\n }\n const r = mapValues(m[field], f);\n if (!r.ok) return r;\n moves.push({ ...m, [field]: r.value });\n }\n out[\"at\"] = moves;\n return undefined;\n };\n // The test of where and the list of the axis list are expressions, also inside reverse.\n const axis = (a: unknown): Result<unknown> => {\n if (!isRecord(a)) return ok(a);\n if (a[\"t\"] === \"list\") {\n const list = mapValues(a[\"list\"], f);\n return list.ok ? ok({ ...a, list: list.value }) : list;\n }\n if (a[\"t\"] === \"reverse\") {\n const inner = axis(a[\"axis\"]);\n return inner.ok ? ok({ ...a, axis: inner.value }) : inner;\n }\n if (a[\"t\"] !== \"where\") return ok(a);\n const inner = axis(a[\"axis\"]);\n if (!inner.ok) return inner;\n const test = mapValues(a[\"test\"], f);\n return test.ok ? ok({ ...a, axis: inner.value, test: test.value }) : test;\n };\n switch (u[\"tag\"]) {\n case \"lit\": {\n if (!Object.hasOwn(u, \"value\")) return ok(out);\n const r = f(u[\"value\"]);\n if (!r.ok) return r;\n out[\"value\"] = r.value;\n return ok(out);\n }\n case \"app\":\n return each(\"args\") ?? ok(out);\n case \"let\":\n return each(\"bind\") ?? child(\"body\") ?? ok(out);\n case \"rec\":\n return each(\"fields\") ?? ok(out);\n case \"each\": {\n const a = axis(u[\"axis\"]);\n if (!a.ok) return a;\n out[\"axis\"] = a.value;\n return child(\"body\") ?? address() ?? ok(out);\n }\n case \"fold\": {\n const a = axis(u[\"axis\"]);\n if (!a.ok) return a;\n out[\"axis\"] = a.value;\n return each(\"init\") ?? each(\"step\") ?? child(\"result\") ?? address() ?? ok(out);\n }\n case \"iterate\":\n return each(\"init\") ?? each(\"step\") ?? (u[\"until\"] === undefined ? undefined : child(\"until\")) ?? child(\"result\") ?? ok(out);\n case \"fn\":\n return child(\"body\") ?? ok(out);\n case \"call\":\n return each(\"args\") ?? ok(out);\n case \"ref\":\n return address() ?? ok(out);\n default:\n return ok(out);\n }\n}\n\n/**\n * This function gives the JSON text of an expression. A literal value that is a domain value needs a domain with\n * `encode`. A literal value that is not JSON data and has no such domain gives the error `#VALUE!`.\n */\n// Stryker disable next-line ArrayDeclaration: a list with a value that is not a domain encodes no value\nexport function serialize(e: Expr, domains: readonly AnyDomain[] = []): Result<string> {\n try {\n // A getter of a literal value can throw, so the encoding is inside the try too.\n const tree = mapValues(e, (v) => encodeValue(v, domains));\n return tree.ok ? ok(JSON.stringify(tree.value)) : fail(tree.error);\n } catch (thrown) {\n if (isStackOverflow(thrown)) return fail(vexError(\"depth\", \"the expression is too deep for the call stack of the engine\", { thrown }));\n return fail(vexError(\"threw\", \"the expression has no JSON form\", { thrown }));\n }\n}\n\n/** This function reads an expression from JSON text. It checks the whole tree. */\n// Stryker disable next-line ArrayDeclaration: a list with a value that is not a domain decodes no value\nexport function parse(text: string, domains: readonly AnyDomain[] = []): Result<Expr> {\n let raw: unknown;\n try {\n raw = JSON.parse(text);\n } catch (thrown) {\n return fail(vexError(\"bad-expression\", \"the text is not JSON\", { thrown }));\n }\n try {\n const tree = mapValues(raw, (v) => decodeValue(v, domains));\n if (!tree.ok) return fail(tree.error);\n return isExpr(tree.value) ? ok(tree.value) : fail(vexError(\"bad-expression\", \"the JSON is not a valid Vex expression\"));\n } catch (thrown) {\n // A JSON text nested deeper than the call stack, or a decoder of a domain that throws.\n if (isStackOverflow(thrown)) return fail(vexError(\"depth\", \"the JSON is too deep for the call stack of the engine\", { thrown }));\n return fail(vexError(\"threw\", \"a decoder of a domain threw an exception\", { thrown }));\n }\n}\n","import type { AnyDomain } from \"./domain.ts\";\nimport { vexError, type VexError } from \"./errors.ts\";\nimport { evaluate, type FreeFn } from \"./evaluate.ts\";\nimport { app, lit, v } from \"./ir.ts\";\nimport { vexList, type ListItem } from \"./list.ts\";\nimport { fail, none, ok, toOptional, type Optional, type Result } from \"./result.ts\";\nimport { space as spaces, type Space } from \"./space.ts\";\n\n/** A monoid: an associative `concat` with an identity element `empty`. */\nexport interface Monoid<M> {\n readonly empty: M;\n readonly concat: (a: M, b: M) => M;\n}\n\n/** Standard monoids. */\nexport const monoids: {\n readonly sum: Monoid<number>;\n readonly product: Monoid<number>;\n readonly all: Monoid<boolean>;\n readonly any: Monoid<boolean>;\n} = {\n sum: { empty: 0, concat: (a, b) => a + b },\n product: { empty: 1, concat: (a, b) => a * b },\n all: { empty: true, concat: (a, b) => a && b },\n any: { empty: false, concat: (a, b) => a || b },\n};\n\n/** One item of a traversal: the start key and the result there. */\nexport interface TraversalItem<K extends string, T> {\n readonly key: K;\n readonly result: Result<T>;\n}\n\n/**\n * A traversal: the results of one program at each start key. The reductions skip error items by default.\n * After `strict()`, an error item makes the reduction that error.\n */\nexport interface Traversal<K extends string, T> {\n readonly items: readonly TraversalItem<K, T>[];\n /** This method gives a traversal whose reductions fail on the first error item. */\n strict(): Traversal<K, T>;\n /** This method gives the result at one key. */\n get(k: K): Optional<T>;\n /** The values of the items without errors. */\n values(): readonly T[];\n /** The keys of the items without errors. */\n keys(): readonly K[];\n /** The errors of the items with errors. */\n errors(): readonly VexError[];\n count(): Optional<number>;\n sum(this: Traversal<K, number>): Optional<number>;\n mean(this: Traversal<K, number>): Optional<number>;\n min(this: Traversal<K, number>): Optional<number>;\n max(this: Traversal<K, number>): Optional<number>;\n any(this: Traversal<K, boolean>): Optional<boolean>;\n all(this: Traversal<K, boolean>): Optional<boolean>;\n none(this: Traversal<K, boolean>): Optional<boolean>;\n /** This method folds the values with a domain op, from the left. */\n reduce(op: string): Optional<T>;\n /** This method gives the result of a reduction, with its error. */\n reduceResult(op: \"count\" | \"sum\" | \"mean\" | \"min\" | \"max\" | \"any\" | \"all\" | \"none\" | \"reduce\", reduceOp?: string): Result<unknown>;\n /** This method maps each value with `f`. If `f` throws, the item has the error `#CALC!`. */\n map<U>(f: (value: T, key: K) => U): Traversal<K, U>;\n /** This method folds the values with a monoid. */\n fold<M>(monoid: Monoid<M>, f: (value: T) => M): M;\n}\n\ninterface TraversalEnv {\n readonly domains: readonly AnyDomain[];\n readonly options?: { readonly fns?: Readonly<Record<string, FreeFn>> };\n}\n\nconst EMPTY_SPACE: Space = spaces.record({ $: {} });\n\nconst opt = <U>(r: Result<unknown>): Optional<U> => toOptional(r as Result<U>);\n\n/** This function makes a traversal from items. */\nexport function traversal<K extends string, T>(items: readonly TraversalItem<K, T>[], env: TraversalEnv, isStrict = false): Traversal<K, T> {\n const reduce = (op: string, reduceOp?: string): Result<unknown> => {\n const list = vexList(items as readonly ListItem[]);\n const args = [v(\"$list\"), ...(reduceOp === undefined ? [] : [lit(reduceOp)]), ...(isStrict ? [lit({ strict: true })] : [])];\n return evaluate(app(op, ...args), {\n space: EMPTY_SPACE,\n origin: \"$\",\n domains: env.domains,\n vars: { $list: list },\n });\n };\n const t: Traversal<K, T> = {\n items,\n strict: () => traversal(items, env, true),\n get: (k) => {\n const item = items.find((it) => it.key === k);\n return item === undefined ? none() : toOptional(item.result);\n },\n values: () => items.flatMap((it) => (it.result.ok ? [it.result.value] : [])),\n keys: () => items.flatMap((it) => (it.result.ok ? [it.key] : [])),\n errors: () => items.flatMap((it) => (it.result.ok ? [] : [it.result.error])),\n count: () => opt(reduce(\"count\")),\n sum: () => opt(reduce(\"sum\")),\n mean: () => opt(reduce(\"mean\")),\n min: () => opt(reduce(\"min\")),\n max: () => opt(reduce(\"max\")),\n any: () => opt(reduce(\"any\")),\n all: () => opt(reduce(\"all\")),\n none: () => opt(reduce(\"none\")),\n reduce: (op) => opt(reduce(\"reduce\", op)),\n reduceResult: (op, reduceOp) => reduce(op, reduceOp),\n map: <U>(f: (value: T, key: K) => U): Traversal<K, U> =>\n traversal(\n items.map((it): TraversalItem<K, U> => {\n if (!it.result.ok) return { key: it.key, result: it.result };\n try {\n return { key: it.key, result: ok(f(it.result.value, it.key)) };\n } catch (thrown) {\n return { key: it.key, result: fail(vexError(\"threw\", \"the map function threw an exception\", { thrown, focus: it.key })) };\n }\n }),\n env,\n isStrict,\n ),\n fold: <M>(monoid: Monoid<M>, f: (value: T) => M): M => t.values().reduce((acc, x) => monoid.concat(acc, f(x)), monoid.empty),\n };\n return t;\n}\n","/**\n * Sheets: named columns of formulas over a space. A formula can read a column at an address, like a cell\n * reference of a spreadsheet. A cell is one column at one key. A run evaluates each cell once, and each cell on a\n * cycle of reads gives `#CYCLE!`.\n *\n * A cell reference is the extension node `ext(\"vex.cell\", { column, at })`. Thus the IR has no new kind, and the\n * JSON form, `deps` and the traces work without a change.\n *\n * A cell can have its own formula. That formula replaces the formula of the column at the key of the cell. A\n * spreadsheet has the same thing: a cell with a formula that is different from the other formulas of its column.\n */\nimport { vexError } from \"./errors.ts\";\nimport { evaluate, explain, nestingOf, type CompileOptions, type EvalOptions, type ExtHandler, type Program } from \"./evaluate.ts\";\nimport { addrExprs, children, ext, isMove, listOf, moveExpr, shapeError, type Axis, type Expr, type FixedMove, type Move } from \"./ir.ts\";\nimport { fail, type Result } from \"./result.ts\";\nimport { resolveAddr, type Space } from \"./space.ts\";\nimport type { Trace } from \"./trace.ts\";\n\n/** The extension kind of a cell reference. */\nexport const CELL_KIND = \"vex.cell\";\n\n/**\n * The data of a cell reference: the column, and the address from the focus. The data of an extension is not an\n * expression, so the address has only fixed moves.\n */\nexport interface CellRef {\n readonly column: string;\n readonly at: readonly FixedMove[];\n}\n\n/** This function makes a cell reference: the column `column` at the address `at` from the focus. */\nexport const cell = (column: string, at: readonly FixedMove[] = []): Expr => ext(CELL_KIND, { column, at } satisfies CellRef);\n\nconst isCellRef = (u: unknown): u is CellRef =>\n typeof u === \"object\" &&\n u !== null &&\n typeof (u as { column?: unknown }).column === \"string\" &&\n Array.isArray((u as { at?: unknown }).at) &&\n (u as { at: readonly unknown[] }).at.every((m) => isMove(m) && moveExpr(m) === undefined);\n\n/** The formulas of single cells: for each column, the formula of each key that has its own formula. */\nexport type CellFormulas = ReadonlyMap<string, ReadonlyMap<string, Expr>>;\n\n/** A table of a run: its space, the formulas of its columns, and the formulas of its cells. */\nexport interface SheetTable {\n readonly space: Space;\n readonly columns: ReadonlyMap<string, Expr>;\n readonly cells?: CellFormulas;\n}\n\n/** The options of a sheet run: the evaluation options without the origin and the trace, and the tables. */\nexport type SheetOptions = Omit<EvalOptions, \"origin\" | \"trace\" | \"tables\"> & {\n /** The cells with their own formula. The formula of a cell replaces the formula of its column at its key. */\n readonly cells?: CellFormulas;\n /** The name of this table, so the axis `table(name)` in a formula of another table can read it. */\n readonly name?: string;\n /** The other tables, by name (SHEET.TABLES). A cell reference reads the table of the space where it evaluates. */\n readonly tables?: ReadonlyMap<string, SheetTable>;\n /**\n * The compiler of the formulas of the columns (SHEET.COMPILE), for example `tiered` of `@mark1russell7/vex-compiler`.\n * Without a compiler, the interpreter evaluates each formula. The compiled program must give the results of the\n * interpreter.\n */\n readonly compile?: CompileFn;\n};\n\n/** A compiler of the formulas of the columns of a run. */\nexport type CompileFn = (expr: Expr, options: CompileOptions) => Program;\n\n/**\n * The compiled programs of the formulas of the columns: one entry for each formula, for the last compiler and options.\n * A compiled program reads the cells of the active run, so each run with the same compiler and options can use it.\n */\nconst PROGRAMS = new WeakMap<Expr, { readonly compile: CompileFn; readonly domains: unknown; readonly fns: unknown; readonly extensions: unknown; readonly program: Program }>();\n\n/** The key of the options without extensions, for the extensions of the compiled programs. */\nconst NO_EXTENSIONS = {};\n\n/** The state of one table in a run. */\ninterface Table {\n /** The words for the table in a message: \"the sheet\" for the main table, or the table and its name. */\n readonly where: string;\n /** A short text for the ids of the cells of the table. */\n readonly tag: string;\n readonly space: Space;\n readonly columns: ReadonlyMap<string, Expr>;\n readonly cells: CellFormulas;\n // For each column, the number of keys at the start of the key order that a warm-up evaluated.\n readonly warmed: Map<string, number>;\n // The position of each key in the key order, made at the first warm-up.\n index: ReadonlyMap<string, number> | undefined;\n /** The result of each finished cell: for each column, the result at each key. */\n readonly done: Map<string, Map<string, Result<unknown>>>;\n}\n\nconst cycleError = (column: string, key: string): Result<never> =>\n fail(vexError(\"cycle\", `the cell \"${column}\" at \"${key}\" is on a cycle of cell references`, { origin: key, focus: key }));\n\n/** The id of a cell. */\nconst idOf = (t: Table, column: string, key: string): string => `${t.tag}\\u0001${column}\\u0000${key}`;\n\n/** This function gives the state of a table at the start of a run. */\nconst tableState = (where: string, i: number, t: SheetTable): Table => ({ where, tag: String(i), space: t.space, columns: t.columns, cells: t.cells ?? new Map(), warmed: new Map(), index: undefined, done: new Map() });\n\n/** This function gives the result of a finished cell, or `undefined`. */\nconst doneOf = (t: Table, column: string, key: string): Result<unknown> | undefined => t.done.get(column)?.get(key);\n\n/** This function keeps the result of a finished cell. */\nfunction setDone(t: Table, column: string, key: string, result: Result<unknown>): void {\n let results = t.done.get(column);\n if (results === undefined) {\n results = new Map();\n t.done.set(column, results);\n }\n results.set(key, result);\n}\n\n/** A direction of the reads of a column from itself: to an earlier key, to a later key, or down a tree to the children. */\ntype Direction = \"before\" | \"after\" | \"down\";\n\n/** This function adds the direction of one move or one axis of a read of a column from itself. */\nfunction addDirection(d: Set<Direction>, m: Move | Axis): void {\n // The reverse order reads the same keys as its axis.\n if (m.t === \"reverse\") {\n addDirection(d, m.axis);\n return;\n }\n if (m.t === \"offset\" || m.t === \"window\") {\n // An offset moves by its first step that is not 0. A window reads the keys from `from` to `to`.\n const steps = m.t === \"offset\" ? [m.d.find((x) => x !== 0) ?? 0] : [m.from, m.to];\n // A step of 0 reads the cell itself, which is a cycle in each order.\n // Stryker disable next-line EqualityOperator: see the comment above\n if (steps.some((x) => x < 0)) d.add(\"before\");\n // Stryker disable next-line EqualityOperator: see the comment above\n if (steps.some((x) => x > 0)) d.add(\"after\");\n } else if (m.t === \"children\" || m.t === \"descendants\") d.add(\"down\");\n // The items of a list can be at each key, so the axis list gives no direction, and the other reads decide the order.\n}\n\n/** This function gives the base axis of an axis, and the tests of its `where` axes. */\nfunction partsOf(axis: Axis): { readonly base: Axis; readonly tests: readonly Expr[] } {\n const tests: Expr[] = [];\n let base = axis;\n while (base.t === \"where\") {\n tests.push(base.test);\n base = base.axis;\n }\n return { base, tests };\n}\n\n/**\n * This function gives the columns that the formulas of the column `self` read with a cell reference: its formula and\n * the formulas of its cells. It also gives the directions of their reads of the column itself. A read in the body or\n * in a test of an axis also has the direction of that axis. It walks each expression with a stack, not with recursion.\n */\nfunction readsOf(t: Table, self: string): { readonly columns: ReadonlySet<string>; readonly directions: ReadonlySet<Direction> } {\n const columns = new Set<string>();\n const directions = new Set<Direction>();\n const formula = t.columns.get(self);\n // An expression that is not valid reads no column. Its evaluation gives the error (EVAL.SHAPE).\n const todo: [Expr, Axis | undefined][] = [...(formula === undefined ? [] : [formula]), ...(t.cells.get(self)?.values() ?? [])].filter((e) => shapeError(e) === undefined).map((e) => [e, undefined]);\n for (let item = todo.pop(); item !== undefined; item = todo.pop()) {\n const [e, axis] = item;\n if (e.tag === \"each\" || e.tag === \"fold\") {\n const { base, tests } = partsOf(e.axis);\n for (const x of [...(e.tag === \"each\" ? [e.body] : Object.values(e.step)), ...tests]) todo.push([x, base]);\n // The values of init, the result of a fold, the list of the axis list and the expressions of the address evaluate\n // at the node, so they keep the outer direction.\n const list = listOf(e.axis);\n for (const x of [...(e.tag === \"fold\" ? [...Object.values(e.init), e.result] : []), ...addrExprs(e.at), ...(list === undefined ? [] : [list])]) todo.push([x, axis]);\n } else if (e.tag !== \"ext\") {\n for (const child of children(e)) todo.push([child, axis]);\n // The data of an extension of another kind can look like a cell reference. It only changes the order of a fill.\n // Stryker disable next-line ConditionalExpression,LogicalOperator: see the comment above\n } else if (e.kind === CELL_KIND && isCellRef(e.data)) {\n columns.add(e.data.column);\n // The directions of the reads of another column only change the order of a fill, because that column comes first.\n // Stryker disable next-line ConditionalExpression: see the comment above\n if (e.data.column === self) for (const m of [...(axis === undefined ? [] : [axis]), ...e.data.at]) addDirection(directions, m);\n }\n }\n return { columns, directions };\n}\n\n/**\n * This function gives the columns of a table in an order where each column comes after the columns that it reads.\n * The columns of a cycle keep their order. The columns with formulas of cells only come last.\n */\nfunction columnOrder(t: Table): readonly string[] {\n const names = new Set([...t.columns.keys(), ...t.cells.keys()]);\n let left = [...names].map((c) => ({ c, needs: [...readsOf(t, c).columns].filter((x) => x !== c && names.has(x)) }));\n const order: string[] = [];\n const placed = new Set<string>();\n // Each pass places each column whose reads are placed. A pass that places no column leaves a cycle, so it places\n // the first column that is left.\n while (left.length > 0) {\n const ready = left.filter((x) => x.needs.every((n) => placed.has(n)));\n for (const x of ready.length > 0 ? ready : left.slice(0, 1)) {\n order.push(x.c);\n placed.add(x.c);\n }\n left = left.filter((x) => !placed.has(x.c));\n }\n return order;\n}\n\n/**\n * This function gives the keys of a space in the order of the reads of a column from itself. A read of a later key\n * reverses the order. In a tree, a read of the children puts the children before their parent.\n */\nfunction keyOrder(s: Space, d: ReadonlySet<Direction>): readonly string[] {\n const reverse = d.has(\"after\") && !d.has(\"before\");\n const childrenOf = s.childrenOf?.bind(s);\n if (childrenOf === undefined) return reverse ? s.keys.toReversed() : s.keys;\n const post = d.has(\"down\");\n // The order with each parent before its children, and the order after the children is that order from the end, with\n // the siblings in the other order. `push` puts the next key to visit at the end of the stack.\n const backwards = post !== reverse;\n const push = (stack: string[], keys: readonly string[]): void => {\n for (const k of backwards ? keys : keys.toReversed()) stack.push(k);\n };\n const isChild = new Set(s.keys.flatMap((k) => childrenOf(k)));\n const stack: string[] = [];\n push(stack, s.keys.filter((k) => !isChild.has(k)));\n const out: string[] = [];\n for (let k = stack.pop(); k !== undefined; k = stack.pop()) {\n out.push(k);\n push(stack, childrenOf(k));\n }\n return post ? out.toReversed() : out;\n}\n\n/** The state of one cell in the search. */\ninterface Visit {\n readonly id: string;\n readonly table: Table;\n readonly column: string;\n readonly key: string;\n readonly index: number;\n low: number;\n reread: boolean;\n result: Result<unknown>;\n /** True when the last evaluation paused, because a cell that it reads is not finished. */\n paused: boolean;\n /** The cell that the evaluation waits for: a cell that the run started, or a cell that paused too. */\n need: Visit | undefined;\n}\n\n/**\n * The budget of the stack for the recursion of a run, in estimated frames. Each engine has more stack than this, so\n * the recursion of a run cannot fill the stack (SHEET.DEEP).\n */\nconst STACK_BUDGET = 3000;\n\n/**\n * One run of a sheet. It keeps the result of each cell that it evaluated. The space does not change, so a cell has\n * one result in a run.\n *\n * The run is a depth-first search with the algorithm of Tarjan for strongly connected components. A cell finishes\n * when its component finishes. Each cell of a component with two or more cells, or with a reference to itself,\n * gives `#CYCLE!`. A read of a cell that is not finished gives `#CYCLE!` too. Thus the order of the evaluations\n * does not change a result, also when `ifError` catches the error of a cycle.\n *\n * The search does not depend on the call stack of the engine (SHEET.DEEP). A read of a cell evaluates that cell\n * with recursion while the stack of the run stays in a budget. When a read is over the budget, the run starts the\n * cell, and the cell that reads it pauses. A paused evaluation reads no other cell and changes no state of the\n * search. The run then evaluates the started cell from its own list, and it evaluates the paused cell again after\n * that cell. A formula is pure (EVAL.PURE), so the second evaluation gives the result of one evaluation.\n *\n * A run can have more tables (SHEET.TABLES). Each table has its own space, and one search covers the cells of all\n * the tables. Thus a cycle across tables gives `#CYCLE!` too.\n */\nexport class SheetRun {\n readonly #main: Table;\n // The tables by name and by space. A cell reference reads the table of the space where it evaluates.\n readonly #byName = new Map<string, Table>();\n readonly #bySpace = new Map<Space, Table>();\n readonly #opts: Omit<EvalOptions, \"origin\" | \"trace\" | \"space\">;\n // The cells on the stack of the search: started, but their component is not finished.\n readonly #visits = new Map<string, Visit>();\n // Stryker disable next-line ArrayDeclaration: the search never reads below the root of a component\n readonly #stack: Visit[] = [];\n // The cell whose formula is in evaluation. At the top level, it is a placeholder that is not a cell.\n #top: Visit;\n // The placeholder at the top in a fill, and true when the evaluation of a fill reads a cell that is not finished.\n readonly #filling: Visit;\n #missed = false;\n #next = 0;\n // The estimated frames of the stack that the evaluations in progress use, and the cost of each program.\n #used = 0;\n readonly #cost = new Map<Expr, number>();\n readonly #budget: number;\n readonly #compile: CompileFn | undefined;\n readonly #compileOptions: CompileOptions;\n // The run that evaluates a formula with a compiled program. Each run is synchronous, so a run inside the evaluation\n // of another run gives the active run back when it ends.\n static #active: SheetRun | undefined;\n // The extensions of the compiled programs, for each object of extensions of the options. Their cell handler reads\n // the cells of the active run, so a compiled program does not depend on one run.\n static readonly #shared = new WeakMap<object, Readonly<Record<string, ExtHandler>>>();\n\n /** `budget` is the budget of the stack in estimated frames. A test can make it small, so the run pauses often. */\n constructor(columns: ReadonlyMap<string, Expr>, opts: SheetOptions, budget: number = STACK_BUDGET) {\n const { cells, name, tables, space, compile, ...rest } = opts;\n this.#main = { where: \"the sheet\", tag: \"0\", space, columns, cells: cells ?? new Map(), warmed: new Map(), index: undefined, done: new Map() };\n this.#bySpace.set(space, this.#main);\n if (name !== undefined) this.#byName.set(name, this.#main);\n if (tables !== undefined) {\n let i = 0;\n for (const [n, t] of tables) {\n if (this.#byName.has(n)) continue;\n const other = tableState(`the table \"${n}\"`, ++i, t);\n this.#byName.set(n, other);\n // A table with the space of an earlier table does not take its cells: the first table keeps the space.\n if (!this.#bySpace.has(t.space)) this.#bySpace.set(t.space, other);\n }\n }\n // Stryker disable next-line all: the placeholder is not a cell, so the search reads none of its fields\n this.#top = { id: \"\", table: this.#main, column: \"\", key: \"\", index: -1, low: -1, reread: false, result: cycleError(\"\", \"\"), paused: false, need: undefined };\n // Stryker disable next-line all: the placeholder is not a cell, so the search reads none of its fields\n this.#filling = { id: \"\", table: this.#main, column: \"\", key: \"\", index: 0, low: 0, reread: false, result: cycleError(\"\", \"\"), paused: false, need: undefined };\n this.#budget = budget;\n this.#compile = compile;\n const spaces = Object.fromEntries([...this.#byName].map(([n, t]) => [n, t.space]));\n this.#opts = { ...rest, tables: spaces, extensions: { ...rest.extensions, [CELL_KIND]: this.#handler } };\n const outer = rest.extensions ?? NO_EXTENSIONS;\n let shared = SheetRun.#shared.get(outer);\n if (shared === undefined) {\n shared = { ...rest.extensions, [CELL_KIND]: SheetRun.#cellOfActive };\n SheetRun.#shared.set(outer, shared);\n }\n this.#compileOptions = { ...this.#opts, extensions: shared };\n }\n\n /** The cell handler of the compiled programs: it reads the cells of the active run. */\n static readonly #cellOfActive: ExtHandler = (data, ctx) => {\n const run = SheetRun.#active;\n return run === undefined ? fail(vexError(\"unbound\", \"a compiled formula reads cells only in the evaluation of a sheet run\")) : run.#handler(data, ctx);\n };\n\n /** This method gives the program of a cell: its own formula, or the formula of its column (SHEET.CELL.FORMULA). */\n #programOf(t: Table, column: string, key: string): Expr | undefined {\n // Stryker disable next-line ConditionalExpression: without formulas of cells, the lookup gives undefined anyway\n const own = t.cells.size === 0 ? undefined : t.cells.get(column)?.get(key);\n return own ?? t.columns.get(column);\n }\n\n /** This method gives the error of a cell without a program. */\n #unbound(t: Table, column: string, key: string): Result<never> {\n const message = t.cells.has(column) ? `the cell \"${column}\" at \"${key}\" has no formula` : `${t.where} has no column \"${column}\"`;\n return fail(vexError(\"unbound\", message, { origin: key, focus: key }));\n }\n\n /** This method gives the table of a name for a read from a host. Without a name, it is the main table. */\n #named(table: string | undefined, key: string): Table | Result<never> {\n if (table === undefined) return this.#main;\n return this.#byName.get(table) ?? fail(vexError(\"no-table\", `the run has no table \"${table}\"`, { origin: key, focus: key }));\n }\n\n readonly #handler: ExtHandler = (data, ctx) => {\n // The interpreter gives an error without an origin the path and the position of its node.\n if (!isCellRef(data)) return fail(vexError(\"bad-expression\", \"a cell reference needs a column name and an address of fixed moves\"));\n const where = resolveAddr(ctx.space, ctx.position, data.at);\n if (!where.ok) return fail({ ...where.error, path: ctx.path });\n // The evaluation of a cell has the space of its table, and the body of the axis table has the space of that table.\n /* v8 ignore next -- @preserve: each space of an evaluation of the run is the space of a table */\n return this.#read(this.#bySpace.get(ctx.space) ?? this.#main, data.column, where.value);\n };\n\n /**\n * This method gives the result of one cell: the column `column` at the key `key` of the main table, or of the table\n * `table`. A read from a host first evaluates the column at the keys before `key`, in key order. Thus a recurrence\n * over the keys reads finished cells.\n */\n cell(column: string, key: string, table?: string): Result<unknown> {\n const t = this.#named(table, key);\n if (!(\"space\" in t)) return t;\n // The placeholder at the top has the index -1. A read inside a formula has a cell at the top, so it does not warm.\n if (this.#top.index >= 0) return this.#read(t, column, key);\n // A finished cell needs no warm-up.\n const done = doneOf(t, column, key);\n if (done !== undefined) return done;\n this.#warmTo(t, column, key);\n return this.#drive(t, column, key);\n }\n\n /** This method evaluates the column `column` at each key before `key` that it did not evaluate before, in key order. */\n #warmTo(t: Table, column: string, key: string): void {\n if (!t.columns.has(column)) return;\n const keys = t.space.keys;\n t.index ??= new Map(keys.map((k, i) => [k, i]));\n const end = t.index.get(key) ?? 0;\n const start = t.warmed.get(column) ?? 0;\n for (let i = start; i < end; i++) this.#drive(t, column, keys[i] ?? key);\n if (end > start) t.warmed.set(column, end);\n }\n\n /** This method gives the estimated frames of the stack that one evaluation of the program `program` uses. */\n #costOf(program: Expr): number {\n let cost = this.#cost.get(program);\n if (cost === undefined) {\n cost = 3 * (shapeError(program) === undefined ? nestingOf(program) : 1) + 16;\n this.#cost.set(program, cost);\n }\n return cost;\n }\n\n /** This method puts a new cell on the stack of the search. */\n #start(t: Table, column: string, key: string): Visit {\n const n = this.#next++;\n const visit: Visit = { id: idOf(t, column, key), table: t, column, key, index: n, low: n, reread: false, result: cycleError(column, key), paused: false, need: undefined };\n this.#visits.set(visit.id, visit);\n this.#stack.push(visit);\n return visit;\n }\n\n /** This method evaluates the formula of a cell once. When the evaluation pauses, the result of the cell does not change. */\n #evaluate(visit: Visit, program: Expr): void {\n const caller = this.#top;\n const cost = this.#costOf(program);\n visit.paused = false;\n visit.need = undefined;\n this.#top = visit;\n this.#used += cost;\n const result = this.#run(visit.table, visit.column, visit.key, program);\n this.#used -= cost;\n this.#top = caller;\n if (!visit.paused) visit.result = result;\n }\n\n /** This method evaluates the formula `program` of a cell, with its compiled program or with the interpreter. */\n #run(t: Table, column: string, key: string, program: Expr): Result<unknown> {\n const options = { ...this.#opts, space: t.space, origin: key };\n const compiled = this.#compiled(t, column, program);\n if (compiled === undefined) return evaluate(program, options);\n const active = SheetRun.#active;\n SheetRun.#active = this;\n const result = compiled.run(options);\n SheetRun.#active = active;\n return result;\n }\n\n /**\n * This method gives the compiled program of the formula of a column, or `undefined` for the interpreter. A formula\n * compiles once for each compiler and options, also across runs.\n */\n #compiled(t: Table, column: string, program: Expr): Program | undefined {\n const compile = this.#compile;\n // The formula of a cell evaluates once in a run, so the run compiles only the formulas of the columns.\n if (compile === undefined || t.columns.get(column) !== program) return undefined;\n const { domains, fns, extensions } = this.#compileOptions;\n const hit = PROGRAMS.get(program);\n if (hit !== undefined && hit.compile === compile && hit.domains === domains && hit.fns === fns && hit.extensions === extensions) return hit.program;\n const compiled = compile(program, this.#compileOptions);\n PROGRAMS.set(program, { compile, domains, fns, extensions, program: compiled });\n return compiled;\n }\n\n /** This method ends a cell whose evaluation did not pause: it finishes its component, or it gives its low to the caller. */\n #end(visit: Visit, caller: Visit | undefined): void {\n if (visit.low === visit.index) this.#finish(visit);\n else if (caller !== undefined) caller.low = Math.min(caller.low, visit.low);\n }\n\n /** This method reads a cell from the formula of the cell at the top. */\n #read(t: Table, column: string, key: string): Result<unknown> {\n const done = doneOf(t, column, key);\n if (done !== undefined) return done;\n const caller = this.#top;\n // A paused evaluation reads no other cell, so it does not follow a path that its final evaluation does not follow.\n // In a fill, the cell goes to the search after the evaluation (SHEET.FILL).\n if (caller.paused) return cycleError(column, key);\n if (caller === this.#filling) {\n this.#missed = true;\n return cycleError(column, key);\n }\n const id = idOf(t, column, key);\n const seen = this.#visits.get(id);\n if (seen !== undefined) {\n // A read of a cell that is not finished: the caller and this cell are on one cycle. The cell is on the\n // stack of the search, so it is in the component of the caller. Thus a component with one cell is cyclic\n // only if that cell reads itself.\n caller.low = Math.min(caller.low, seen.index);\n seen.reread = true;\n return cycleError(column, key);\n }\n const program = this.#programOf(t, column, key);\n if (program === undefined) return this.#unbound(t, column, key);\n const visit = this.#start(t, column, key);\n if (this.#used + this.#costOf(program) > this.#budget) {\n // Over the budget: the caller pauses, and the run evaluates the new cell from its own list.\n caller.paused = true;\n caller.need = visit;\n return cycleError(column, key);\n }\n this.#evaluate(visit, program);\n if (visit.paused) {\n caller.paused = true;\n caller.need = visit;\n return cycleError(column, key);\n }\n this.#end(visit, caller);\n return doneOf(t, column, key) ?? cycleError(column, key);\n }\n\n /** This method evaluates a cell from the top level. The cells that pause go on a list, not on the call stack. */\n #drive(t: Table, column: string, key: string): Result<unknown> {\n const done = doneOf(t, column, key);\n if (done !== undefined) return done;\n if (this.#programOf(t, column, key) === undefined) return this.#unbound(t, column, key);\n const work: Visit[] = [this.#start(t, column, key)];\n for (let visit = work.at(-1); visit !== undefined; visit = work.at(-1)) {\n const program = this.#programOf(visit.table, visit.column, visit.key);\n /* v8 ignore next -- @preserve: a visit exists only for a cell with a program */\n if (program === undefined) break;\n this.#evaluate(visit, program);\n if (visit.paused) {\n // The cells that the evaluation waits for go on the list, the last one on the top.\n for (let need = visit.need; need !== undefined; need = need.need) work.push(need);\n continue;\n }\n work.pop();\n this.#end(visit, work.at(-1));\n }\n return doneOf(t, column, key) ?? cycleError(column, key);\n }\n\n /** This method takes the component of `root` from the stack, and sets the final result of each of its cells. */\n #finish(root: Visit): void {\n // The root is near the top of the stack, so the search starts at the top: a deep chain needs no long scan.\n const members = this.#stack.splice(this.#stack.lastIndexOf(root));\n // A component of two or more cells reads its root again, so root.reread alone decides. The length test is a guard.\n // Stryker disable next-line ConditionalExpression,LogicalOperator: members.length > 1 implies root.reread\n const cyclic = members.length > 1 || root.reread;\n for (const m of members) {\n // Stryker disable next-line CallExpression: a finished cell has a result, and a read looks for the result first\n this.#visits.delete(m.id);\n setDone(m.table, m.column, m.key, cyclic ? cycleError(m.column, m.key) : m.result);\n }\n }\n\n /** This method evaluates one cell with a trace of the nodes of its program. The result is the result of the cell. */\n explain(column: string, key: string, table?: string): Trace {\n const result = this.cell(column, key, table);\n const t = this.#named(table, key);\n const program = \"space\" in t ? this.#programOf(t, column, key) : undefined;\n if (program === undefined || !(\"space\" in t)) return { events: [], result };\n return { events: explain(program, { ...this.#opts, space: t.space, origin: key }).events, result };\n }\n\n /**\n * This method evaluates each cell of the table `table`, or of the main table (SHEET.FILL). Each column comes after\n * the columns that it reads, and the keys of a column come in the order of its reads from itself. Thus most reads\n * find a finished cell. An evaluation that reads a cell that is not finished has no effect, and the search then\n * evaluates its cell. A read of a cell gives the same result after a fill.\n */\n fill(table?: string): void {\n const t = table === undefined ? this.#main : this.#byName.get(table);\n // A read inside a formula has a cell at the top. A fill there has no effect.\n if (t === undefined || this.#top.index >= 0) return;\n const host = this.#top;\n for (const column of columnOrder(t)) {\n for (const key of keyOrder(t.space, readsOf(t, column).directions)) {\n const program = this.#programOf(t, column, key);\n if (program === undefined || doneOf(t, column, key) !== undefined) continue;\n this.#top = this.#filling;\n this.#missed = false;\n const result = this.#run(t, column, key, program);\n this.#top = host;\n if (this.#missed) this.#drive(t, column, key);\n else setDone(t, column, key, result);\n }\n }\n }\n\n /**\n * This method evaluates the column `column` at each key before `key`, in key order. A recurrence over the keys,\n * for example a running total, then reads finished cells.\n */\n warm(column: string, key: string, table?: string): void {\n const t = this.#named(table, key);\n // Stryker disable next-line all: a warm-up changes no result, only the depth of the recursion (SHEET.ORDER)\n if (\"space\" in t) this.#warmTo(t, column, key);\n }\n}\n","/**\n * The typed builder. Method calls make an expression of the IR. The builder has no other job: it does not\n * evaluate anything until a caller asks for a value.\n */\nimport type { AnyDomain, Domain, OpSpec, PrimitiveKind } from \"./domain.ts\";\nimport type { VexError } from \"./errors.ts\";\nimport { evaluate, explain, type EvalOptions, type ExtHandler, type FreeFn } from \"./evaluate.ts\";\nimport { app, call as callExpr, each, ext, fn as fnExpr, fold as foldExpr, index as indexMove, iterate as iterateExpr, key as keyMove, let_, lit, offset as offsetMove, other as otherMove, origin as originMove, parent as parentMove, rec, ref, toPath, v, type Axis, type Expr, type FixedMove, type Move } from \"./ir.ts\";\nimport { cell as cellRef, SheetRun, type CellFormulas } from \"./sheet.ts\";\nimport { toOptional, type Optional, type Result } from \"./result.ts\";\nimport type { Space } from \"./space.ts\";\nimport type { Trace } from \"./trace.ts\";\nimport type { VexList } from \"./list.ts\";\nimport { traversal, type Traversal } from \"./traversal.ts\";\n\n// ---------------------------------------------------------------- argument tokens\n\ndeclare const ARG_TYPE: unique symbol;\ndeclare const CHAIN_VALUE: unique symbol;\ndeclare const FN_RESULT: unique symbol;\n\n/** An argument token: an expression with the static type `T` of its value. */\nexport interface Arg<T> {\n readonly kind: \"vex.arg\";\n readonly expr: Expr;\n /** This phantom member carries the type. It is not present at run time. */\n readonly [ARG_TYPE]?: T;\n}\n\nconst argToken = <T>(expr: Expr): Arg<T> => ({ kind: \"vex.arg\", expr });\n\n\n// ---------------------------------------------------------------- type helpers\n\n/** The keys of any member of a union of record types. */\ntype AllKeys<O> = O extends unknown ? keyof O : never;\n\n/** The type of field `P` in the members of `O` that have it. */\ntype FieldType<O, P extends PropertyKey> = O extends unknown ? (P extends keyof O ? O[P] : never) : never;\n\n/**\n * The merged view of a union of record types: each field of any member, with the union of its types. A record\n * without the field gives `#N/A` at run time.\n */\nexport type Merge<O> = { readonly [P in AllKeys<O>]: FieldType<O, P> };\n\n/** The keys of `O` whose values have the type `T`. */\nexport type KeysOfType<O, T> = { [P in keyof O]-?: [NonNullable<O[P]>] extends [never] ? never : NonNullable<O[P]> extends T ? P : never }[keyof O] & string;\n\n/** The method names of `D`. */\nexport type MethodKeys<D> = { [P in keyof D]-?: D[P] extends (...args: never[]) => unknown ? P : never }[keyof D] & string;\n\n/** The value type of a domain. */\nexport type DomainValue<Dm> = Dm extends Domain<string, infer D, infer _Ops> ? D : never;\n\ntype OpsOf<Dm> = Dm extends Domain<string, unknown, infer Ops> ? Ops : Dm extends { readonly ops: infer Ops } ? Ops : never;\n\n/** The op names that a chain over a value of domain `Dm` can use. */\nexport type OpNames<Dm> =\n | (keyof OpsOf<Dm> & string)\n | (Dm extends { readonly methods: \"all\" } ? MethodKeys<DomainValue<Dm>> : never);\n\ntype FnOf<Dm, M extends string> = M extends keyof OpsOf<Dm>\n ? OpsOf<Dm>[M] extends { readonly fn: (self: never, ...args: infer P) => infer R }\n ? (...args: P) => R\n : M extends keyof DomainValue<Dm>\n ? DomainValue<Dm>[M]\n : never\n : M extends keyof DomainValue<Dm>\n ? DomainValue<Dm>[M]\n : never;\n\n/** The parameters of op `M` after the receiver. */\nexport type OpParams<Dm, M extends string> = FnOf<Dm, M> extends (...args: infer P) => unknown ? P : never;\n\n/** The value type that op `M` gives. */\nexport type OpReturn<Dm, M extends string> = FnOf<Dm, M> extends (...args: never[]) => infer R ? R : never;\n\ntype Lifts<Dm, M extends string> = M extends keyof OpsOf<Dm> ? (OpsOf<Dm>[M] extends { readonly liftScalar: true } ? true : false) : false;\n\n/** The first domain of `Dms` whose values include `T`, or `never`. */\nexport type DomainFor<Dms extends readonly AnyDomain[], T> = Dms extends readonly [infer H, ...infer R extends readonly AnyDomain[]]\n ? [T] extends [never]\n ? never\n : [T] extends [DomainValue<H>]\n ? H\n : DomainFor<R, T>\n : never;\n\ntype UnionToIntersection<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;\ntype LastOf<U> = UnionToIntersection<U extends unknown ? () => U : never> extends () => infer R ? R : never;\n\n/** `true` if `other()` is permitted for the key type: a pair of keys, or keys that the compiler does not know. */\nexport type AllowsOther<K extends string> = string extends K\n ? true\n : `${number}` extends K\n ? true\n : [Exclude<K, LastOf<K>>] extends [never]\n ? false\n : [Exclude<Exclude<K, LastOf<K>>, LastOf<Exclude<K, LastOf<K>>>>] extends [never]\n ? true\n : false;\n\n/**\n * The inputs for an argument with the parameter type `P`. The input can be a literal of type `P`, but not a bare\n * string. It can be a field of the record with type `P`, an argument token, or a chain that gives `P`. If the op\n * lifts scalars, it can also be a number.\n */\nexport type ArgInput<P, Ctx extends ChainContext, Lift extends boolean> =\n | (P extends string ? never : P)\n | KeysOfType<Ctx[\"record\"], P>\n | Arg<P>\n | ChainOf<Ctx, P>\n | (Lift extends true ? ([P] extends [DomainValue<DomainFor<Ctx[\"domains\"], P>>] ? LiftedNumber<Ctx> : never) : never);\n\n/**\n * A number argument for a domain parameter of an op with `liftScalar` (TYPE.LIFT): a number, a field with numbers, an\n * argument or a chain. The interpreter lifts each of them with `fromScalar` (CALL.LIFT).\n */\ntype LiftedNumber<Ctx extends ChainContext> = number | KeysOfType<Ctx[\"record\"], number> | Arg<number> | ChainOf<Ctx, number>;\n\ntype MapArgs<P extends readonly unknown[], Ctx extends ChainContext, Lift extends boolean> = { [I in keyof P]: ArgInput<P[I], Ctx, Lift> };\n\n/** A table of free functions. The first parameter of a function gets the current value of the chain. */\nexport type FnTable = Readonly<Record<string, (...args: never[]) => unknown>>;\n\n/** The free functions of a builder without `withOptions`: none, so `call` accepts no name. */\n// oxlint-disable-next-line typescript/no-generated-empty-object-type -- an empty table is the intent.\nexport type NoFns = Record<never, never>;\n\n/** The static context of a chain: its domains, its key type, its record type and its free functions. */\nexport interface ChainContext {\n readonly domains: readonly AnyDomain[];\n readonly keys: string;\n readonly record: unknown;\n readonly fns?: FnTable;\n}\n\ntype FnsOf<Ctx extends ChainContext> = NonNullable<Ctx[\"fns\"]>;\ntype FnParams<F> = F extends (...args: infer P) => unknown ? P : never;\ntype FirstParam<P> = P extends readonly [infer A, ...unknown[]] ? A : unknown;\ntype RestParams<P> = P extends readonly [unknown, ...infer R] ? R : [];\n\n/** The names of the free functions whose first parameter accepts a value of type `T`. */\nexport type CallableFns<Ctx extends ChainContext, T> = {\n [K in keyof FnsOf<Ctx>]: [T] extends [FirstParam<FnParams<FnsOf<Ctx>[K]>>] ? K : never;\n}[keyof FnsOf<Ctx>] &\n string;\n\n/** The inputs for the parameters of the free function `N` after its first parameter. */\nexport type CallArgs<Ctx extends ChainContext, N extends keyof FnsOf<Ctx>> = MapArgs<RestParams<FnParams<FnsOf<Ctx>[N]>>, Ctx, false>;\n\n/** The return type of the free function `N`. */\nexport type CallReturn<Ctx extends ChainContext, N extends keyof FnsOf<Ctx>> = FnsOf<Ctx>[N] extends (...args: never[]) => infer R ? R : unknown;\n\n/** The ops section `._` of a chain whose value has domain `Dm`. */\nexport type OpsProxy<Ctx extends ChainContext, Dm> = {\n readonly [M in OpNames<Dm>]: (...args: MapArgs<OpParams<Dm, M>, Ctx, Lifts<Dm, M>>) => ChainOf<Ctx, OpReturn<Dm, M>>;\n};\n\n// ---------------------------------------------------------------- chain types\n\n/** The members of every chain. */\nexport interface ChainBase<Ctx extends ChainContext, T> {\n readonly kind: \"vex.chain\";\n /** This phantom member carries the value type. It is not present at run time. */\n readonly [CHAIN_VALUE]?: T;\n /** The expression of the chain, as plain data. */\n readonly program: Expr;\n /** This method evaluates the chain at a key. An error gives `none`. */\n at(k: Ctx[\"keys\"]): Optional<T>;\n /** This method is the same as `at`. The v0.9 spec calls it `value`. */\n value(k: Ctx[\"keys\"]): Optional<T>;\n /** This method evaluates the chain at a key, and gives the error if there is one. */\n result(k: Ctx[\"keys\"]): Result<T>;\n /** This method evaluates the chain at a key, with a trace of each node. */\n explain(k: Ctx[\"keys\"]): Trace;\n /** This method evaluates the chain at each key of the space (the start axis). */\n all(): Traversal<Ctx[\"keys\"], T>;\n /** This method gives a chain whose value is a field of the record at the current address. */\n from<P extends keyof Ctx[\"record\"] & string>(field: P): ChainOf<Ctx, NonNullable<Ctx[\"record\"][P]>>;\n /**\n * Navigation: later field references read at the key `k`. A chain of a text gives the key, and it evaluates at the\n * focus before the moves (NAV.COMPUTED).\n */\n to(k: Ctx[\"keys\"] | ChainBase<Ctx, string>): ChainOf<Ctx, T>;\n /**\n * Navigation: later field references read at the key with this position in the key order. A chain of a number gives\n * the position, and it evaluates at the focus before the moves (NAV.COMPUTED).\n */\n index(i: number | ChainBase<Ctx, number>): ChainOf<Ctx, T>;\n /** Navigation: later field references read at a relative position in an array or a grid. */\n offset(...d: readonly number[]): ChainOf<Ctx, T>;\n /** Navigation: later field references read at the origin again. */\n origin(): ChainOf<Ctx, T>;\n /** Navigation: later field references read at the parent of the focus, in a tree space. A root gives `#REF!`. */\n parent(): ChainOf<Ctx, T>;\n /** This method uses `fallback` when the chain gives an error. */\n ifError<U>(fallback: ArgInput<U, Ctx, false> | T): ChainOf<Ctx, T | U>;\n /**\n * This method gives `then` when the boolean value is true, and `otherwise` when it is false (the form `if`). Only\n * the selected branch evaluates.\n */\n if<U, V>(this: ChainBase<Ctx, boolean>, then: ArgInput<U, Ctx, false>, otherwise: ArgInput<V, Ctx, false>): ChainOf<Ctx, U | V>;\n /**\n * This method applies the free function `name` of `withOptions`. The function gets the current value as its first\n * argument, then `args`. The types accept only the functions whose first parameter accepts the current value.\n */\n call<N extends CallableFns<Ctx, T>>(name: N, ...args: CallArgs<Ctx, N>): ChainOf<Ctx, CallReturn<Ctx, N>>;\n /** This method evaluates each branch with the current value, and gives a record of the results. */\n fork<const B extends Readonly<Record<string, (c: ChainOf<Ctx, T>) => ChainBase<Ctx, unknown>>>>(branches: B): ChainOf<Ctx, { readonly [N in keyof B]: ValueOf<ReturnType<B[N]>> }>;\n /**\n * This method makes up to `limit` steps (ITERATE.LIMIT). `init` gives the names and their first values, and `step`\n * gives the next values. A true `until` stops the steps (ITERATE.UNTIL). `result` gives the value of the chain.\n */\n iterate<const I extends Readonly<Record<string, unknown>>, R>(\n limit: number,\n init: I,\n step: (vars: LoopVars<Ctx, I>) => NoInfer<LoopStep<Ctx, I>>,\n result: (vars: LoopVars<Ctx, I>) => ArgInput<R, Ctx, false>,\n opts?: { readonly until?: (vars: LoopVars<Ctx, I>) => ArgInput<boolean, Ctx, false> },\n ): ChainOf<Ctx, R>;\n /** This method binds names for the body. The body gets a variable token for each name. */\n with<const B extends Readonly<Record<string, unknown>>, U>(\n binds: B,\n body: (c: ChainOf<Ctx, T>, vars: { readonly [N in keyof B]: Arg<ArgValue<Ctx, B[N]>> }) => ChainBase<Ctx, U>,\n ): ChainOf<Ctx, U>;\n /**\n * This method binds functions of `root.fn` (BUILD.FN) and gives the value of `body`. `call` gives a chain of a call of\n * each function. A function cannot call another function of the same `functions`, so it uses an outer one (FN.TOTAL).\n */\n functions<const F extends Readonly<Record<string, FnDef<readonly FnParamKind[], unknown>>>, U>(fns: F, body: (c: ChainOf<Ctx, T>, call: FnCalls<Ctx, F>) => ChainBase<Ctx, U>): ChainOf<Ctx, U>;\n /** The others axis: the body evaluates at each key except the focus. Its start value is the current value. */\n others<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The neighbors axis of a grid. */\n neighbors<U>(n: 4 | 8, body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The all axis inside the expression: the body evaluates at each key, with the current value as start value. */\n each<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The children axis of a tree space: the body evaluates at each child of the focus. */\n children<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The ancestors axis of a tree space: the parent first, the root last. */\n ancestors<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The descendants axis of a tree space: depth first, each parent before its children. */\n descendants<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The siblings axis of a tree space: the other children of the parent, or the other roots for a root. */\n siblings<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /**\n * The window axis of an array space or a tree space: the keys at the offsets from `from` to `to` of the focus, in\n * order. The offset 0 is the focus. An offset outside the space has no target.\n */\n window<U>(from: number, to: number, body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /**\n * The table axis: the body evaluates at each key of the table `name` of the evaluation, in the space of that table.\n * The body reads the fields of that table, but the types of the chain are the types of this space.\n */\n table<U>(name: string, body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The successors axis of a graph space: the ends of the edges from the focus. In a tree space, the children. */\n successors<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The predecessors axis of a graph space: the keys with an edge to the focus. In a tree space, the parent. */\n predecessors<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n /** The reachable axis of a graph space: each key that a path of edges reaches, in breadth-first order. */\n reachable<U>(body: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, U>, opts?: AxisOpts<Ctx, T>): ListChain<Ctx, U>;\n}\n\n/** The options of an axis. */\nexport interface AxisOpts<Ctx extends ChainContext, T> {\n /** A test at each target. The body evaluates only at the targets where the test gives `true`. */\n readonly where?: (c: ChainOf<Ctx, T>) => ChainBase<Ctx, boolean>;\n /** With `true`, the targets come in the reverse order (AXIS.REVERSE). The axis table has no reverse order. */\n readonly reverse?: boolean;\n}\n\n/** A function of the builder in its implementation: the kinds of its parameters, and the function that gives its body. */\ninterface FnDefImpl {\n readonly kind: \"vex.fn\";\n readonly params: readonly string[];\n readonly build: (...params: ChainImpl[]) => { readonly program: Expr };\n}\n\n/** The options of an axis in the implementation of the builder. */\ntype AxisOptsImpl = { readonly where?: (c: ChainImpl) => { readonly program: Expr }; readonly reverse?: boolean };\n\n/** The members of a chain whose value has a domain. */\nexport interface DomainMembers<Ctx extends ChainContext, Dm> {\n /** The ops of the domain of the current value. */\n readonly _: OpsProxy<Ctx, Dm>;\n}\n\n/** The members of a chain over a space whose keys permit `other()`. */\nexport interface OtherMembers<Ctx extends ChainContext, T> {\n /** Navigation: later field references read at the other key of the pair. */\n other(): ChainOf<Ctx, T>;\n}\n\n/** A chain with the current value type `T`. */\nexport type ChainOf<Ctx extends ChainContext, T> = ChainBase<Ctx, T> &\n ([DomainFor<Ctx[\"domains\"], T>] extends [never] ? unknown : DomainMembers<Ctx, DomainFor<Ctx[\"domains\"], T>>) &\n (AllowsOther<Ctx[\"keys\"]> extends true ? OtherMembers<Ctx, T> : unknown);\n\n/** The value type of a chain. */\nexport type ValueOf<C> = C extends { readonly [CHAIN_VALUE]?: infer T } ? T : never;\n\n/** The value type of an argument input. */\nexport type ArgValue<Ctx extends ChainContext, A> = A extends Arg<infer T>\n ? T\n : A extends { readonly kind: \"vex.chain\" }\n ? ValueOf<A>\n : A extends keyof Ctx[\"record\"] & string\n ? NonNullable<Ctx[\"record\"][A]>\n : A;\n\n/** A chain whose value is a list: the result of an axis. */\n/** The type of a value of a name of a loop: a literal of `init` gives its primitive type. */\ntype LoopValue<Ctx extends ChainContext, A> = ArgValue<Ctx, A> extends infer T ? (T extends number ? number : T extends string ? string : T extends boolean ? boolean : T) : never;\n\n/** The names of a loop of the builder: a chain of the value of each name of `init` (LOOP.NAMES). */\nexport type LoopVars<Ctx extends ChainContext, I> = { readonly [N in keyof I]: ChainOf<Ctx, LoopValue<Ctx, I[N]>> };\n\n/** The next values of a step of a loop: a value for some of the names of `init`. */\nexport type LoopStep<Ctx extends ChainContext, I> = { readonly [N in keyof I]?: ArgInput<LoopValue<Ctx, I[N]>, Ctx, false> };\n\n/** The kind of a parameter of a function of the builder (BUILD.FN): a primitive type, or `any`. */\nexport type FnParamKind = PrimitiveKind | \"any\";\n\n/** The type of a value of a kind of a parameter. */\nexport type KindValue<K> = K extends \"number\" ? number : K extends \"string\" ? string : K extends \"boolean\" ? boolean : unknown;\n\n/** A chain of each parameter of a function of the builder. */\nexport type ParamChains<Ctx extends ChainContext, P extends readonly FnParamKind[]> = { readonly [I in keyof P]: ChainOf<Ctx, KindValue<P[I]>> };\n\n/** A function of the builder (BUILD.FN): the kinds of its parameters and its body. `functions` binds it. */\nexport interface FnDef<P extends readonly FnParamKind[], R> {\n readonly kind: \"vex.fn\";\n readonly params: P;\n /** This phantom member carries the type of the result. It is not present at run time. */\n readonly [FN_RESULT]?: R;\n}\n\n/** The calls of the functions of `functions`: each gives a chain of a call (FN.CALL). */\nexport type FnCalls<Ctx extends ChainContext, F> = {\n readonly [N in keyof F]: F[N] extends FnDef<infer P, infer R> ? (...args: { readonly [I in keyof P]: ArgInput<KindValue<P[I]>, Ctx, false> }) => ChainOf<Ctx, R> : never;\n};\n\nexport interface ListChain<Ctx extends ChainContext, U> {\n readonly kind: \"vex.list-chain\";\n /** The expression of the chain, as plain data. */\n readonly program: Expr;\n /**\n * This method folds the items in the order of the axis (FOLD.ORDER). `init` gives the names and their first values.\n * `step` gives the next values from the names and the item, a chain at the target. `result` gives the value.\n */\n fold<const I extends Readonly<Record<string, unknown>>, R>(\n init: I,\n step: (vars: LoopVars<Ctx, I>, item: ChainOf<Ctx, U>) => NoInfer<LoopStep<Ctx, I>>,\n result: (vars: LoopVars<Ctx, I>) => ArgInput<R, Ctx, false>,\n ): ChainOf<Ctx, R>;\n count(opts?: ListOpts): ChainOf<Ctx, number>;\n sum(this: ListChain<Ctx, number>, opts?: ListOpts): ChainOf<Ctx, number>;\n mean(this: ListChain<Ctx, number>, opts?: ListOpts): ChainOf<Ctx, number>;\n min(this: ListChain<Ctx, number>, opts?: ListOpts): ChainOf<Ctx, number>;\n max(this: ListChain<Ctx, number>, opts?: ListOpts): ChainOf<Ctx, number>;\n any(this: ListChain<Ctx, boolean>, opts?: ListOpts): ChainOf<Ctx, boolean>;\n all(this: ListChain<Ctx, boolean>, opts?: ListOpts): ChainOf<Ctx, boolean>;\n none(this: ListChain<Ctx, boolean>, opts?: ListOpts): ChainOf<Ctx, boolean>;\n values(opts?: ListOpts): ChainOf<Ctx, readonly U[]>;\n /** The keys of the items with a value, in the order of the axis. */\n keys(opts?: ListOpts): ChainOf<Ctx, readonly Ctx[\"keys\"][]>;\n /** The error of each item that failed, in the order of the axis. */\n errors(): ChainOf<Ctx, readonly VexError[]>;\n first(opts?: ListOpts): ChainOf<Ctx, U>;\n reduce(op: OpNames<DomainFor<Ctx[\"domains\"], U>>, opts?: ReduceOpts<Ctx>): ChainOf<Ctx, U>;\n /** The items in the order of their values, from the smallest (LIST.SORT). The values are numbers or texts of one kind. */\n sortBy(opts?: ListOpts): ListChain<Ctx, U>;\n /** The first `n` items (LIST.TAKE). */\n take(n: number, opts?: ListOpts): ListChain<Ctx, U>;\n /** The value of the item at the position `i`, from 0 (LIST.NTH). */\n nth(i: number, opts?: ListOpts): ChainOf<Ctx, U>;\n /**\n * The axis list (AXIS.LIST): the body evaluates at the key of each item, in the order of the list. The body reads the\n * fields of the record of the item. The chain of the body has no value of its own.\n */\n each<V>(body: (c: ChainOf<Ctx, null>) => ChainBase<Ctx, V>, opts?: AxisOpts<Ctx, null>): ListChain<Ctx, V>;\n /** The list at the origin `k`: one item for each target of the axis, with its key and its result. */\n result(k: Ctx[\"keys\"]): Result<VexList<U>>;\n /** The list at the origin `k`, as an `Optional`. */\n at(k: Ctx[\"keys\"]): Optional<VexList<U>>;\n /** The trace of the evaluation of the list at the origin `k`. */\n explain(k: Ctx[\"keys\"]): Trace;\n}\n\n/** The options of a list reduction. */\nexport interface ListOpts {\n /** With `true`, an error item makes the result that error. The default skips error items. */\n readonly strict?: boolean;\n}\n\n/** The options of `reduce`. `domain` names the domain whose identity an empty list gives (LIST.EMPTY). */\nexport interface ReduceOpts<Ctx extends ChainContext> extends ListOpts {\n readonly domain?: Ctx[\"domains\"][number][\"name\"];\n}\n\n/** The root of the builder for one space. */\nexport interface Root<Ctx extends ChainContext> {\n /** This method starts a chain with a field of the record at the focus. */\n from<P extends keyof Ctx[\"record\"] & string>(field: P): ChainOf<Ctx, NonNullable<Ctx[\"record\"][P]>>;\n /** This method starts a chain with a value. A string is a field reference, as in an argument. */\n start<const T>(value: T): ChainOf<Ctx, ArgValue<Ctx, T>>;\n /** This method makes an absolute reference: the field of the record at key `k`. */\n of<P extends keyof Ctx[\"record\"] & string>(k: Ctx[\"keys\"], field: P): Arg<NonNullable<Ctx[\"record\"][P]>>;\n /** This method makes a reference to a dotted path at the focus, with the type that the caller gives. */\n field<T>(path: string): Arg<T>;\n /** This method makes a literal argument. Use it for a string or an array: a bare string is a field reference. */\n lit<const T>(value: T): Arg<T>;\n /** This method makes an absolute reference to a dotted path at key `k`, with the type that the caller gives. */\n ofPath<T>(k: Ctx[\"keys\"], path: string): Arg<T>;\n /** This method makes a record argument from field arguments. */\n rec<const F extends Readonly<Record<string, unknown>>>(fields: F): Arg<{ readonly [N in keyof F]: ArgValue<Ctx, F[N]> }>;\n /**\n * This method makes an extension argument: the node `ext(kind, data)`. The handler of `kind` in the options of\n * `withOptions` gives its value. The caller gives the type `T` of that value.\n */\n ext<T>(kind: string, data?: unknown): Arg<T>;\n /** This method starts a sheet over the space: named columns of formulas. Refer to `Sheet`. */\n sheet(): Sheet<Ctx, object>;\n /**\n * This method makes a function (BUILD.FN) with the kinds of its parameters. The body gets a chain of each parameter,\n * and it evaluates at the focus of each call. The method `functions` of a chain binds the function.\n */\n fn<const P extends readonly FnParamKind[], R>(params: P, body: (...params: ParamChains<Ctx, P>) => ChainBase<Ctx, R>): FnDef<P, R>;\n /** The space of the root. */\n readonly space: Space<Ctx[\"keys\"], Ctx[\"record\"]>;\n}\n\n/** The root of a column formula: the root of the builder, and references to the cells of the sheet. */\nexport interface SheetRoot<Ctx extends ChainContext, Cols> extends Root<Ctx> {\n /**\n * This method makes a cell reference: the column `column` at the key `at`, or at the address `at` from the focus.\n * The address has only fixed moves. Without `at`, it reads at the focus. The type is the type of a column before\n * this one.\n */\n cell<N extends keyof Cols & string>(column: N, at?: Ctx[\"keys\"] | readonly FixedMove[]): Arg<Cols[N]>;\n /** This method makes a cell reference to any column, also this column or a later one. The caller gives the type. */\n cell<T>(column: string, at?: Ctx[\"keys\"] | readonly FixedMove[]): Arg<T>;\n}\n\n/** One row of a sheet: the key and the result of each column. */\nexport interface SheetRow<K extends string, Cols> {\n readonly key: K;\n readonly cells: { readonly [N in keyof Cols]: Result<Cols[N]> };\n}\n\n/**\n * A sheet: named columns of formulas over a space, like the computed columns of a spreadsheet. A formula reads the\n * other columns with `cell`. Each evaluation evaluates a cell once, and each cell on a cycle of references gives\n * `#CYCLE!`. A sheet is immutable: `column` gives a new sheet.\n */\nexport interface Sheet<Ctx extends ChainContext, Cols, Decl = object> {\n /**\n * This method gives a new sheet with one more column. The formula gets a root with `cell`. If `declare` gave the\n * column a type, the formula must give a value of that type.\n */\n column<const N extends string, C extends ChainBase<Ctx, DeclaredType<Decl, N>>>(\n name: N,\n formula: (r: SheetRoot<Ctx, Cols & Decl>) => C,\n ): Sheet<Ctx, Cols & { readonly [P in N]: ValueOf<C> }, Decl>;\n /**\n * This method gives the types of columns before their formulas. A formula can then read a declared column with\n * `cell` and its type: the column itself (a recurrence) or a later column. It has no effect at run time.\n */\n declare<D extends Readonly<Record<string, unknown>>>(): Sheet<Ctx, Cols, Decl & D>;\n /**\n * This method gives a new sheet in which the cell of the column `column` at the key `k` has its own formula. That\n * formula replaces the formula of the column at the key `k`. It must give a value of the type of the column.\n */\n cellFormula<const N extends keyof (Cols & Decl) & string>(\n k: Ctx[\"keys\"],\n column: N,\n formula: (r: SheetRoot<Ctx, Cols & Decl>) => ChainBase<Ctx, (Cols & Decl)[N]>,\n ): Sheet<Ctx, Cols, Decl>;\n /** The program of each column. */\n readonly columns: Readonly<Record<string, Expr>>;\n /** The program of each cell with its own formula, by column and then by key. */\n readonly cellFormulas: Readonly<Record<string, Readonly<Record<string, Expr>>>>;\n /** This method evaluates one cell, and gives the error if there is one. */\n result<N extends keyof Cols & string>(k: Ctx[\"keys\"], column: N): Result<Cols[N]>;\n /** This method evaluates one cell. An error gives `none`. */\n at<N extends keyof Cols & string>(k: Ctx[\"keys\"], column: N): Optional<Cols[N]>;\n /** This method evaluates one cell, with a trace of the nodes of its column. */\n explain(k: Ctx[\"keys\"], column: keyof Cols & string): Trace;\n /** This method evaluates each cell, in key order, with one result for each cell. */\n table(): readonly SheetRow<Ctx[\"keys\"], Cols>[];\n}\n\n/** The declared type of the column `N`, or `unknown` for a column without a declaration. */\nexport type DeclaredType<Decl, N extends string> = N extends keyof Decl ? Decl[N] : unknown;\n\n/** The options of the builder. */\nexport interface VexOptions<F extends FnTable = FnTable> {\n /** Free function ops. A chain applies them with `call`. */\n readonly fns?: F;\n /** Handlers of extension expression kinds. */\n readonly extensions?: Readonly<Record<string, ExtHandler>>;\n}\n\n/** The entry point for a list of domains. */\nexport interface VexEntry<Dms extends readonly AnyDomain[], F extends FnTable = NoFns> {\n /** This method gives the root of the builder for a space. */\n over<K extends string, O>(s: Space<K, O>): Root<{ readonly domains: Dms; readonly keys: K; readonly record: Merge<O>; readonly fns: F }>;\n /** The domains. */\n readonly domains: Dms;\n}\n\n// ---------------------------------------------------------------- run time\n\n/** The options as the interpreter takes them: free functions get untyped arguments at run time. */\ninterface RuntimeOptions {\n readonly fns?: Readonly<Record<string, FreeFn>>;\n readonly extensions?: Readonly<Record<string, ExtHandler>>;\n}\n\n/** This function gives the run-time form of the options. A typed free function gets the values that the types promise. */\nconst runtimeOptions = (options: VexOptions): RuntimeOptions => ({\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(options.fns === undefined ? {} : { fns: options.fns as Readonly<Record<string, FreeFn>> }),\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(options.extensions === undefined ? {} : { extensions: options.extensions }),\n});\n\ninterface Env {\n readonly space: Space;\n readonly domains: readonly AnyDomain[];\n readonly options: RuntimeOptions;\n}\n\ninterface State {\n readonly env: Env;\n /** The current value. */\n readonly expr: Expr;\n /** The address where later field references read. */\n readonly addr: readonly Move[];\n /** The depth of nested axis and binding bodies, for unique variable names. */\n readonly depth: number;\n}\n\nconst kindOf = (u: unknown): unknown => (u as { kind?: unknown } | null | undefined)?.kind;\nconst isArg = (u: unknown): u is Arg<unknown> => kindOf(u) === \"vex.arg\";\nconst isChainLike = (u: unknown): u is { readonly program: Expr } => kindOf(u) === \"vex.chain\" || kindOf(u) === \"vex.list-chain\";\n\n/** This function turns a builder argument into an expression. A bare string is a field reference at `addr`. */\nfunction toExpr(a: unknown, addr: readonly Move[]): Expr {\n if (typeof a === \"string\") return ref(toPath(a), addr);\n if (isArg(a)) return a.expr;\n if (isChainLike(a)) return a.program;\n return lit(a);\n}\n\n/** This function gives the expressions of a step of a loop, with the unique names of the loop. */\nfunction stepExprs(step: Readonly<Record<string, unknown>>, unique: ReadonlyMap<string, string>, addr: readonly Move[]): Readonly<Record<string, Expr>> {\n const out: Record<string, Expr> = {};\n for (const [n, a] of Object.entries(step)) {\n const name = unique.get(n);\n if (name === undefined) throw new TypeError(`the name \"${n}\" of the step is not a name of init`);\n out[name] = toExpr(a, addr);\n }\n return out;\n}\n\nconst PROXY_RESERVED = new Set([\"then\", \"catch\", \"finally\", \"toJSON\", \"valueOf\", \"toString\", \"constructor\", \"inspect\", \"asymmetricMatch\", \"$$typeof\", \"nodeType\"]);\n\nclass ChainImpl {\n readonly kind = \"vex.chain\" as const;\n readonly #s: State;\n\n constructor(s: State) {\n this.#s = s;\n }\n\n get program(): Expr {\n return this.#s.expr;\n }\n\n get _(): Readonly<Record<string, (...args: readonly unknown[]) => ChainImpl>> {\n const s = this.#s;\n return new Proxy(Object.create(null) as Record<string, never>, {\n get: (_t, prop): unknown => {\n if (typeof prop !== \"string\" || PROXY_RESERVED.has(prop)) return undefined;\n return (...args: readonly unknown[]): ChainImpl => new ChainImpl({ ...s, expr: app(prop, s.expr, ...args.map((a) => toExpr(a, s.addr))) });\n },\n });\n }\n\n #opts(k: string): EvalOptions {\n return evalOptions(this.#s, k);\n }\n\n result(k: string): Result<unknown> {\n return evaluate(this.#s.expr, this.#opts(k));\n }\n at(k: string): Optional<unknown> {\n return toOptional(this.result(k));\n }\n value(k: string): Optional<unknown> {\n return this.at(k);\n }\n explain(k: string): Trace {\n return explain(this.#s.expr, this.#opts(k));\n }\n all(): Traversal<string, unknown> {\n const { env } = this.#s;\n const items = env.space.keys.map((k) => ({ key: k, result: this.result(k) }));\n return traversal(items, env);\n }\n\n from(field: string): ChainImpl {\n return new ChainImpl({ ...this.#s, expr: ref(toPath(field), this.#s.addr) });\n }\n\n #move(m: Move): ChainImpl {\n return new ChainImpl({ ...this.#s, addr: [...this.#s.addr, m] });\n }\n to(k: string | { readonly program: Expr }): ChainImpl {\n return this.#move(keyMove(typeof k === \"string\" ? k : k.program));\n }\n index(i: number | { readonly program: Expr }): ChainImpl {\n return this.#move(indexMove(typeof i === \"number\" ? i : i.program));\n }\n offset(...d: readonly number[]): ChainImpl {\n return this.#move(offsetMove(...d));\n }\n other(): ChainImpl {\n return this.#move(otherMove);\n }\n origin(): ChainImpl {\n return this.#move(originMove);\n }\n parent(): ChainImpl {\n return this.#move(parentMove);\n }\n\n call(name: string, ...args: readonly unknown[]): ChainImpl {\n return new ChainImpl({ ...this.#s, expr: app(name, this.#s.expr, ...args.map((a) => toExpr(a, this.#s.addr))) });\n }\n if(then: unknown, otherwise: unknown): ChainImpl {\n return new ChainImpl({ ...this.#s, expr: app(\"if\", this.#s.expr, toExpr(then, this.#s.addr), toExpr(otherwise, this.#s.addr)) });\n }\n ifError(fallback: unknown): ChainImpl {\n return new ChainImpl({ ...this.#s, expr: app(\"ifError\", this.#s.expr, toExpr(fallback, this.#s.addr)) });\n }\n\n /** This method binds the current value to a fresh name, and gives a chain that starts from that name. */\n #bound(): { readonly name: string; readonly start: ChainImpl } {\n const name = `$${this.#s.depth}`;\n return { name, start: new ChainImpl({ ...this.#s, expr: v(name), depth: this.#s.depth + 1 }) };\n }\n\n fork(branches: Readonly<Record<string, (c: ChainImpl) => { readonly program: Expr }>>): ChainImpl {\n const { name, start } = this.#bound();\n const fields: Record<string, Expr> = {};\n for (const [n, f] of Object.entries(branches)) fields[n] = f(start).program;\n return new ChainImpl({ ...this.#s, expr: let_({ [name]: this.#s.expr }, rec(fields)) });\n }\n\n with(binds: Readonly<Record<string, unknown>>, body: (c: ChainImpl, vars: Readonly<Record<string, Arg<unknown>>>) => { readonly program: Expr }): ChainImpl {\n const depth = this.#s.depth;\n const bindExprs: Record<string, Expr> = {};\n const vars: Record<string, Arg<unknown>> = {};\n for (const [n, a] of Object.entries(binds)) {\n const unique = `${n}$${depth}`;\n bindExprs[unique] = toExpr(a, this.#s.addr);\n vars[n] = argToken(v(unique));\n }\n const inner = body(new ChainImpl({ ...this.#s, depth: depth + 1 }), vars);\n return new ChainImpl({ ...this.#s, expr: let_(bindExprs, inner.program) });\n }\n\n functions(fns: Readonly<Record<string, FnDefImpl>>, body: (c: ChainImpl, call: Readonly<Record<string, (...args: readonly unknown[]) => ChainImpl>>) => { readonly program: Expr }): ChainImpl {\n const depth = this.#s.depth;\n const binds: Record<string, Expr> = {};\n const calls: Record<string, (...args: readonly unknown[]) => ChainImpl> = {};\n for (const [n, def] of Object.entries(fns)) {\n if ((def as { readonly kind?: unknown }).kind !== \"vex.fn\") throw new TypeError(`the function \"${n}\" is not a function of root.fn`);\n const unique = `${n}$${depth}`;\n const params = def.params.map((_k, i) => `${unique}$${i}`);\n // A parameter is a chain at the focus of the call, so a field of the body reads at the call.\n const chains = params.map((p) => new ChainImpl({ ...this.#s, expr: v(p), addr: [], depth: depth + 1 }));\n binds[unique] = fnExpr(params, def.build(...chains).program);\n calls[n] = (...args) => new ChainImpl({ ...this.#s, expr: callExpr(unique, ...args.map((a) => toExpr(a, []))), addr: [], depth: depth + 1 });\n }\n const inner = body(new ChainImpl({ ...this.#s, depth: depth + 1 }), calls);\n return new ChainImpl({ ...this.#s, expr: let_(binds, inner.program) });\n }\n\n /**\n * This method gives the names of a loop. Each name of `init` gets a name that is unique at the depth of the chain.\n * It also gets its first value at the address of the chain, and a chain of its value.\n */\n loopNames(init: Readonly<Record<string, unknown>>): { readonly unique: ReadonlyMap<string, string>; readonly first: Readonly<Record<string, Expr>>; readonly vars: Readonly<Record<string, ChainImpl>> } {\n const depth = this.#s.depth;\n const unique = new Map<string, string>();\n const first: Record<string, Expr> = {};\n const vars: Record<string, ChainImpl> = {};\n for (const [n, a] of Object.entries(init)) {\n const name = `${n}$${depth}`;\n unique.set(n, name);\n first[name] = toExpr(a, this.#s.addr);\n vars[n] = new ChainImpl({ ...this.#s, expr: v(name), addr: [], depth: depth + 1 });\n }\n return { unique, first, vars };\n }\n\n iterate(\n limit: number,\n init: Readonly<Record<string, unknown>>,\n step: (vars: Readonly<Record<string, ChainImpl>>) => Readonly<Record<string, unknown>>,\n result: (vars: Readonly<Record<string, ChainImpl>>) => unknown,\n opts?: { readonly until?: (vars: Readonly<Record<string, ChainImpl>>) => unknown },\n ): ChainImpl {\n const { unique, first, vars } = this.loopNames(init);\n const next = stepExprs(step(vars), unique, this.#s.addr);\n const until = opts?.until === undefined ? undefined : toExpr(opts.until(vars), this.#s.addr);\n return new ChainImpl({ ...this.#s, expr: iterateExpr(limit, first, next, toExpr(result(vars), this.#s.addr), until) });\n }\n\n #axis(a: Axis, body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n const { name, start } = this.#bound();\n // Inside the axis, the focus is the target, so the address of the body starts empty.\n const inTarget = new ChainImpl({ ...start.#s, addr: [] });\n const inner = body(inTarget);\n const ordered: Axis = opts?.reverse === true ? { t: \"reverse\", axis: a } : a;\n const axis: Axis = opts?.where === undefined ? ordered : { t: \"where\", axis: ordered, test: opts.where(inTarget).program };\n // The moves before the axis are its address: parent().children(f) gives f at each child of the parent.\n return new ListChainImpl({ ...this.#s, expr: let_({ [name]: this.#s.expr }, each(axis, inner.program, this.#s.addr)) });\n }\n others(body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"others\" }, body, opts);\n }\n neighbors(n: 4 | 8, body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"neighbors\", n }, body, opts);\n }\n each(body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"all\" }, body, opts);\n }\n children(body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"children\" }, body, opts);\n }\n ancestors(body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"ancestors\" }, body, opts);\n }\n descendants(body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"descendants\" }, body, opts);\n }\n siblings(body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"siblings\" }, body, opts);\n }\n window(from: number, to: number, body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"window\", from, to }, body, opts);\n }\n table(name: string, body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"table\", name }, body, opts);\n }\n successors(body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"successors\" }, body, opts);\n }\n predecessors(body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"predecessors\" }, body, opts);\n }\n reachable(body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n return this.#axis({ t: \"reachable\" }, body, opts);\n }\n}\n\n/** This function gives the options of an evaluation of a chain or a list chain at the origin `k`. */\nfunction evalOptions(s: State, k: string): EvalOptions {\n const { env } = s;\n return {\n space: env.space,\n origin: k,\n domains: env.domains,\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(env.options.fns === undefined ? {} : { fns: env.options.fns }),\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(env.options.extensions === undefined ? {} : { extensions: env.options.extensions }),\n };\n}\n\nclass ListChainImpl {\n readonly kind = \"vex.list-chain\" as const;\n readonly #s: State;\n constructor(s: State) {\n this.#s = s;\n }\n get program(): Expr {\n return this.#s.expr;\n }\n fold(\n init: Readonly<Record<string, unknown>>,\n step: (vars: Readonly<Record<string, ChainImpl>>, item: ChainImpl) => Readonly<Record<string, unknown>>,\n result: (vars: Readonly<Record<string, ChainImpl>>) => unknown,\n ): ChainImpl {\n // The list of an axis is a let of the start value around the axis, and the list of `each` of a list is the axis\n // alone. The fold keeps the let, and the body of the axis is the item of each step.\n const e = this.#s.expr;\n const loop = e.tag === \"let\" ? e.body : e;\n if (loop.tag !== \"each\") throw new TypeError(\"fold needs the list of an axis: go over the items of the list with each first\");\n const names = new ChainImpl({ ...this.#s, expr: lit(null) }).loopNames(init);\n const item = new ChainImpl({ ...this.#s, expr: loop.body, addr: [] });\n const next = stepExprs(step(names.vars, item), names.unique, []);\n const folded = foldExpr(loop.axis, names.first, next, toExpr(result(names.vars), this.#s.addr), loop.at);\n return new ChainImpl({ ...this.#s, expr: e.tag === \"let\" ? let_(e.bind, folded) : folded });\n }\n\n #op(op: string, extra: readonly Expr[], opts?: ListOpts & { readonly domain?: string }): ChainImpl {\n const options = { ...(opts?.strict === true ? { strict: true } : {}), ...(opts?.domain === undefined ? {} : { domain: opts.domain }) };\n const args = Object.keys(options).length > 0 ? [...extra, lit(options)] : extra;\n return new ChainImpl({ ...this.#s, expr: app(op, this.#s.expr, ...args) });\n }\n count(opts?: ListOpts): ChainImpl {\n return this.#op(\"count\", [], opts);\n }\n sum(opts?: ListOpts): ChainImpl {\n return this.#op(\"sum\", [], opts);\n }\n mean(opts?: ListOpts): ChainImpl {\n return this.#op(\"mean\", [], opts);\n }\n min(opts?: ListOpts): ChainImpl {\n return this.#op(\"min\", [], opts);\n }\n max(opts?: ListOpts): ChainImpl {\n return this.#op(\"max\", [], opts);\n }\n any(opts?: ListOpts): ChainImpl {\n return this.#op(\"any\", [], opts);\n }\n all(opts?: ListOpts): ChainImpl {\n return this.#op(\"all\", [], opts);\n }\n none(opts?: ListOpts): ChainImpl {\n return this.#op(\"none\", [], opts);\n }\n values(opts?: ListOpts): ChainImpl {\n return this.#op(\"values\", [], opts);\n }\n keys(opts?: ListOpts): ChainImpl {\n return this.#op(\"keys\", [], opts);\n }\n errors(): ChainImpl {\n return this.#op(\"errors\", []);\n }\n first(opts?: ListOpts): ChainImpl {\n return this.#op(\"first\", [], opts);\n }\n reduce(op: string, opts?: ListOpts & { readonly domain?: string }): ChainImpl {\n return this.#op(\"reduce\", [lit(op)], opts);\n }\n #list(op: string, extra: readonly Expr[], opts?: ListOpts): ListChainImpl {\n return new ListChainImpl({ ...this.#s, expr: this.#op(op, extra, opts).program });\n }\n sortBy(opts?: ListOpts): ListChainImpl {\n return this.#list(\"sortBy\", [], opts);\n }\n take(n: number, opts?: ListOpts): ListChainImpl {\n return this.#list(\"take\", [lit(n)], opts);\n }\n nth(i: number, opts?: ListOpts): ChainImpl {\n return this.#op(\"nth\", [lit(i)], opts);\n }\n each(body: (c: ChainImpl) => { readonly program: Expr }, opts?: AxisOptsImpl): ListChainImpl {\n // The chain of the body is at the key of the item, and it has no value of its own.\n const start = new ChainImpl({ ...this.#s, expr: lit(null), addr: [], depth: this.#s.depth + 1 });\n const list: Axis = { t: \"list\", list: this.#s.expr };\n const ordered: Axis = opts?.reverse === true ? { t: \"reverse\", axis: list } : list;\n const axis: Axis = opts?.where === undefined ? ordered : { t: \"where\", axis: ordered, test: opts.where(start).program };\n return new ListChainImpl({ ...this.#s, expr: each(axis, body(start).program) });\n }\n result(k: string): Result<unknown> {\n return evaluate(this.#s.expr, evalOptions(this.#s, k));\n }\n at(k: string): Optional<unknown> {\n return toOptional(this.result(k));\n }\n explain(k: string): Trace {\n return explain(this.#s.expr, evalOptions(this.#s, k));\n }\n}\n\nclass RootImpl {\n readonly #env: Env;\n constructor(env: Env) {\n this.#env = env;\n }\n get space(): Space {\n return this.#env.space;\n }\n #chain(expr: Expr): ChainImpl {\n return new ChainImpl({ env: this.#env, expr, addr: [], depth: 0 });\n }\n from(field: string): ChainImpl {\n return this.#chain(ref(toPath(field)));\n }\n start(value: unknown): ChainImpl {\n return this.#chain(toExpr(value, []));\n }\n of(k: string, field: string): Arg<unknown> {\n return argToken(ref(toPath(field), [keyMove(k)]));\n }\n field(path: string): Arg<unknown> {\n return argToken(ref(toPath(path)));\n }\n lit(value: unknown): Arg<unknown> {\n return argToken(lit(value));\n }\n ofPath(k: string, path: string): Arg<unknown> {\n return argToken(ref(toPath(path), [keyMove(k)]));\n }\n ext(kind: string, data: unknown = null): Arg<unknown> {\n return argToken(ext(kind, data));\n }\n sheet(): SheetImpl {\n return new SheetImpl(this.#env, new Map());\n }\n fn(params: readonly string[], build: (...params: ChainImpl[]) => { readonly program: Expr }): FnDefImpl {\n return { kind: \"vex.fn\", params, build };\n }\n rec(fields: Readonly<Record<string, unknown>>): Arg<unknown> {\n const out: Record<string, Expr> = {};\n for (const [n, a] of Object.entries(fields)) out[n] = toExpr(a, []);\n return argToken(rec(out));\n }\n}\n\nclass SheetRootImpl extends RootImpl {\n cell(column: string, at?: string | readonly FixedMove[]): Arg<unknown> {\n return argToken(cellRef(column, typeof at === \"string\" ? [keyMove(at)] : at));\n }\n}\n\nclass SheetImpl {\n readonly #env: Env;\n readonly #columns: ReadonlyMap<string, Expr>;\n readonly #cells: CellFormulas;\n constructor(env: Env, columns: ReadonlyMap<string, Expr>, cells: CellFormulas = new Map()) {\n this.#env = env;\n this.#columns = columns;\n this.#cells = cells;\n }\n get columns(): Readonly<Record<string, Expr>> {\n return Object.freeze(Object.fromEntries(this.#columns));\n }\n get cellFormulas(): Readonly<Record<string, Readonly<Record<string, Expr>>>> {\n return Object.freeze(Object.fromEntries([...this.#cells].map(([c, keys]) => [c, Object.freeze(Object.fromEntries(keys))])));\n }\n declare(): SheetImpl {\n return this;\n }\n column(name: string, formula: (r: SheetRootImpl) => { readonly program: Expr }): SheetImpl {\n const program = formula(new SheetRootImpl(this.#env)).program;\n return new SheetImpl(this.#env, new Map([...this.#columns, [name, program]]), this.#cells);\n }\n cellFormula(k: string, column: string, formula: (r: SheetRootImpl) => { readonly program: Expr }): SheetImpl {\n const program = formula(new SheetRootImpl(this.#env)).program;\n const keys = new Map([...(this.#cells.get(column) ?? []), [k, program]]);\n return new SheetImpl(this.#env, this.#columns, new Map([...this.#cells, [column, keys]]));\n }\n #run(): SheetRun {\n const { space: s, domains, options } = this.#env;\n return new SheetRun(this.#columns, {\n space: s,\n domains,\n cells: this.#cells,\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(options.fns === undefined ? {} : { fns: options.fns }),\n // Stryker disable next-line ConditionalExpression: an undefined option and an absent option are the same\n ...(options.extensions === undefined ? {} : { extensions: options.extensions }),\n });\n }\n result(k: string, column: string): Result<unknown> {\n const run = this.#run();\n run.warm(column, k);\n return run.cell(column, k);\n }\n at(k: string, column: string): Optional<unknown> {\n return toOptional(this.result(k, column));\n }\n explain(k: string, column: string): Trace {\n const run = this.#run();\n run.warm(column, k);\n return run.explain(column, k);\n }\n table(): readonly SheetRow<string, Record<string, unknown>>[] {\n const run = this.#run();\n // The table reads each cell, so a fill evaluates them in the order of their reads first (SHEET.FILL).\n run.fill();\n const names = [...this.#columns.keys()];\n return this.#env.space.keys.map((key) => ({ key, cells: Object.fromEntries(names.map((c) => [c, run.cell(c, key)])) }));\n }\n}\n\n/**\n * This function gives the entry point of the builder for a list of domains. The interpreter finds the op of a\n * value in the first domain that accepts the value.\n */\nexport function vex<const Dms extends readonly AnyDomain[]>(\n ...domains: Dms\n): VexEntry<Dms> & { withOptions<const F extends FnTable = NoFns>(options: VexOptions<F>): VexEntry<Dms, F> } {\n const make = <F extends FnTable>(options: VexOptions<F>): VexEntry<Dms, F> => ({\n domains,\n over: <K extends string, O>(s: Space<K, O>): Root<{ readonly domains: Dms; readonly keys: K; readonly record: Merge<O>; readonly fns: F }> =>\n new RootImpl({ space: s, domains, options: runtimeOptions(options) }) as unknown as Root<{\n readonly domains: Dms;\n readonly keys: K;\n readonly record: Merge<O>;\n readonly fns: F;\n }>,\n });\n return { ...make<NoFns>({}), withOptions: make };\n}\n\n/** The type of a domain value, from the domain object. */\nexport type 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