[Oberon] Negative integer literals in Oberon

Chris Burrows chris at cfbsoftware.com
Sat Apr 25 23:52:17 CEST 2020


It all depends on what size (i.e. number of bits) INTEGER is defined as on the system you are using as to what range of numbers are valid INTEGERs. Since 2011, the range of INTEGER values is no longer defined in the Language Report; it is implementation-dependent. 

 

In the Project Oberon (2013) RISC5 compiler, INTEGER is 32 bit so 90909090H is a valid INTEGER. Maybe you used the default (-O2) option in VOC? If so, INTEGER is 16 bit so 90909090H would be too large. Make sure you are compiling with the VOC –OC option instead if you want INTEGER to be treated as a 32 bit quantity.

 

Note that 9090H would be a negative number on a 16-bit INTEGER system but a positive number on a 32-bit INTEGER system.

 

Regards,

Chris Burrows

CFB Software

https://www.astrobe.com

 

From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of Arthur Yefimov
Sent: Sunday, 26 April 2020 12:38 AM
To: oberon at lists.inf.ethz.ch
Subject: [Oberon] Negative integer literals in Oberon

 

While developing the compiler[1], we got a question

whether it is possible to write the following:

PROCEDURE DWord(n: INTEGER);
...
DWord (90909090H)


(where INTEGER is 32-bit).

Some compilers give an error (i.e. VOC), while this works in the

Project Oberon (2013) compiler. This would turn out to be quite convenient,

because the purpose of DWord in our code was to write 4 bytes to the file

given as INTEGER (using little-endian byte order).

 

DWord has the following implementation (module Generator[2]):


PROCEDURE DWord (n: INTEGER);
BEGIN
  Files.Write (r, CHR (n MOD 100H));
  Files.Write (r, CHR (n DIV 100H MOD 100H));
  Files.Write (r, CHR (n DIV 10000H MOD 100H));
  Files.Write (r, CHR (n DIV 1000000H))
END DWord;

The Oberon language report does not indicate that literal 90909090H

should be considered an error if INTEGER has 32 bits.


In this experiment, an online RISC emulator[3] was used.

 

References:

[1] https://github.com/kekcleader/oberon

[2] https://github.com/kekcleader/oberon/blob/master/Mod/Generator.Mod

[3] http://schierlm.github.io/OberonEmulator/emu-wasm.html?image=FullDiskImage <http://schierlm.github.io/OberonEmulator/emu-wasm.html?image=FullDiskImage&width=1024&height=768> &width=1024&height=768

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20200426/e2c11cbb/attachment.html>


More information about the Oberon mailing list