Module interpreter

class sismic.interpreter.Interpreter(statechart, *, evaluator_klass=<class 'sismic.code.python.PythonEvaluator'>, initial_context=None, ignore_contract=False)

Bases: object

A discrete interpreter that executes a statechart according to a semantic close to SCXML.

Parameters:
  • statechart (Statechart) – statechart to interpret
  • evaluator_klass (Callable[…, Evaluator]) – An optional callable (eg. a class) that takes an interpreter and an optional initial context as input and return an Evaluator instance that will be used to initialize the interpreter. By default, the PythonEvaluator class will be used.
  • initial_context (Optional[Mapping[str, Any]]) – an optional initial context that will be provided to the evaluator. By default, an empty context is provided
  • ignore_contract (bool) – set to True to ignore contract checking during the execution.
bind(interpreter_or_callable)

Bind an interpreter or a callable to the current interpreter. Each time an internal event is sent by this interpreter, any bound object will be called with the same event. If interpreter_or_callable is an Interpreter instance, its queue method is called. This is, if i1 and i2 are interpreters, i1.bind(i2) is equivalent to i1.bind(i2.queue).

Parameters:interpreter_or_callable (Union[Interpreter, Callable[[Event], Any]]) – interpreter or callable to bind
Return type:None
Returns:self so it can be chained
bind_property_statechart(statechart_or_interpreter)

Bind a property statechart to the current interpreter. A property statechart receives meta-events from the current interpreter depending on what happens:

  • step started: when a macro step starts.
  • step ended: when a macro step ends.
  • event consumed: when an event is consumed. The consumed event is exposed through the event attribute.
  • event sent: when an event is sent. The sent event is exposed through the event attribute.
  • state exited: when a state is exited. The exited state is exposed through the state attribute.
  • state entered: when a state is entered. The entered state is exposed through the state attribute.
  • transition processed: when a transition is processed. The source state, target state and the event are exposed respectively through the source, target and event attribute.

The internal clock of all property statecharts will be synced with the one of the current interpreter. As soon as a property statechart reaches a final state, a PropertyStatechartError will be raised, implicitly meaning that the property expressed by the corresponding property statechart is not satisfied.

Parameters:statechart_or_interpreter (Union[Statechart, Interpreter]) – A property statechart or an interpreter of a property statechart.
Return type:None
configuration

List of active states names, ordered by depth. Ties are broken according to the lexicographic order on the state name.

Return type:List[str]
context

The context of execution.

Return type:Mapping[str, Any]
execute(max_steps=-1)

Repeatedly calls execute_once and return a list containing the returned values of execute_once.

Notice that this does NOT return an iterator but computes the whole list first before returning it.

Parameters:max_steps (int) – An upper bound on the number steps that are computed and returned. Default is -1, no limit. Set to a positive integer to avoid infinite loops in the statechart execution.
Return type:List[MacroStep]
Returns:A list of MacroStep instances
execute_once()

Select transitions that can be fired based on available queued events, process them and stabilize the interpreter. When multiple transitions are selected, they are atomically processed: states are exited, transition is processed, states are entered, statechart is stabilized and only after that, the next transition is processed.

Return type:Optional[MacroStep]
Returns:a macro step or None if nothing happened
final

Boolean indicating whether this interpreter is in a final configuration.

Return type:bool
queue(event_or_name, *events_or_names)

Queue one or more events to the interpreter external queue.

Parameters:
  • event_or_name (Union[str, Event]) – an Event instance, or the name of an event.
  • events_or_names (Union[str, Event]) – additional Event instances, or names of events.
Return type:

Interpreter

Returns:

self so it can be chained.

statechart

Embedded statechart

Return type:Statechart
time

Time value (in seconds) for the internal clock

Return type:float
class sismic.interpreter.Event(name, **additional_parameters)

Bases: object

Simple event with a name and (optionally) some data. Unless the attribute already exists, each key from data is exposed as an attribute of this class.

The list of defined attributes can be obtained using dir(event).

Parameters:
  • name (str) – Name of the event
  • data – additional data (mapping, dict-like)
class sismic.interpreter.InternalEvent(name, **additional_parameters)

Bases: sismic.model.events.Event

Subclass of Event that represents an internal event.

class sismic.interpreter.MetaEvent(name, **additional_parameters)

Bases: sismic.model.events.Event

Subclass of Event that represents a MetaEvent, as used in property statecharts.