UNIT definition

Language reference ››
Parent Previous Next

A typical PMP unit contains the following elements:

unit-definition =
UNIT unit-name ";"
interface-part
implementation-part
[ initialization-part ]
END "." .

interface-part =
INTERFACE
[ uses-declaration ]
{
[ constants-declarations ]
[ types-declarations ]
[ variables-declarations ]
[ procedure-or-function-interface-declarations ]
} .

implementation-part =
IMPLEMENTATION
{
[ constants-declarations ]
[ types-declarations ]
[ variables-declarations ]
[ procedure-or-function-declarations ]
} .

initialization-part =
INITIALIZATION
{ block } .

<unit-name> must match the name declared in the <uses-declaration> of the program ou unit that uses this unit.

If a file path is not specified (see the program definition in previous paragraph), the unit name serves as a file name and cannot be expressed as a string, so long file names are allowed but they must contain only valid identifier characters.

Symbols, procedures and functions that are declared in the interface section will be visible outside the unit (declared as "global" for the linker).

Procedure and function arguments declarations in the implementation section must match the declarations of the interface section, or may be omitted (as in TP / Delphi).

PMP does not support an "USES" declaration in the implementation section, so take care about circular references between units.

PMP supports an "initialization" section in units. Initializations are called before execution of the main program statements.

A unit cannot have a processor definition, since it should be built for a main program.  

When a unit is compiled during a project "make" or "build", the unit uses the main program's definitions (processor, frequency, conditional defines ...).

A unit generates its own assembler source file (.asm) and a "precompiled unit" file (.pcu) that contains data and code definitions of the unit, in an intermediate pre-processed form that is loaded when the unit is used. PMP takes care about unit .pas, .asm and .pcu files time stamps match and will rebuild units that are out of date.

Since some optimizations are processor dependent, if some program / unit declarations of processor characteristics or definitions mismatches, PMP automatically rebuilds the unit latest definitions.

The unit may contain one or more optional special procedures qualified with the INTERRUPT modifier, which are used to define sets of statements that are intended to be executed as interrupt service routines.


The unit initialization block is an optional section and must be the last defined block of a unit, just before the terminal END:

This block is executed once immediately upon processor reset, before execution of the main program block (The order of execution is the order of the units compilation).  



INITIALIZATION

 CLR(TheVar);

END.