ptolemy.caltrop.actors
Class CalInterpreter

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.caltrop.actors.CalInterpreter
All Implemented Interfaces:
Actor, Changeable, java.lang.Cloneable, Debuggable, DebugListener, Derivable, Executable, Instantiable, ModelErrorHandler, MoMLExportable, Nameable, java.io.Serializable, TypedActor

public class CalInterpreter
extends TypedAtomicActor

This actor interprets CAL source as an actor inside the Ptolemy II framework. It has a calCode string attribute that contains the text of a CAL actor. It configures itself according to CAL code string (setting up ports, parameters, types etc.) and then proceeds to execute the actor by interpreting the actions using the DataflowActorInterpreter infrastructure.

The actor interpreter is configured by a context that injects the appropriate Token-based value system into the evaluation of the actions. This is implemented in the class PtolemyPlatform.

For further documentation on CAL, see the Language Report.

Since:
Ptolemy II 4.0
Version:
$Id: CalInterpreter.java,v 1.26 2004/04/13 18:37:29 cxh Exp $
Author:
Jörn W. Janneck Christopher Chang
See Also:
DataflowActorInterpreter, Context, PtolemyPlatform, Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
 StringAttribute calCode
          The CAL source to be interpreted.
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
CalInterpreter(CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 void attributeChanged(Attribute attribute)
          The only attribute whose modifications are handled is the calCode attribute, which contains the source code of the CAL actor.
 void fire()
          Fire the actor.
 void initialize()
          Initialize the actor, clearing its input channels.
 boolean postfire()
          Commit the last state changes.
 boolean prefire()
          This method should be invoked once per iteration, before the first invocation of fire() in that iteration.
 void preinitialize()
          Populate the initial actor environment.
 void printDebug(java.lang.String msg)
           
 boolean superPrefire()
           
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, iterate, newReceiver, outputPortList, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
iterate, stop, stopFire, terminate, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

calCode

public StringAttribute calCode
The CAL source to be interpreted.

Constructor Detail

CalInterpreter

public CalInterpreter(CompositeEntity container,
                      java.lang.String name)
               throws NameDuplicationException,
                      IllegalActionException
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
The only attribute whose modifications are handled is the calCode attribute, which contains the source code of the CAL actor.

Whenever the source is changed, the text is parsed, transformed, and translated into an internal data structure used for interpretation.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that changed.
Throws:
IllegalActionException - If an error occurs parsing or transforming the CAL source code.

preinitialize

public void preinitialize()
                   throws IllegalActionException
Populate the initial actor environment. This is done by binding the parameters to the user-supplied values and then evaluating the definitions of state variables and creating the corresponding bindings.

Specified by:
preinitialize in interface Executable
Overrides:
preinitialize in class AtomicActor
Throws:
IllegalActionException - If an error occurred during the retrieval of parameter values or the evaluation of actor state variable values.

initialize

public void initialize()
                throws IllegalActionException
Initialize the actor, clearing its input channels.

Specified by:
initialize in interface Executable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If the superclass throws it.

prefire

public boolean prefire()
                throws IllegalActionException
Description copied from interface: Executable
This method should be invoked once per iteration, before the first invocation of fire() in that iteration. It returns true if the iteration can proceed (the fire() method can be invoked). Thus this method will typically check preconditions for an iteration, if there are any. In an opaque, non-atomic entity, it may move data into an inner subsystem. The execution of this method is bounded.

Specified by:
prefire in interface Executable
Overrides:
prefire in class AtomicActor
Returns:
True if this actor is ready for firing, false otherwise.
Throws:
IllegalActionException - Not thrown in this base class.

fire

public void fire()
          throws IllegalActionException
Description copied from interface: Executable
Fire the actor. This may be invoked several times between invocations of prefire() and postfire(). Output data may (and normally will) be produced. Typically, the fire() method performs the computation associated with an actor. This method is not required to have bounded execution. However, after endFire() is called, this method should return in bounded time.

Specified by:
fire in interface Executable
Overrides:
fire in class AtomicActor
Throws:
IllegalActionException - Not thrown in this base class.

postfire

public boolean postfire()
                 throws IllegalActionException
Commit the last state changes.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
Returns whatever super.postfire() returns.
Throws:
IllegalActionException - If the superclass throws it.

superPrefire

public boolean superPrefire()
                     throws IllegalActionException
Throws:
IllegalActionException

printDebug

public void printDebug(java.lang.String msg)