Page 1 of 1

ASSERT & Error.Mod (version 8.0)

Posted: Mon Oct 25, 2021 8:31 am
by gray
Astrobe for RISC v8.0 provides a new module Error.Mod. It is used, for example, in Math.Mod:

Code: Select all

PROCEDURE Sqrt*(x: REAL): REAL;
  (* ... *)
BEGIN
  ASSERT(x >= 0.0, Error.input);
  (* ... *)
END Sqrt;
That is, to provide an error code for ASSERT via a second parameter (which could be any integer value, does not have to be from Error.Mod).

However, I don't understand how that error code can be used at run-time. The code generated with or without the error code is the same (apart from different positions in the trap instruction):

Code: Select all

PROCEDURE Sqrt*(x: REAL): REAL;
  (* ... *)
  ASSERT(x >= 0.0, Error.input);
.   3   80E00004H  LDW   r0,  sp, 4
.   4   D507EF7CH  BL,LT r12 trap #7, pos: 2031
  (* ... *)

Code: Select all

PROCEDURE Sqrt*(x: REAL): REAL;
  (* ... *)
  ASSERT(x >= 0.0);
.   3   80E00004H  LDW   r0,  sp, 4
.   4   D507E27CH  BL,LT r12 trap #7, pos: 2018
  (* ... *)
System.Trap, where the error code could be used, is unchanged in v8.0.

What do I miss here? How can I use the error code given in the ASSERT statement?

Re: ASSERT & Error.Mod (version 8.0)

Posted: Mon Oct 25, 2021 9:06 am
by cfbsoftware
You are not missing anything - it is one of those unfortunate 'backward compatibility' issues. I'll make a note to document it in the Astrobe for RISC5 Oberon Programming Guide.

The 2008 Oberon Language Report that Wirth's Oberon SA (StrongArm) compiler conformed to, defined an optional second parameter to the ASSERT statement that could be used as an error code. The Astrobe compilers (including the latest Astrobe for Cortex-M compilers) all originated from that code.

At sometime between 2008 and 2016 this option was removed from the report and hence was not implemented in the Project Oberon RISC5 compiler. This is the compiler that Astrobe for RISC5 originates from. To avoid users having to make numerous source code changes when porting code from Astrobe for Cortex-M, our Astrobe for RISC5 compiler still allows the second parameter but it has no effect at runtime.