/** * The interpreter: step 6 of the bar cycle, and the whole architecture of the * language in one loop. * * **It walks a list. There is no `eval`, no generated function and no code * built from text anywhere in it**, which is what lets the language run inside * an application under a content security policy that forbids turning text into * code, and what lets a platform run many customers' scripts in one process. * The compiler emits data and this walks it; that is the foundation of the * whole design rather than a preference. * * **What verification already proved, this does not re-check.** A verified * program cannot underflow the stack, cannot jump out of bounds, cannot address * a slot that does not exist and cannot loop without charging the budget (3.5). * So the loop below pops without testing for an empty stack and indexes without * testing a bound, and every remaining failure is a script error with a source * position, which is the only kind of failure a user should ever see. * * **The budget is checked on the path every instruction takes.** One increment * and one comparison, because the alternative is a loop an engine hopes will * end. The loop budget itself is charged by `TICK` and by nothing else, so two * engines run out at the same iteration of the same loop on the same bar (8.5). */ import type { Span } from '../span/index.js'; import type { Budget } from './budget.js'; import type { Channels } from './channels.js'; import type { BarView, Guard, HostFacts, ManifestEntry, PositionFacts } from './library/index.js'; import type { Memory } from './memory.js'; import type { Registers } from './registers.js'; import type { CompiledProgram, Position } from './types.js'; import type { Heap, Value } from './values/index.js'; /** Everything the interpreter is handed once, at load. */ export interface MachineParts { readonly program: CompiledProgram; readonly registers: Registers; readonly memory: Memory; readonly channels: Channels; readonly heap: Heap; readonly budget: Budget; readonly guard: Guard; readonly host: HostFacts; /** The strategy's own position, read from the run's ledger. */ readonly position: PositionFacts; /** The library entry behind each `lib.functions` index, resolved at load. */ readonly library: readonly ManifestEntry[]; /** The position table of each function body, by function index. */ readonly fnPositions: readonly (readonly Position[])[]; spanAt(line: number, column: number): Span; } export declare class Machine { private readonly parts; private readonly top; private readonly callers; private frame; private view; private barIndex; /** The loop whose `TICK` executed most recently, for OS5001's line. */ private lastLoop; /** * The value a top level `RET` handed back, `compiled-program.md` 2.16.1. * * A program's own `code` ends in `HALT` and produces nothing, so this stays * absent for it. A request body ends in `RET` and its value is the read's * value for that requested bar, which is the one thing the interpreter has to * hand out rather than write into a register or a channel. */ private returned; private readonly ctx; private readonly ops; constructor(parts: MachineParts, view: BarView); /** Step 3: the stack, the slots and the frame stack all start empty. */ begin(view: BarView, index: number): void; /** What the last `run` handed back, for an instruction list that ends in `RET`. */ result(): Value; /** The slot array of frame 0, which inputs and grids are written into. */ slots(): Value[]; /** Where the instruction that just executed came from. */ here(): Span; /** * Runs the bar. * * The dispatch is a switch over the opcode name. A name rather than a number * is what the format carries (2.14) so that a program is readable and * diffable by hand; an engine may map names to its own integers at load and * must not depend on any numbering, because none is defined. */ run(): void; private loopLine; /** What the operations in `operations.ts` need, built once. */ private operations; /** `ADD` with the string ceiling applied, since it is the one that grows one. */ private joined; /** * `CALL_LIB`. * * A call whose manifest entry carries an effect does not perform it: it * appends a record holding the function index and the argument values as they * stood, and pushes absent. The machine does that here rather than in the * entry, so an effect cannot be forgotten by whoever writes the next one. */ private callLibrary; /** `CALL_FN`: everything it needs is in the call site, 4.10. */ private callFunction; /** The name a value goes by, which a library call asks for by the same route. */ nameOf(value: Value): string; } //# sourceMappingURL=machine.d.ts.map