[Oberon] Dynamic type of record var parameter
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Tue Jan 12 16:21:51 CET 2021
> My understanding is that you need to use a type guard to
> assert that p can be assumed to have a dynamic type of p2:
>
> i.e. p := q; check(p(p2)^);
>
This would indeed produce the correct output (“is p2” instead of “is p0”)
in the provided test program.
However, the correct dynamic type could also be passed by the compiler
instead of relying on the programmer to “know” what the dynamic type is.
To fix this in the compiler, one needs to change procedure ORG.VarParam
From:
PROCEDURE VarParam*(VAR x: Item; ftype: ORB.Type);
VAR xmd: INTEGER;
BEGIN ..
..
ELSIF ftype.form = ORB.Record THEN
IF xmd = ORB.Par THEN Put2(Ldr, RH, SP, x.a+4+frame); incR ELSE loadTypTagAdr(x.type) END
END
END VarParam;
To:
PROCEDURE VarParam*(VAR x: Item; ftype: ORB.Type);
VAR xmd: INTEGER;
BEGIN ..
..
ELSIF ftype.form = ORB.Record THEN
IF x.deref THEN Put2(Ldr, RH, 0, -8); incR (*pass the dynamic type rather than the static type*)
ELSIF xmd = ORB.Par THEN Put2(Ldr, RH, SP, x.a+4+frame); incR
ELSE loadTypTagAdr(x.type) END
END
END VarParam;
and make a few other small modifications to set x.deref whenever a pointer has been dereferenced.
The full solution can be found here:
http://github.com/andreaspirklbauer/Oberon-allow-dereferenced-pointer-as-var-parameter
Andreas
More information about the Oberon
mailing list