Ptolemy Language Description

The Ptolemy language ptlang is a preprocessor language and was created to make it easier to write and document primitives to run under MLDesigner. Instead of writing all the class definitions and initialization code required for a primitive, the programmer can concentrate on writing the functionality of a primitive and let the preprocessor generate the standard initialization code for ports, parameters, 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 .htm extension.

Compiling Primitives

The definition of a primitive named Yyy in domain Xxx should appear in a file with the name XxxYyy.pl. The class that implements this primitive will be named XxxYyy. MLDesigner automatically uses the command ptlang XxxYyy.pl to invoke the preprocessor. The preprocessor will produce the files XxxYyy.cc, XxxYyy.h, and XxxYyy.htm in the directory of the primitive source file. The preprocessor does not attempt to parse the parts of the language that consist of C++ code, e.g., the methods. For these parts, it simply counts curly braces to find the ends of the items in question. It generates #line directives so the C++ compiler will print error messages, if any, with respect to the original source file.

Example

To make things more clear consider this example:

  1. Go to the Tree View and expand the tree to MLD Libraries→SDF Domain→Nonlinear
  2. Click on the Sin item and choose Save As from the context menu to open the Save as New Model dialog.
  3. Set the Logical name and Physical Name to MySin.
  4. Select a writable library in which to save the copied primitive.
  5. Click the OK button to save the primitive.

You now have a sine function primitive that is described by the file SDFMySin.pl, MySin.mml and SDFMySin.htm as well as a makefile in the selected library. Running the preprocessor (compiling the primitive) produces the three files SDFMySin.h, SDFMySin.cc and SDFMySin.<MLDARCH>.o. The names are determined not by the input filename but by concatenating the domain and name fields. These files define a class named SDFMySin.

At the time of this writing, only one type of declaration may appear at the top level of a MLDesigner language file, a defprimitive , used to define a whole primitive. The defprimitive section itself is composed of subitems that describe various properties and definitions of the primitive. All sub items are of the form keyword { body }, where the body may itself be composed of sub items, or may be C++ code, in which case the MLDesigner language preprocessor checks it only for balanced curly braces.

Keywords are not reserved words, they may also be used as identifiers in the C++ code body.