/** * Cells and library state, and the checkpoint that rolls them back. * * `compiled-program.md` section 6 is one mechanism serving three purposes: * making a moving bar idempotent, letting a debugger step backwards, and making * a chart replay exact. They are the same problem, and an engine that * implements the checkpoint gets all three. * * **The representation is an undo journal, and the specification allows it.** * 6.2 is explicit that an engine may implement a checkpoint as a full copy, * copy on write, an undo journal, or nothing at all when it can prove the state * is unchanged, because the requirement is the semantics and not the shape. A * full copy of every cell and every state region at every bar is a cost * proportional to the program on a bar that changed one number, and a live * chart pays it on every tick. So a cell's previous value is recorded the first * time a bar writes it and a state region is copied the first time a bar * touches it, and a bar that changes nothing costs nothing at all. * * **`live var` is the one exception, and it is the whole of 6.3.** Everything * else rolls back, so executing a moving bar ten times gives the same answer as * executing it once. A `"live"` cell keeps its current value, which is what * makes a script using one not reproducible by design. Its previous value is * still recorded, because a debugger stepping backwards has to be able to show * what the value actually was rather than what a replay would recompute. */ import type { StateRecord } from './library/index.js'; import type { Cell, StateRegion } from './types.js'; import type { Value } from './values/index.js'; export declare class Memory { private readonly values; private readonly initialised; private readonly live; private readonly regions; private readonly undoCells; private readonly undoRegions; constructor(cells: readonly Cell[], states: readonly StateRegion[]); /** * `CELL_INIT`: whether the cell is already initialised. * * The cell is marked before the initialiser runs, not after. The two differ * only if the initialiser could reach the same `CELL_INIT` again, which needs * recursion, which is an error; marking first means the flag is set by one * instruction rather than by a pair that must stay together across a jump. */ initialise(cell: number): boolean; load(cell: number): Value; store(cell: number, value: Value): void; /** The region a `CALL_LIB` names, created on first use and kept across bars. */ region(index: number): StateRecord; private recordCell; /** What each cell held when this bar began, which is what a debugger shows. */ previousCells(): ReadonlyMap; /** 6.3: restore the checkpoint, except that `"live"` cells keep their value. */ rollback(): void; /** The checkpoint at the end of this bar: everything since is accepted. */ commit(): void; /** Every value a cell holds, for the heap's reachability walk. */ walk(visit: (value: Value) => void): void; } //# sourceMappingURL=memory.d.ts.map