Class DataflowActorInterpreter
- java.lang.Object
-
- ptolemy.caltrop.ddi.util.DataflowActorInterpreter
-
- Direct Known Subclasses:
DataflowWithRatesActorInterpreter
public class DataflowActorInterpreter extends java.lang.Object
The actor interpreter provides an abstract interface to the execution of an actor. It provides a number of operations on the actions of an actor, allowing clients to test them for firability and execute them.An instance of this class maintains some internal state identifying the action it currently works on. It expects its methods to be called in a particular order, viz.
actionSetup(action)
--actionEvaluatePrecondition()
--actionStep()
--actionComputeOutputs()
During such a sequence, the methods operate on action n, which was selected by the call toactionSetup(action)
. At any point in time, the client may callactionClear()
, which deselects the action and deletes the references to the resources used by the action environment created during setup.- Since:
- Ptolemy II 4.0
- Version:
- $Id$
- Author:
- Jörn W. Janneck
- See Also:
Actor
,Action
,actionSetup(caltrop.interpreter.ast.Action)
,actionEvaluatePrecondition()
,actionStep()
,actionComputeOutputs()
,actionClear()
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (cxh)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DataflowActorInterpreter.EnvironmentKey
protected static class
DataflowActorInterpreter.MultipleTokenReaderThunk
protected static class
DataflowActorInterpreter.SingleTokenReaderThunk
A single token reader thunk encapsulates the operation of reading a single token from a specified channel.
-
Field Summary
Fields Modifier and Type Field Description protected caltrop.interpreter.ast.Actor
actor
protected caltrop.interpreter.environment.Environment
actorEnv
protected caltrop.interpreter.Context
context
protected caltrop.interpreter.environment.Environment
env
protected caltrop.interpreter.ast.Action
envAction
protected java.util.Map
inputPortMap
-
Constructor Summary
Constructors Constructor Description DataflowActorInterpreter(caltrop.interpreter.ast.Actor actor, caltrop.interpreter.Context context, caltrop.interpreter.environment.Environment actorEnv, java.util.Map inputPortMap, java.util.Map outputPortMap)
Defines a new actor interpreter for the specified actor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionClear()
Clear action selection.void
actionComputeOutputs()
Compute the output tokens and send them to the specified (at construction time) output channels.boolean
actionEvaluatePrecondition()
Evaluate the preconditions for the action and return its result.void
actionSetup(caltrop.interpreter.ast.Action action)
Set up the local environment of the specified action.void
actionStep()
Execute the action body, potentially changing the value of actor state variables and action-scope variables.caltrop.interpreter.ast.Action
currentAction()
Return the current action.int
nActions()
Return the number of actions in this actor.int
nInitializers()
Return the number of initializers in this actor.void
setOutputPortMap(java.util.Map outputPortMap)
-
-
-
Field Detail
-
actor
protected caltrop.interpreter.ast.Actor actor
-
context
protected caltrop.interpreter.Context context
-
actorEnv
protected caltrop.interpreter.environment.Environment actorEnv
-
env
protected caltrop.interpreter.environment.Environment env
-
envAction
protected caltrop.interpreter.ast.Action envAction
-
inputPortMap
protected java.util.Map inputPortMap
-
-
Constructor Detail
-
DataflowActorInterpreter
public DataflowActorInterpreter(caltrop.interpreter.ast.Actor actor, caltrop.interpreter.Context context, caltrop.interpreter.environment.Environment actorEnv, java.util.Map inputPortMap, java.util.Map outputPortMap)
Defines a new actor interpreter for the specified actor.- Parameters:
actor
- The actor.context
- The interpretation context.actorEnv
- The global environment.inputPortMap
- Map from input port names to channels.outputPortMap
- Map from output port names to channels.- See Also:
InputChannel
,OutputChannel
-
-
Method Detail
-
actionSetup
public void actionSetup(caltrop.interpreter.ast.Action action)
Set up the local environment of the specified action. This method is the only way a new action may be set up for execution. If completed successfully, the action environment and the action are stored in the state of this interpreter, and other methods may operate on them.- Parameters:
action
- The action to setup.
-
actionEvaluatePrecondition
public boolean actionEvaluatePrecondition()
Evaluate the preconditions for the action and return its result. If this method returns false, some condition required for the successful completion of the action is not satisfied. This might be an insufficient number of input tokens, or some other condition depending on the value of the tokens or state variables.Note that the converse need not hold---depending on the model of computation, a true return value does not necessarily imply that the action will successfully execute. It may represent an approximation to a complete precondition, in which case the model of computation is not responsible.
- Returns:
- True, if the action precondition was satisfied.
- Throws:
caltrop.interpreter.InterpreterException
- If the evaluation of the guards could not be successfully completed.
-
actionStep
public void actionStep()
Execute the action body, potentially changing the value of actor state variables and action-scope variables.- Throws:
caltrop.interpreter.InterpreterException
- If the action body could not be executed successfully.
-
actionComputeOutputs
public void actionComputeOutputs()
Compute the output tokens and send them to the specified (at construction time) output channels.- See Also:
DataflowActorInterpreter
-
actionClear
public void actionClear()
Clear action selection. The reference to the environment is cleared, too, allowing the system to reclaim any resources associated with it.
-
currentAction
public caltrop.interpreter.ast.Action currentAction()
Return the current action. This is null if none has been selected.- Returns:
- The current action, null if none.
-
nActions
public int nActions()
Return the number of actions in this actor.- Returns:
- Number of actions.
-
nInitializers
public int nInitializers()
Return the number of initializers in this actor.- Returns:
- Number of initializers.
-
setOutputPortMap
public void setOutputPortMap(java.util.Map outputPortMap)
-
-