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 python selects the installed built-in template named python.

  • -o generated/python chooses the generated output directory.

  • --clear makes 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