First generated runtime
This tutorial is the shortest path from one FCSTM model to one usable generated
runtime. It uses the packaged Python built-in template through --template;
it does not point at the repository templates/ source tree.
Use Generation tasks when you need recipes for all built-in templates, native smoke checks, generated README entry points, or failure handling. Use Built-in templates reference and Template configuration reference when you need exact facts.
What you will run
The input model has three leaf states and three event-triggered transitions:
def int counter = 0;
state SimpleMachine {
state Idle;
state Running;
state Stopped;
[*] -> Idle;
Idle -> Running :: Start effect {
counter = 0;
};
Running -> Stopped :: Stop effect {
counter = counter + 1;
};
Stopped -> Idle :: Reset;
}
Generate Python code
Render the packaged Python template into a fresh output directory:
pyfcstm generate -i simple_machine.fcstm --template python -o generated/python --clear
The important pieces of the command are:
--template pythonselects the installed built-in template namedpython.-o generated/pythonchooses the generated output directory.--clearmakes the tutorial repeatable by deleting the previous output directory contents before rendering.
A successful run writes machine-specific files. For this model the output has three top-level files:
README.md
README_zh.md
machine.py
machine.py is the generated runtime. The README files are generated from
the same model and are part of the output contract: read them when integrating
that particular generated machine.
Run the generated class
A minimal consumer imports the generated class, constructs it, performs the initial cycle, and then submits event paths:
print("generated files:", ", ".join(path.name for path in sorted(output.iterdir())))
module = load_machine_module(output / "machine.py")
machine = module.SimpleMachineMachine()
machine.cycle()
print("initial:", state_text(machine))
for label, event in [
("after Start", "SimpleMachine.Idle.Start"),
("after Stop", "SimpleMachine.Running.Stop"),
("after Reset", "SimpleMachine.Stopped.Reset"),
]:
machine.cycle(event)
print(f"{label}:", state_text(machine))
The checked-in demo prints the generated files, then shows the state and
counter value after each event:
generated files: README.md, README_zh.md, machine.py
initial: SimpleMachine.Idle counter=0
after Start: SimpleMachine.Running counter=0
after Stop: SimpleMachine.Stopped counter=1
after Reset: SimpleMachine.Idle counter=1
This proves only the first-success path: generation succeeded, the generated Python file is importable, and a small event sequence runs. It is not a full semantic-alignment proof for every FCSTM construct.
Where to go next
Generate
c,c_poll,cpp, orcpp_polloutputs with Generation tasks.Author a custom template directory with Template author tasks.
Understand the renderer pipeline with Template rendering explanation.
Look up built-in template contracts in Built-in templates reference.