/** * A request expression, executed over the requested bars, * `compiled-program.md` 2.16.1. * * **The body is a program the machine already knows how to run.** It holds the * tables a program holds for the machine of section 3 and none of the tables * that describe a chart, so the whole of this file is: build a program-shaped * view whose code, frame, registers, cells, states, functions and loops are the * body's own, keep the constant pool and the library manifest the program's, * and drive the same interpreter over it once per requested bar. Nothing new is * asked of the instruction loop, which is why the body ends in `RET` rather * than in an opcode of its own. * * **Every table is counted from zero and none of them is the program's.** The * registers are the requested instrument's bars and the cells and state regions * step once per requested bar, so an engine that reached into the program's * tables would put this chart's history behind another chart's name. The two * that are shared, `consts` and `lib.functions`, hold nothing that depends on a * bar. * * **A requested bar moves exactly as the chart's newest bar does.** `settle` is * a bar that has closed and `peek` is the one still forming, and `peek` rolls * the state back before it runs so that peeking the same bucket on ten chart * bars gives the same answer as peeking it once. That is the mechanism of * section 6 applied one level down, and it is what makes a `"developing"` read * mean the bucket so far rather than the bucket in full. */ import type { Span } from '../span/index.js'; import type { HostBar } from './bars.js'; import type { BarSource } from './bar-source.js'; import type { Clock, EngineLimits } from './budget.js'; import { Registers } from './registers.js'; import type { HostFacts, ManifestEntry, PositionFacts } from './library/index.js'; import type { CompiledProgram, Request } from './types.js'; import { Heap } from './values/index.js'; import type { Value } from './values/index.js'; /** One setting the body reads, resolved once at load like every other input. */ export interface BodyInput { readonly series: number; readonly value: Value; } /** * The reads written inside this one, as the body drives them. * * Declared here rather than imported, so the dependency points one way: the * fold knows about a body and a body knows only the shape of what it has to * step. A nested read folds the bars this body is running on, which are handed * over one requested bar at a time, so a nested `"lookahead"` read sees no * further than the requested bar being executed. That is the same thing the * mode does on a live chart's newest bucket, one level down. */ export interface NestedRequests { readonly empty: boolean; fill(registers: Registers, bars: BarSource, index: number, fresh: boolean): void; } export interface BodyParts { /** The program-shaped view of the body, built by `bodyProgram`. */ readonly program: CompiledProgram; readonly limits: EngineLimits; readonly clock: Clock | undefined; readonly host: HostFacts; readonly position: PositionFacts; readonly library: readonly ManifestEntry[]; readonly inputs: readonly BodyInput[]; readonly nested: NestedRequests | undefined; spanAt(line: number, column: number): Span; } /** * The body's tables wearing a program's shape. * * A copy of the parent with nine fields replaced, rather than a second * declaration, so that the one thing the two share by design, the constant pool * and the manifest, is shared by construction and cannot drift. */ export declare function bodyProgram(parent: CompiledProgram, request: Request): CompiledProgram; export declare class RequestBody { private readonly parts; private readonly registers; private readonly memory; private readonly heap; private readonly budget; private readonly machine; /** Requested bars that have closed, which is the index the next one takes. */ private settled; /** Executions of the requested bar currently forming, for `bar.updates`. */ private touches; /** The previous requested bar's close, which `trueRange` inside a body needs. */ private lastClose; /** The requested bars themselves, kept only when a read inside folds them. */ private readonly history; private readonly historySource; /** * The value the last closed requested bar handed back. * * Held so that the sweep does not reclaim it. A confirmed read takes the last * closed bucket's value on every chart bar of the next bucket, so the value * outlives the execution that produced it, and if it is an object the object * has to outlive it too. */ private handed; constructor(parts: BodyParts); /** How many requested bars have closed, which a warmup is counted against. */ get closed(): number; /** The body's own heap, which a read written inside it lands its value in. */ get objects(): Heap; /** * The requested bar still forming. * * Rolls back to the last closed bar first, so a bucket peeked on every chart * bar inside it costs one execution each and leaves no trace of the previous * one. Nothing is committed: the bucket is still moving. */ peek(bar: HostBar): Value; /** * The requested bar has closed. * * The last execution of that bar is the one that counts, and the state it * leaves becomes the checkpoint the next bar starts from. `settle` is * idempotent only in the sense every checkpoint is: it is called once per * requested bar, by the one place that knows a bucket has ended. */ settle(bar: HostBar): Value; private execute; /** * A value the body produced, as a value of the machine that asked for it. * * A number, a string, a colour or absence is the same value in both, and * nothing is copied. An object is not: a reference is an index into one heap, * and the body's heap is its own, so handing the index over would name * whatever the other heap happens to hold at that index. So the object is * copied, and copied again on every bar that reads it, because the copy lives * in a heap whose rollback undoes the bar it was made on. * * Only an array can arrive here. A read that declared a grid or drew an object * is refused at the call (OS3006), so those two kinds cannot exist in a body. */ carry(value: Value, into: Heap): Value; private viewOf; } //# sourceMappingURL=request-body.d.ts.map