Dynamic local array implementation
From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Luca Boasso Sent: Friday, 13 October 2017 1:18 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Clarifying type compatibility in Oberon-07
Re: The implementation of local dynamic arrays:
Wouldn't you need a frame pointer to implement it? The current compiler does not need one, since the stack frame size is know at compile time, adding this feature would break this invariant. Am I missing something?
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] Regards, Chris Burrows CFB Software http://www.astrobe.com
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
participants (2)
-
Chris Burrows -
Luca Boasso