collectiori. For example, in Jensen's model a dedicated register ; points at elements of arrays at each level of subscription. That*is, it points into the middle of the array. Now he knows by the nature of Algol 60 that the array will still be there when he accesses that element ; This may not be the case with an Algol such as Algol R where arrays are assignable values; For example.
The Interface between Jensen's compiler/and code 1 generator is reverse fpolish. His description of a variable in this interface codé amounts to nothing apart from its name. As we have ] seen, type inf ormation should be included also. We note that other entities such as procédures should be described and perhaps take part in the simulation.
Portability . ‘
Jensen describes a technique used for the implementation of Algol 60 Oh/a particular machine. It is desirable to make available a good
38
begin / r '
■ integer array ( 1 : : 1 0 ) fred ;
integer array ( 40 ; ; 60 ) jim ;
fred( 1 0 ) := begin fred ;= jim ; ... 6 end ;
In the above program fragment a value is assigned to.the 10th element - of the array currently in "fred" just before calculation of the
assignment value. However the array value in "fred" is changed by the'
side effect. The ellipsis code could cause a garbage collection in ^ which case the old array in "fred" might no longer be accessible. Now
Jensen keeps a pointer ( UAa ) directly to the array element being
accessed. After the assignment , to "fred" the original array is ^ "floating around" with nothing referring to it - thus it might be .i garbage collected. If so, no harm is done since thé assignment to the / tenth element will change a location in the free space of the heap.
But, if the space is reallocatéd it will have the nasty effect of
changing a value in a new data structure. Another consideration ] involving a heap is the identification of /yalues which are pointers ].v/1
and thé following of these during the marking phase of garbage
collection. Thus a heap involves considerably moté work in ensuring : its consistency at run time.
■ ■■ ■
-ii
Descriptions v/J
high level language on a variety of machines. Thus the new code generation technique must consider portability % with respect to the compiler ,and the code generator ; In the implementation of a language there are three levels of abstraction, the source, the underlying abstract machiné and the real machine. As far as portability is /cpncernedvWe must investigate the mapping between the source and the
abstract machine code and between the at)stfact and the real machine. Optimisation
"The process of object code optimisation can be* considered in two forms, eftén referred to as local and global optimisation. /.;/»The first technique jlnvplves the opt imisa t iqh of small subsections of the geiierated coding without being concerned with any overall features displayed in the program. The second form on the other hand, considers the whole source ;■ program in an attempt to improve the efficiency of the object
code generated." [Bril72]
The technique of pseudo-evaluation lends itself to both local and
■ / ' % .
global Optimisation. Richards [Rich71] says /-
"Good global organisation is often a better way of achieving efficient code than any amount of local optimisation."
He suggests that general, design.decisions such as register dedication, K
. '"'Il
procedure calling mechanisms, data representation, stack organisation,
variable allocation and addressing are>all very important. These all i can be done with pseudo-evaluation and to some extent help form the
. .. , ' '
simulated run time environment. The technique allows a reasonable level of local optimisation, mo r e than - pe epho 1 e optimisation would {
. -i ' . ■ ' ' , - '‘"/j
allow. Tbis may be/achieved by the fact that data is described in the- 1 simulation. Instead of emitting code for an opération we need only ; i
's
] . ^ ,v; : 40
%-'' '-^K'XK/ ' '" ' * . - . " ' "y ' : ' : . { change the description of the result. This reflects that code
production for some operations has been delayed and provides /. information on what must be done. This goes some way towards the K: situation in producing code., from a tree where all subnodes are
/K" '
i'--
' ' ' A K/ ' - ‘H
available at the same time as- a nqde. , Here, because/ of the postfix I1 " -'A'-/' ' . .
V notation We only meet the node after the. subnodes have beén processed. - ;l Better code may be generated in the light of a wider context thus by IJ
K . ' ! ' ' y ' - ' iy - y '' - ' /y ' - . .
/ building up enough information we are " in a stronger c position to J
kr . .A'. ' "y- ' ''yyy'^"%:'.''
' optimise. We suggest that this is better than peephole optimisation y.. on generated code because it is easier to save descriptions, no
ri further pass is necessary and the context may be wider :t^^^ a | y practicable peephole window;' The technique however does not lend : ib
itself to control\ or data flow analysis. Similar optimisation
4/ techniques are outwith the scope of this thesis. ir ,1
K ; ' ■ . ,, \ , y 4 , .
y . Our aim was to provide a inethod of code generation which lis readily . ^ i
i ' / y ' 4 . . ' . ' i '
y: _ understandableimplementable without much difficulty, able to provide/y //] f reasonably good code and able to have optimisation added: if necessaryé One
y of the problems with local optimisation is thé number of ad hoc rules
| 4 - ;y, , ; : / / / / _ i
1' introduced [RobeSl] which tend to obscure the underlying techtiique. We
feel that a straightforward pseudo-evaluation code generator should be ? '% '% writténf aitér";'séme time considering; global {organisation. Some measurement
// should be taken of the code produced and then local pptimisatiohs; layered /
i on top.^ I" ' ' ' J
I/
' X-.'
y Jensen's pseudo-evaluation technique certainly seemed to pptehtially
■S-. :
fit the , criteria above. Other code generation techniques were considered and rejected due mainly to their difficulty of understanding or implementation. The existence of a simple improvable technique; isuch as
Jensen's proved to be a highly attractive magnet. next chapter /Il
\ 4 ' \ \ X"; .. .. .... ' /U
describes the implementation of Algol R using psendp-revaluation,