silk.machine.generate.

Silk source from a Definition: the transition table of each chart as a static function.

Details#

The program owns its types: the state union, the event union, the context and the effects, with the names <Name>, <Name>Event, <Name>Context and <Name>Effect, and one state union per region chart, named after the chart. It also owns the guard functions, named guard<State><Event> for a transition on an event and when<State> for an eventless one. In the chart of a region the chart's name comes first: guard<Chart><State><Event> and when<Chart><State>. The generated module imports all of them from the module passed as types and declares one pub static fn <chart>Chart() per chart, which the program returns from Machine.chart of that chart's state union.

The initial state and the target of a transition are written as values, such as Editor.Open { bold: Bold.Off, italic: Italic.Plain }: the state, with each region at the initial state of its chart. A state that holds data of its own cannot be generated, because a definition does not have that data.

A state with a history gets a Chart.history or Chart.shallowHistory row that names a field of the context, a History of the chart's state union, and a transition to the history is written with Chart.resume.

Every state, event and region field name in the definition is checked against the unions when the generated module is compiled, so a definition that names a state the program does not have fails there.

Gotchas#

Several guarded transitions of one state on one event share one guard function name. Give them one function, or edit the definition so that they differ.

Import as Generate with import silk.machine.generate { Generate }.

Public declarations: 1.

Generate#

silk
pub struct Generate

Implementation Generate#

silk
impl Generate

Associated function write#

silk
pub effect fn write(definition: &Definition, types: string) -> ()
    ! WriterError
    ? &mut Writer

Writes the Silk module for definition. types is the module path that declares the program's types and guard functions, for example "light".

Category: State machines.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page