/** * The state one compile of one file shares, and the small answers every pass * asks of it. * * The passes that emit code are ordinary functions taking this and a node, on * the same arrangement the checker uses, so a reader can follow one expression * from its syntax to its instructions without holding a class hierarchy in * their head. Everything mutable is here and nowhere else. */ import type { Argument, Call, Expression, Name, NameReference } from '../ast/index.js'; import type { Binding, CheckedCall, CheckedInput, CheckedScript, LibraryEntry } from '../check/index.js'; import type { RequestScope } from './request-scope.js'; import type { DiagnosticSink } from '../diagnostics/index.js'; import type { SourceFile } from '../source/index.js'; import type { Span } from '../span/index.js'; import { CodeBuilder } from './code.js'; import { GapLog } from './gaps.js'; import { FrameLayout, Layout } from './layout.js'; import { ConstantPool } from './pool.js'; import type { Alert, Band, CompiledFunction, CompiledInput, Grid, LibraryFunction, Level, Loop, Marker, Paint, Plot, Request } from './program.js'; import type { Value } from './values.js'; /** * The calls that declare part of the file's fixed shape and compile to no * `CALL_LIB` at all. * * This is the split the format turns on. A `plot` call is an entry in * `outputs.plots` plus one `EMIT` per bar; `input` is a row of the settings * dialog and an engine writing a slot at step 5; `table` is a declared grid. * None of them is a function an engine calls, so none of them belongs in * `lib.functions`, whose only purpose is to be named by a `CALL_LIB` (2.5). */ /** * The calls that declare part of the file rather than computing anything. * * None of them is a `CALL_LIB`, so none of them is in the engine's library * manifest and none of them can be looked for there. The list is exported so a * test that asks which names an engine has to implement can subtract these * rather than carry a second copy of them. */ export declare const DECLARATION_CALLS: ReadonlySet; export interface EmitOptions { /** The library manifest version, tied to `openscript.language` (2.5). */ readonly manifest?: number; /** The engine's declared state region count, for OS5004. */ readonly maxStates?: number; /** The engine's instruction ceiling, for OS5009. */ readonly maxInstructions?: number; /** Give every top-level name a register, which is `debug.retain` (2.10). */ readonly retain?: boolean; } /** One call site under construction; its bases are filled once totals are known. */ export interface Site { readonly index: number; fn: number; argc: number; cellBase: number; stateBase: number; series: number[]; /** The body this site's `fn` entry was built from, for the base walk. */ frame: FrameLayout | undefined; /** Sites reached from inside that body, so bases nest without overlapping. */ children: number[]; } /** A loop being emitted, and where `break` and `continue` jump to. */ export interface LoopFrame { readonly id: number; readonly breaks: number[]; readonly continues: number[]; } /** The frame a pass is emitting into: the top level, or one function body. */ export declare class Frame { readonly layout: FrameLayout; readonly builder: CodeBuilder; readonly loops: LoopFrame[]; /** Sites created while emitting this frame, in the order they were created. */ readonly sites: number[]; /** A parameter's position, for `HISTP`, by the binding that declared it. */ readonly parameters: Map; readonly topLevel: boolean; constructor(topLevel: boolean); } export declare class Emitter { readonly pool: ConstantPool; readonly layout: Layout; readonly gaps: GapLog; readonly libraryFunctions: LibraryFunction[]; /** The signature behind each entry, which is what `requires` is derived from. */ readonly calledEntries: LibraryEntry[]; readonly sites: Site[]; readonly functions: CompiledFunction[]; readonly functionPos: (readonly [number, readonly (readonly [number, number, number])[]])[]; readonly loops: Loop[]; /** A frame per emitted function entry, for the cell and state base walk. */ readonly functionFrames: FrameLayout[]; /** * File-scope names given a register although nothing reads their history. * * A slot belongs to one frame, so a name a function body reads has to live * somewhere every frame can address; `registers.ts` is where that is decided. */ readonly promoted: Set; /** Cells and input slots carrying a register beside them, kept in step per bar. */ readonly shadowed: Set; /** * Cells a function body reads, whose register is kept in step within the bar. * * A cell operand is relative to its own frame (2.11, 3.3), so a body has no * instruction that reaches a file-scope `var`. A register is addressed the * same way from every frame, so the value goes in one beside the cell: read * from the cell at the start of the bar, written again at every assignment, * so a body called at any point in the bar reads what the cell holds then. */ readonly carried: Set; /** Bodies being emitted, so a call graph with a cycle in it stops (11.4). */ readonly emitting: Set; /** * The file's fixed shape, filled in source order as the declarations are met. * * Source order is declaration order is legend order, so nothing sorts these * afterwards: the script already decided, and a second decision here would be * a second answer (2.8). */ readonly plots: Plot[]; readonly fills: Band[]; readonly levels: Level[]; readonly markers: Marker[]; readonly tables: Grid[]; readonly alerts: Alert[]; readonly inputs: CompiledInput[]; barColor: Paint | null; background: Paint | null; /** The plot key a declaration handle holds, so `fill` can name two of them. */ readonly handleKeys: Map; /** Names holding a declaration handle, which lives where the declaration put it. */ readonly handles: Set; /** The reads of 2.16, and the request a name holding one came from. */ readonly requests: Request[]; readonly requestOf: Map; /** The register one read's value lands in, so one call asks one question. */ readonly requestSeries: Map; /** * The read whose expression is being emitted, when this emitter is one. * * An expression inside a read is compiled over other bars, so it gets an * emitter of its own rather than a flag on a frame: its registers, its cells * and its state regions are counted from zero on the requested bars, and a * pass that read the parent's would emit a program that computes this * chart's numbers under another chart's name. */ readonly request: RequestScope | undefined; private readonly libraryIndex; /** A leaf body, which calls no user function, is shared by every call site. */ private readonly sharedBodies; readonly file: SourceFile; readonly checked: CheckedScript; readonly sink: DiagnosticSink; readonly options: EmitOptions; constructor(file: SourceFile, checked: CheckedScript, sink: DiagnosticSink, options: EmitOptions, parent?: Emitter, request?: RequestScope); /** An emitter for one read's expression, sharing what does not depend on a bar. */ forRequest(request: RequestScope): Emitter; /** The checker's answer for one call, which the emitter never re-derives. */ callAt(call: Call): CheckedCall | undefined; /** The declaration a name means, from the checker's own resolution. */ bindingAt(reference: NameReference): Binding | undefined; /** The input one `input()` call declares, from the checker's own table. */ inputAt(call: Call): CheckedInput | undefined; /** Whether a call is a declaration rather than something an engine calls. */ isDeclaration(name: string): boolean; /** * The index of a library function in `lib.functions`, adding it on first use. * * `state` and `effect` are recorded beside the name because 2.5 requires them * and because they are facts an engine already knows: they are there to be * disagreed with at load, which is how a program compiled against a newer * library is caught before it computes a wrong number. */ libraryFunction(entry: LibraryEntry): number; newSite(fn: number, argc: number): Site; newLoop(kind: Loop['kind'], span: Span): number; /** A body that calls no user function is one entry however many sites reach it. */ shareableBody(checkedFunction: number): number | undefined; rememberShareableBody(checkedFunction: number, emitted: number): void; gap(what: string, specification: string, span: Span | undefined, blocking: boolean): void; /** * The value an expression has before bar 0, or nothing when it has none. * * The environment is built here because folding needs two answers only the * checker has: which declaration a name means, and which signature a call * resolved to with its arguments already in parameter order. */ fold(expression: Expression): Value | undefined; private foldEnvironment; } /** * The key one input is known by: `inputs[].key`, and what a `{ "input": key }` * field names (2.3 and 2.6). * * Here rather than beside the table it keys, because three places name an * input by key and a second spelling of this would be a field that points at * no row. * * **Never the input's position.** `host-interface.md` 8.1 promises a key * "survives every edit that does not rename it", and a positional key keeps * that promise for no edit at all: inserting one tunable above another moves * every key below it, and a value a user stored against the third row lands on * the fourth, silently, because both are numbers and 8.3 has nothing to refuse. * An input written where a value belongs is assigned to no name, so its key is * its title, which is what the user sees and what changing is the rename 8.1 * allows to lose a value. The two cannot collide: two inputs sharing a title * are OS3017, a title spelling another input's name is OS3022, and a title * that is not there at all is OS3021, so a key of `""` here is a program the * checker has already refused. */ export declare function inputKey(input: CheckedInput): string; /** * Which of the five effects a library call carries, `compiled-program.md` 2.5 * and 5.4. * * The rule an entry is read by rather than a list of names, because a list in a * second place is a list that drifts. A call with an effect does not perform it * when it executes: it appends a record and **pushes absent as its result**. So * a call whose result a script uses cannot carry one, and that single sentence * settles every case in version 1. * * `order` is every call that spends money: `strategyOnly`, written with * brackets, and returning nothing. A `pos.*` reading is not one, because it is * read bare; `order.qtyForRisk` is not one, because it returns a number the * script goes on to size an order with. * * `log` is `print`, which reaches a log outside the machine. * * `draw` and `signal` are not reachable in version 1 and the emitter says so * rather than guessing. A drawing object lives in the object heap, which rolls * back with everything else (6.1), so a drawing needs no deferral to be * idempotent on a moving bar; a table cell is written to a per-bar output * buffer that is committed with the columns (2.8); and a marker and an alert * reach the host through a channel declared `defer`, not through a call. */ export declare function effectOf(entry: LibraryEntry): LibraryFunction['effect']; /** * The arguments a `CALL_LIB` pushes for one entry, which is its `arity` (2.5). * * The same for every entry but the order functions, which carry one argument * more than the language surface shows: the names of the arguments the script * wrote. `calls.ts` says why an order call needs it and no other call does. * * Stated here rather than at the two places that need it, because the count the * program records and the count the instruction pushes disagreeing is a program * no engine will load. */ export declare function arityOf(entry: LibraryEntry): number; /** The argument written for one parameter of a resolved call, or nothing. */ export declare function argumentAt(checked: CheckedCall, entry: LibraryEntry, name: string): Argument | undefined; /** * Every top-level name and the expression it is given, in source order. * * Two passes need it before any instruction is emitted: one to find the names * that hold a declaration handle, and one to find the names that hold a read. * Both have to answer about a name written below the line that asks, so both * run over the file rather than over what has been emitted so far. */ export declare function declaredNames(e: Emitter): readonly DeclaredName[]; /** One of those names, and whether `var` was written in front of it. */ export interface DeclaredName { readonly name: Name; readonly value: Expression; readonly persistent: boolean; } /** The dotted name a callee spells, for a call the checker did not resolve. */ export declare function calleeText(expression: Expression): string; //# sourceMappingURL=context.d.ts.map