Documentation
¶
Overview ¶
Package gen turns a state machine's intermediate representation into typed Go stub source — an "eject" codegen.
Eject walks an state.IR and emits a single gofmt'd Go source file containing:
- a Context type synthesized from the IR's context schema (a struct when the schema declares fields, otherwise a map[string]any alias);
- one panic-bodied stub per referenced behavior (guard, action, assign, service), each typed to the exact engine signature with the synthesized Context substituted for the machine's context type parameter; and
- a Provide function that registers every stub against a state.Registry by its original IR name.
The emitted file is a starting point a host fills in: every stub panics with a TODO until implemented, but the file compiles and its Provide type-checks against the real registry, so the wiring is proven before any behavior is written.
Output is deterministic: names are sorted and the file is rendered from sorted slices, so ejecting the same IR twice yields byte-identical source.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Eject ¶
func Eject[S comparable, E comparable, C any](ir state.IR[S, E, C], opts ...Option) ([]byte, error)
Eject renders the given IR to typed Go stub source.
Signature choice (a): the IR is walked directly. The type parameters S, E, and C are unused by the codegen — the IR's behavior references (state.Ref) and its context schema (state.ContextSchema) are non-generic, so the walk and the emitted source are driven entirely by those concrete shapes. The parameters remain on the signature so callers can pass an state.IR loaded from a typed machine without reflection or an interface wrapper, keeping Eject a drop-in over a typed machine's loaded IR.
The returned bytes are a single gofmt'd Go source file. On a formatting failure (which indicates a codegen bug) the error wraps the unformatted source so it can be inspected.
Types ¶
type Option ¶
type Option func(*config)
Option configures an Eject call. Options form an additive variadic tail on Eject; required inputs stay positional and new capabilities arrive as new Options, never as changes to existing signatures.
func WithContextTypeName ¶
WithContextTypeName sets the name of the generated context type — the type substituted wherever the engine signatures reference the machine's context type parameter. The default is "Context". An empty name is ignored.
func WithPackageName ¶
WithPackageName sets the package clause of the generated file. The default is "machine". An empty name is ignored, leaving the default in place.