Skip to main content

Crate statifier

Crate statifier 

Source
Expand description

An SCXML statechart interpreter core, a conformant sibling of the Elixir reference statifier, checked against the conformance corpus the reference publishes.

compile reads an SCXML document into a Machine: an immutable value, cheap to clone and safe to share between threads, that holds every state interned in document order and every expression compiled through the predicator crate. A document it cannot compile is answered with the Refusals of the first stage that refused it.

Machine::start starts a chart in execution: a State, an immutable value that State::step (an external event) and State::advance (the virtual clock) move, each answering the new state and the Effects the call produced. The driver takes no runtime, thread, clock or I/O of its own: a send of a type the host registered (Options::send_types) is answered as an effect for the host to deliver, and the crate never calls host code.

use statifier::{Options, Value};

let machine = statifier::compile(
    r#"<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="a">
         <state id="a"><transition event="e.go" target="b"/></state>
         <final id="b"/>
       </scxml>"#,
)
.map_err(|refusals| format!("{refusals:?}"))?;
let started = machine.start(Options::new("s-1"))?;
assert_eq!(started.state.configuration(), ["a"]);

let moved = started.state.step("e.go", Value::Undefined)?;
assert_eq!(moved.state.done().map(|done| done.configuration.clone()), Some(vec!["b".to_owned()]));

State::export_position writes a chart’s position in the string-id vocabulary, and Machine::import_position reads one back onto the same chart or another that holds every state it names. A position carries the interpreter’s state only: the virtual clock, a pending timer and a queued external event are the host’s to reschedule.

§Refusals are values

No function panics on a document or a position a host passes: every refusal is a value (Refusal, Error, ExportError, ImportError), every public enum is #[non_exhaustive], and nothing is configured globally.

§Features and compatibility

The optional basichttp feature, off by default, adds the basichttp module: the Basic HTTP Event I/O Processor a host registers, delivers a send through and decodes a received request with, and the Transport trait it implements, with the request, response and error values it exchanges. It adds no dependency and the crate ships no transport.

The serde feature, off by default, implements Serialize and Deserialize for a Position, an Effect and a Done, with the types they reach, and turns on the predicator crate’s own for a Value. The crate has one runtime dependency, the predicator crate, forbids unsafe code, needs std, and builds for wasm32-unknown-unknown. The README holds the full compatibility and conformance statements.

Modules§

basichttp
The specification’s Basic HTTP Event I/O Processor, and the seam a host fills to carry its sends.

Structs§

AcceptsCheck
What Machine::check_accepts answers: the declared names the chart can never select on, and the descriptors it listens for that the declaration does not state.
ActiveInvocation
A live invocation, as a position names it: the state whose <invoke> started it, which of that state’s <invoke> elements, in document order from 0, and the invoke id.
Done
What a stopped chart answers (State::done).
Machine
A compiled chart: an immutable value, cheap to clone, that any number of threads may share.
Map
The map type of a chart’s datamodel and of a map value: the predicator crate’s own, re-exported beside Value, with its key type. A predicator map: Keys, each with a Value, kept in key order.
Moved
What a call that moves a chart answers: the new state, and the effects the call produced, in the order they were produced.
Options
What Machine::start takes.
Position
A chart’s position in the string-id vocabulary: every field of the reference’s export, a state named by the id the document wrote and the root never named.
Refusal
One refusal: the reason, a message for a person, and the span refused.
Span
A span of the source: 1-based lines and columns, 0-based byte offsets and an exclusive end. Columns count code points, and only a line feed starts a new line.
State
A chart in execution: an immutable value, as cheap to clone as its datamodel. Each call that moves it answers a new state and leaves this one unchanged.
Warning
A warning on a chart that compiles: a finding the engine has a behavior for either way, which never stops a chart compiling.

Enums§

BlockOwner
The block of executable content an effect came from. State and transition indexes count in document order, the <scxml> root being state 0, and ordinal counts a state’s blocks of one kind from 0.
CompileReason
Why a valid document does not compile.
DefaultTransitionOwner
The slot a default transition came from: a state’s <initial> element or a <history>’s own transitions, with the owning state’s id.
Effect
One effect: something the chart did that a host may observe.
Error
Why a driver call was refused.
ExportError
Why State::export_position refused.
ImportError
Why Machine::import_position refused.
IoProcessorEntry
The _ioprocessors entry a host supplies for a send type it registers (Options::ioprocessors).
Key
The map type of a chart’s datamodel and of a map value: the predicator crate’s own, re-exported beside Value, with its key type. A map key: one of the four kinds the reference’s instruction-set text lets index a map, a string, an integer, a boolean or undefined. (null is not one of the four; a lookup by null is a miss, not an error.)
LoweringReason
Why lowering refused something, with the detail each reason carries.
PathSegment
One segment of a resolved datamodel location.
ReadReason
Why a document was refused.
Reason
Why a chart was refused: the stage that refused it, with that stage’s own reason.
RoundBudget
The most rounds one macrostep may take.
Status
Whether a chart has finished stopping: the reference’s status.
ValidationReason
Why a document does not validate, with the detail each reason carries. Each variant is one of the reference’s reasons, under its name.
Value
The value type of a chart’s datamodel: the predicator crate’s own value, re-exported rather than mirrored, so a value a host passes in and a value an expression answers are one type. A predicator value.
WarningReason
Why a document draws a warning: a finding the engine has a behavior for either way.

Functions§

compile
Compiles the SCXML document source into its machine.