[Oberon] FPGA - Oberon7 - Type Cast

Tomas Kral thomas.kral at email.cz
Wed Oct 3 15:38:33 CEST 2018


On Wed, 3 Oct 2018 21:33:45 +0930
Chris Burrows <chris at cfbsoftware.com> wrote:

> SYSTEM.VAL(RecBuf, rec)

Hi Chris,

Thank you, I thought this cast is not to be allowed.

I resolved by retyping structures as pointers that map over a
uniform buffer that is sized enough.
O := Out, S := SYSTEM;
...
TYPE
  R1 = POINTER TO R1Desc;
  R2 = POINTER TO R2Desc;
  R1Desc = RECORD a, b, c, d: CHAR END;
  R2Desc = RECORD a: ARRAY 2 OF CHAR; b: ARRAY 2 OF CHAR END;
  Buf = ARRAY 16 OF BYTE;
...
VAR buf: Buf; r1 : R1; r2: R2;
...

Files.ReadBytes(R, buf, S.SIZE(R1Desc));
r1 := S.VAL(R1, S.ADR(buf));
O.Char(r1.a); O.Char(r1.b); O.Char(r1.c); O.Char(r1.d); O.Ln;
...
Files.ReadBytes(R, buf, S.SIZE(R2Desc));
r2 := S.VAL(R2, S.ADR(buf));
O.Char(r2.a[0]); O.Char(r2.a[1]); O.Char(r2.b[0]); O.Char(r2.b[1]);
O.Ln;

-- 
Tomas Kral <thomas.kral at email.cz>


More information about the Oberon mailing list