Dynamic type of record var parameter
> 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... Andreas
On Tue, 12 Jan 2021 16:21:51 +0100, Andreas Pirklbauer wrote:
The full solution can be found here:
http://github.com/andreaspirklbauer/Oberon-allow-dereferenced-pointer-as-var... Thank you for the quick and detailed analysis. And many thanks to all the others who responded and have given information. Greetings, chris
participants (2)
-
Andreas Pirklbauer -
chris