[Oberon] Dynamic local array implementation

Luca Boasso luke.boasso at gmail.com
Fri Oct 13 01:35:52 CEST 2017


> The Astrobe compiler does use a frame pointer. Given the local variable
> 'a' declared as:
>
> VAR
>   a: ARRAY OF INTEGER;
>
> The code generated by NEW(a, 10) is as follows:
>
>     MOV      r10,10
>     STR      r10,[fp,-8]
>     MOV      r10,r10 lsl 2
>     SUB      sp,sp,r10
>     STR      sp,[fp,-4]
>
>

I see, that is similar to what I was expecting.
If my understanding is correct,  [fp, -8] and [fp, -4] represent an array
descriptor, where you store the length and address on the stack
respectively. SP is decremented by length*element size to make space for
the array.Very neat!
Is [fp,-4] the beginning or the end of the array "a"?

I have checked "An Oberon Compiler for the ARM Processor" p. 26 and it
seems like in that compiler dynamic arrays are allocated on the heap:

PROCEDURE P;
  VAR k: INTEGER;
    a: ARRAY OF INTEGER;
BEGIN NEW(a, 10); a[k] := 100
END P;

The code generated by NEW(a, 10) is as follows:

  SUB R11 FP 8    adr a
  MOV R10 R0 10   len
  MOV R9 R0 4     element size
  BL  0                  NEW (updated by loader)


Do you know if that system had a garbage collector?   I am surprised by
that implementation, I thought it was doing something like your Astrobe
compiler.

Regards,
Luca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20171012/efdb9b30/attachment.html>


More information about the Oberon mailing list