[Oberon] SYSTEM Modules

Chris Burrows chris at cfbsoftware.com
Sat Nov 10 11:45:31 CET 2018


I've been working on a lot of low-level STM32 microcontroller modules
recently and have been finding the numerous references to SYSTEM are
interfering with the readability. In an extreme case I have a module
consisting of 45 statements which has 42 occurrences of the word SYSTEM! The
next worst has 36 occurrences of SYSTEM in 47 statements. Consequently I'm
investigating if there is a better way of doing this.

 

1.       The programming language Oberon SA was the immediate predecessor of
Oberon-07. It was specifically designed to be suitable for targeting
realtime applications and was used to write the flight control software for
model helicopters. Consequently there would have been extensive use of
SYSYTEM functions. It eliminated the pseudo-module SYSTEM altogether and
allowed procedures like PUT, GET and BIT to be called without a qualifier in
the same way as ODD, INC etc.

 

2.       I've seen others skirt around the problem by using S as an alias
for SYSTEM. That seems like a half-baked solution / workaround to me.

 

3.       Modula-2 had a number of different ways of relaxing explicit
qualification of imported items.  I much prefer Oberon's simpler,
consistent, mechanism for all cases - except SYSTEM.

 

I'd still like to retain the use of the SYSTEM pseudo-module SYSTEM
qualifiers so that they stand out in a module where they only appear rarely
and I do not want to modify the way other IMPORTs work.

 

Consequently I'm thinking of implementing an extension to the Astrobe
Oberon-07 compilers. This will allow low-level modules to be specified by
prefixing the keyword MODULE with the keyword SYSTEM (similarly to the
DEFINITION and IMPLEMENTATION module prefixes in Modula-2). Such system
modules would allow / require any SYSTEM objects to be referenced
unqualified. 

 

E.g. for the STM32 RTC functions:

 

SYSTEM MODULE Clock;

 

IMPORT MCU;

 

CONST

  RTCBase = MCU.RTCBase;

  TR  = RTCBase + 00H;

  ISR = RTCBase + 0CH;

 

  (* ISR bits *)

  RSF   = 5;

 

PROCEDURE* Seconds*(): INTEGER;

VAR

  time: INTEGER;

BEGIN

  REPEAT UNTIL BIT(ISR, RSF);

  GET(TR, time);

  RETURN 10 * UBF(time, 6, 4) + UBF(time, 3, 0) 

END Seconds;

 

Instead of:

 

PROCEDURE* Seconds*(): INTEGER;

VAR

  time: INTEGER;

BEGIN

  REPEAT UNTIL SYSTEM.BIT(ISR, RSF);

  SYSTEM.GET(TR, time);

  RETURN 10 * SYSTEM.UBF(time, 6, 4) + SYSTEM.UBF(time, 3, 0) 

END Seconds;

 

Note: bitfield := UBF(word, msb, lsb) is an Astrobe SYSTEM function
extension which replaces the UBFX, unsigned bitfield extract, function
discussed here recently.

 

Any comments?

 

Any other suggestions for solving this problem?

 

 

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


More information about the Oberon mailing list