89 lines
2.8 KiB
Plaintext
89 lines
2.8 KiB
Plaintext
.sp 1.5i
|
|
.nr H1 3
|
|
.NH
|
|
Conformant Arrays
|
|
.nh
|
|
.LP
|
|
.sp
|
|
A fifth kind of parameter, besides the value, variable, procedure, and function
|
|
parameter, is the conformant array parameter (\fBISO 6.6.3.7\fR). This
|
|
parameter, undoubtedly the major addition to Pascal from the compiler writer's
|
|
point of view, has been implemented. With this kind of parameter, the required
|
|
bounds of the index-type of an actual parameter are not fixed, but are
|
|
restricted to a specified range of values. Two types of conformant array
|
|
parameters can be distinguished: variable conformant array parameters and
|
|
value conformant array parameters.
|
|
.sp
|
|
.NH 2
|
|
Variable conformant array parameters
|
|
.LP
|
|
.sp
|
|
The treatment of variable conformant array parameters is comparable with the
|
|
normal variable parameter.
|
|
Both have in common that the parameter mechanism used is \fIcall by
|
|
reference\fR.
|
|
.br
|
|
An example is:
|
|
.br
|
|
.in +5m
|
|
to sort variable length arrays of integers, the following Pascal procedure could be used:
|
|
|
|
.nf
|
|
\fBprocedure\fR bubblesort(\fBvar\fR A : \fBarray\fR[low..high : integer] \fBof\fR integer);
|
|
\fBvar\fR i, j : integer;
|
|
\fBbegin
|
|
for\fR j := high - 1 \fBdownto\fR low \fBdo
|
|
for\fR i := low \fBto\fR j \fBdo
|
|
if\fR A[i+1] < A[i] \fBthen\fI interchange A[i] and A[i+1]
|
|
\fBend\fR;
|
|
.fi
|
|
.in -5m
|
|
|
|
For every actual parameter, the base address of the array is pushed on the
|
|
stack and for every index-type-specification, exactly one array descriptor
|
|
is pushed.
|
|
.sp
|
|
.NH 2
|
|
Value conformant array parameters
|
|
.LP
|
|
.sp
|
|
The treatment of value conformant array parameters is more complex than its
|
|
variable counterpart.
|
|
.br
|
|
An example is:
|
|
.br
|
|
.in +5m
|
|
an unpacked array of characters could be printed as a string with the following program part:
|
|
|
|
.nf
|
|
\fBprocedure\fR WriteAsString( A : \fBarray\fR[low..high : integer] \fBof\fR char);
|
|
\fBvar\fR i : integer;
|
|
\fBbegin
|
|
for\fR i := low \fBto\fR high \fBdo\fR write(A[i]);
|
|
\fBend\fR;
|
|
.fi
|
|
.in -5m
|
|
|
|
The calling procedure pushes the base address of the actual parameter and
|
|
the array descriptors belonging to it on the stack. Subsequently the procedure
|
|
using the conformant array parameter is called. Because it is a \fIcall by
|
|
value\fR, the called procedure has to create a copy of the actual parameter.
|
|
This implies that the calling procedure knows how much space on the stack
|
|
must be reserved for the parameters. If the actual-parameter is a conformant
|
|
array, the called procedure keeps track of the size of the activation record.
|
|
Hence the restrictions on the use of value conformant array parameters, as
|
|
specified in \fBISO 6.6.3.7.2\fR, are dropped.
|
|
|
|
A description of the EM code generated by the compiler is:
|
|
|
|
.nf
|
|
.ft I
|
|
load the stack adjustment sofar
|
|
load base address of array parameter
|
|
compute the size in bytes of the array
|
|
add this size to the stack adjustment
|
|
copy the array
|
|
remember the new address of the array
|
|
.ft R
|
|
.fi
|