94 Chapter Four
TYPE instruction IS
RECORD
opcode : optype;
src : INTEGER;
dst : INTEGER;
END RECORD;
The first line declares the enumerated type optype, which is used as
one of the record field types. The second line starts the declaration of the
record. The record type declaration begins with the keyword RECORDand
ends with the clause END RECORD. All of the declarations between these
two keywords are field declarations for the record.
Each field of the record represents a unique storage area that can
be read from and assigned data of the appropriate type. This example
declares three fields:opcodeof typeoptype, andsrcanddstof type
INTEGER. Each field can be referenced by using the name of the record,
followed by a period and the field name. Following is an example of this
type of access:
PROCESS(X)
VARIABLE inst : instruction;
VARIABLE source, dest : INTEGER;
VARIABLE operator : optype;
BEGIN
source := inst.src; --Ok line 1
dest := inst.src; --Ok line 2
source := inst.opcode; --error line 3
operator := inst.opcode; --Ok line 4
inst.src := dest; --Ok line 5
inst.dst := dest; --Ok line 6
inst := (add, dest, 2); --Ok line 7
inst := (source); --error line 8
END PROCESS;
This example declares variable inst, which is of type instruction. Also,
variables matching the record field types are declared. Lines 1 and 2 show
fields of the record being assigned to local process variables. The assign-
ments are legal because the types match. Notice the period after the name
of the record to select the field.
Line 3 shows an illegal case. The type of field opcodedoes not match
the type of variable source. The compiler will flag this statement as a type
mismatch error. Line 4 shows the correct assignment occurring between
the field opcodeand a variable that matches its type.