ptlang
, was created to make it easier to write and document star class definitions to run under Ptolemy. Instead of writing all the class definitions and initialization code required for a Ptolemy star, the user can concentrate on writing the action code for a star and let the preprocessor generate the standard initialization code for portholes, states, etc. The preprocessor generates standard C++ code, divided into two files (a header file with a
.h
extension and an implementation file with a
.cc
extension). It also generates standardized documentation, in a file with a
.html
extension, to be included in the manual. In releases before Ptolemy 0.7, Ptolemy used .t
files, which conained
troff source YYY
in domain XXX
should appear in file with the name XXXYYY.pl
. The class that implements this star will be named XXXYYY
. Then, running the commandXXXYYY.cc
, XXXYYY.h
, and XXXYYY.html
. Implementation of the preprocessor
The preprocessor is written in
yacc
and C. It does not attempt to parse the parts of the language that consist of C++ code (for example, go
methods); for these, it simply counts curly braces to find the ends of the items in question. It outputs #line
directives so the C++ compiler will print error messages, if any, with respect to the original source file.
SDFRect.pl
: SDFRect.h
, SDFRect.cc
and SDFRect.html
; the names are determined not by the input filename but by concatenating the domain and name fields. These files define a class named SDFRect
.
At the time of this writing, only one type of declaration may appear at the top level of a Ptolemy language file, a defstar
, used to define a star. Sometime in the future, a defgalaxy
section may also be supported. The defstar
section is itself composed of subitems that define various attributes of the star. All subitems are of the form
body
may itself be composed of sub-subitems, or may be C++ code (in which case the Ptolemy language preprocessor checks it only for balanced curly braces). Note that the keywords are not reserved words; they may also be used as identifiers in the body.defstar
directive. The items are given in the order in which they typically appear in a star definition (although they can appear in any order). An alphabetical listing and summary of directives is given in table identifier
specifies the domain (again, case is important).identifier
specifies the base class. The .h
file for the base class is automatically included in the output .h
file, assuming it can be located (you may need to create a makefile).
For example, the LMS
star in the SDF
domain is derived from the FIR
star. The full name of the base class is SDFFIR
, but the derivedfrom
statement allows you to say either
derivedfrom
statement may also be written derivedFrom
or derived
.
profile
pigi command. It has the syntaxtext
is simply a section of text that will become the short descriptor of the star. You may also write desc
instead of descriptor
. A principal use of the short descriptor is to get on-screen help, so the descriptor should not include any troff formatting commands. Unlike the htmldoc
(described below), it does not pass through troff. The following are legal descriptors: htmldoc
directive, explained below. However, it should be long enough so that it is sufficient to explain the function of the star.number
is a version number, and the MO/DA/YR
is the version date. If you are using SCCS for version control then the following syntax will work well:%W%
will be replaced with a string of the form: @(#)
filename
num, where num is the version number, and %G%
will be replaced with a properly formatted date..h
, .cc
, and .t
files. The syntax is%Q%
keyword to update the date when a file is changed. A typical copyright line might look like:directory
is the location of the star. This item is for documentation only.htmldoc
item.ptlang
can be viewed by any HTML viewer, but certain features, such as the <tcl></tcl>
directive are only operational when viewed with Tycho. For complete documentation for the Tycho HTML viewer, see the HTML viewer Help menu.name
field is the name of the state; the type
field is its type, which may be one of
int
,
float
,
string
,
complex
,
fix
,
intarray
,
floatarray
,
complexarray
,
precision
, or
stringarray
. Case is ignored for the type argument.
The
default
item specifies the default initial value of the state; its argument is either a string (enclosed in quotation marks) or a numeric value. The above entry could equivalently have been written:
ComplexArray
:real
and imag
evaluate to integers or floats.
The precision
state is used to give the precision of
fixed-point values. These values may be other states or may be internal to the star. The default can be specified in either of two ways:
The desc
(or
descriptor
) item, which is optional but highly recommended, attaches a descriptor to the state. The same formatting options are available as with the star descriptor.
Finally, the
attributes
keyword specifies state attributes. At present, two attributes are defined for all states:
A_CONSTANT
and
A_SETTABLE
(along with their complements
A_NONCONSTANT
and
A_NONSETTABLE
). If a state has the A_CONSTANT
attribute, then its value is not modified by the run-time code in the star (it is up to you as the star writer to ensure that this condition is satisfied). States with the A_NONCONSTANT
attribute may change when the star is run. If a state has the A_SETTABLE
attribute, then user interfaces (such as pigi
) will prompt the user for values when directives such as edit-parameters are given. States without this attribute are not presented to the user; such states always start with their default values as the initial value. If no attributes are specified, the default is A_CONSTANT
|A_SETTABLE
. Thus, in the above example, the attributes
directive is unnecessary. The notation "A_CONSTANT
|A_SETTABLE
" indicates a logical "or" of two flags. Confusingly, this means that they both apply (A_CONSTANT
and A_SETTABLE
).
Code generation stars use a great number of attributes, many specific to the language model for which code is being generated. Read chapter 13, "Code Generation", and the documentation for the appropriate code generation domain to learn more about these.
Mechanisms for accessing and updating states in C++ methods associated with a star are explained below, in sections 2.4.3 on page 2-21 and 2.4.4 on page 2-23.
state
, it contains subitems. Here is an example:name
specifies the porthole name. This is a required item. type
specifies the particle type. The scalar types are
int
,
float
,
fix
,
complex
,
message
, or
anytype
. Again, case does not matter for the type value. The matrix types are
int_matrix_env
,
float_matrix_env
,
complex_matrix_env
, and
fix_matrix_env
. The type
item may be omitted; the default type is anytype
. For more information on all of these, please see chapter
4,
"Data Types".
There is an alternative syntax for the type field of a porthole; this syntax is used in connection with ANYTYPE
to specify a link between the types of two portholes. The syntax is
name
is the name of another porthole. This indicates that this porthole inherits its type from the specified porthole. For example, here is a portion of the definition of the SDF Fork
star:body
is a piece of C++ code. It can be of any length. Note that the constructor is invoked only when the class is first instantiated; actions that must be performed before every simulation run should appear in the setup
or begin
methods, not the constructor.public
, private
, or protected
keywords. If you have such members, the conscalls
keyword provides a mechanism for passing arguments to the constructors of those members. Simply list the names of the members followed by the list of constructor arguments for each, separated by commas if there is more than one. The syntax is:member1
, and member2
should have been previously defined in a public
, private
, or protected
section (see
page 2-14).begin
method, or setup
method; termination functions that happen with every run should appear in the wrapup
function1. The optional keyword inline
may appear before destructor
; if so, the destructor function definition appears inline, in the header file. Since the destructor for all stars is virtual, this is only a win when the star is used as a base for derivation.setup
method, which is called every time the simulation is started, before any
compile-time scheduling is performed. The syntax is:inline
may appear before the setup
keyword. It is common for this method to set parameters of input and output portholes, and to initialize states. The code syntax for doing this is explained starting on
page 2-16. In some domains, with some targets, the setup
method may be called more than once during initiation. You must keep this in mind if you use it to allocate or initialize memory.begin
method, which is called every time the simulation is started, but after the scheduler setup
method is called (i.e., after any
compile-time scheduling is performed). The syntax is:inline
may appear before the go
keyword. The go method will typically read input particles and write outputs, and will be invoked many times during the course of a simulation. The code syntax for the body is explained starting on
page 2-16.wrapup
method, which is called at the completion of a simulation. The syntax is:inline
may appear before the wrapup
keyword. The wrapup method might typically display or store final state values. The code syntax for doing this is explained starting on
page 2-16. Note that the wrapup
method is not invoked if an error occurs during execution. Thus, the wrapup
method cannot be used reliably to free allocated memory. Instead, you should free memory from the previous run in the setup
or begin
method, prior to allocating new memory, and in the destructor.protkey
is public
, protected
, or private
. Example, from the XMgraph
star:XGraph
, defined in the Ptolemy kernel, and a double-precision number. If any of the added members require arguments for their constructors, use the conscalls
item to specify them..cc
file, or the .h
file, to #include
extra files. A certain number of files are automatically included, when the preprocessor can determine that they are needed, so they do not need to be explicitly specified. The syntax is:inclist
is a comma-separated list of include files. Each filename must be surrounded either by quotation marks or by "<
" and ">
" (for system include files like <math.h>
). .cc
file after the include files but before everything else; it can be used to define static non-class functions, declare external variables, or anything else. The outermost pair of curly braces is stripped. The syntax is:.h
file after the include files but before everything else. This can be used, for example, to define classes used by your star. The outermost pair of curly braces is stripped.method
item provides a fully general way to specify an additional method for the class of star that is being defined. Here is an example:method
keyword, which must be one of the following:virtual
keyword makes a virtual member function. If the pure
virtual
keyword is given, a pure virtual member function is declared (there must be no code
item in this case). The function type pure
is a synonym for pure
virtual
. The inline
function type declares the function to be inline. name:
access:
public
, protected
, or private
. If the item is omitted, protected
is assumed.arglist:
type:
void
(no value is returned).code:
pure
keyword appears, in which case this item cannot appear.myExecTime()
function, which is used in code generation to specify how many time units are required to execute the star's code. The syntax is:inline
may appear before the exectime
keyword. The body
defines the body of a function that returns an integer value.Copyright © 1990-1997, University of California. All rights reserved.