gen

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func WithContextTypeName(name string) Option

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

func WithPackageName(name string) Option

WithPackageName sets the package clause of the generated file. The default is "machine". An empty name is ignored, leaving the default in place.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL