conf.doc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. .nf
  31. \fBprocedure\fR bubblesort(\fBvar\fR A : \fBarray\fR[low..high : integer] \fBof\fR integer);
  32. \fBvar\fR i, j : integer;
  33. \fBbegin
  34. for\fR j := high - 1 \fBdownto\fR low \fBdo
  35. for\fR i := low \fBto\fR j \fBdo
  36. if\fR A[i+1] < A[i] \fBthen\fI interchange A[i] and A[i+1]
  37. \fBend\fR;
  38. .fi
  39. .in -5m
  40. For every actual parameter, the base address of the array is pushed on the
  41. stack and for every index-type-specification, exactly one array descriptor
  42. is pushed.
  43. .sp
  44. .NH 2
  45. Value conformant array parameters
  46. .LP
  47. .sp
  48. The treatment of value conformant array parameters is more complex than its
  49. variable counterpart.
  50. .br
  51. An example is:
  52. .br
  53. .in +5m
  54. an unpacked array of characters could be printed as a string with the following program part:
  55. .nf
  56. \fBprocedure\fR WriteAsString( A : \fBarray\fR[low..high : integer] \fBof\fR char);
  57. \fBvar\fR i : integer;
  58. \fBbegin
  59. for\fR i := low \fBto\fR high \fBdo\fR write(A[i]);
  60. \fBend\fR;
  61. .fi
  62. .in -5m
  63. The calling procedure pushes the base address of the actual parameter and
  64. the array descriptors belonging to it on the stack. Subsequently the procedure
  65. using the conformant array parameter is called. Because it is a \fIcall by
  66. value\fR, the called procedure has to create a copy of the actual parameter.
  67. This implies that the calling procedure knows how much space on the stack
  68. must be reserved for the parameters. If the actual-parameter is a conformant
  69. array, the called procedure keeps track of the size of the activation record.
  70. Hence the restrictions on the use of value conformant array parameters, as
  71. specified in \fBISO 6.6.3.7.2\fR, are dropped.
  72. A description of the EM code generated by the compiler is:
  73. .nf
  74. .ft I
  75. load the stack adjustment sofar
  76. load base address of array parameter
  77. compute the size in bytes of the array
  78. add this size to the stack adjustment
  79. copy the array
  80. remember the new address of the array
  81. .ft R
  82. .fi