Pristine Ack-5.5
[Ack-5.5.git] / doc / pascal / conf.doc
1 .sp 1.5i
2 .nr H1 3
3 .NH
4 Conformant Arrays
5 .nh
6 .LP
7 .sp
8 A fifth kind of parameter, besides the value, variable, procedure, and function
9 parameter, is the conformant array parameter (\fBISO 6.6.3.7\fR). This
10 parameter, undoubtedly the major addition to Pascal from the compiler writer's
11 point of view, has been implemented. With this kind of parameter, the required
12 bounds of the index-type of an actual parameter are not fixed, but are
13 restricted to a specified range of values. Two types of conformant array
14 parameters can be distinguished: variable conformant array parameters and
15 value conformant array parameters.
16 .sp
17 .NH 2
18 Variable conformant array parameters
19 .LP
20 .sp
21 The treatment of variable conformant array parameters is comparable with the
22 normal variable parameter.
23 Both have in common that the parameter mechanism used is \fIcall by
24 reference\fR.
25 .br
26 An example is:
27 .br
28 .in +5m
29 to sort variable length arrays of integers, the following Pascal procedure could be used:
30
31 .nf
32 \fBprocedure\fR bubblesort(\fBvar\fR A : \fBarray\fR[low..high : integer] \fBof\fR integer);
33 \fBvar\fR i, j : integer;
34 \fBbegin
35         for\fR j := high - 1 \fBdownto\fR low \fBdo
36                 for\fR i := low \fBto\fR j \fBdo
37                         if\fR A[i+1] < A[i] \fBthen\fI interchange A[i] and A[i+1]
38 \fBend\fR;
39 .fi
40 .in -5m
41
42 For every actual parameter, the base address of the array is pushed on the
43 stack and for every index-type-specification, exactly one array descriptor
44 is pushed.
45 .sp
46 .NH 2
47 Value conformant array parameters
48 .LP
49 .sp
50 The treatment of value conformant array parameters is more complex than its
51 variable counterpart.
52 .br
53 An example is:
54 .br
55 .in +5m
56 an unpacked array of characters could be printed as a string with the following program part:
57
58 .nf
59 \fBprocedure\fR WriteAsString( A : \fBarray\fR[low..high : integer] \fBof\fR char);
60 \fBvar\fR i : integer;
61 \fBbegin
62         for\fR i := low \fBto\fR high \fBdo\fR write(A[i]);
63 \fBend\fR;
64 .fi
65 .in -5m
66
67 The calling procedure pushes the base address of the actual parameter and
68 the array descriptors belonging to it on the stack. Subsequently the procedure
69 using the conformant array parameter is called. Because it is a \fIcall by
70 value\fR, the called procedure has to create a copy of the actual parameter.
71 This implies that the calling procedure knows how much space on the stack
72 must be reserved for the parameters. If the actual-parameter is a conformant
73 array, the called procedure keeps track of the size of the activation record.
74 Hence the restrictions on the use of value conformant array parameters, as
75 specified in \fBISO 6.6.3.7.2\fR, are dropped.
76
77 A description of the EM code generated by the compiler is:
78
79 .nf
80 .ft I
81 load the stack adjustment sofar
82 load base address of array parameter
83 compute the size in bytes of the array
84 add this size to the stack adjustment
85 copy the array
86 remember the new address of the array
87 .ft R
88 .fi