[Oberon] FPGA - Two BYTE entities
Jörg
joerg.straube at iaeth.ch
Mon Sep 25 08:58:57 CEST 2017
Tomas
There are two changes in Oberon-07 you have to be aware of when porting code from a previous version of Oberon to Oberon-07.
1) Two byte entities (what you called SHORTs) do not exist in ProejctOberon.
In previous Oberons, you had INTEGER (2 bytes) and LONGINT (4 bytes)
ProjectOberon officially only offers INTEGER (4 bytes).
However, the compiler in ProjectOberon still accepts the type LONGINT (not defined in the Oberon-07 language report) but treats it internally as INTEGER.
2) In Oberon-07 the procedure Files.ReadBytes is declared as
PROCEDURE ReadBytes(r: Rider; VAR x: ARRAY OF BYTE; n: INTEGER);
In previous Oberons this procedure was declared as
PROCEDURE ReadBytes(r: Rider, VAR x: ARRAY OF SYSTEM.BYTE, n: INTEGER);
This subtle change has a huge impact on type compatibility; the special construct ARRAY OF SYSTEM.BYTE allowed to use a variable of any type. So you could write ReadBytes(r, word, 2); ReadBytes(r, real, 4); ReadBytes(r, set, 2); ReadBytes(r, record, 10);
ReadBytes effectively accepted ANY type you wanted. You can call that construct wonderful and great or you can call it nasty and evil.
This trick does not exist in Oberon-07 anymore!
So, if you want to port the statement
ReadBytes(r, i, 2)
to Oberon-07 you would have to write
TYPE A = ARRAY 4 OF BYTE;
i := 0;
ReadBytes(r, SYSTEM.VAL(A, i), 2)
You first have to declare a type of 4 bytes, then you have to initialize all 4 bytes of „i" to zero and only fill in the 2 lower ones with the bytes in the file.
As you now are forced to use SYSTEM, you immediately detect your code might not be portable anymore as it depends on endianess. This code only works, if the endianess of the two byte entity stored in the file and the endianess of the variable „i" in memory are the same.
In short, you still can use ReadBytes in Oberon-07. But the portable way to read two byte entities is read two bytes independently and calculate the value with i := b1 + b2*100H.
br
Joerg
> Am 23.09.2017 um 21:27 schrieb Tomas Kral <thomas.kral at email.cz>:
>
> Hi,
>
> On FPGA Oberon we have (long) WORDS and BYTES, reading SHORTS(two
> bytes), requires some coding.
>
> (* this works *)
> Files.ReadByte(R, bt0); Files.ReadByte(R, bt1); short := bt0 +
> bt1*100H
>
> (* this does not *)
> Files.ReadBytes(R, short, 2);
>
> I saw above in ETH Oberon code frequently.
>
>
> --
> Tomas Kral <thomas.kral at email.cz>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
More information about the Oberon
mailing list