Skip to main content
Elaborates the definition (cached per definition) and returns the first state of a new simulation: tick 0, every signal "X", and every gate due for its first evaluation.

Options

Options are fixed when the simulation starts and carry over to every later state.
number
default:"10000"
The maximum number of steps a single run() call may take. Must be a positive integer.
boolean
default:"false"
Record every wire change, so trace() can return it.

SimulationState

A frozen object describing one moment of the simulation. Methods that move the simulation forward return a new state and never change the one they’re called on.

Properties

number
Simulation time: the next tick to be processed.
boolean
True when no wire changes are pending and every gate has had its first evaluation.
readonly SignalTransition[]
The wire changes applied by the step that produced this state, in wire order. Empty for the first state and for states returned by set().

Moving forward

(inputs: { [K in I]?: Signal }) => SimulationState
A new state with these external inputs pending. They take effect on the next step. Returns the same state if nothing would change. Throws SimulationError for unknown names or invalid values, without applying anything.
() => SimulationState
A new state, one tick later. It applies the pending changes, evaluates the gates that read a changed wire, and makes their changed outputs pending.
() => SimulationState
A new state, stepped until stable. Returns the same state if it’s already stable. Throws StabilizationError after maxTicks steps.

Reading

(output: O) => Signal
The current value of one external output.
() => { [K in O]: Signal }
The current values of all external outputs.
() => SimulationSnapshot
Plain, serializable data: { tick, stable, pendingEvents, signals, wires }. signals maps every hierarchical port id to its value, and wires maps every wire id to { value, ports }.
() => readonly SignalTransition[]
A frozen array of every wire change from tick 0 up to this state, ordered by tick and then by wire id. Empty unless trace: true.

Example