@turing-machine-js/machine
A composable Turing-machine engine for JavaScript: multi-tape, subroutine composition via withOverriddenHaltState, Mermaid round-trip, and runtime breakpoints.
For runtime highlight + breakpoint rendering on top of the engine's Graph, plus a byte-identical edge-label formatter and snippet-recording artifacts, see the companion package @turing-machine-js/visuals.
Table of contents
- Install
- Quick start
- Building from a state table
- Classes —
Alphabet·Tape·TapeBlock·TapeCommand·Command·State·Reference·TuringMachine - Subroutine composition with
withOverriddenHaltState - State tags
- Debugging breakpoints
- Special objects —
haltState· Sentinels: halt vs abort ·ifOtherSymbol·movements·symbolCommands - Introspection and testing
- Diagram conventions
- Versioning notes
- Libraries
- Links
Install
Using npm:
npm install @turing-machine-js/machine
Quick start
Replace every b on the tape with *:
import {
Alphabet,
State,
Tape,
TapeBlock,
TuringMachine,
haltState,
ifOtherSymbol,
movements,
} from '@turing-machine-js/machine';
const alphabet = new Alphabet([' ', 'a', 'b', 'c', '*']);
const tape = new Tape({ alphabet, symbols: ['a', 'b', 'c', 'b', 'a'] });
const tapeBlock = TapeBlock.fromTapes([tape]);
const machine = new TuringMachine({ tapeBlock });
machine.run({
initialState: new State({
[tapeBlock.symbol(['b'])]: {
command: [{ symbol: '*', movement: movements.right }],
},
[tapeBlock.symbol([alphabet.blankSymbol])]: {
command: [{ movement: movements.left }],
nextState: haltState,
},
[ifOtherSymbol]: {
command: [{ movement: movements.right }],
},
}, 'replaceB'),
});
console.log(tape.symbols.join('').trim()); // a*c*a
The state graph for the example above (toMermaid(toGraph(replaceB, tapeBlock))):
flowchart TD
%% alphabets: [[" ","a","b","c","*"]]
s0(((halt)))
u1["replaceB"]
idle([idle])
idle -. enter .-> u1
u1 -- "['b'] → ['*']/[R]" --> u1
u1 -- "[B] → [K]/[L]" --> s0
u1 -- "[*] → [K]/[R]" --> u1
Reading this specific diagram: replaceB (the rectangle) is the start state, marked by the dotted enter arrow from the idle sentinel. Three self-or-halt transitions: read 'b' → write '*' and step right; read anything else (*) → keep, step right; read blank (B) → keep, step left, halt. Full notation reference — shapes, edge styles, label vocabulary — in §Diagram conventions.
A State is keyed by JS Symbols returned from tapeBlock.symbol(pattern) — the pattern lists the expected symbol under each tape's head. Sentinels and constants used throughout: ifOtherSymbol is the fallback key when nothing else matches; transitioning into haltState stops the run; movements.{left,right,stay} direct head moves; symbolCommands.{keep,erase} are write shortcuts. Full definitions in §Special objects.
For multi-tape machines, pass one element per tape: tapeBlock.symbol(['0', 'a']) matches only when tape 1 is at '0' and tape 2 is at 'a'. See the multi-tape example in §Diagram conventions for what the rendered graph looks like.
Building from a state table
If you prefer a textbook-style declarative API where every transition is one row of (state, currentSymbol) → (nextState, nextSymbol, movement), you can build a small helper on top of the raw API. The whole thing fits in ~30 lines:
import {
Alphabet,
Reference,
State,
TapeBlock,
TuringMachine,
haltState,
ifOtherSymbol,
movements,
symbolCommands,
} from '@turing-machine-js/machine';
function buildFromTable({ alphabetString, initialState, finalStates, table }) {
const alphabet = new Alphabet(alphabetString.split(''));
const tapeBlock = TapeBlock.fromAlphabets([alphabet]);
const movementOf = { L: movements.left, R: movements.right, S: movements.stay };
// Pre-create a Reference per state name so transitions can point forward.
const refs = Object.fromEntries(Object.keys(table).map((name) => [name, new Reference()]));
const states = {};
for (const [name, row] of Object.entries(table)) {
const def = {};
for (const [read, action] of Object.entries(row)) {
const key = read === '*' ? ifOtherSymbol : tapeBlock.symbol([read]);
def[key] = {
command: {
symbol: action.write ?? symbolCommands.keep,
movement: movementOf[action.move ?? 'S'],
},
nextState: finalStates.includes(action.goto) ? haltState : refs[action.goto],
};
}
states[name] = new State(def, name);
refs[name].bind(states[name]);
}
return { tapeBlock, machine: new TuringMachine({ tapeBlock }), initialState: states[initialState] };
}
// Same "replace b with *" example as above, written declaratively:
const { tapeBlock, machine, initialState } = buildFromTable({
alphabetString: ' abc*',
initialState: 'scan',
finalStates: ['HALT'],
table: {
scan: {
'b': { write: '*', move: 'R', goto: 'scan' },
' ': { move: 'L', goto: 'HALT' },
'*': { move: 'R', goto: 'scan' }, // '*' = ifOtherSymbol
},
},
});
This is what @turing-machine-js/builder provides as a separate package. Inline lets you tweak the format (multi-tape, OR-patterns, custom action shapes) freely; the builder package is more opinionated and limited to single-tape, single-symbol-per-row transitions.
Classes
Alphabet
The set of single-character symbols a tape can hold. The first symbol passed to the constructor is the blank — it fills any tape cell the head reaches before that cell has been written. At least two unique single-character symbols are required.
const alphabet = new Alphabet([' ', '0', '1']);
alphabet.blankSymbol; // ' '
alphabet.symbols; // [' ', '0', '1']
alphabet.has('0'); // true
alphabet.index('1'); // 2
Tape
An infinite-in-both-directions sequence of cells over an Alphabet, plus a head position. Cells the head moves into that haven't been written are blank.
const tape = new Tape({ alphabet, symbols: ['a', 'b', 'c'], position: 0 });
tape.symbol; // 'a' (cell under head)
tape.right(); // move head right; auto-extends with blanks at the edge
tape.symbol = 'X'; // write the cell under head
For visualization-friendly UIs, Tape exposes a fixed-width viewport centered on the head:
const tape = new Tape({ alphabet, symbols: ['a', 'b', 'c'], viewportWidth: 7 });
tape.viewport; // 7-cell snapshot centered on the head, padded with blanks
tape.viewportWidth; // 7 (the constructor bumps even values to the next odd)
viewportWidth defaults to 1 and must be ≥ 1; tape.viewport always has exactly viewportWidth cells regardless of how many symbols the tape actually holds. Useful for rendering a sliding window in a UI; ignore if you only need tape.symbols / tape.position.
For wire-data tape transmission (worker boundaries, snippet recording, snapshot tests), the package exports the TapeSnapshot type ({ symbols: string[]; position: number }) and a pure-function equivalent of Tape.viewport:
import { tapeViewport } from '@turing-machine-js/machine';
const snapshot = { symbols: ['a', 'b', 'c'], position: 1 };
const { cells, headIndex } = tapeViewport(snapshot, 7, ' ');
// cells: [' ',' ','a','b','c',' ',' '], headIndex: 3
tapeViewport(snapshot, width, blank) returns { cells, headIndex } with cells.length === width (out-of-bounds positions padded with blank) and headIndex === Math.floor(width / 2). Throws RangeError on non-positive or non-integer width. Tape.viewport and tapeViewport share an internal centering core, so the two routes produce identical results when given equivalent inputs. (TapeSnapshot + tapeViewport are also re-exported from @turing-machine-js/visuals for backwards-compatible imports from earlier alphas; canonical home is @turing-machine-js/machine as of v7.0.0-alpha.8, #227.)
TapeBlock
A bundle of one or more Tapes that the machine reads/writes together in lock-step. Construct via either factory:
TapeBlock.fromAlphabets([alphabetA, alphabetB]); // creates fresh blank tapes
TapeBlock.fromTapes([tape1, tape2]); // reuses existing tapes
The key method is tapeBlock.symbol(pattern): it returns an interned JS Symbol that simultaneously serves as a State's transition key and matches the current configuration across all tapes. The pattern is one alphabet character per tape; pass several patterns by concatenating to express alternatives.
tapeBlock.symbol(['^']); // single tape: matches '^'
tapeBlock.symbol(['^', '0', '1', '
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
const cmds = [
{ symbol: '0', movement: movements.right }, // write '0' and move right
{ movement: movements.left }, // keep current symbol, move left
{ symbol: symbolCommands.erase }, // write the blank, stay
{}, // no-op
];
You'll rarely construct TapeCommand instances yourself — pass plain objects in your State definitions and they're wrapped automatically.
Command
A bundle of TapeCommands, one per tape in the TapeBlock. Like TapeCommand, you usually pass a plain array in the State definition rather than constructing Command directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS Symbols from tapeBlock.symbol(...) (or ifOtherSymbol for the catch-all). Each value is { command, nextState }.
const s = new State({
[tapeBlock.symbol(['1'])]: { command: { symbol: '0', movement: movements.right } },
[tapeBlock.symbol(['
Notable members and statics:
state.id, state.name — identity (isHalt is id === 0).
state.withOverriddenHaltState(other) — returns a CallFrame (a State subclass, so it flows anywhere a State does) whose would-be halt transitions fall through to other. The subroutine-call composition mechanism (see library-binary-numbers/src/index.ts for examples). instanceof CallFrame is the wrapper discriminator.
State.toGraph(state, tapeBlock) — walks the reachable graph from state and returns a serializable Graph (states, transitions, alphabets).
State.fromGraph(graph) — inverse of toGraph: rebuilds State instances + a fresh TapeBlock from a Graph. Round-trips together with toMermaid / fromMermaid.
State.collectStates(state, tapeBlock) — walks the same graph and returns a Map<number, {state, transitionSymbols}> keyed by GraphNode.id. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live State instance or the per-pattern Symbol for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair State.toGraph with toMermaid to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
import { State, toMermaid } from '@turing-machine-js/machine';
const graph = State.toGraph(s, tapeBlock);
console.log(toMermaid(graph));
The string toMermaid produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
flowchart TD
%% alphabets: [[" ","0","1","$"]]
s0(((halt)))
u1["name"]
idle([idle])
idle -. enter .-> u1
u1 -- "['1'] → ['0']/[R]" --> u1
u1 -- "['
Edge labels are read → write/move. Write commands: K = keep (no write), E = erase (write the blank). Literal alphabet symbols are quoted ('1', '). Movements: L (left), R (right), S (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the toMermaid output into mermaid.live and switch to the stateDiagram-v2 renderer, or post-process the output to your preferred format.
fromMermaid parses the same format back into a Graph. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in test/round-trip.spec.ts for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — fromGraph recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a State needs to point at another State that doesn't exist yet (cyclic graphs). Construct unbound, pass as nextState, call .bind(actualState) once that state has been built.
const ref = new Reference();
const a = new State({ [symbol(['x'])]: { nextState: ref } }, 'a');
const b = new State({ [symbol(['y'])]: { nextState: a } }, 'b');
ref.bind(b); // a's transition now resolves to b at run time
The resulting cycle (toMermaid(toGraph(a, tapeBlock))):
flowchart TD
%% alphabets: [[" ","x","y"]]
u1["a"]
u2["b"]
idle([idle])
idle -. enter .-> u1
u1 -- "['x'] → [K]/[S]" --> u2
u2 -- "['y'] → [K]/[S]" --> u1
idle -. enter .-> points at the initial state passed to toGraph (a here); b is reachable from a via the bound Reference.
reference.ref returns the bound state and throws if the reference is still unbound when the machine runs. bind() is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one TapeBlock and drives a state graph until it reaches haltState.
const machine = new TuringMachine({ tapeBlock });
// Run to halt — `run()` is synchronous and returns a RunResult:
const result = machine.run({ initialState, stepsLimit: 1e5 });
// result: { outcome: 'halted' | 'aborted', state, stack, step } — see
// "Sentinels: halt vs abort" below for the aborted case.
// Or step-by-step (useful for tracing / observation):
for (const step of machine.runStepByStep({ initialState })) {
console.log(step.state.name, step.currentSymbols, '→', step.nextSymbols, step.movements);
}
// For interactive debugging (breakpoints, step-in / step-over / step-out,
// throttle, click-pause), construct a DebugSession — see "Debugging" below.
Each yielded step (MachineState) has these fields:
Field
Type
Meaning
step
number
1-indexed iteration number
state
State
the state about to execute
currentSymbols
string[]
per-tape head symbols, before the command applies
nextSymbols
string[]
per-tape symbols that will be written
movements
symbol[]
per-tape head moves (movements.left/right/stay)
nextState
State
the state that will execute next
matchedTransition
{ id: string, matchKinds: ('wildcard'|'literal')[] }
the transition the engine picked for this iter — see Matched transition below
stepsLimit (default 1e5) guards against runaway loops — exceeding it throws.
Choosing between run(), runStepByStep(), and DebugSession
Three non-overlapping entry points, picked by the consumer's actual need:
run()
runStepByStep()
new DebugSession(machine, ...)
Shape
sync, returns RunResult
sync generator, returns RunResult
async session with events
Observation
none
per-iter via .next()
event-based (pause, step, iter, halt)
Step controls
—
—
continue / stepIn / stepOver / stepOut / pause / stop
Throttle
—
—
setRunInterval(ms)
Breakpoint handling
not consulted — runs straight to halt
not consulted — yields every iter; state.debug is ignored
the only mode that reacts — fires a pause event
Best for
run-to-halt with no observation overhead
tracing, snapshots, test harnesses, custom batching
UI debuggers, IDE extensions, educational demos
Rule of thumb. No observation → run(). Sync per-iter observation → iterate runStepByStep(). Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a DebugSession.
run() / runStepByStep() both return a RunResult — { outcome: 'halted' | 'aborted', state, stack, step }, call-scoped so re-running the same machine never leaks stale state from a previous call. runStepByStep's generator carries the value as its return (visible in the final { done: true, value }) — a plain for...of discards it, so per-iter consumers that need the outcome either drain the generator manually (as run() does internally) or check the final yield's nextState identity. See §Sentinels: halt vs abort for the full shape and the abortState counterpart to haltState.
Breakpoint detection lives only in DebugSession. runStepByStep is the pure-iteration primitive — it advances the machine and reports a minimal MachineState with no pause/debug field, ignoring state.debug entirely. DebugSession is what evaluates the filters and turns a match into a pause event. (A consumer that wants its own breakpoint behavior on the raw generator can read state.debug itself.)
Matched transition
Every yielded MachineState carries a matchedTransition describing which transition the engine picked for that iter. The engine already resolves this via state.getNextState(symbol) internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous (source, nextState) pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from toGraph.
matchedTransition: {
id: string; // resolvable in toGraph
matchKinds: ('wildcard' | 'literal')[]; // per-tape, length = tape count
}
id — ${stateId}.${transitionIx}. Resolvable in toGraph's output: graph.nodes[stateId].transitions has an entry with the matching id. For wrapper-entry iters (source is a wrapper produced by withOverriddenHaltState), id references the bare's transition — the wrapper's own transitions array in toGraph is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing id.split('.')[0] against state.id: different → wrapper delegation.
matchKinds — per-tape match kind for the matched alternative's selector at each tape position. 'wildcard' if the position held ifOtherSymbol (catch-all) in the winning alternative; 'literal' if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
for (const m of machine.runStepByStep({initialState})) {
const wildcardPositions = m.matchedTransition.matchKinds // per-tape, e.g. ['wildcard', 'literal']
.map((k, i) => k === 'wildcard' ? i : -1)
.filter((i) => i >= 0);
console.log(`step ${m.step}: fired transition ${m.matchedTransition.id} (wildcards at tapes: ${wildcardPositions.join(',') || 'none'})`);
}
Subroutine composition with withOverriddenHaltState
state.withOverriddenHaltState(other) returns a CallFrame — a State subclass that delegates transition lookups and debug to state (its bare) and whose would-be halt transitions fall through to other at run time. The bare is left untouched. Because a CallFrame is a State, it flows anywhere a State does (as a nextState, through toGraph/fromGraph); instanceof CallFrame distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
import { Alphabet, State, TapeBlock, TuringMachine, Tape, haltState, ifOtherSymbol, movements, symbolCommands } from '@turing-machine-js/machine';
const alphabet = new Alphabet([' ', 'a', 'b', 'X']);
const tapeBlock = TapeBlock.fromAlphabets([alphabet]);
const { symbol } = tapeBlock;
// Reusable subroutine 1: walk right until 'X', halt on it.
const scanToX = new State({
[symbol(['X'])]: { nextState: haltState },
[ifOtherSymbol]: { command: { movement: movements.right } },
}, 'scanToX');
// Reusable subroutine 2: erase the head cell, halt.
const eraseHere = new State({
[ifOtherSymbol]: { command: { symbol: symbolCommands.erase }, nextState: haltState },
}, 'eraseHere');
// Compose: scan to X, then ERASE it. scanToX is unmodified.
const scanThenErase = scanToX.withOverriddenHaltState(eraseHere);
const tape = new Tape({ alphabet, symbols: ['a', 'b', 'X', 'b', 'a'] });
tapeBlock.replaceTape(tape);
await new TuringMachine({ tapeBlock }).run({ initialState: scanThenErase });
console.log(tape.symbols.join('')); // "ab ba" — the X at index 2 is gone, head landed there.
What changes between running scanToX standalone and running the composed wrapper:
toMermaid(toGraph(scanToX, tapeBlock)) — the standalone subroutine:
flowchart TD
%% alphabets: [[" ","a","b","X"]]
s0(((halt)))
u1["scanToX"]
idle([idle])
idle -. enter .-> u1
u1 -- "['X'] → [K]/[S]" --> s0
u1 -- "[*] → [K]/[R]" --> u1
toMermaid(toGraph(scanThenErase, tapeBlock)) — the wrapped composition:
flowchart TD
%% alphabets: [[" ","a","b","X"]]
s0(((halt)))
u2["eraseHere"]
u3[["scanToX(eraseHere)"]]
idle([idle])
subgraph w_1["callable subtree of scanToX"]
u1["scanToX"]
s0-1(((halt)))
end
idle -. enter .-> u3
u3 == "call" ==> u1
w_1 -. "return" .-> u3
u3 --> u2
u1 -- "['X'] → [K]/[S]" --> s0-1
u1 -- "[*] → [K]/[R]" --> u1
u2 -- "[*] → [E]/[S]" --> s0
Reading guide — the v7 callable-subtree emit (introduced in #174) models withOverriddenHaltState as a function call: the wrapper is the call site, the bare's subtree is the callable body.
[[scanToX(eraseHere)]] (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — idle -. enter .-> arrives here — and shows the composite name (bare(override)). Wrappers have no transitions of their own; they delegate to the bare via the call arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in library-binary-numbers/minusOne) renders INSIDE its owner frame's subgraph with the same [[…]] shape (see #223).
subgraph w_1["callable subtree of scanToX"] is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare u1["scanToX"], any body states reachable from the bare, and a local halt marker s0-1(((halt))) where the bare's halt-bound transitions land — s0-1 reads as "frame 1's local stand-in for s0" (see §Mermaid id scheme for the full namespacing rule).
- The bold
==> call from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted
-. return .-> from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on s0-1) and the stack pops. The wrapper's solid --> u2 (to eraseHere) is the post-return continuation; ordinary transition under the function-call mental model.
- Real
(((halt))) outside any subgraph (s0) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by eraseHere after it erases the cell.
Reading runtime sequence on tape ['a','b','X','b','a']: enter at wrapper [[scanToX(eraseHere)]] (with eraseHere queued as the override); call into the subtree of scanToX; [*] → [K]/[R] self-loops on u1 until the head sees X; the ['X'] → [K]/[S] edge lands on s0-1; return to the wrapper; solid --> u2 to eraseHere; eraseHere runs [*] → [E]/[S] and halts at real s0. Run terminates.
Round-trip stability. toMermaid → fromMermaid → toGraph → toMermaid is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like library-binary-numbers's invertNumber (used by two wrappers in minusOne) render as a single subtree with two & -joined call arrows, and fromGraph rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime State ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use equivalentOn to confirm behavioural identity (allAgree: true) when bytewise comparison no longer applies.
Wrappers nest: inner.withOverriddenHaltState(middle).withOverriddenHaltState(outer) chains halt-redirects through middle → outer → halt. library-binary-numbers/src/index.ts's minusOne (the ~(~x + 1) composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, equivalentOn comparisons, or any structural identity; they ride alongside the State.
const s = new State({...}, 'walkToBlank::1')
.tag('hot', 'subroutine-entry');
s.tags; // readonly ['hot', 'subroutine-entry'] — frozen snapshot
s.untag('hot');
s.tags; // readonly ['subroutine-entry']
Scoped to the wrapper instance. Under withOverriddenHaltState memoization (#175), A.wohs(t1) and A.wohs(t2) are distinct CallFrame instances even though both delegate to the same bare A. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from withOverriddenHaltState start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. state.toGraph writes the tag set to GraphNode.tags; state.fromGraph reads it back and reapplies. toMermaid renders tags two ways: inline in the node label (uN["name<br>tag1, tag2"], universal Mermaid line break) and as classDef tag_<sanitized> + class uN tag_<sanitized> lines for color grouping. fromMermaid splits the label on <br> as source of truth; the class lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the DebugSession class, constructed directly with a TuringMachine. Breakpoints are configured on the engine (state.debug / haltState.debug / abortState.debug); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external pause(), and a per-iter throttle.
import { DebugSession } from '@turing-machine-js/machine';
const session = new DebugSession(machine, { initialState });
session.on('pause', (m) => {
console.log(`paused at ${m.state.name}, ${m.pause.side} side, cause: ${m.pause.cause}`);
session.stepIn(); // or stepOver(), stepOut(), continue(), stop()
});
session.on('step', (m) => { /* fires once per iter, mid-iter */ });
session.on('iter', (m) => { /* fires once per iter, end-of-iter */ });
session.on('halt', (result) => { /* fires on natural halt (not on stop()) */ });
session.on('abort', (result) => { /* fires when the run hits abortState (not on stop()) */ });
await session.start(); // resolves on halt, abort, or stop()
Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads state.debug / haltState.debug / abortState.debug and fires a pause event when a filter matches.
import { State, abortState, haltState, ifOtherSymbol } from '@turing-machine-js/machine';
const myState = new State({...});
// state.debug is always a DebugConfig instance — chained writes work
// without prior whole-object assignment:
myState.debug.before = true;
myState.debug.after = [symA];
// Whole-object assignment also works for one-shot setup:
myState.debug = { before: true };
myState.debug = { before: [symA] };
myState.debug = { before: [symA], after: [symA] };
// Pause when the engine is about to enter halt (program exit OR subroutine pop).
// haltState.debug is a `boolean` (#207) — halt is terminal, so there's only
// one meaningful pause moment (post-triggering-iter, before halt processing).
haltState.debug = true;
haltState.debug = false; // turn off
haltState.debug = null; // alias of false (reset)
// abortState.debug mirrors haltState.debug (#239) — same boolean shape, same
// single pause moment: the AFTER side of the iter whose transition targets
// abortState, fired before the terminal 'abort' event.
abortState.debug = true;
abortState.debug = false; // turn off
abortState.debug = null; // alias of false (reset)
// Reset filters later on a regular state — next read returns a fresh empty DebugConfig:
myState.debug = null;
haltState.debug and abortState.debug are boolean-only. Any object-shaped write ({ before: true }, { after: true }, { before: true, after: true }) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — m.state is the triggering state (not the sentinel itself), m.pause.side === 'after'.
An after-side breakpoint on the sentinel-triggering state collapses with haltState.debug / abortState.debug into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one pause event (side: 'after', cause: 'breakpoint'), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states A → B: A's after and B's before are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form haltState.debug.before = true (or abortState.debug.before = true) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean false; assigning .before to that boolean is a no-op in non-strict mode (silent), a TypeError in strict mode. The engine setter only sees whole-object writes (haltState.debug = X / abortState.debug = X). Always use the whole-object form: = true / = false / = null.
The debug field is mutable — toggle breakpoints at runtime without rebuilding the graph. A CallFrame (from state.withOverriddenHaltState(...)) delegates its debug to the bare, so an assignment on the original is visible from every wrapper and vice versa. state.debug is always a DebugConfig instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is Object.seal-ed — typos like state.debug.bofore = true throw TypeError instead of silently creating a useless property.
Filter semantics: true is a wildcard (match any symbol). [ifOtherSymbol] is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: haltState and abortState are both module-level singletons. Setting either one's .debug affects every machine in the process; clear in afterEach / finally for test isolation.
DebugSession API
Method
Description
start(): Promise<void>
Begin execution. Resolves on natural halt, abort, or after stop(). Single-use — a second call throws.
continue()
Resume from a pause and run to the next breakpoint or halt.
stepIn()
Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into.
stepOver()
Resume and pause at the next iter back at (or above) the click-time halt-stack depth (depth ≤ clickTimeDepth) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over.
stepOut()
Resume and pause at the next iter strictly shallower than the click-time depth (depth < clickTimeDepth) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out.
pause()
Request a pause from outside the loop. Fires on the next iter with cause: 'manual'. If a breakpoint matches that same iter, the breakpoint wins (single pause, cause: 'breakpoint').
stop()
Terminate immediately. halt event does NOT fire.
setRunInterval(ms)
Insert an awaited setTimeout(ms) at the end of each iter. 0 disables. Useful for visualization UIs.
on(event, listener) / off(event, listener)
Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below.
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth D, stepIn pauses at the next iter (any depth), stepOver at the next iter with depth ≤ D, stepOut at the next iter with depth < D. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a withOverriddenHaltState wrapper). One engine-specific nuance: composition is continuation-passing (A.wohs(B) = "run A, then B" — sequential, where wohs is withOverriddenHaltState), so a flat .wohs() chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
Event
Argument
Dispatch
Fires
pause
PausedMachineState (MachineState + pause: {side, cause})
Implicitly awaited via internal pause-promise — engine blocks until continue / stepIn / stepOver / stepOut / stop is called. Listener Promise itself is fire-and-forget.
A breakpoint matched, a step-mode endpoint was reached, or session.pause() was requested.
step
MachineState
Fire-and-forget (sync hot-loop tracing).
Once per iter, between any before-pause and after-pause.
iter
MachineState
Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis.
Once per iter, at end. After any after-pause.
halt
RunResult
Fire-and-forget.
Once, on natural halt. Does NOT fire when stop() was called.
abort
RunResult
Fire-and-forget.
Once, when the run hits abortState. Does NOT fire when stop() was called.
halt and abort are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's RunResult ({outcome, state, stack, step} — see §RunResult) as their listener's argument.
The pause descriptor: m.pause
pause listeners receive a PausedMachineState — a plain MachineState plus a pause: { side, cause } descriptor (raw runStepByStep yields have no such field).
side — 'before' or 'after'. Exactly one: DebugSession dispatches the two timings as separate pause events, so a descriptor is always one-sided. ('step' / 'manual' causes only ever fire on the 'before' side.)
cause — distinguishes the origin:
'breakpoint' — a state.debug filter matched, or haltState.debug === true / abortState.debug === true triggered.
'step' — a stepIn / stepOver / stepOut directive's natural endpoint was reached.
'manual' — session.pause() was called from outside.
When an iter satisfies more than one trigger, exactly one pause event fires — never two at the same iter — and cause is chosen by precedence:
breakpoint > step > manual
So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports cause: 'breakpoint'; a manual pause that coincides with a step endpoint reports cause: 'step'. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (stepIn / stepOver / stepOut) is dropped on the next pause dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call stepIn / stepOver / stepOut again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric GraphNode.id — the user clicked a state node, or a transition edge in a rendered SVG. State.collectStates(initial, tapeBlock) returns a Map keyed by that numeric id, with the live State instance and the per-pattern Symbol array as its value:
import { State, ifOtherSymbol } from '@turing-machine-js/machine';
const stateMap = State.collectStates(initial, tapeBlock);
// Toggle a state-level breakpoint by id (any pattern triggers).
const entry = stateMap.get(clickedStateId);
if (entry) {
entry.state.debug.before = true;
}
// Per-pattern breakpoint by GraphTransition.id — the contract is
// positional: `transitionSymbols[K]` is the Symbol that the
// `${stateId}-${K}` GraphTransition fires on.
const [n, k] = clickedEdgeId.split('-').map(Number);
const e = stateMap.get(n);
const sym = e?.transitionSymbols[k];
if (e && sym) {
e.state.debug.before = [sym];
}
Coverage rules: regular / bare states get the full [...#symbolToDataMap.keys()] including ifOtherSymbol at its natural slot; wrappers and the halt singleton get empty transitionSymbols; synthetic halt markers (Graph nodes with id = -2 * frameId, one per callable-subtree frame) are excluded from the map. See State.collectStates JSDoc for the full contract.
stateMap.get(0)!.state === haltState — the entry at id 0 is the process-wide halt singleton. Toggling its debug affects every machine in the runtime, same caveat as direct haltState.debug writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use session.setRunInterval(ms):
const session = new DebugSession(machine, { initialState });
session.setRunInterval(50); // 50ms between iters
session.on('iter', (m) => { /* update UI with iter snapshot */ });
await session.start();
The throttle inserts an awaited setTimeout(ms) at the end of every iter, after both pause dispatches (if any) and the iter event. Updates take effect on the next iter. 0 disables.
v7 migration from run({onPause, onStep, onIter, debug})
v7 splits the v6 mixed-mode run() into three non-overlapping entry points. Old shape → new shape:
// v6 — async run() with optional callbacks
await machine.run({
initialState,
onStep: (m) => { ... },
onPause: async (m) => { ... },
onIter: async (m) => { ... },
debug: true,
});
// v7 — DebugSession for interactive use
const session = new DebugSession(machine, { initialState });
session.on('step', (m) => { ... });
session.on('pause', (m) => { ...; session.continue(); });
session.on('iter', (m) => { ... });
await session.start();
Or, if you only used run({ initialState }) with no callbacks, just drop the await — run() is now synchronous:
// v6
await machine.run({ initialState });
// v7
machine.run({ initialState });
For sync per-iter tracing without breakpoint-driven flow, iterate the runStepByStep generator directly — onStep no longer exists:
// v6
await machine.run({ initialState, onStep: (m) => trace(m) });
// v7
for (const m of machine.runStepByStep({ initialState })) {
trace(m);
}
The debug: false master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a pause listener, breakpoints fire-and-resume invisibly (the session's start() still resolves cleanly), or you can use runStepByStep directly, which ignores state.debug altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened onStep to void | Promise<void> and added an inline await, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using onPause self-rearm on state.debug.after = true; that workaround is superseded by onIter in v6.4.0+.)
Special objects
haltState
A singleton State (id === 0). Transitioning into it stops the run. Imported as a named export from @turing-machine-js/machine; do not construct your own — state.isHalt checks identity against this single instance. See §Sentinels: halt vs abort for abortState, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
haltState and abortState are the two members of the sentinel family (state.isSentinel ≡ id <= 0) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
haltState (id === 0) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: state.withOverriddenHaltState(next) builds bigger machines out of halt-on-completion subroutines.
abortState (id === -1, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by withOverriddenHaltState — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no Error is thrown when a run ends this way.
abortState is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for abortState when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
import { Alphabet, State, Tape, TapeBlock, TuringMachine, abortState, haltState, ifOtherSymbol } from '@turing-machine-js/machine';
const alphabet = new Alphabet([' ', 'a', 'b']);
const tapeBlock = TapeBlock.fromTapes([new Tape({ alphabet, symbols: ['a'] })]);
const { symbol } = tapeBlock;
const cont = new State({ [ifOtherSymbol]: { nextState: haltState } }, 'cont');
const inner = new State({
[symbol(['a'])]: { nextState: abortState }, // legal: abort as a transition TARGET
[ifOtherSymbol]: { nextState: haltState },
}, 'inner');
const outer = inner.withOverriddenHaltState(cont); // subroutine call: run inner, then cont
inner.withOverriddenHaltState(abortState); // throws — abortState can't be a continuation
abortState.withOverriddenHaltState(inner); // throws — abortState can't be overridden
Identity: abortState.id === -1, abortState.isAbort === true, abortState.isHalt === false; state.isSentinel (id <= 0) is true for both sentinels and false for every user state. abortState.debug is a boolean, mirroring haltState.debug — see §Debugging.
toMermaid(State.toGraph(outer, tapeBlock)) for the wrapped machine above:
flowchart TD
%% alphabets: [[" ","a","b"]]
s1(((abort)))
s0(((halt)))
u1["cont"]
u3[["inner(cont)"]]
idle([idle])
subgraph w_2["callable subtree of inner"]
u2["inner"]
s0-2(((halt)))
end
idle -. enter .-> u3
u3 == "call" ==> u2
w_2 -. "return" .-> u3
u3 --> u1
u1 -- "[*] → [K]/[S]" --> s0
u2 -- "['a'] → [K]/[S]" --> s1
u2 -- "[*] → [K]/[S]" --> s0-2
classDef abortSentinel stroke:#c0392b,stroke-width:2px,stroke-dasharray:4 3
class s1 abortSentinel
The solid u2 -- "['a'] → [K]/[S]" --> s1 edge is the abort punch-through: it leaves inner's callable-subtree subgraph (w_2) and lands straight on the global abortState node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, w_2 -. "return" .-> u3: that one only fires when inner instead falls through to ifOtherSymbol, lands on the frame-local halt marker s0-2, and returns normally through the wrapper to cont.
RunResult
run() and runStepByStep() both return a call-scoped RunResult:
type RunResult = {
outcome: 'halted' | 'aborted';
state: State; // the state whose transition triggered the sentinel
stack: readonly State[]; // frozen; [] for 'halted' by construction
step: number; // 1-based iter count; 0 if initialState was itself a sentinel
};
'halted' implies stack === [], by construction, for a run that terminates NATURALLY — a haltState transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
'aborted': stack is the frozen backtrace of continuations abortState punched through — precisely the call-chain information an abort would otherwise discard. state is the triggering state, unwrapped to its bare if the transition fired from inside a withOverriddenHaltState wrapper (mirrors matchedTransition's same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via
generator.throw(haltState) on the runStepByStep generator — does NOT go through a natural halt/abort transition — it reports 'halted', but stack is whatever it stood at when the throw landed (not necessarily []) and state is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat:
runStepByStep's generator carries the same object as its return value (visible in the final { done: true, value }) — but a plain for...of discards generator returns. The canonical step-level signal is the one runStepByStep always had: the last yielded MachineState's nextState === abortState.
// Continuing the cont/inner/outer example above:
const result = new TuringMachine({ tapeBlock }).run({ initialState: outer });
// head reads 'a' → inner's transition fires → abortState, punching straight through `cont`:
// { outcome: 'aborted', state: inner, stack: [cont], step: 1 }
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
Thing
Mermaid id
Was
user states
u{id} (u1, u2, …)
s{id}
sentinels
s{ordinal} — halt s0, abort s1, a hypothetical 3rd sentinel s2, …
(halt was already s0)
halt marker, frame f
s0-{f} — "frame-f-local stand-in for s0"
c{f}
frame subgraphs
w_{f}
unchanged
idle
idle
unchanged
mermaidIdFor(id) / parseMermaidId(mermaidId) (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric Graph ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (-frameId → -2 * frameId, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel Symbol used as a key in a State definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in TapeCommand.movement:
movements.left — move the head one cell left
movements.right — move the head one cell right
movements.stay — leave the head where it is
symbolCommands
Special values for TapeCommand.symbol:
symbolCommands.keep — leave the current cell unchanged (default)
symbolCommands.erase — write the alphabet's blank symbol
Introspection and testing
@turing-machine-js/machine ships two complementary runtime utilities:
summarize / summarizeGraph — structural analysis. Looks at the state graph without running it.
import { summarize } from '@turing-machine-js/machine';
const stats = summarize(myState, myTapeBlock);
// {
// stateCount, transitionCount,
// compositionEdgeCount, maxCompositionDepth,
// selfLoopCount, hasCycles,
// tapeCount, alphabetCardinalities,
// }
State.inspect(state) returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
equivalentOn — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
import { equivalentOn } from '@turing-machine-js/machine';
const report = equivalentOn(
{ state: referenceState, getTapeBlock: () => referenceTapeBlock.clone() },
{ state: candidateState, getTapeBlock: () => candidateTapeBlock.clone() },
['^1
For different alphabets, pass { reference, candidate } paired cases plus a custom output comparator. See packages/machine/src/utilities/equivalence.spec.ts for worked examples.
Together: use summarize to ask "is this machine the right shape?" (size, composition, cycles), and equivalentOn to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see State.toGraph / State.fromGraph and toMermaid / fromMermaid.
Diagram conventions
The full reference for reading toMermaid output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
Shape
Meaning
s0(((halt)))
the halt state
uN["name"]
a regular state (or a bare, when inside a subgraph)
uN[["composite-name"]]
a withOverriddenHaltState wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223)
s0-F(((halt))) inside a subgraph
frame F's halt marker (visualization aid; maps back to the singleton haltState at runtime)
s1(((abort)))
the abortState sentinel — same terminal shape as halt, distinguished by a dashed-red classDef abortSentinel; emitted only when the graph actually references it (see §Sentinels: halt vs abort)
idle([idle])
pre-execution sentinel (not a real state)
Node ids follow a namespaced scheme (u/s/s0-) — see §Mermaid id scheme for the full mapping and the mermaidIdFor / parseMermaidId helpers.
Edge styles
Style
Where
Meaning
--> regular solid
between states; wrapper → override
plain transition / wrapper's post-return continuation
==> "call" thick solid
wrapper → bare
the wrapper's call into its callable subtree; reserved for wrapper-to-bare
w_N -. "return" .-> dotted
subtree → wrapper
the subtree's halt-marker has incoming → control returns to the calling wrapper
w_N -. "halt" .-> dotted
subtree → s0
the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt)
--> regular solid, crossing a subgraph boundary
any state (including in-frame) → s1
abort punch-through: drawn straight to the global abortState node, deliberately in contrast with halt's frame-local s0-F marker + dotted dispatch — no per-frame retargeting, no abort marker
idle -. enter .-> dotted
from idle to initial state
execution-start marker
The & ribbon syntax (s_W1 & s_W2 == "call" ==> s_A) collapses multiple wrappers that share a bare into one arrow. Bold ==> is reserved exclusively for the wrapper-to-bare call arrow.
Groupings
subgraph w_N["callable subtree of NAME"] … end wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label "callable scope: A ∪ B".
Tags
Tagged states (via state.tag('hot', 'sampled') — see §State tags) render two ways simultaneously:
- Inline in the node label:
uN["name<br>tag1, tag2"] — the <br> is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class:
classDef tag_<sanitized> fill:#...,stroke:#... per unique tag (6-color palette selected by tag-name hash), plus class uN,uM tag_<sanitized> listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The <br>-embedded label is the source of truth for fromMermaid round-trip; the classDef/class lines are decorative and regenerate on the next toMermaid emit. Tag-name sanitization in classDef identifiers: any char outside [A-Za-z0-9_-] is replaced with _. Labels preserve the raw tag names.
Edge label format
[reads] → [writes]/[moves]. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
Glyph
Where
Meaning
'X'
read, write
literal alphabet symbol (single-quoted)
*
read only
ifOtherSymbol catch-all (ASCII *; a literal * in the alphabet renders as the quoted '*', so the marker stays unambiguous)
B
read only
the tape's blank symbol (a literal B in the alphabet appears as 'B', so the marker stays unambiguous)
K
write only
keep (no write)
E
write only
erase (write the tape's blank)
L / R / S
move only
left / right / stay
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape:
['^']|['1']|['0']
- Multi-tape:
['0','a']|['1','b'] — "(tape 1='0' AND tape 2='a') OR (tape 1='1' AND tape 2='b')"
The compact in-bracket form ['^'|'1'] is rejected by fromMermaid — and never emitted by toMermaid. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (['0'|'1','a'|'b'] could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
flowchart TD
%% alphabets: [[" ","0","1"],[" ","0","1"]]
s0(((halt)))
u1["copy"]
idle([idle])
idle -. enter .-> u1
u1 -- "['0',*] → [K,'0']/[R,R]" --> u1
u1 -- "['1',*] → [K,'1']/[R,R]" --> u1
u1 -- "[B,*] → [K]/[S]" --> s0
Reading ['0',*] → [K,'0']/[R,R]:
- Read
['0',*] — tape 1 must be literal '0'; tape 2 is ifOtherSymbol (any).
- Write
[K,'0'] — tape 1: keep; tape 2: write literal '0'.
- Move
[R,R] — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — run() became async (Promise<void>). Per-state runtime breakpoints landed (state.debug.before / state.debug.after); run() accepted an onDebugBreak hook. MachineState exposed on each yield.
v5 — onDebugBreak renamed to onPause. New run({ debug: boolean }) master switch suppresses all onPause dispatches without unsetting state.debug assignments. Assigning a truthy .after to haltState.debug now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: haltState.debug is now boolean, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to before → step → after, all firing on the same yield. Previously after fired on iter K+1's tick with a prevYield substitution dance; that substitution is gone. (The MachineState.debugBreak field shape held through v6; v7 removes it — breakpoint detection moved into DebugSession, and the pause descriptor is now m.pause: {side, cause} on the pause event only.)
v6.1 — state.debug ergonomics: the field is now always a non-null DebugConfig instance (lazy-initialized on first read), so chained field writes like state.debug.before = true work on a fresh state without a prior whole-object assignment. The DebugConfig instance is Object.seal-ed, so typos like state.debug.bofore = true throw TypeError at write time instead of silently creating a useless property. state.debug = null continues to work but semantically means "reset filters" — the next read returns a fresh empty DebugConfig (#150).
v6.2 (superseded by v6.3.0) — widened onStep's signature to (m) => void | Promise<void> and added an inline await onStep(...) in the run loop, enabling throttle-in-onStep patterns. This overturned the docstring-stated contract that onStep is sync (microtask-free); the right place for per-iter throttling is onPause with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — onStep reverted to its v6.0–v6.1 sync contract — (m) => void, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New onIter hook on run(): awaited, fires once at the end of every iter (after both onPause dispatches on the same yield), unaffected by the debug master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync onStep (tracing) and conditional onPause (user breakpoints). Three-hook contract is now onStep (sync, mid-iter) / onPause (awaited, on state.debug match) / onIter (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's onPause-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed State.collectStates lookup + DebugSession step controls + CallFrame + tapeViewport/TapeSnapshot. Stable release on the latest dist-tag: npm install @turing-machine-js/machine. Highlights across the v7 alpha cycle:
alpha.8 — TapeSnapshot type + tapeViewport helper (#227) moved into the engine from @turing-machine-js/visuals, next to the live Tape class (visuals re-exports for consumer-import stability). Tape.viewport getter refactored to share its centering loop with tapeViewport via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate cellAt lambdas. See §Tape.
alpha.7 — CallFrame extraction (#213) — withOverriddenHaltState's wrapper is now a first-class CallFrame extends State subclass that delegates transition lookups + debug to its bare; instanceof State preserved (additive), instanceof CallFrame discriminates wrappers. Plus toMermaid framed-wrapper emit fix (#223) — toGraph's reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. library-binary-numbers/minusOne's goToNumberStart(invertNumberGoToNumberWithInversion) inside invertNumber's callable subtree) render inside the owner subgraph rather than escaping to the top level. library-binary-numbers/states.md regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. run() is now sync + callback-free; runStepByStep is the pure-iteration primitive (no state.debug filter evaluation); a new DebugSession class (new DebugSession(machine, {initialState})) owns all interactive debugging via pause / step / iter / halt events, depth-based stepIn / stepOver / stepOut, external pause() / stop() / setRunInterval(ms). Per-yield m.debugBreak: {before?, after?, cause} replaced by one-sided m.pause: {side, cause} on pause events only. See §Debugging.
alpha.5 — Per-iter matchedTransition (#205) on every MachineState yield ({id, matchKinds}, id is ${stateId}.${ix} resolvable in toGraph). haltState.debug collapsed to a boolean (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with m.state = the triggering state. HaltState typed alias narrows debug to boolean at the canonical access path.
alpha.4 — State.collectStates(initial, tapeBlock) (#195) returns a Map<number, {state, transitionSymbols}> keyed by GraphNode.id so downstream tooling can mutate state.debug by numeric id and set per-pattern breakpoints by GraphTransition.id. Graph serialization extracted to utilities/stateGraph.ts with a Symbol-keyed @internal accessor on State (#180; no public-API change — the State.toGraph / .fromGraph statics remain as thin delegates). Two upstream fixes: toMermaid HTML-entity-escapes user content in labels so alphabets containing ", <, etc. parse correctly (#194); runStepByStep's halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same TuringMachine instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). state.tag(...) / .untag(...) / .tags API; GraphNode.tags: string[] round-trips through toGraph/fromGraph; toMermaid emits tags two ways simultaneously — inline via <br> in node labels (sN["name<br>tag1, tag2"]) and as classDef/class for color grouping. Tags live on the State instance (not on the shared #symbolToDataMap), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree toMermaid emit refinement (#174). The wrapper is a separate [[composite-name]] node OUTSIDE the subgraph; the bare's reachable subtree becomes a subgraph w_${frameId}["callable subtree of NAME"] block. Frames computed via union-find — shared bares dedupe with & ribbons on call arrows. Bold ==> "call" reserved for wrapper-to-bare; dotted -.-> for frame dispatch (return / halt / enter). Plus engine memoization (#175) and nested-chain collapse (#176) for .wohs().
alpha.1 — initial v7 composition-representation overhaul:
withOverrodeHaltState → withOverriddenHaltState (#149). Grammar fix on a name introduced in 2019: the past-participle overridden fits the "with a halt-state that has been ___" naming idiom; overrode (simple past) didn't. Hard cutover — no deprecated alias. The getter (state.overrodeHaltState → state.overriddenHaltState) and the serialized Graph data field (node.overrodeHaltStateId → node.overriddenHaltStateId) rename in lockstep. Consumer migration: global find/replace OverrodeHaltState → OverriddenHaltState and overrodeHaltState → overriddenHaltState. Persisted State.toGraph JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148).
withOverriddenHaltState's composite name format changed from flat bare>override to nested bare(override). Same nesting depth reads as A(B(A)) (bare = A, override = B(A)) versus A(B)(A) (bare = A(B), override = A) — two structurally-different wrap-trees that the old >-flat notation collided into the single string A>B>A. As a consequence, user-provided state names must not contain ( or ) — State now throws at construction time if a user passes such a name. The > character stays valid in user names (no longer reserved). The inspect() / toGraph / toMermaid outputs carry the new format. states.md files in library-binary-numbers regenerate accordingly.
toMermaid callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). withOverriddenHaltState is modeled as a function call: the wrapper is a [[composite-name]] call site OUTSIDE any subgraph, the bare's reachable subtree becomes a subgraph w_${frameId}["callable subtree of NAME"] … end block containing the bare + body states + a per-frame halt marker c${frameId}(((halt))). Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (library-binary-numbers/minusOne's invertNumber) appear ONCE with & -joined call arrows from each wrapper. Bold ==> "call" arrows are reserved for the wrapper-to-bare call; dotted -.-> is reserved for frame-level dispatch (return / halt / enter). The retired -. onHalt .-> keyword is replaced by a solid --> override arrow (just an ordinary transition under the call/return mental model). GraphNode gains isWrapper, bareStateId, frameId fields (and drops isWrapped). No per-context duplication: a shared bare emits a single de-duped subtree and fromGraph rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (equivalentOn) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with
^…$ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
]); // single tape: matches any of '^', '0', '1', '
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__
You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__
The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__
The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15__
__INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__
Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
Field
Type
Meaning
__INLINE_CODE_138__
__INLINE_CODE_139__
1-indexed iteration number
__INLINE_CODE_140__
__INLINE_CODE_141__
the state about to execute
__INLINE_CODE_142__
__INLINE_CODE_143__
per-tape head symbols, before the command applies
__INLINE_CODE_144__
__INLINE_CODE_145__
per-tape symbols that will be written
__INLINE_CODE_146__
__INLINE_CODE_147__
per-tape head moves (__INLINE_CODE_148__)
__INLINE_CODE_149__
__INLINE_CODE_150__
the state that will execute next
__INLINE_CODE_151__
__INLINE_CODE_152__
the transition the engine picked for this iter — see Matched transition below
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
__INLINE_CODE_158__
__INLINE_CODE_159__
__INLINE_CODE_160__
Shape
sync, returns __INLINE_CODE_161__
sync generator, returns __INLINE_CODE_162__
async session with events
Observation
none
per-iter via __INLINE_CODE_163__
event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__)
Step controls
—
—
__INLINE_CODE_168__
Throttle
—
—
__INLINE_CODE_169__
Breakpoint handling
not consulted — runs straight to halt
not consulted — yields every iter; __INLINE_CODE_170__ is ignored
the only mode that reacts — fires a __INLINE_CODE_171__ event
Best for
run-to-halt with no observation overhead
tracing, snapshots, test harnesses, custom batching
UI debuggers, IDE extensions, educational demos
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17__
__INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__
Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__
What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20__
__INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__
Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__
Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__
Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24__
__INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
Method
Description
__INLINE_CODE_353__
Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws.
__INLINE_CODE_355__
Resume from a pause and run to the next breakpoint or halt.
__INLINE_CODE_356__
Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into.
__INLINE_CODE_357__
Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over.
__INLINE_CODE_359__
Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out.
__INLINE_CODE_361__
Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__).
__INLINE_CODE_364__
Terminate immediately. __INLINE_CODE_365__ event does NOT fire.
__INLINE_CODE_366__
Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs.
__INLINE_CODE_369__
Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below.
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
Event
Argument
Dispatch
Fires
__INLINE_CODE_381__
__INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__)
Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget.
A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested.
__INLINE_CODE_387__
__INLINE_CODE_388__
Fire-and-forget (sync hot-loop tracing).
Once per iter, between any before-pause and after-pause.
__INLINE_CODE_389__
__INLINE_CODE_390__
Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis.
Once per iter, at end. After any after-pause.
__INLINE_CODE_391__
__INLINE_CODE_392__
Fire-and-forget.
Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called.
__INLINE_CODE_394__
__INLINE_CODE_395__
Fire-and-forget.
Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called.
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__
So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__
Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__
The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__
Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__
For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__
The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__
Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__
The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__
- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
__CODE_BLOCK_34__
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
Thing
Mermaid id
Was
user states
__INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …)
__INLINE_CODE_540__
sentinels
__INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, …
(halt was already __INLINE_CODE_545__)
halt marker, frame __INLINE_CODE_546__
__INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__"
__INLINE_CODE_550__
frame subgraphs
__INLINE_CODE_551__
unchanged
idle
__INLINE_CODE_552__
unchanged
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35__
__INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
Shape
Meaning
__INLINE_CODE_581__
the halt state
__INLINE_CODE_582__
a regular state (or a bare, when inside a subgraph)
__INLINE_CODE_583__
a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223)
__INLINE_CODE_585__ inside a subgraph
frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime)
__INLINE_CODE_588__
the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort)
__INLINE_CODE_591__
pre-execution sentinel (not a real state)
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
Style
Where
Meaning
__INLINE_CODE_597__ regular solid
between states; wrapper → override
plain transition / wrapper's post-return continuation
__INLINE_CODE_598__ thick solid
wrapper → bare
the wrapper's call into its callable subtree; reserved for wrapper-to-bare
__INLINE_CODE_599__ dotted
subtree → wrapper
the subtree's halt-marker has incoming → control returns to the calling wrapper
__INLINE_CODE_600__ dotted
subtree → __INLINE_CODE_601__
the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt)
__INLINE_CODE_602__ regular solid, crossing a subgraph boundary
any state (including in-frame) → __INLINE_CODE_603__
abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker
__INLINE_CODE_606__ dotted
from __INLINE_CODE_607__ to initial state
execution-start marker
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
Glyph
Where
Meaning
__INLINE_CODE_628__
read, write
literal alphabet symbol (single-quoted)
__INLINE_CODE_629__
read only
__INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous)
__INLINE_CODE_634__
read only
the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous)
__INLINE_CODE_637__
write only
keep (no write)
__INLINE_CODE_638__
write only
erase (write the tape's blank)
__INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__
move only
left / right / stay
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__
Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
tapeBlock.symbol(['0', 'a']); // 2 tapes: matches when tape 1 is '0' AND tape 2 is 'a'
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__
You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__
The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__
The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15__
__INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__
Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
Field
Type
Meaning
__INLINE_CODE_138__
__INLINE_CODE_139__
1-indexed iteration number
__INLINE_CODE_140__
__INLINE_CODE_141__
the state about to execute
__INLINE_CODE_142__
__INLINE_CODE_143__
per-tape head symbols, before the command applies
__INLINE_CODE_144__
__INLINE_CODE_145__
per-tape symbols that will be written
__INLINE_CODE_146__
__INLINE_CODE_147__
per-tape head moves (__INLINE_CODE_148__)
__INLINE_CODE_149__
__INLINE_CODE_150__
the state that will execute next
__INLINE_CODE_151__
__INLINE_CODE_152__
the transition the engine picked for this iter — see Matched transition below
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
__INLINE_CODE_158__
__INLINE_CODE_159__
__INLINE_CODE_160__
Shape
sync, returns __INLINE_CODE_161__
sync generator, returns __INLINE_CODE_162__
async session with events
Observation
none
per-iter via __INLINE_CODE_163__
event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__)
Step controls
—
—
__INLINE_CODE_168__
Throttle
—
—
__INLINE_CODE_169__
Breakpoint handling
not consulted — runs straight to halt
not consulted — yields every iter; __INLINE_CODE_170__ is ignored
the only mode that reacts — fires a __INLINE_CODE_171__ event
Best for
run-to-halt with no observation overhead
tracing, snapshots, test harnesses, custom batching
UI debuggers, IDE extensions, educational demos
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17__
__INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__
Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__
What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20__
__INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__
Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__
Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__
Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24__
__INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
Method
Description
__INLINE_CODE_353__
Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws.
__INLINE_CODE_355__
Resume from a pause and run to the next breakpoint or halt.
__INLINE_CODE_356__
Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into.
__INLINE_CODE_357__
Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over.
__INLINE_CODE_359__
Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out.
__INLINE_CODE_361__
Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__).
__INLINE_CODE_364__
Terminate immediately. __INLINE_CODE_365__ event does NOT fire.
__INLINE_CODE_366__
Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs.
__INLINE_CODE_369__
Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below.
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
Event
Argument
Dispatch
Fires
__INLINE_CODE_381__
__INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__)
Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget.
A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested.
__INLINE_CODE_387__
__INLINE_CODE_388__
Fire-and-forget (sync hot-loop tracing).
Once per iter, between any before-pause and after-pause.
__INLINE_CODE_389__
__INLINE_CODE_390__
Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis.
Once per iter, at end. After any after-pause.
__INLINE_CODE_391__
__INLINE_CODE_392__
Fire-and-forget.
Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called.
__INLINE_CODE_394__
__INLINE_CODE_395__
Fire-and-forget.
Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called.
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__
So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__
Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__
The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__
Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__
For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__
The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__
Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__
The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__
- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
__CODE_BLOCK_34__
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
Thing
Mermaid id
Was
user states
__INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …)
__INLINE_CODE_540__
sentinels
__INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, …
(halt was already __INLINE_CODE_545__)
halt marker, frame __INLINE_CODE_546__
__INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__"
__INLINE_CODE_550__
frame subgraphs
__INLINE_CODE_551__
unchanged
idle
__INLINE_CODE_552__
unchanged
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35__
__INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
Shape
Meaning
__INLINE_CODE_581__
the halt state
__INLINE_CODE_582__
a regular state (or a bare, when inside a subgraph)
__INLINE_CODE_583__
a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223)
__INLINE_CODE_585__ inside a subgraph
frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime)
__INLINE_CODE_588__
the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort)
__INLINE_CODE_591__
pre-execution sentinel (not a real state)
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
Style
Where
Meaning
__INLINE_CODE_597__ regular solid
between states; wrapper → override
plain transition / wrapper's post-return continuation
__INLINE_CODE_598__ thick solid
wrapper → bare
the wrapper's call into its callable subtree; reserved for wrapper-to-bare
__INLINE_CODE_599__ dotted
subtree → wrapper
the subtree's halt-marker has incoming → control returns to the calling wrapper
__INLINE_CODE_600__ dotted
subtree → __INLINE_CODE_601__
the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt)
__INLINE_CODE_602__ regular solid, crossing a subgraph boundary
any state (including in-frame) → __INLINE_CODE_603__
abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker
__INLINE_CODE_606__ dotted
from __INLINE_CODE_607__ to initial state
execution-start marker
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
Glyph
Where
Meaning
__INLINE_CODE_628__
read, write
literal alphabet symbol (single-quoted)
__INLINE_CODE_629__
read only
__INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous)
__INLINE_CODE_634__
read only
the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous)
__INLINE_CODE_637__
write only
keep (no write)
__INLINE_CODE_638__
write only
erase (write the tape's blank)
__INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__
move only
left / right / stay
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__
Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
])]: { command: { movement: movements.left }, nextState: haltState },
}, 'name');
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__
The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__
The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15__
__INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__
Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
Field
Type
Meaning
__INLINE_CODE_138__
__INLINE_CODE_139__
1-indexed iteration number
__INLINE_CODE_140__
__INLINE_CODE_141__
the state about to execute
__INLINE_CODE_142__
__INLINE_CODE_143__
per-tape head symbols, before the command applies
__INLINE_CODE_144__
__INLINE_CODE_145__
per-tape symbols that will be written
__INLINE_CODE_146__
__INLINE_CODE_147__
per-tape head moves (__INLINE_CODE_148__)
__INLINE_CODE_149__
__INLINE_CODE_150__
the state that will execute next
__INLINE_CODE_151__
__INLINE_CODE_152__
the transition the engine picked for this iter — see Matched transition below
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
__INLINE_CODE_158__
__INLINE_CODE_159__
__INLINE_CODE_160__
Shape
sync, returns __INLINE_CODE_161__
sync generator, returns __INLINE_CODE_162__
async session with events
Observation
none
per-iter via __INLINE_CODE_163__
event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__)
Step controls
—
—
__INLINE_CODE_168__
Throttle
—
—
__INLINE_CODE_169__
Breakpoint handling
not consulted — runs straight to halt
not consulted — yields every iter; __INLINE_CODE_170__ is ignored
the only mode that reacts — fires a __INLINE_CODE_171__ event
Best for
run-to-halt with no observation overhead
tracing, snapshots, test harnesses, custom batching
UI debuggers, IDE extensions, educational demos
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17__
__INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__
Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__
What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20__
__INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__
Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__
Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__
Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24__
__INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
Method
Description
__INLINE_CODE_353__
Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws.
__INLINE_CODE_355__
Resume from a pause and run to the next breakpoint or halt.
__INLINE_CODE_356__
Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into.
__INLINE_CODE_357__
Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over.
__INLINE_CODE_359__
Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out.
__INLINE_CODE_361__
Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__).
__INLINE_CODE_364__
Terminate immediately. __INLINE_CODE_365__ event does NOT fire.
__INLINE_CODE_366__
Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs.
__INLINE_CODE_369__
Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below.
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
Event
Argument
Dispatch
Fires
__INLINE_CODE_381__
__INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__)
Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget.
A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested.
__INLINE_CODE_387__
__INLINE_CODE_388__
Fire-and-forget (sync hot-loop tracing).
Once per iter, between any before-pause and after-pause.
__INLINE_CODE_389__
__INLINE_CODE_390__
Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis.
Once per iter, at end. After any after-pause.
__INLINE_CODE_391__
__INLINE_CODE_392__
Fire-and-forget.
Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called.
__INLINE_CODE_394__
__INLINE_CODE_395__
Fire-and-forget.
Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called.
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__
So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__
Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__
The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__
Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__
For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__
The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__
Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__
The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__
- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
__CODE_BLOCK_34__
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
Thing
Mermaid id
Was
user states
__INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …)
__INLINE_CODE_540__
sentinels
__INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, …
(halt was already __INLINE_CODE_545__)
halt marker, frame __INLINE_CODE_546__
__INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__"
__INLINE_CODE_550__
frame subgraphs
__INLINE_CODE_551__
unchanged
idle
__INLINE_CODE_552__
unchanged
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35__
__INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
Shape
Meaning
__INLINE_CODE_581__
the halt state
__INLINE_CODE_582__
a regular state (or a bare, when inside a subgraph)
__INLINE_CODE_583__
a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223)
__INLINE_CODE_585__ inside a subgraph
frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime)
__INLINE_CODE_588__
the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort)
__INLINE_CODE_591__
pre-execution sentinel (not a real state)
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
Style
Where
Meaning
__INLINE_CODE_597__ regular solid
between states; wrapper → override
plain transition / wrapper's post-return continuation
__INLINE_CODE_598__ thick solid
wrapper → bare
the wrapper's call into its callable subtree; reserved for wrapper-to-bare
__INLINE_CODE_599__ dotted
subtree → wrapper
the subtree's halt-marker has incoming → control returns to the calling wrapper
__INLINE_CODE_600__ dotted
subtree → __INLINE_CODE_601__
the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt)
__INLINE_CODE_602__ regular solid, crossing a subgraph boundary
any state (including in-frame) → __INLINE_CODE_603__
abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker
__INLINE_CODE_606__ dotted
from __INLINE_CODE_607__ to initial state
execution-start marker
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
Glyph
Where
Meaning
__INLINE_CODE_628__
read, write
literal alphabet symbol (single-quoted)
__INLINE_CODE_629__
read only
__INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous)
__INLINE_CODE_634__
read only
the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous)
__INLINE_CODE_637__
write only
keep (no write)
__INLINE_CODE_638__
write only
erase (write the tape's blank)
__INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__
move only
left / right / stay
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__
Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
]); // single tape: matches any of '^', '0', '1', '
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__
You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__
The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__
The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15__
__INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__
Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
Field
Type
Meaning
__INLINE_CODE_138__
__INLINE_CODE_139__
1-indexed iteration number
__INLINE_CODE_140__
__INLINE_CODE_141__
the state about to execute
__INLINE_CODE_142__
__INLINE_CODE_143__
per-tape head symbols, before the command applies
__INLINE_CODE_144__
__INLINE_CODE_145__
per-tape symbols that will be written
__INLINE_CODE_146__
__INLINE_CODE_147__
per-tape head moves (__INLINE_CODE_148__)
__INLINE_CODE_149__
__INLINE_CODE_150__
the state that will execute next
__INLINE_CODE_151__
__INLINE_CODE_152__
the transition the engine picked for this iter — see Matched transition below
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
__INLINE_CODE_158__
__INLINE_CODE_159__
__INLINE_CODE_160__
Shape
sync, returns __INLINE_CODE_161__
sync generator, returns __INLINE_CODE_162__
async session with events
Observation
none
per-iter via __INLINE_CODE_163__
event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__)
Step controls
—
—
__INLINE_CODE_168__
Throttle
—
—
__INLINE_CODE_169__
Breakpoint handling
not consulted — runs straight to halt
not consulted — yields every iter; __INLINE_CODE_170__ is ignored
the only mode that reacts — fires a __INLINE_CODE_171__ event
Best for
run-to-halt with no observation overhead
tracing, snapshots, test harnesses, custom batching
UI debuggers, IDE extensions, educational demos
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17__
__INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__
Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__
What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20__
__INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__
Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__
Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__
Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24__
__INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
Method
Description
__INLINE_CODE_353__
Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws.
__INLINE_CODE_355__
Resume from a pause and run to the next breakpoint or halt.
__INLINE_CODE_356__
Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into.
__INLINE_CODE_357__
Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over.
__INLINE_CODE_359__
Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out.
__INLINE_CODE_361__
Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__).
__INLINE_CODE_364__
Terminate immediately. __INLINE_CODE_365__ event does NOT fire.
__INLINE_CODE_366__
Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs.
__INLINE_CODE_369__
Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below.
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
Event
Argument
Dispatch
Fires
__INLINE_CODE_381__
__INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__)
Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget.
A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested.
__INLINE_CODE_387__
__INLINE_CODE_388__
Fire-and-forget (sync hot-loop tracing).
Once per iter, between any before-pause and after-pause.
__INLINE_CODE_389__
__INLINE_CODE_390__
Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis.
Once per iter, at end. After any after-pause.
__INLINE_CODE_391__
__INLINE_CODE_392__
Fire-and-forget.
Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called.
__INLINE_CODE_394__
__INLINE_CODE_395__
Fire-and-forget.
Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called.
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__
So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__
Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__
The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__
Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__
For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__
The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__
Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__
The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__
- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
__CODE_BLOCK_34__
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
Thing
Mermaid id
Was
user states
__INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …)
__INLINE_CODE_540__
sentinels
__INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, …
(halt was already __INLINE_CODE_545__)
halt marker, frame __INLINE_CODE_546__
__INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__"
__INLINE_CODE_550__
frame subgraphs
__INLINE_CODE_551__
unchanged
idle
__INLINE_CODE_552__
unchanged
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35__
__INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
Shape
Meaning
__INLINE_CODE_581__
the halt state
__INLINE_CODE_582__
a regular state (or a bare, when inside a subgraph)
__INLINE_CODE_583__
a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223)
__INLINE_CODE_585__ inside a subgraph
frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime)
__INLINE_CODE_588__
the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort)
__INLINE_CODE_591__
pre-execution sentinel (not a real state)
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
Style
Where
Meaning
__INLINE_CODE_597__ regular solid
between states; wrapper → override
plain transition / wrapper's post-return continuation
__INLINE_CODE_598__ thick solid
wrapper → bare
the wrapper's call into its callable subtree; reserved for wrapper-to-bare
__INLINE_CODE_599__ dotted
subtree → wrapper
the subtree's halt-marker has incoming → control returns to the calling wrapper
__INLINE_CODE_600__ dotted
subtree → __INLINE_CODE_601__
the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt)
__INLINE_CODE_602__ regular solid, crossing a subgraph boundary
any state (including in-frame) → __INLINE_CODE_603__
abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker
__INLINE_CODE_606__ dotted
from __INLINE_CODE_607__ to initial state
execution-start marker
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
Glyph
Where
Meaning
__INLINE_CODE_628__
read, write
literal alphabet symbol (single-quoted)
__INLINE_CODE_629__
read only
__INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous)
__INLINE_CODE_634__
read only
the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous)
__INLINE_CODE_637__
write only
keep (no write)
__INLINE_CODE_638__
write only
erase (write the tape's blank)
__INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__
move only
left / right / stay
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__
Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
tapeBlock.symbol(['0', 'a']); // 2 tapes: matches when tape 1 is '0' AND tape 2 is 'a'
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
const ref = new Reference();
const a = new State({ [symbol(['x'])]: { nextState: ref } }, 'a');
const b = new State({ [symbol(['y'])]: { nextState: a } }, 'b');
ref.bind(b); // a's transition now resolves to b at run time
The resulting cycle (__INLINE_CODE_125__):
flowchart TD
%% alphabets: [[" ","x","y"]]
u1["a"]
u2["b"]
idle([idle])
idle -. enter .-> u1
u1 -- "['x'] → [K]/[S]" --> u2
u2 -- "['y'] → [K]/[S]" --> u1
__INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
const machine = new TuringMachine({ tapeBlock });
// Run to halt — `run()` is synchronous and returns a RunResult:
const result = machine.run({ initialState, stepsLimit: 1e5 });
// result: { outcome: 'halted' | 'aborted', state, stack, step } — see
// "Sentinels: halt vs abort" below for the aborted case.
// Or step-by-step (useful for tracing / observation):
for (const step of machine.runStepByStep({ initialState })) {
console.log(step.state.name, step.currentSymbols, '→', step.nextSymbols, step.movements);
}
// For interactive debugging (breakpoints, step-in / step-over / step-out,
// throttle, click-pause), construct a DebugSession — see "Debugging" below.
Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
matchedTransition: {
id: string; // resolvable in toGraph
matchKinds: ('wildcard' | 'literal')[]; // per-tape, length = tape count
}
__INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
for (const m of machine.runStepByStep({initialState})) {
const wildcardPositions = m.matchedTransition.matchKinds // per-tape, e.g. ['wildcard', 'literal']
.map((k, i) => k === 'wildcard' ? i : -1)
.filter((i) => i >= 0);
console.log(`step ${m.step}: fired transition ${m.matchedTransition.id} (wildcards at tapes: ${wildcardPositions.join(',') || 'none'})`);
}
Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
import { Alphabet, State, TapeBlock, TuringMachine, Tape, haltState, ifOtherSymbol, movements, symbolCommands } from '@turing-machine-js/machine';
const alphabet = new Alphabet([' ', 'a', 'b', 'X']);
const tapeBlock = TapeBlock.fromAlphabets([alphabet]);
const { symbol } = tapeBlock;
// Reusable subroutine 1: walk right until 'X', halt on it.
const scanToX = new State({
[symbol(['X'])]: { nextState: haltState },
[ifOtherSymbol]: { command: { movement: movements.right } },
}, 'scanToX');
// Reusable subroutine 2: erase the head cell, halt.
const eraseHere = new State({
[ifOtherSymbol]: { command: { symbol: symbolCommands.erase }, nextState: haltState },
}, 'eraseHere');
// Compose: scan to X, then ERASE it. scanToX is unmodified.
const scanThenErase = scanToX.withOverriddenHaltState(eraseHere);
const tape = new Tape({ alphabet, symbols: ['a', 'b', 'X', 'b', 'a'] });
tapeBlock.replaceTape(tape);
await new TuringMachine({ tapeBlock }).run({ initialState: scanThenErase });
console.log(tape.symbols.join('')); // "ab ba" — the X at index 2 is gone, head landed there.
What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
flowchart TD
%% alphabets: [[" ","a","b","X"]]
s0(((halt)))
u1["scanToX"]
idle([idle])
idle -. enter .-> u1
u1 -- "['X'] → [K]/[S]" --> s0
u1 -- "[*] → [K]/[R]" --> u1
__INLINE_CODE_230__ — the wrapped composition:
flowchart TD
%% alphabets: [[" ","a","b","X"]]
s0(((halt)))
u2["eraseHere"]
u3[["scanToX(eraseHere)"]]
idle([idle])
subgraph w_1["callable subtree of scanToX"]
u1["scanToX"]
s0-1(((halt)))
end
idle -. enter .-> u3
u3 == "call" ==> u1
w_1 -. "return" .-> u3
u3 --> u2
u1 -- "['X'] → [K]/[S]" --> s0-1
u1 -- "[*] → [K]/[R]" --> u1
u2 -- "[*] → [E]/[S]" --> s0
Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
const s = new State({...}, 'walkToBlank::1')
.tag('hot', 'subroutine-entry');
s.tags; // readonly ['hot', 'subroutine-entry'] — frozen snapshot
s.untag('hot');
s.tags; // readonly ['subroutine-entry']
Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
import { DebugSession } from '@turing-machine-js/machine';
const session = new DebugSession(machine, { initialState });
session.on('pause', (m) => {
console.log(`paused at ${m.state.name}, ${m.pause.side} side, cause: ${m.pause.cause}`);
session.stepIn(); // or stepOver(), stepOut(), continue(), stop()
});
session.on('step', (m) => { /* fires once per iter, mid-iter */ });
session.on('iter', (m) => { /* fires once per iter, end-of-iter */ });
session.on('halt', (result) => { /* fires on natural halt (not on stop()) */ });
session.on('abort', (result) => { /* fires when the run hits abortState (not on stop()) */ });
await session.start(); // resolves on halt, abort, or stop()
Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
import { State, abortState, haltState, ifOtherSymbol } from '@turing-machine-js/machine';
const myState = new State({...});
// state.debug is always a DebugConfig instance — chained writes work
// without prior whole-object assignment:
myState.debug.before = true;
myState.debug.after = [symA];
// Whole-object assignment also works for one-shot setup:
myState.debug = { before: true };
myState.debug = { before: [symA] };
myState.debug = { before: [symA], after: [symA] };
// Pause when the engine is about to enter halt (program exit OR subroutine pop).
// haltState.debug is a `boolean` (#207) — halt is terminal, so there's only
// one meaningful pause moment (post-triggering-iter, before halt processing).
haltState.debug = true;
haltState.debug = false; // turn off
haltState.debug = null; // alias of false (reset)
// abortState.debug mirrors haltState.debug (#239) — same boolean shape, same
// single pause moment: the AFTER side of the iter whose transition targets
// abortState, fired before the terminal 'abort' event.
abortState.debug = true;
abortState.debug = false; // turn off
abortState.debug = null; // alias of false (reset)
// Reset filters later on a regular state — next read returns a fresh empty DebugConfig:
myState.debug = null;
__INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
breakpoint > step > manual
So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
import { State, ifOtherSymbol } from '@turing-machine-js/machine';
const stateMap = State.collectStates(initial, tapeBlock);
// Toggle a state-level breakpoint by id (any pattern triggers).
const entry = stateMap.get(clickedStateId);
if (entry) {
entry.state.debug.before = true;
}
// Per-pattern breakpoint by GraphTransition.id — the contract is
// positional: `transitionSymbols[K]` is the Symbol that the
// `${stateId}-${K}` GraphTransition fires on.
const [n, k] = clickedEdgeId.split('-').map(Number);
const e = stateMap.get(n);
const sym = e?.transitionSymbols[k];
if (e && sym) {
e.state.debug.before = [sym];
}
Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
const session = new DebugSession(machine, { initialState });
session.setRunInterval(50); // 50ms between iters
session.on('iter', (m) => { /* update UI with iter snapshot */ });
await session.start();
The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
// v6 — async run() with optional callbacks
await machine.run({
initialState,
onStep: (m) => { ... },
onPause: async (m) => { ... },
onIter: async (m) => { ... },
debug: true,
});
// v7 — DebugSession for interactive use
const session = new DebugSession(machine, { initialState });
session.on('step', (m) => { ... });
session.on('pause', (m) => { ...; session.continue(); });
session.on('iter', (m) => { ... });
await session.start();
Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
// v6
await machine.run({ initialState });
// v7
machine.run({ initialState });
For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
// v6
await machine.run({ initialState, onStep: (m) => trace(m) });
// v7
for (const m of machine.runStepByStep({ initialState })) {
trace(m);
}
The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
import { Alphabet, State, Tape, TapeBlock, TuringMachine, abortState, haltState, ifOtherSymbol } from '@turing-machine-js/machine';
const alphabet = new Alphabet([' ', 'a', 'b']);
const tapeBlock = TapeBlock.fromTapes([new Tape({ alphabet, symbols: ['a'] })]);
const { symbol } = tapeBlock;
const cont = new State({ [ifOtherSymbol]: { nextState: haltState } }, 'cont');
const inner = new State({
[symbol(['a'])]: { nextState: abortState }, // legal: abort as a transition TARGET
[ifOtherSymbol]: { nextState: haltState },
}, 'inner');
const outer = inner.withOverriddenHaltState(cont); // subroutine call: run inner, then cont
inner.withOverriddenHaltState(abortState); // throws — abortState can't be a continuation
abortState.withOverriddenHaltState(inner); // throws — abortState can't be overridden
Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
flowchart TD
%% alphabets: [[" ","a","b"]]
s1(((abort)))
s0(((halt)))
u1["cont"]
u3[["inner(cont)"]]
idle([idle])
subgraph w_2["callable subtree of inner"]
u2["inner"]
s0-2(((halt)))
end
idle -. enter .-> u3
u3 == "call" ==> u2
w_2 -. "return" .-> u3
u3 --> u1
u1 -- "[*] → [K]/[S]" --> s0
u2 -- "['a'] → [K]/[S]" --> s1
u2 -- "[*] → [K]/[S]" --> s0-2
classDef abortSentinel stroke:#c0392b,stroke-width:2px,stroke-dasharray:4 3
class s1 abortSentinel
The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
type RunResult = {
outcome: 'halted' | 'aborted';
state: State; // the state whose transition triggered the sentinel
stack: readonly State[]; // frozen; [] for 'halted' by construction
step: number; // 1-based iter count; 0 if initialState was itself a sentinel
};
- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
// Continuing the cont/inner/outer example above:
const result = new TuringMachine({ tapeBlock }).run({ initialState: outer });
// head reads 'a' → inner's transition fires → abortState, punching straight through `cont`:
// { outcome: 'aborted', state: inner, stack: [cont], step: 1 }
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
import { summarize } from '@turing-machine-js/machine';
const stats = summarize(myState, myTapeBlock);
// {
// stateCount, transitionCount,
// compositionEdgeCount, maxCompositionDepth,
// selfLoopCount, hasCycles,
// tapeCount, alphabetCardinalities,
// }
__INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
import { equivalentOn } from '@turing-machine-js/machine';
const report = equivalentOn(
{ state: referenceState, getTapeBlock: () => referenceTapeBlock.clone() },
{ state: candidateState, getTapeBlock: () => candidateTapeBlock.clone() },
['^1
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
Shape
Meaning
__INLINE_CODE_581__
the halt state
__INLINE_CODE_582__
a regular state (or a bare, when inside a subgraph)
__INLINE_CODE_583__
a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223)
__INLINE_CODE_585__ inside a subgraph
frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime)
__INLINE_CODE_588__
the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort)
__INLINE_CODE_591__
pre-execution sentinel (not a real state)
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
Style
Where
Meaning
__INLINE_CODE_597__ regular solid
between states; wrapper → override
plain transition / wrapper's post-return continuation
__INLINE_CODE_598__ thick solid
wrapper → bare
the wrapper's call into its callable subtree; reserved for wrapper-to-bare
__INLINE_CODE_599__ dotted
subtree → wrapper
the subtree's halt-marker has incoming → control returns to the calling wrapper
__INLINE_CODE_600__ dotted
subtree → __INLINE_CODE_601__
the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt)
__INLINE_CODE_602__ regular solid, crossing a subgraph boundary
any state (including in-frame) → __INLINE_CODE_603__
abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker
__INLINE_CODE_606__ dotted
from __INLINE_CODE_607__ to initial state
execution-start marker
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
Glyph
Where
Meaning
__INLINE_CODE_628__
read, write
literal alphabet symbol (single-quoted)
__INLINE_CODE_629__
read only
__INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous)
__INLINE_CODE_634__
read only
the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous)
__INLINE_CODE_637__
write only
keep (no write)
__INLINE_CODE_638__
write only
erase (write the tape's blank)
__INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__
move only
left / right / stay
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
flowchart TD
%% alphabets: [[" ","0","1"],[" ","0","1"]]
s0(((halt)))
u1["copy"]
idle([idle])
idle -. enter .-> u1
u1 -- "['0',*] → [K,'0']/[R,R]" --> u1
u1 -- "['1',*] → [K,'1']/[R,R]" --> u1
u1 -- "[B,*] → [K]/[S]" --> s0
Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
]); // single tape: matches any of '^', '0', '1', '
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__
You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__
The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__
The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15__
__INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__
Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
Field
Type
Meaning
__INLINE_CODE_138__
__INLINE_CODE_139__
1-indexed iteration number
__INLINE_CODE_140__
__INLINE_CODE_141__
the state about to execute
__INLINE_CODE_142__
__INLINE_CODE_143__
per-tape head symbols, before the command applies
__INLINE_CODE_144__
__INLINE_CODE_145__
per-tape symbols that will be written
__INLINE_CODE_146__
__INLINE_CODE_147__
per-tape head moves (__INLINE_CODE_148__)
__INLINE_CODE_149__
__INLINE_CODE_150__
the state that will execute next
__INLINE_CODE_151__
__INLINE_CODE_152__
the transition the engine picked for this iter — see Matched transition below
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
__INLINE_CODE_158__
__INLINE_CODE_159__
__INLINE_CODE_160__
Shape
sync, returns __INLINE_CODE_161__
sync generator, returns __INLINE_CODE_162__
async session with events
Observation
none
per-iter via __INLINE_CODE_163__
event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__)
Step controls
—
—
__INLINE_CODE_168__
Throttle
—
—
__INLINE_CODE_169__
Breakpoint handling
not consulted — runs straight to halt
not consulted — yields every iter; __INLINE_CODE_170__ is ignored
the only mode that reacts — fires a __INLINE_CODE_171__ event
Best for
run-to-halt with no observation overhead
tracing, snapshots, test harnesses, custom batching
UI debuggers, IDE extensions, educational demos
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17__
__INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__
Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__
What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20__
__INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__
Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__
Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__
Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24__
__INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
Method
Description
__INLINE_CODE_353__
Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws.
__INLINE_CODE_355__
Resume from a pause and run to the next breakpoint or halt.
__INLINE_CODE_356__
Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into.
__INLINE_CODE_357__
Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over.
__INLINE_CODE_359__
Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out.
__INLINE_CODE_361__
Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__).
__INLINE_CODE_364__
Terminate immediately. __INLINE_CODE_365__ event does NOT fire.
__INLINE_CODE_366__
Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs.
__INLINE_CODE_369__
Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below.
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
Event
Argument
Dispatch
Fires
__INLINE_CODE_381__
__INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__)
Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget.
A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested.
__INLINE_CODE_387__
__INLINE_CODE_388__
Fire-and-forget (sync hot-loop tracing).
Once per iter, between any before-pause and after-pause.
__INLINE_CODE_389__
__INLINE_CODE_390__
Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis.
Once per iter, at end. After any after-pause.
__INLINE_CODE_391__
__INLINE_CODE_392__
Fire-and-forget.
Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called.
__INLINE_CODE_394__
__INLINE_CODE_395__
Fire-and-forget.
Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called.
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__
So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__
Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__
The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__
Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__
For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__
The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__
Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__
The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__
- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
__CODE_BLOCK_34__
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
Thing
Mermaid id
Was
user states
__INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …)
__INLINE_CODE_540__
sentinels
__INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, …
(halt was already __INLINE_CODE_545__)
halt marker, frame __INLINE_CODE_546__
__INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__"
__INLINE_CODE_550__
frame subgraphs
__INLINE_CODE_551__
unchanged
idle
__INLINE_CODE_552__
unchanged
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35__
__INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
Shape
Meaning
__INLINE_CODE_581__
the halt state
__INLINE_CODE_582__
a regular state (or a bare, when inside a subgraph)
__INLINE_CODE_583__
a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223)
__INLINE_CODE_585__ inside a subgraph
frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime)
__INLINE_CODE_588__
the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort)
__INLINE_CODE_591__
pre-execution sentinel (not a real state)
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
Style
Where
Meaning
__INLINE_CODE_597__ regular solid
between states; wrapper → override
plain transition / wrapper's post-return continuation
__INLINE_CODE_598__ thick solid
wrapper → bare
the wrapper's call into its callable subtree; reserved for wrapper-to-bare
__INLINE_CODE_599__ dotted
subtree → wrapper
the subtree's halt-marker has incoming → control returns to the calling wrapper
__INLINE_CODE_600__ dotted
subtree → __INLINE_CODE_601__
the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt)
__INLINE_CODE_602__ regular solid, crossing a subgraph boundary
any state (including in-frame) → __INLINE_CODE_603__
abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker
__INLINE_CODE_606__ dotted
from __INLINE_CODE_607__ to initial state
execution-start marker
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
Glyph
Where
Meaning
__INLINE_CODE_628__
read, write
literal alphabet symbol (single-quoted)
__INLINE_CODE_629__
read only
__INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous)
__INLINE_CODE_634__
read only
the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous)
__INLINE_CODE_637__
write only
keep (no write)
__INLINE_CODE_638__
write only
erase (write the tape's blank)
__INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__
move only
left / right / stay
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__
Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
tapeBlock.symbol(['0', 'a']); // 2 tapes: matches when tape 1 is '0' AND tape 2 is 'a'
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia
TapeCommand
A single-tape instruction the machine applies in one step: optionally write a symbol, optionally move the head. Defaults to keep current symbol, do not move.
__CODE_BLOCK_10__You'll rarely construct __INLINE_CODE_67__ instances yourself — pass plain objects in your __INLINE_CODE_68__ definitions and they're wrapped automatically.
Command
A bundle of __INLINE_CODE_69__s, one per tape in the __INLINE_CODE_70__. Like __INLINE_CODE_71__, you usually pass a plain array in the __INLINE_CODE_72__ definition rather than constructing __INLINE_CODE_73__ directly.
State
A node in the transition graph. Construct with a definition object whose keys are JS __INLINE_CODE_74__s from __INLINE_CODE_75__ (or __INLINE_CODE_76__ for the catch-all). Each value is __INLINE_CODE_77__.
__CODE_BLOCK_11__Notable members and statics:
- __INLINE_CODE_78__, __INLINE_CODE_79__ — identity (__INLINE_CODE_80__ is __INLINE_CODE_81__).
- __INLINE_CODE_82__ — returns a __INLINE_CODE_83__ (a __INLINE_CODE_84__ subclass, so it flows anywhere a __INLINE_CODE_85__ does) whose would-be halt transitions fall through to __INLINE_CODE_86__. The subroutine-call composition mechanism (see __INLINE_CODE_87__ for examples). __INLINE_CODE_88__ is the wrapper discriminator.
- __INLINE_CODE_89__ — walks the reachable graph from __INLINE_CODE_90__ and returns a serializable __INLINE_CODE_91__ (states, transitions, alphabets).
- __INLINE_CODE_92__ — inverse of __INLINE_CODE_93__: rebuilds __INLINE_CODE_94__ instances + a fresh __INLINE_CODE_95__ from a __INLINE_CODE_96__. Round-trips together with __INLINE_CODE_97__ / __INLINE_CODE_98__.
- __INLINE_CODE_99__ — walks the same graph and returns a __INLINE_CODE_100__ keyed by __INLINE_CODE_101__. Use when downstream tooling holds a numeric id (e.g. a clicked node in a rendered graph) and needs the live __INLINE_CODE_102__ instance or the per-pattern __INLINE_CODE_103__ for breakpoint setup. See Setting breakpoints by graph id.
For visualization, pair __INLINE_CODE_104__ with __INLINE_CODE_105__ to render the graph in any Mermaid-aware viewer (GitHub, VS Code, mermaid.live):
__CODE_BLOCK_12__The string __INLINE_CODE_106__ produces is a real Mermaid flowchart that renders in-place anywhere Mermaid is supported:
__CODE_BLOCK_13__Edge labels are __INLINE_CODE_107__. Write commands: __INLINE_CODE_108__ = keep (no write), __INLINE_CODE_109__ = erase (write the blank). Literal alphabet symbols are quoted (__INLINE_CODE_110__, __INLINE_CODE_111__). Movements: __INLINE_CODE_112__ (left), __INLINE_CODE_113__ (right), __INLINE_CODE_114__ (stay).
Mermaid renders at most one edge per source/target pair. If a state has two distinct transitions back to itself (or two parallel transitions to the same target), only one shows in the diagram. The string output is correct — this is a viewer-side limitation. For graphs with multiple parallel edges, paste the __INLINE_CODE_115__ output into mermaid.live and switch to the __INLINE_CODE_116__ renderer, or post-process the output to your preferred format.
__INLINE_CODE_117__ parses the same format back into a __INLINE_CODE_118__. The round-trip is behaviorally lossless — the rebuilt graph runs to the same outputs on the same inputs (tested in __INLINE_CODE_119__ for the binary-numbers libraries). Under the v7 callable-subtree emit (#174), bytewise stability holds across rebuilds even for shared-bare cases (modulo state-id renumbering, which the test normalizes). The composite name is not stored as any graph node's label — __INLINE_CODE_120__ recomputes it fresh on reconstruction — so the accumulation problem from #138 cannot reoccur.
Reference
A forward-declaration handle, used when a __INLINE_CODE_121__ needs to point at another __INLINE_CODE_122__ that doesn't exist yet (cyclic graphs). Construct unbound, pass as __INLINE_CODE_123__, call __INLINE_CODE_124__ once that state has been built.
__CODE_BLOCK_14__The resulting cycle (__INLINE_CODE_125__):
__CODE_BLOCK_15____INLINE_CODE_126__ points at the initial state passed to __INLINE_CODE_127__ (__INLINE_CODE_128__ here); __INLINE_CODE_129__ is reachable from __INLINE_CODE_130__ via the bound __INLINE_CODE_131__.
__INLINE_CODE_132__ returns the bound state and throws if the reference is still unbound when the machine runs. __INLINE_CODE_133__ is sticky — the first call wins; subsequent calls are silent no-ops that return the existing binding.
TuringMachine
The runtime. Owns one __INLINE_CODE_134__ and drives a state graph until it reaches __INLINE_CODE_135__.
__CODE_BLOCK_16__Each yielded __INLINE_CODE_136__ (__INLINE_CODE_137__) has these fields:
| Field | Type | Meaning |
|---|---|---|
| __INLINE_CODE_138__ | __INLINE_CODE_139__ | 1-indexed iteration number |
| __INLINE_CODE_140__ | __INLINE_CODE_141__ | the state about to execute |
| __INLINE_CODE_142__ | __INLINE_CODE_143__ | per-tape head symbols, before the command applies |
| __INLINE_CODE_144__ | __INLINE_CODE_145__ | per-tape symbols that will be written |
| __INLINE_CODE_146__ | __INLINE_CODE_147__ | per-tape head moves (__INLINE_CODE_148__) |
| __INLINE_CODE_149__ | __INLINE_CODE_150__ | the state that will execute next |
| __INLINE_CODE_151__ | __INLINE_CODE_152__ | the transition the engine picked for this iter — see Matched transition below |
__INLINE_CODE_153__ (default __INLINE_CODE_154__) guards against runaway loops — exceeding it throws.
Choosing between __INLINE_CODE_155__, __INLINE_CODE_156__, and __INLINE_CODE_157__
Three non-overlapping entry points, picked by the consumer's actual need:
| __INLINE_CODE_158__ | __INLINE_CODE_159__ | __INLINE_CODE_160__ | |
|---|---|---|---|
| Shape | sync, returns __INLINE_CODE_161__ | sync generator, returns __INLINE_CODE_162__ | async session with events |
| Observation | none | per-iter via __INLINE_CODE_163__ | event-based (__INLINE_CODE_164__, __INLINE_CODE_165__, __INLINE_CODE_166__, __INLINE_CODE_167__) |
| Step controls | — | — | __INLINE_CODE_168__ |
| Throttle | — | — | __INLINE_CODE_169__ |
| Breakpoint handling | not consulted — runs straight to halt | not consulted — yields every iter; __INLINE_CODE_170__ is ignored | the only mode that reacts — fires a __INLINE_CODE_171__ event |
| Best for | run-to-halt with no observation overhead | tracing, snapshots, test harnesses, custom batching | UI debuggers, IDE extensions, educational demos |
Rule of thumb. No observation → __INLINE_CODE_172__. Sync per-iter observation → iterate __INLINE_CODE_173__. Anything interactive (breakpoints, step controls, throttle, click-pause) → construct a __INLINE_CODE_174__.
__INLINE_CODE_175__ / __INLINE_CODE_176__ both return a __INLINE_CODE_177__ — __INLINE_CODE_178__, call-scoped so re-running the same machine never leaks stale state from a previous call. __INLINE_CODE_179__'s generator carries the value as its __INLINE_CODE_180__ (visible in the final __INLINE_CODE_181__) — a plain __INLINE_CODE_182__ discards it, so per-iter consumers that need the outcome either drain the generator manually (as __INLINE_CODE_183__ does internally) or check the final yield's __INLINE_CODE_184__ identity. See §Sentinels: halt vs abort for the full shape and the __INLINE_CODE_185__ counterpart to __INLINE_CODE_186__.
Breakpoint detection lives only in __INLINE_CODE_187__. __INLINE_CODE_188__ is the pure-iteration primitive — it advances the machine and reports a minimal __INLINE_CODE_189__ with no pause/debug field, ignoring __INLINE_CODE_190__ entirely. __INLINE_CODE_191__ is what evaluates the filters and turns a match into a __INLINE_CODE_192__ event. (A consumer that wants its own breakpoint behavior on the raw generator can read __INLINE_CODE_193__ itself.)
Matched transition
Every yielded __INLINE_CODE_194__ carries a __INLINE_CODE_195__ describing which transition the engine picked for that iter. The engine already resolves this via __INLINE_CODE_196__ internally; this field exposes the resolution to consumers so visualizations, log formatters, and coverage maps don't have to re-derive an ambiguous __INLINE_CODE_197__ pair (which collides when multiple transitions on the same source share a destination) or parse pattern strings from __INLINE_CODE_198__.
__CODE_BLOCK_17____INLINE_CODE_199__ — __INLINE_CODE_200__. Resolvable in __INLINE_CODE_201__'s output: __INLINE_CODE_202__ has an entry with the matching __INLINE_CODE_203__. For wrapper-entry iters (source is a wrapper produced by __INLINE_CODE_204__), __INLINE_CODE_205__ references the bare's transition — the wrapper's own __INLINE_CODE_206__ array in __INLINE_CODE_207__ is empty because wrappers delegate, and the pattern actually lives on the bare. Detect by comparing __INLINE_CODE_208__ against __INLINE_CODE_209__: different → wrapper delegation.
__INLINE_CODE_210__ — per-tape match kind for the matched alternative's selector at each tape position. __INLINE_CODE_211__ if the position held __INLINE_CODE_212__ (catch-all) in the winning alternative; __INLINE_CODE_213__ if it held a specific symbol or symbol-list. Length always equals tape count.
Example use:
__CODE_BLOCK_18__Subroutine composition with __INLINE_CODE_214__
__INLINE_CODE_215__ returns a __INLINE_CODE_216__ — a __INLINE_CODE_217__ subclass that delegates transition lookups and __INLINE_CODE_218__ to __INLINE_CODE_219__ (its bare) and whose would-be halt transitions fall through to __INLINE_CODE_220__ at run time. The bare is left untouched. Because a __INLINE_CODE_221__ is a __INLINE_CODE_222__, it flows anywhere a __INLINE_CODE_223__ does (as a __INLINE_CODE_224__, through __INLINE_CODE_225__/__INLINE_CODE_226__); __INLINE_CODE_227__ distinguishes it from a plain state. This is the engine's only composition primitive — bigger machines are built by stacking smaller halt-on-completion subroutines.
__CODE_BLOCK_19__What changes between running __INLINE_CODE_228__ standalone and running the composed wrapper:
__INLINE_CODE_229__ — the standalone subroutine:
__CODE_BLOCK_20____INLINE_CODE_230__ — the wrapped composition:
__CODE_BLOCK_21__Reading guide — the v7 callable-subtree emit (introduced in #174) models __INLINE_CODE_231__ as a function call: the wrapper is the call site, the bare's subtree is the callable body.
- __INLINE_CODE_232__ (Mermaid subroutine / double-walled-rectangle shape) is the wrapper node. It's the runtime entry point — __INLINE_CODE_233__ arrives here — and shows the composite name (__INLINE_CODE_234__). Wrappers have no transitions of their own; they delegate to the bare via the __INLINE_CODE_235__ arrow. Placement: this top-level wrapper is drawn OUTSIDE any subgraph; a wrapper that participates in a caller's frame (e.g. an inner-call continuation of another wrapper, as in __INLINE_CODE_236__) renders INSIDE its owner frame's subgraph with the same __INLINE_CODE_237__ shape (see #223).
- __INLINE_CODE_238__ is the bare's callable subtree — the scope of code that runs when the wrapper is "called." It contains the bare __INLINE_CODE_239__, any body states reachable from the bare, and a local halt marker __INLINE_CODE_240__ where the bare's halt-bound transitions land — __INLINE_CODE_241__ reads as "frame 1's local stand-in for __INLINE_CODE_242__" (see §Mermaid id scheme for the full namespacing rule).
- The bold __INLINE_CODE_243__ from wrapper to bare is the call arrow — visual signature of "wrapper invokes this callable subtree, pushing its override onto the runtime stack." Bold arrows are reserved for wrapper-to-bare calls; counting them in a diagram counts the wrappers in play.
- The dotted __INLINE_CODE_244__ from the subtree back to the wrapper is the return arrow — fires when the bare halts (lands on __INLINE_CODE_245__) and the stack pops. The wrapper's solid __INLINE_CODE_246__ (to __INLINE_CODE_247__) is the post-return continuation; ordinary transition under the function-call mental model.
- Real __INLINE_CODE_248__ outside any subgraph (__INLINE_CODE_249__) is the actual run terminus. Reached only by states OUTSIDE any callable subtree — here, by __INLINE_CODE_250__ after it erases the cell.
Reading runtime sequence on tape __INLINE_CODE_251__: enter at wrapper __INLINE_CODE_252__ (with __INLINE_CODE_253__ queued as the override); __INLINE_CODE_254__ into the subtree of __INLINE_CODE_255__; __INLINE_CODE_256__ self-loops on __INLINE_CODE_257__ until the head sees __INLINE_CODE_258__; the __INLINE_CODE_259__ edge lands on __INLINE_CODE_260__; __INLINE_CODE_261__ to the wrapper; solid __INLINE_CODE_262__ to __INLINE_CODE_263__; __INLINE_CODE_264__ runs __INLINE_CODE_265__ and halts at real __INLINE_CODE_266__. Run terminates.
Round-trip stability. __INLINE_CODE_267__ is bytewise stable for simple wrapped states (#139 regression). The callable-subtree emit (#174) eliminates per-context duplication: shared bares like __INLINE_CODE_268__'s __INLINE_CODE_269__ (used by two wrappers in __INLINE_CODE_270__) render as a single subtree with two __INLINE_CODE_271__-joined call arrows, and __INLINE_CODE_272__ rebuilds one shared instance — the sharing survives the round-trip. Bytewise stability does not extend to shared-bare cases, though: node ids are runtime __INLINE_CODE_273__ ids reassigned on every rebuild, and a shared bare's post-rebuild id no longer follows the original emission order, so the serialization reorders. Use __INLINE_CODE_274__ to confirm behavioural identity (__INLINE_CODE_275__) when bytewise comparison no longer applies.
Wrappers nest: __INLINE_CODE_276__ chains halt-redirects through __INLINE_CODE_277__. __INLINE_CODE_278__'s __INLINE_CODE_279__ (the __INLINE_CODE_280__ composition) uses a 4-deep nest of wrappers.
State tags
A State carries an optional set of string tags — out-of-band metadata for visualization grouping and debugger labels. Tags don't affect runtime transition lookup, __INLINE_CODE_281__ comparisons, or any structural identity; they ride alongside the State.
__CODE_BLOCK_22__Scoped to the wrapper instance. Under __INLINE_CODE_282__ memoization (#175), __INLINE_CODE_283__ and __INLINE_CODE_284__ are distinct __INLINE_CODE_285__ instances even though both delegate to the same bare __INLINE_CODE_286__. Tags live on the frame instance, so tagging one wrapper doesn't propagate to siblings sharing the same bare. Wrappers from __INLINE_CODE_287__ start with an empty tag set (do not inherit from bare); the caller tags explicitly as needed.
Round-trip preserved. __INLINE_CODE_288__ writes the tag set to __INLINE_CODE_289__; __INLINE_CODE_290__ reads it back and reapplies. __INLINE_CODE_291__ renders tags two ways: inline in the node label (__INLINE_CODE_292__, universal Mermaid line break) and as __INLINE_CODE_293__ + __INLINE_CODE_294__ lines for color grouping. __INLINE_CODE_295__ splits the label on __INLINE_CODE_296__ as source of truth; the __INLINE_CODE_297__ lines are decorative and discarded on parse.
See §Diagram conventions § Tags for the full emit shape.
Debugging
The library exposes interactive debugging through the __INLINE_CODE_298__ class, constructed directly with a __INLINE_CODE_299__. Breakpoints are configured on the engine (__INLINE_CODE_300__ / __INLINE_CODE_301__ / __INLINE_CODE_302__); the session dispatches them as events plus offers step-in / step-over / step-out controls, an external __INLINE_CODE_303__, and a per-iter throttle.
__CODE_BLOCK_23__Configuring breakpoints
Breakpoints live on the engine, not on the session. The session reads __INLINE_CODE_304__ / __INLINE_CODE_305__ / __INLINE_CODE_306__ and fires a __INLINE_CODE_307__ event when a filter matches.
__CODE_BLOCK_24____INLINE_CODE_308__ and __INLINE_CODE_309__ are __INLINE_CODE_310__-only. Any object-shaped write (__INLINE_CODE_311__, __INLINE_CODE_312__, __INLINE_CODE_313__) throws at write time on either sentinel. The pause fires on the AFTER side of the iter whose transition leads to the sentinel — __INLINE_CODE_314__ is the triggering state (not the sentinel itself), __INLINE_CODE_315__.
An __INLINE_CODE_316__-side breakpoint on the sentinel-triggering state collapses with __INLINE_CODE_317__ / __INLINE_CODE_318__ into a single pause. Both target the AFTER side of the same iter — the one whose transition leads to halt or abort — and the engine fires at most one pause per iter-side, so you get one __INLINE_CODE_319__ event (__INLINE_CODE_320__, __INLINE_CODE_321__), not two. This is intentional: neither sentinel has an iteration of its own, so "after the triggering state" and "before halt/abort" are the same execution moment. (Contrast two ordinary states __INLINE_CODE_322__: __INLINE_CODE_323__'s __INLINE_CODE_324__ and __INLINE_CODE_325__'s __INLINE_CODE_326__ are different iters, so they fire as two pauses.) There is deliberately no flag to emit a second, ephemeral sentinel pause — one event for one real moment.
Chained-form __INLINE_CODE_327__ (or __INLINE_CODE_328__) doesn't throw in non-strict mode — this is a JavaScript primitive quirk, not engine behavior. The getter returns the boolean __INLINE_CODE_329__; assigning __INLINE_CODE_330__ to that boolean is a no-op in non-strict mode (silent), a __INLINE_CODE_331__ in strict mode. The engine setter only sees whole-object writes (__INLINE_CODE_332__ / __INLINE_CODE_333__). Always use the whole-object form: __INLINE_CODE_334__ / __INLINE_CODE_335__ / __INLINE_CODE_336__.
The __INLINE_CODE_337__ field is mutable — toggle breakpoints at runtime without rebuilding the graph. A __INLINE_CODE_338__ (from __INLINE_CODE_339__) delegates its __INLINE_CODE_340__ to the bare, so an assignment on the original is visible from every wrapper and vice versa. __INLINE_CODE_341__ is always a __INLINE_CODE_342__ instance (lazy-initialized on first read); plain-object input is wrapped automatically. The instance is __INLINE_CODE_343__-ed — typos like __INLINE_CODE_344__ throw __INLINE_CODE_345__ instead of silently creating a useless property.
Filter semantics: __INLINE_CODE_346__ is a wildcard (match any symbol). __INLINE_CODE_347__ is NOT a wildcard — it matches only the catch-all resolution case (same meaning as in transition keys).
Caveat: __INLINE_CODE_348__ and __INLINE_CODE_349__ are both module-level singletons. Setting either one's __INLINE_CODE_350__ affects every machine in the process; clear in __INLINE_CODE_351__ / __INLINE_CODE_352__ for test isolation.
DebugSession API
| Method | Description |
|---|---|
| __INLINE_CODE_353__ | Begin execution. Resolves on natural halt, abort, or after __INLINE_CODE_354__. Single-use — a second call throws. |
| __INLINE_CODE_355__ | Resume from a pause and run to the next breakpoint or halt. |
| __INLINE_CODE_356__ | Resume and pause at the very next iter, regardless of depth — descends into any subroutine the current iter enters. Mirrors DevTools Step Into. |
| __INLINE_CODE_357__ | Resume and pause at the next iter back at (or above) the click-time halt-stack depth (__INLINE_CODE_358__) — subroutines the stepped-over iter enters run to completion without pausing inside. Mirrors DevTools Step Over. |
| __INLINE_CODE_359__ | Resume and pause at the next iter strictly shallower than the click-time depth (__INLINE_CODE_360__) — i.e. once the current frame has been popped. Throws if the click-time depth is 0 (no enclosing frame to exit). Mirrors DevTools Step Out. |
| __INLINE_CODE_361__ | Request a pause from outside the loop. Fires on the next iter with __INLINE_CODE_362__. If a breakpoint matches that same iter, the breakpoint wins (single pause, __INLINE_CODE_363__). |
| __INLINE_CODE_364__ | Terminate immediately. __INLINE_CODE_365__ event does NOT fire. |
| __INLINE_CODE_366__ | Insert an awaited __INLINE_CODE_367__ at the end of each iter. __INLINE_CODE_368__ disables. Useful for visualization UIs. |
| __INLINE_CODE_369__ | Register / unregister listeners. Multiple listeners per event are supported. Listener dispatch differs by event — see Events below. |
The three step controls are depth-based to mirror DevTools: from a pause at halt-stack depth __INLINE_CODE_370__, __INLINE_CODE_371__ pauses at the next iter (any depth), __INLINE_CODE_372__ at the next iter with __INLINE_CODE_373__, __INLINE_CODE_374__ at the next iter with __INLINE_CODE_375__. For a plain iter (no subroutine entry) all of Into/Over coincide — they differ only under genuine nesting (a bare that itself enters a __INLINE_CODE_376__ wrapper). One engine-specific nuance: composition is continuation-passing (__INLINE_CODE_377__ = "run A, then B" — sequential, where __INLINE_CODE_378__ is __INLINE_CODE_379__), so a flat __INLINE_CODE_380__ chain has no real nesting and Over/Out behave the same there; the distinction appears only when a subroutine's body enters another wrapper.
Events
| Event | Argument | Dispatch | Fires |
|---|---|---|---|
| __INLINE_CODE_381__ | __INLINE_CODE_382__ (__INLINE_CODE_383__ + __INLINE_CODE_384__) | Implicitly awaited via internal pause-promise — engine blocks until __INLINE_CODE_385__ is called. Listener Promise itself is fire-and-forget. | A breakpoint matched, a step-mode endpoint was reached, or __INLINE_CODE_386__ was requested. |
| __INLINE_CODE_387__ | __INLINE_CODE_388__ | Fire-and-forget (sync hot-loop tracing). | Once per iter, between any before-pause and after-pause. |
| __INLINE_CODE_389__ | __INLINE_CODE_390__ | Awaited (sequenced, blocks the engine). Use for throttle / per-iter coordination / step-boundary synthesis. | Once per iter, at end. After any after-pause. |
| __INLINE_CODE_391__ | __INLINE_CODE_392__ | Fire-and-forget. | Once, on natural halt. Does NOT fire when __INLINE_CODE_393__ was called. |
| __INLINE_CODE_394__ | __INLINE_CODE_395__ | Fire-and-forget. | Once, when the run hits __INLINE_CODE_396__. Does NOT fire when __INLINE_CODE_397__ was called. |
__INLINE_CODE_398__ and __INLINE_CODE_399__ are mutually exclusive terminal events — a run ends in exactly one of the two, never both, and both carry the same run's __INLINE_CODE_400__ (__INLINE_CODE_401__ — see §RunResult) as their listener's argument.
The pause descriptor: __INLINE_CODE_402__
__INLINE_CODE_403__ listeners receive a __INLINE_CODE_404__ — a plain __INLINE_CODE_405__ plus a __INLINE_CODE_406__ descriptor (raw __INLINE_CODE_407__ yields have no such field).
- __INLINE_CODE_408__ — __INLINE_CODE_409__ or __INLINE_CODE_410__. Exactly one: DebugSession dispatches the two timings as separate __INLINE_CODE_411__ events, so a descriptor is always one-sided. (__INLINE_CODE_412__ / __INLINE_CODE_413__ causes only ever fire on the __INLINE_CODE_414__ side.)
- __INLINE_CODE_415__ — distinguishes the origin:
- __INLINE_CODE_416__ — a __INLINE_CODE_417__ filter matched, or __INLINE_CODE_418__ / __INLINE_CODE_419__ triggered.
- __INLINE_CODE_420__ — a __INLINE_CODE_421__ / __INLINE_CODE_422__ / __INLINE_CODE_423__ directive's natural endpoint was reached.
- __INLINE_CODE_424__ — __INLINE_CODE_425__ was called from outside.
When an iter satisfies more than one trigger, exactly one __INLINE_CODE_426__ event fires — never two at the same iter — and __INLINE_CODE_427__ is chosen by precedence:
__CODE_BLOCK_25__So a step-mode endpoint (or a pending manual pause) that lands exactly on a breakpoint reports __INLINE_CODE_428__; a manual pause that coincides with a step endpoint reports __INLINE_CODE_429__. Rationale: a breakpoint is the user's explicit, persistent intent ("always stop here"), so it's the most informative attribution; a step directive is a specific computed endpoint, more specific than the vaguer "pause soon" of a manual request. The step-mode is still consumed (one-shot rule below) regardless of which cause is reported — if the iter was the step's endpoint, the step is satisfied. Matches IDE convention (a breakpoint on the line you step onto reports as a breakpoint stop).
One-shot step-mode rule
Every active step-mode (__INLINE_CODE_430__ / __INLINE_CODE_431__ / __INLINE_CODE_432__) is dropped on the next __INLINE_CODE_433__ dispatch — whether that dispatch is the step's own endpoint, an inner breakpoint that fired sooner, or a manual pause. To keep stepping, call __INLINE_CODE_434__ / __INLINE_CODE_435__ / __INLINE_CODE_436__ again from the new pause. Matches IDE convention.
Setting breakpoints by graph id
Downstream UIs (graph renderers, debugger panels) often have only a numeric __INLINE_CODE_437__ — the user clicked a state node, or a transition edge in a rendered SVG. __INLINE_CODE_438__ returns a __INLINE_CODE_439__ keyed by that numeric id, with the live __INLINE_CODE_440__ instance and the per-pattern __INLINE_CODE_441__ array as its value:
__CODE_BLOCK_26__Coverage rules: regular / bare states get the full __INLINE_CODE_442__ including __INLINE_CODE_443__ at its natural slot; wrappers and the halt singleton get empty __INLINE_CODE_444__; synthetic halt markers (Graph nodes with __INLINE_CODE_445__, one per callable-subtree frame) are excluded from the map. See __INLINE_CODE_446__ JSDoc for the full contract.
__INLINE_CODE_447__ — the entry at id __INLINE_CODE_448__ is the process-wide halt singleton. Toggling its __INLINE_CODE_449__ affects every machine in the runtime, same caveat as direct __INLINE_CODE_450__ writes.
Throttle pattern
For per-iter throttle / animation / "wait between steps" UIs, use __INLINE_CODE_451__:
__CODE_BLOCK_27__The throttle inserts an awaited __INLINE_CODE_452__ at the end of every iter, after both __INLINE_CODE_453__ dispatches (if any) and the __INLINE_CODE_454__ event. Updates take effect on the next iter. __INLINE_CODE_455__ disables.
v7 migration from __INLINE_CODE_456__
v7 splits the v6 mixed-mode __INLINE_CODE_457__ into three non-overlapping entry points. Old shape → new shape:
__CODE_BLOCK_28__Or, if you only used __INLINE_CODE_458__ with no callbacks, just drop the __INLINE_CODE_459__ — __INLINE_CODE_460__ is now synchronous:
__CODE_BLOCK_29__For sync per-iter tracing without breakpoint-driven flow, iterate the __INLINE_CODE_461__ generator directly — __INLINE_CODE_462__ no longer exists:
__CODE_BLOCK_30__The __INLINE_CODE_463__ master switch is gone — in v7 the session is the only consumer of breakpoints; if you don't register a __INLINE_CODE_464__ listener, breakpoints fire-and-resume invisibly (the session's __INLINE_CODE_465__ still resolves cleanly), or you can use __INLINE_CODE_466__ directly, which ignores __INLINE_CODE_467__ altogether (its yields carry no pause field).
(History: v6.2.0 briefly widened __INLINE_CODE_468__ to __INLINE_CODE_469__ and added an inline __INLINE_CODE_470__, motivated by this same throttle use case. That was a mistake — restored to sync in v6.3.0. v6.3.0 documented a workaround using __INLINE_CODE_471__ self-rearm on __INLINE_CODE_472__; that workaround is superseded by __INLINE_CODE_473__ in v6.4.0+.)
Special objects
haltState
A singleton __INLINE_CODE_474__ (__INLINE_CODE_475__). Transitioning into it stops the run. Imported as a named export from __INLINE_CODE_476__; do not construct your own — __INLINE_CODE_477__ checks identity against this single instance. See §Sentinels: halt vs abort for __INLINE_CODE_478__, the non-overridable counterpart used for abnormal termination.
Sentinels: halt vs abort
__INLINE_CODE_479__ and __INLINE_CODE_480__ are the two members of the sentinel family (__INLINE_CODE_481__ ≡ __INLINE_CODE_482__) — the only states a machine can transition into that end a run rather than continue it. They mean different things:
- __INLINE_CODE_483__ (__INLINE_CODE_484__) inside a subroutine means return — the run-loop pops the halt-stack and resumes at the caller's continuation. It's the composable case: __INLINE_CODE_485__ builds bigger machines out of halt-on-completion subroutines.
- __INLINE_CODE_486__ (__INLINE_CODE_487__, #239) means stop everything. It is never popped by the subroutine halt-stack and never composed by __INLINE_CODE_488__ — it punches straight through call/return and terminates the run, through any call depth. Aborting is a legitimate program outcome, not a host failure: no __INLINE_CODE_489__ is thrown when a run ends this way.
__INLINE_CODE_490__ is strictly opt-in. The existing idiom — reserve an alphabet symbol and write an in-band error marker before halting — remains the right tool for most machines. Reach for __INLINE_CODE_491__ when in-band signaling doesn't fit: a 2-symbol machine has no alphabet symbol left to spare for "termination kind," or the final tape must stay a clean result (e.g. golden tests that diff tapes byte-for-byte).
__CODE_BLOCK_31__Identity: __INLINE_CODE_492__, __INLINE_CODE_493__, __INLINE_CODE_494__; __INLINE_CODE_495__ (__INLINE_CODE_496__) is __INLINE_CODE_497__ for both sentinels and __INLINE_CODE_498__ for every user state. __INLINE_CODE_499__ is a __INLINE_CODE_500__, mirroring __INLINE_CODE_501__ — see §Debugging.
__INLINE_CODE_502__ for the wrapped machine above:
__CODE_BLOCK_32__The solid __INLINE_CODE_503__ edge is the abort punch-through: it leaves __INLINE_CODE_504__'s callable-subtree subgraph (__INLINE_CODE_505__) and lands straight on the global __INLINE_CODE_506__ node, bypassing the frame entirely — no marker, no dispatch. Contrast the frame's own dotted dispatch, __INLINE_CODE_507__: that one only fires when __INLINE_CODE_508__ instead falls through to __INLINE_CODE_509__, lands on the frame-local halt marker __INLINE_CODE_510__, and returns normally through the wrapper to __INLINE_CODE_511__.
RunResult
__INLINE_CODE_512__ and __INLINE_CODE_513__ both return a call-scoped __INLINE_CODE_514__:
__CODE_BLOCK_33__- __INLINE_CODE_515__ implies __INLINE_CODE_516__, by construction, for a run that terminates NATURALLY — a __INLINE_CODE_517__ transition inside a subroutine pops and resumes; the run only reaches real halt once every pushed frame has already popped. No union type is needed to model the two natural outcomes because this invariant always holds for them.
- __INLINE_CODE_518__: __INLINE_CODE_519__ is the frozen backtrace of continuations __INLINE_CODE_520__ punched through — precisely the call-chain information an abort would otherwise discard. __INLINE_CODE_521__ is the triggering state, unwrapped to its bare if the transition fired from inside a __INLINE_CODE_522__ wrapper (mirrors __INLINE_CODE_523__'s same unwrap — see §Matched transition).
- External stop caveat: a run stopped externally — e.g. via __INLINE_CODE_524__ on the __INLINE_CODE_525__ generator — does NOT go through a natural halt/abort transition — it reports __INLINE_CODE_526__, but __INLINE_CODE_527__ is whatever it stood at when the throw landed (not necessarily __INLINE_CODE_528__) and __INLINE_CODE_529__ is the PREVIOUS iteration's state, not a sentinel-triggering one.
- Generator-return caveat: __INLINE_CODE_530__'s generator carries the same object as its __INLINE_CODE_531__ value (visible in the final __INLINE_CODE_532__) — but a plain __INLINE_CODE_533__ discards generator returns. The canonical step-level signal is the one __INLINE_CODE_534__ always had: the last yielded __INLINE_CODE_535__'s __INLINE_CODE_536__.
Mermaid id scheme
Diagrams namespace node ids by prefix so a rendered graph reads user states, sentinels, and per-frame plumbing apart at a glance:
| Thing | Mermaid id | Was |
|---|---|---|
| user states | __INLINE_CODE_537__ (__INLINE_CODE_538__, __INLINE_CODE_539__, …) | __INLINE_CODE_540__ |
| sentinels | __INLINE_CODE_541__ — halt __INLINE_CODE_542__, abort __INLINE_CODE_543__, a hypothetical 3rd sentinel __INLINE_CODE_544__, … | (halt was already __INLINE_CODE_545__) |
| halt marker, frame __INLINE_CODE_546__ | __INLINE_CODE_547__ — "frame-__INLINE_CODE_548__-local stand-in for __INLINE_CODE_549__" | __INLINE_CODE_550__ |
| frame subgraphs | __INLINE_CODE_551__ | unchanged |
| idle | __INLINE_CODE_552__ | unchanged |
__INLINE_CODE_553__ / __INLINE_CODE_554__ (both exported) implement the mapping and its inverse. Changelog one-liner: rendered-output churn only — the numeric __INLINE_CODE_555__ ids for user states and halt are unchanged; only the Mermaid string ids and the synthetic halt-marker's numeric id (__INLINE_CODE_556__ → __INLINE_CODE_557__, freeing the odd negatives for sentinels) moved.
ifOtherSymbol
A sentinel __INLINE_CODE_558__ used as a key in a __INLINE_CODE_559__ definition to mean match any symbol not handled by the other keys (the fallback transition).
movements
Per-tape head movement directives passed in __INLINE_CODE_560__:
- __INLINE_CODE_561__ — move the head one cell left
- __INLINE_CODE_562__ — move the head one cell right
- __INLINE_CODE_563__ — leave the head where it is
symbolCommands
Special values for __INLINE_CODE_564__:
- __INLINE_CODE_565__ — leave the current cell unchanged (default)
- __INLINE_CODE_566__ — write the alphabet's blank symbol
Introspection and testing
__INLINE_CODE_567__ ships two complementary runtime utilities:
__INLINE_CODE_568__ / __INLINE_CODE_569__ — structural analysis. Looks at the state graph without running it.
__CODE_BLOCK_35____INLINE_CODE_570__ returns the same kind of data for a single state (transitions, override-halt target, etc.) without traversing the graph.
__INLINE_CODE_571__ — behavioral comparison. Runs two machines on a list of test inputs and reports whether their outputs agree, where they first diverge, and how many steps each took.
__CODE_BLOCK_36__For different alphabets, pass __INLINE_CODE_572__ paired cases plus a custom output comparator. See __INLINE_CODE_573__ for worked examples.
Together: use __INLINE_CODE_574__ to ask "is this machine the right shape?" (size, composition, cycles), and __INLINE_CODE_575__ to ask "does this machine compute the right thing?" (correctness against a reference). Useful when comparing two implementations of the same algorithm — e.g., the marker-based and bare binary libraries — or when grading student-written machines against a reference.
For visualization and round-tripping, see __INLINE_CODE_576__ / __INLINE_CODE_577__ and __INLINE_CODE_578__ / __INLINE_CODE_579__.
Diagram conventions
The full reference for reading __INLINE_CODE_580__ output — shapes, edge styles, and the bracketed edge-label vocabulary. All shapes and arrows are standard Mermaid flowchart syntax; any Mermaid renderer (GitHub preview, IDE plugins, mermaid-js client-side) paints these diagrams the same way.
Node shapes
| Shape | Meaning |
|---|---|
| __INLINE_CODE_581__ | the halt state |
| __INLINE_CODE_582__ | a regular state (or a bare, when inside a subgraph) |
| __INLINE_CODE_583__ | a __INLINE_CODE_584__ wrapper (call site; outside any subgraph when top-level, INSIDE its owner frame's subgraph when its continuation chain participates in a caller's frame — see §Subroutine composition and #223) |
| __INLINE_CODE_585__ inside a subgraph | frame __INLINE_CODE_586__'s halt marker (visualization aid; maps back to the singleton __INLINE_CODE_587__ at runtime) |
| __INLINE_CODE_588__ | the __INLINE_CODE_589__ sentinel — same terminal shape as halt, distinguished by a dashed-red __INLINE_CODE_590__; emitted only when the graph actually references it (see §Sentinels: halt vs abort) |
| __INLINE_CODE_591__ | pre-execution sentinel (not a real state) |
Node ids follow a namespaced scheme (__INLINE_CODE_592__/__INLINE_CODE_593__/__INLINE_CODE_594__) — see §Mermaid id scheme for the full mapping and the __INLINE_CODE_595__ / __INLINE_CODE_596__ helpers.
Edge styles
| Style | Where | Meaning |
|---|---|---|
| __INLINE_CODE_597__ regular solid | between states; wrapper → override | plain transition / wrapper's post-return continuation |
| __INLINE_CODE_598__ thick solid | wrapper → bare | the wrapper's call into its callable subtree; reserved for wrapper-to-bare |
| __INLINE_CODE_599__ dotted | subtree → wrapper | the subtree's halt-marker has incoming → control returns to the calling wrapper |
| __INLINE_CODE_600__ dotted | subtree → __INLINE_CODE_601__ | the subtree has a non-wrapper entry path → halt-marker can fire with empty stack (real halt) |
| __INLINE_CODE_602__ regular solid, crossing a subgraph boundary | any state (including in-frame) → __INLINE_CODE_603__ | abort punch-through: drawn straight to the global __INLINE_CODE_604__ node, deliberately in contrast with halt's frame-local __INLINE_CODE_605__ marker + dotted dispatch — no per-frame retargeting, no abort marker |
| __INLINE_CODE_606__ dotted | from __INLINE_CODE_607__ to initial state | execution-start marker |
The __INLINE_CODE_608__ ribbon syntax (__INLINE_CODE_609__) collapses multiple wrappers that share a bare into one arrow. Bold __INLINE_CODE_610__ is reserved exclusively for the wrapper-to-bare __INLINE_CODE_611__ arrow.
Groupings
__INLINE_CODE_612__ wraps a bare + its body + a halt marker — the callable scope of code that runs when a wrapper "calls" the bare. Multi-bare frames (union-find merged from shared body states) use the label __INLINE_CODE_613__.
Tags
Tagged states (via __INLINE_CODE_614__ — see §State tags) render two ways simultaneously:
- Inline in the node label: __INLINE_CODE_615__ — the __INLINE_CODE_616__ is Mermaid's universal line break, so the tags display as a second line under the state name in any renderer.
- As a color class: __INLINE_CODE_617__ per unique tag (6-color palette selected by tag-name hash), plus __INLINE_CODE_618__ listing all nodes carrying the tag. Lets the eye group related states by color even when their names are scattered across the diagram.
The __INLINE_CODE_619__-embedded label is the source of truth for __INLINE_CODE_620__ round-trip; the __INLINE_CODE_621__/__INLINE_CODE_622__ lines are decorative and regenerate on the next __INLINE_CODE_623__ emit. Tag-name sanitization in __INLINE_CODE_624__ identifiers: any char outside __INLINE_CODE_625__ is replaced with __INLINE_CODE_626__. Labels preserve the raw tag names.
Edge label format
__INLINE_CODE_627__. Each bracketed list is a tape-block reading — one entry per tape; brackets always present, even single-tape.
| Glyph | Where | Meaning |
|---|---|---|
| __INLINE_CODE_628__ | read, write | literal alphabet symbol (single-quoted) |
| __INLINE_CODE_629__ | read only | __INLINE_CODE_630__ catch-all (ASCII __INLINE_CODE_631__; a literal __INLINE_CODE_632__ in the alphabet renders as the quoted __INLINE_CODE_633__, so the marker stays unambiguous) |
| __INLINE_CODE_634__ | read only | the tape's blank symbol (a literal __INLINE_CODE_635__ in the alphabet appears as __INLINE_CODE_636__, so the marker stays unambiguous) |
| __INLINE_CODE_637__ | write only | keep (no write) |
| __INLINE_CODE_638__ | write only | erase (write the tape's blank) |
| __INLINE_CODE_639__ / __INLINE_CODE_640__ / __INLINE_CODE_641__ | move only | left / right / stay |
Alternation rule
Alternative read patterns are always per-pattern-bracket:
- Single-tape: __INLINE_CODE_642__
- Multi-tape: __INLINE_CODE_643__ — "(tape 1=__INLINE_CODE_644__ AND tape 2=__INLINE_CODE_645__) OR (tape 1=__INLINE_CODE_646__ AND tape 2=__INLINE_CODE_647__)"
The compact in-bracket form __INLINE_CODE_648__ is rejected by __INLINE_CODE_649__ — and never emitted by __INLINE_CODE_650__. The reason is pedagogical: each alternative is its own drawn transition, and the compact form would read as cross-product semantics in multi-tape (__INLINE_CODE_651__ could mean 4 combinations rather than 2 paired alternatives). One consistent rule across tape counts: each alternative is a full bracketed pattern.
Multi-tape example
A 2-tape "copier" machine — as long as tape 1 reads a non-blank, write the same symbol to tape 2 and step both right; halt when tape 1 reads blank:
__CODE_BLOCK_37__Reading __INLINE_CODE_652__:
- Read __INLINE_CODE_653__ — tape 1 must be literal __INLINE_CODE_654__; tape 2 is __INLINE_CODE_655__ (any).
- Write __INLINE_CODE_656__ — tape 1: keep; tape 2: write literal __INLINE_CODE_657__.
- Move __INLINE_CODE_658__ — both tapes step right.
Versioning notes
API surface changes since v3, in past tense so the timing of each piece is explicit:
v4 — __INLINE_CODE_659__ became async (__INLINE_CODE_660__). Per-state runtime breakpoints landed (__INLINE_CODE_661__ / __INLINE_CODE_662__); __INLINE_CODE_663__ accepted an __INLINE_CODE_664__ hook. __INLINE_CODE_665__ exposed on each yield.
v5 — __INLINE_CODE_666__ renamed to __INLINE_CODE_667__. New __INLINE_CODE_668__ master switch suppresses all __INLINE_CODE_669__ dispatches without unsetting __INLINE_CODE_670__ assignments. Assigning a truthy __INLINE_CODE_671__ to __INLINE_CODE_672__ now throws at write time (halt is terminal — no iteration-after-halt to anchor on). Superseded in v7 by #207: __INLINE_CODE_673__ is now __INLINE_CODE_674__, all object-shaped writes throw.
v6 — Per-iter lifecycle reordered to __INLINE_CODE_675__, all firing on the same yield. Previously __INLINE_CODE_676__ fired on iter K+1's tick with a __INLINE_CODE_677__ substitution dance; that substitution is gone. (The __INLINE_CODE_678__ field shape held through v6; v7 removes it — breakpoint detection moved into __INLINE_CODE_679__, and the pause descriptor is now __INLINE_CODE_680__ on the __INLINE_CODE_681__ event only.)
v6.1 — __INLINE_CODE_682__ ergonomics: the field is now always a non-null __INLINE_CODE_683__ instance (lazy-initialized on first read), so chained field writes like __INLINE_CODE_684__ work on a fresh state without a prior whole-object assignment. The __INLINE_CODE_685__ instance is __INLINE_CODE_686__-ed, so typos like __INLINE_CODE_687__ throw __INLINE_CODE_688__ at write time instead of silently creating a useless property. __INLINE_CODE_689__ continues to work but semantically means "reset filters" — the next read returns a fresh empty __INLINE_CODE_690__ (#150).
v6.2 (superseded by v6.3.0) — widened __INLINE_CODE_691__'s signature to __INLINE_CODE_692__ and added an inline __INLINE_CODE_693__ in the run loop, enabling throttle-in-__INLINE_CODE_694__ patterns. This overturned the docstring-stated contract that __INLINE_CODE_695__ is sync (microtask-free); the right place for per-iter throttling is __INLINE_CODE_696__ with self-rearm (see Throttle pattern). Restored in v6.3.0.
v6.3 — __INLINE_CODE_697__ reverted to its v6.0–v6.1 sync contract — __INLINE_CODE_698__, called synchronously inside the run loop. The Throttle pattern section documents the engine-native shape for per-iter throttle / "wait between iters" UIs. No other API changes.
v6.4 — New __INLINE_CODE_699__ hook on __INLINE_CODE_700__: awaited, fires once at the end of every iter (after both __INLINE_CODE_701__ dispatches on the same yield), unaffected by the __INLINE_CODE_702__ master switch. Use for per-iter throttle / animation / coordination needing a suspend point; complements the existing sync __INLINE_CODE_703__ (tracing) and conditional __INLINE_CODE_704__ (user breakpoints). Three-hook contract is now __INLINE_CODE_705__ (sync, mid-iter) / __INLINE_CODE_706__ (awaited, on __INLINE_CODE_707__ match) / __INLINE_CODE_708__ (awaited, end-of-iter). Additive — peer-deps unchanged. The v6.3.0 README's __INLINE_CODE_709__-rearm throttle workaround is superseded.
v7 (2026-06-03) — Composition-representation overhaul + first-class state tags + id-keyed __INLINE_CODE_710__ lookup + __INLINE_CODE_711__ step controls + __INLINE_CODE_712__ + __INLINE_CODE_713__/__INLINE_CODE_714__. Stable release on the __INLINE_CODE_715__ dist-tag: __INLINE_CODE_716__. Highlights across the v7 alpha cycle:
alpha.8 — __INLINE_CODE_717__ type + __INLINE_CODE_718__ helper (#227) moved into the engine from __INLINE_CODE_719__, next to the live __INLINE_CODE_720__ class (visuals re-exports for consumer-import stability). __INLINE_CODE_721__ getter refactored to share its centering loop with __INLINE_CODE_722__ via an internal core — the centering math now lives once; the two public surfaces supply their own data-shape-appropriate __INLINE_CODE_723__ lambdas. See §Tape.
alpha.7 — __INLINE_CODE_724__ extraction (#213) — __INLINE_CODE_725__'s wrapper is now a first-class __INLINE_CODE_726__ subclass that delegates transition lookups + __INLINE_CODE_727__ to its bare; __INLINE_CODE_728__ preserved (additive), __INLINE_CODE_729__ discriminates wrappers. Plus __INLINE_CODE_730__ framed-wrapper emit fix (#223) — __INLINE_CODE_731__'s reach-set now tunnels through wrappers AND captures the wrappers themselves, so framed-wrapper-continuations (e.g. __INLINE_CODE_732__'s __INLINE_CODE_733__ inside __INLINE_CODE_734__'s callable subtree) render inside the owner subgraph rather than escaping to the top level. __INLINE_CODE_735__ regenerated under the new emit.
alpha.6 — Debugger step controls (#102) — full reshape of the debug surface. __INLINE_CODE_736__ is now sync + callback-free; __INLINE_CODE_737__ is the pure-iteration primitive (no __INLINE_CODE_738__ filter evaluation); a new __INLINE_CODE_739__ class (__INLINE_CODE_740__) owns all interactive debugging via __INLINE_CODE_741__ / __INLINE_CODE_742__ / __INLINE_CODE_743__ / __INLINE_CODE_744__ events, depth-based __INLINE_CODE_745__ / __INLINE_CODE_746__ / __INLINE_CODE_747__, external __INLINE_CODE_748__ / __INLINE_CODE_749__ / __INLINE_CODE_750__. Per-yield __INLINE_CODE_751__ replaced by one-sided __INLINE_CODE_752__ on __INLINE_CODE_753__ events only. See §Debugging.
alpha.5 — Per-iter __INLINE_CODE_754__ (#205) on every __INLINE_CODE_755__ yield (__INLINE_CODE_756__, __INLINE_CODE_757__ is __INLINE_CODE_758__ resolvable in __INLINE_CODE_759__). __INLINE_CODE_760__ collapsed to a __INLINE_CODE_761__ (#207) — object-shaped writes throw; halt pause fires on the AFTER side of the halt-triggering iter with __INLINE_CODE_762__ = the triggering state. __INLINE_CODE_763__ typed alias narrows __INLINE_CODE_764__ to __INLINE_CODE_765__ at the canonical access path.
alpha.4 — __INLINE_CODE_766__ (#195) returns a __INLINE_CODE_767__ keyed by __INLINE_CODE_768__ so downstream tooling can mutate __INLINE_CODE_769__ by numeric id and set per-pattern breakpoints by __INLINE_CODE_770__. Graph serialization extracted to __INLINE_CODE_771__ with a Symbol-keyed __INLINE_CODE_772__ accessor on __INLINE_CODE_773__ (#180; no public-API change — the __INLINE_CODE_774__ / __INLINE_CODE_775__ statics remain as thin delegates). Two upstream fixes: __INLINE_CODE_776__ HTML-entity-escapes user content in labels so alphabets containing __INLINE_CODE_777__, __INLINE_CODE_778__, etc. parse correctly (#194); __INLINE_CODE_779__'s halt stack is now run-scoped, fixing a memory leak / ghost-iteration when the same __INLINE_CODE_780__ instance is reused across calls (#196). See §Setting breakpoints by graph id.
alpha.3 — first-class State tags (#186). __INLINE_CODE_781__ API; __INLINE_CODE_782__ round-trips through __INLINE_CODE_783__/__INLINE_CODE_784__; __INLINE_CODE_785__ emits tags two ways simultaneously — inline via __INLINE_CODE_786__ in node labels (__INLINE_CODE_787__) and as __INLINE_CODE_788__/__INLINE_CODE_789__ for color grouping. Tags live on the State instance (not on the shared __INLINE_CODE_790__), so engine #175 memoization doesn't leak tags across wrappers sharing a bare. See §State tags.
alpha.2 — callable-subtree __INLINE_CODE_791__ emit refinement (#174). The wrapper is a separate __INLINE_CODE_792__ node OUTSIDE the subgraph; the bare's reachable subtree becomes a __INLINE_CODE_793__ block. Frames computed via union-find — shared bares dedupe with __INLINE_CODE_794__ ribbons on call arrows. Bold __INLINE_CODE_795__ reserved for wrapper-to-bare; dotted __INLINE_CODE_796__ for frame dispatch (__INLINE_CODE_797__ / __INLINE_CODE_798__ / __INLINE_CODE_799__). Plus engine memoization (#175) and nested-chain collapse (#176) for __INLINE_CODE_800__.
alpha.1 — initial v7 composition-representation overhaul:
- __INLINE_CODE_801__ → __INLINE_CODE_802__ (#149). Grammar fix on a name introduced in 2019: the past-participle __INLINE_CODE_803__ fits the "with a halt-state that has been ___" naming idiom; __INLINE_CODE_804__ (simple past) didn't. Hard cutover — no deprecated alias. The getter (__INLINE_CODE_805__ → __INLINE_CODE_806__) and the serialized __INLINE_CODE_807__ data field (__INLINE_CODE_808__ → __INLINE_CODE_809__) rename in lockstep. Consumer migration: global find/replace __INLINE_CODE_810__ → __INLINE_CODE_811__ and __INLINE_CODE_812__ → __INLINE_CODE_813__. Persisted __INLINE_CODE_814__ JSON dumps would need the same field-rename treatment, but persistence isn't a known consumer pattern.
- Paren-based wrapped-state naming (#148). __INLINE_CODE_815__'s composite name format changed from flat __INLINE_CODE_816__ to nested __INLINE_CODE_817__. Same nesting depth reads as __INLINE_CODE_818__ (bare = __INLINE_CODE_819__, override = __INLINE_CODE_820__) versus __INLINE_CODE_821__ (bare = __INLINE_CODE_822__, override = __INLINE_CODE_823__) — two structurally-different wrap-trees that the old __INLINE_CODE_824__-flat notation collided into the single string __INLINE_CODE_825__. As a consequence, user-provided state names must not contain __INLINE_CODE_826__ or __INLINE_CODE_827__ — __INLINE_CODE_828__ now throws at construction time if a user passes such a name. The __INLINE_CODE_829__ character stays valid in user names (no longer reserved). The __INLINE_CODE_830__ / __INLINE_CODE_831__ / __INLINE_CODE_832__ outputs carry the new format. __INLINE_CODE_833__ files in __INLINE_CODE_834__ regenerate accordingly.
- __INLINE_CODE_835__ callable-subtree emit (#174, supersedes the alpha.1 collapsed-bare shape from #138/#139). __INLINE_CODE_836__ is modeled as a function call: the wrapper is a __INLINE_CODE_837__ call site OUTSIDE any subgraph, the bare's reachable subtree becomes a __INLINE_CODE_838__ block containing the bare + body states + a per-frame halt marker __INLINE_CODE_839__. Frames are computed via union-find on bare-reachability — overlapping reach sets merge into a single union frame, so shared bares (__INLINE_CODE_840__'s __INLINE_CODE_841__) appear ONCE with __INLINE_CODE_842__-joined call arrows from each wrapper. Bold __INLINE_CODE_843__ arrows are reserved for the wrapper-to-bare call; dotted __INLINE_CODE_844__ is reserved for frame-level dispatch (__INLINE_CODE_845__ / __INLINE_CODE_846__ / __INLINE_CODE_847__). The retired __INLINE_CODE_848__ keyword is replaced by a solid __INLINE_CODE_849__ arrow (just an ordinary transition under the call/return mental model). __INLINE_CODE_850__ gains __INLINE_CODE_851__, __INLINE_CODE_852__, __INLINE_CODE_853__ fields (and drops __INLINE_CODE_854__). No per-context duplication: a shared bare emits a single de-duped subtree and __INLINE_CODE_855__ rebuilds one shared instance. Bytewise round-trip stability holds for simple wrappers; shared-bare cases stay behaviourally equivalent (__INLINE_CODE_856__) but not byte-stable, because node ids are reassigned on rebuild and the serialization reorders.
For the full release history, see the GitHub releases page.
Libraries
- @turing-machine-js/library-binary-numbers — binary arithmetic with __INLINE_CODE_857__ markers, multi-number-per-tape support
- @turing-machine-js/library-binary-numbers-bare — same operations on a 3-symbol alphabet, single-number-per-tape, much smaller state graphs
Links
- Turing Machine on Wikipedia