Re (2): [Oberon] identity of two VARs
Bernhard Egger
bernhard at aces.snu.ac.kr
Fri Sep 16 04:03:42 CEST 2005
> I'm missing a subtlety. source[0] is where source begins
> and target[0] is where target begins.
> So how can (SYSTEM.ADR(source[0]) = SYSTEM.ADR(target[0]))
> differ from (SYSTEM.ADR(source) = SYSTEM.ADR(target))?
Oberon is garbage collected and type-safe, so arays are not just
contiguous blocks of memory, but also have type information which
contains the length, for example. This allows the runtime to do runtime
array bound checking.
The (global) source variable is internally a pointer to that array
structure on the heap and not necessarily identical to the beginning of
the data (source[0]). For arrays not containing other pointer elements,
a SysBlk is used to allocate an array on the heap. (see Pieter Muller's
dissertation, http://e-collection.ethbib.ethz.ch/ecol-pool/diss/fulltext/eth14755.pdf,
p. 169). Local variables use different structures.
Therefore, SYSTEM.ADR(source) and SYSTEM.ADR(source[0]) can differ
depending on how the array is allocated (stack/heap) and the compiler
interprets 'source' without array indexes.
>
> Perhaps an example?
>
as you can see from the example below:
SYSTEM.ADR(heap) # SYSTEM.ADR(heap[0]), but
SYSTEM.ADR(global) = SYSTEM.ADR(global[0]) and
SYSTEM.ADR(local) = SYSTEM.ADR(local[0]):
MODULE AddressTest;
IMPORT
AosOut, SYSTEM;
TYPE
H = POINTER TO ARRAY OF LONGINT;
VAR global : ARRAY 8 OF LONGINT;
PROCEDURE Test*(par : ANY) : ANY;
VAR local: ARRAY 8 OF LONGINT;
heap: H;
BEGIN
NEW(heap, 100);
AosOut.String("SYSTEM.ADR(heap)= "); AosOut.Int(SYSTEM.ADR(heap), 0); AosOut.Ln;
AosOut.String("SYSTEM.ADR(heap[0])= ");AosOut.Int(SYSTEM.ADR(heap[0]), 0); AosOut.Ln;
AosOut.String("SYSTEM.ADR(global)= "); AosOut.Int(SYSTEM.ADR(global), 0); AosOut.Ln;
AosOut.String("SYSTEM.ADR(global[0])= "); AosOut.Int(SYSTEM.ADR(global[0]), 0); AosOut.Ln;
AosOut.String("SYSTEM.ADR(local)= "); AosOut.Int(SYSTEM.ADR(local), 0); AosOut.Ln;
AosOut.String("SYSTEM.ADR(local[0])= "); AosOut.Int(SYSTEM.ADR(local[0]), 0); AosOut.Ln;
RETURN NIL
END Test;
END AddressTest.Test ~
S.Free AddressTest ~
SYSTEM.ADR(heap)= -2059403332
SYSTEM.ADR(heap[0])= 73838632
SYSTEM.ADR(global)= 73837480
SYSTEM.ADR(global[0])= 73837480
SYSTEM.ADR(local)= -2059403328
SYSTEM.ADR(local[0])= -2059403328
Bernhard
> Thanks, ... Peter
More information about the Oberon
mailing list