Types

Language reference ››
Parent Previous Next

See also: Pointer types, Records, Dynamic Records.


 

Types are limited in PMP; for the current implementation, the allowed type declarations are:

 

type-declaration =
TYPE
{
string-type-declaration |
one-dimension-array-type-declaration |
record-type-declaration |
dynamic-record-type-declaration |
pointer-type-definition |
enumeration-type-definition |
range-type-definition |
set-type-definition
} .
string-type-declaration =
       identifier "=" STRING [ "[" numeric-constant-expression "]" ] ";" .
one-dimension-array-type-declaration =
       identifier "=" ARRAY "[" array-dimension-range "]" OF simple-type ";" .
array-dimension-range =
       ( numeric-constant-expression [ ".." numeric-constant-expression ]) | range-typed-identifier .
record-type-declaration = identifier "=" RECORD
       simple-field-declaration { "," simple-field-declaration }
       END ";" .
dynamic-record-type-declaration = identifier "=" RECORD
       simple-field-declaration { "," simple-field-declaration }
       method-declaration { "," method-declaration }
       property-declaration { "," property-declaration }
       END ";" .
pointer-type-definition = identifier "=" "^" ( simple-type | identifier ) ";" .
enumeration-type-definition = identifier "=" "(" enumeration-item {"," enumeration-item } ")" ";" .
enumeration-item =  identifier [ "=" enumeration-value ] .
enumeration-value = 0..255 .
range-type-definition = identifier "=" constant-expression ".." constant-expression ";" .
set-type-definition =  identifier "=" SET OF enumeration-type | constant-expression ".." constant-expression ";" .
method-declaration = procedure-declaration | function-declaration . 
property-declaration = PROPERTY identifier ":" type-identifier [ READ read-method ] [ WRITE write-method ] .


No full type checking so ranges may contain mixed values. In the example below, the syntax tMyRange3 = Monday..12; would be accepted.

An ARRAY may be defined with a single argument which is the total number of elements, the low bound will be 0.


TYPE
  tMyString = STRING[10];
  tMyArray = ARRAY[1..10] OF BYTE;
  tMyArray2 = ARRAY[10] OF BYTE; // Extended syntax mode only
  tMyRecord = RECORD
    X, Y: BYTE;
    B1, B2: BOOLEAN;
  END;
  tMyWordPtr = ^WORD;
  tMyRecordPtr = ^tMyRecord;
  tMyEnum = (Sunday, Monday, Tuesday, Thursday, Wednesday, Friday, Saturday);
  tMyRange1 = 12..24;
  tMyRange2 = Monday..Saturday;
  tMyArray2 = ARRAY[tMyRange] OF BYTE;

  tMyModes = (MASTER = 0b010, SLAVE1 = 0b101, SLAVE2); // MASTER value is 2, SLAVE1 value is 5, SLAVE2 value is 6
  tMyArray3 = ARRAY[tMyModes] OF BYTE; // the array bounds are 2..6


On Enumeration types:


In non-strict type checking mode, an enumeration is managed as a BYTE or a BOOLEAN (see below).


To take advantage of bit variables, PMP manages an enumeration that has one or two values (without an assigned numeric position, see below) as a BOOLEAN; it may be seen as a way to make an alias to FALSE and TRUE that are more readable (see the LCD unit). A variable defined as such an enumeration occupies always one bit and assigning a BOOLEAN is not a type mismatch.

In all other cases an enumeration occupies a BYTE.


TYPE
  tMyEnum = (Disabled, Enabled);
VAR
  MyEnum: tMyEnum;
...
  MyEnum := Enabled; // Same as assigning TRUE.

 

NEW! (V2.1) :


By default, the position (value = ord(item)) of the enumerated identifiers starts from 0 for the first and is incremented for each subsequent identifier.

One or several identifier position (value) may be assigned individually as a constant expression giving an unsigned BYTE. If an item has no assigned position (value), its position (value) is the position of the previous item plus one or 0 if it is the first one.

The LOW() built-in function returns the smallest value in the list; if none was assigned, it returns 0.

The HIGH() built-in function returns the highest value in the list; if none was assigned, it returns the number of items minus one.

The LENGTH() built-in function returns the difference between the smallest and the highest value in the list, plus one; if none was assigned, it returns the number of items.

If an enumeration type is used as an ARRAY bounds declaration, the array bounds will be LOW(<enumeration-type>..HIGH(<enumeration-type>).

If PRED() or SUCC() is used on an item of an enumeration type that has non-consecutive values, the result may be a value that is not in the listed items but in the LOW-HIGH range.



On Pascal SET:


NEW! (V2.1) :


The standard Pascal SET and its operators ( + - * IN) had been implemented, but with some limitations and PMP-specific behaviors:



TYPE
  tMyEnum = (Sunday, Monday, Tuesday, Thursday, Wednesday, Friday, Saturday);
  tMySet = SET OF tMyEnum;
  tMyRange = Monday..Saturday;
  tMySet2 = SET OF tMyRange;