- class sismic.interpreter.Interpreter(statechart, *, evaluator_klass=<class 'sismic.code.python.PythonEvaluator'>, initial_context=None, clock=None, ignore_contract=False)¶
A discrete interpreter that executes a statechart according to a semantic close to SCXML (eventless transitions first, inner-first/source state semantics).
Statechart) – statechart to interpret
Evaluator]) – An optional callable (e.g. a class) that takes an interpreter and an optional initial context as input and returns an Evaluator instance that will be used to initialize the interpreter. By default, the PythonEvaluator class will be used.
Clock) – A BaseClock instance that will be used to set this interpreter internal time. By default, a SimulatedClock is used.
bool) – set to True to ignore contract checking during the execution.
Attach given listener to the current interpreter.
The listener is called each time a meta-event is emitted by current interpreter. Emitted meta-events are:
step started: when a (possibly empty) macro step starts. The current time of the step is available through the
step ended: when a (possibly empty) macro step ends.
event consumed: when an event is consumed. The consumed event is exposed through the
event sent: when an event is sent. The sent event is exposed through the
state exited: when a state is exited. The exited state is exposed through the
state entered: when a state is entered. The entered state is exposed through the
transition processed: when a transition is processed. The source state, target state and the event ard exposed respectively through the
Every meta-event that is sent from within the statechart.
This is a low-level interface for
sismic.interpreter.listenerfor common listeners/wrappers.
Bind an interpreter (or a callable) to the current interpreter.
Internal events sent by this interpreter will be propagated as external events. 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).
This method is a higher-level interface for
x = interpreter.bind(...), use
interpreter.detach(x)to unbind a previously bound interpreter.
- bind_property_statechart(statechart, *, interpreter_klass=None)¶
Bind a property statechart to the current interpreter.
A property statechart receives meta-events from the current interpreter depending on what happens. See
attachmethod for a full list of meta-events.
The internal clock of all property statecharts is synced with the one of the current interpreter. As soon as a property statechart reaches a final state, a
PropertyStatechartErrorwill be raised, meaning that the property expressed by the corresponding property statechart is not satisfied. Property statecharts are automatically executed when they are bound to an interpreter.
Since Sismic 1.4.0: passing an interpreter as first argument is deprecated.
This method is a higher-level interface for
x = interpreter.bind_property_statechart(...), use
interpreter.detach(x)to unbind a previously bound property statechart.
- property configuration: List[str]¶
List of active states names, ordered by depth. Ties are broken according to the lexicographic order on the state name.
Remove given listener from the ones that are currently attached to this interpreter.
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.
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.
- queue(event_or_name, *event_or_names, **parameters)¶
Create and queue given events to the external event queue.
If an event has a delay parameter, it will be processed by the first call to execute_once as soon as self.clock.time exceeds current self.time + event.delay.
If named parameters are provided, they will be added to all events that are provided by name.
- class sismic.interpreter.Event(name, **additional_parameters)¶
An event with a name and (optionally) some data passed as named parameters.
The list of parameters can be obtained using dir(event). Notice that name and data are reserved names. If a delay parameter is provided, then this event will be considered as a delayed event (and won’t be executed until given delay has elapsed).
When two events are compared, they are considered equal if their names and their data are equal.
str) – name of the event.
data – additional data passed as named parameters.
- class sismic.interpreter.InternalEvent(name, **additional_parameters)¶
Subclass of Event that represents an internal event.