[Oberon] SYSTEM.PTR vs SYSTEM.ADDRESS

Diego Sardina dsar at eml.cc
Tue Nov 1 18:11:52 CET 2022


On Mon, Oct 31, 2022, at 10:23 PM, thutt at harp-project.com wrote:
> Joerg writes:
>
>  > I can only guess what SYSTEM.PTR and SYSTEM.ADDRESS are; I assume
>  > these are TYPEs with special compatibility rules. As those are not
>  > defined in Oberon but by your compiler, please consult your
>  > compiler’s manual for details.
>
> SYSTEM.PTR is a generic pointer type.  It can be assigned any other
> pointer type, and is most often (in my experience) used to accept
> generic pointers as a procedure parameter.   There are uses of
> SYSTEM.PTR in Fonts.Mod (to gain access to font data loaded in a
> system block of memory), Display.Mod (to allocate system blocks of
> memory for display patterns), and in Types.Mod (to gain access to
> internal information about a pointer's type at runtime).
>
> I don't know have any information about implementation of
> SYSTEM.ADDRESS.
>

On Tue, Nov 1, 2022, at 2:59 PM, Артур Ефимов wrote:
> SYSTEM.PTR is a pointer type, managed by the garbage collector,
> and SYSTEM.ADDRESS is an INTEGER. It is not managed by the
> garbage collector.

SYSTEM.ADDRESS isn't defined in Oberon. It was used in Modula-2 for dealing with addresses, compatible with all pointers types and the CARDINAL type.

https://freepages.modula2.org/report4/modula-2.html#SEC39

However Wirth in Oberon just uses LONGINT as address type. Some Oberon implementations (not Oberon-2 ones) added back SYSTEM.ADDRESS from Modula-2, such as Ulm Oberon with the same rules of Modula-2.

In Oberon-2 SYSTEM.ADDRESS was reintroduced under the name SYSTEM.PTR with compatibility with all pointer types but integers. So except for the compatibility with integers, they are conceptually *the same*.

More interesting is how to achieve the same with Oberon using just LONGINT:

(* Oberon / Oberon-07 *)
PROCEDURE Foo (obj: LONGINT);
  VAR myobj: MyType;
BEGIN
  myobj := SYSTEM.VAL(MyType, obj);
  [...]
END Foo;

Foo(SYSTEM.ADR(myobj^));

(* Oberon-2 *)
PROCEDURE Foo (obj: SYSTEM.PTR);
  VAR myobj: MyType;
BEGIN
  myobj := SYSTEM.VAL(MyType, obj);
  [...]
END Foo;

Foo2(myobj);

In my opinion the presence of SYSTEM.ADDRESS / SYSTEM.PTR is more convenient. It's also more clear what is going to be passed.

--
Diego Sardina


More information about the Oberon mailing list