[Oberon] Numerical CASE Statements in Project Oberon

Chris Burrows chris at cfbsoftware.com
Sat Nov 21 05:33:25 CET 2015


> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> John Stout
> Sent: Friday, 20 November 2015 12:40 AM
> To: oberon at lists.inf.ethz.ch
> Subject: Re: [Oberon] Numerical CASE Statements in Project Oberon
> 
> Jan
> 
> I wasn't suggesting that we NOT implement it, just that compiling it
> (implementing it) to a series of compiled IF THEN statements may be
> more in keeping with NW's view.
> 

I have not been able to find any NW reference that advocates implementing CASE by emulating IF THEN ELSE. Every such reference I am aware of advocates the use of jump tables. e.g.

Project Oberon (2005), 12.2 Code Patterns:

"Case statements serve to select a statement sequence from a set of cases according to an index value. Selection is represented by a direct branch to the selected case; the CASE instruction takes the branch distance from a table using the indexed addressing mode. We conclude from the following code that missing cases yield a table entry leading to a trap instruction (BPT 16). The table of offsets is located in the module's area for constants."

Compiler Construction (2005), 11.3:

"Consider the implementation of the case statement of Oberon (see Appendix A.2). Its essential property is that it uses a table of jump addresses for the various cases, and an indexed jump instruction."

An Oberon Compiler for the ARM Processor (2007), 15. The Case Statement

"The case statement serves to select a statement according to an integer, just as an element is selected from an array. This helps to avoid long cascades of if-elsif statements and increases efficiency. However, case statements are recommended only if the set of selectable statements is reasonably large. The compiler generates an internal array of the labels of the component statements. The specific jump address (label) is chosen by the index specified in the case clause."

Regards,
Chris Burrows

CFB Software
http://www.astrobe.com




More information about the Oberon mailing list