[Oberon] PO 2013 allows one to "override" predefined procedures and functions

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Fri May 14 16:19:46 CEST 2021


Wojtek,

The run time behaviour of this “feature” is to simply override the predefined identifier, which then is
no longer available in the current scope. So no crash. One can even override things like INTEGER, etc.

Actually, the compiler itself does some overriding in this way, namely with the three procedures
ORG.ADC, ORG.SBC, ORB.UML. Inside these three procedures the corresponding predefined
identifier (ADC, SBC or UML) is of course not available.

To disallow this kind of “overrriding” in the compiler, one could for example:

1. Rename ORG.ADC, ORG.SBC, ORB.UML to ORG.Adc, ORG.Sbc, ORB.Uml

2. Adapt ORP.StandFunc accordingly to use the new procedure names

3. Adapt ORB.NewObj such that it now also checks the predefined identifiers as follows:

    x := universe;
    WHILE (x # NIL) & (x.name # id) DO x := x.next END ;
    IF x = NIL THEN (*...ok...*) ELSE ORS.Mark("predefined identifier”) END

to arrive at something along the lines of:

  PROCEDURE NewObj*(VAR obj: Object; id: ORS.Ident; class: INTEGER);  (*insert new Object with name id*)
    VAR new, x: Object;
  BEGIN x := universe.next;
    WHILE (x # NIL) & (x.name # id) DO x := x.next END ;
    IF x = NIL THEN x := topScope;
      WHILE (x.next # NIL) & (x.next.name # id) DO x := x.next END ;
      IF x.next = NIL THEN
        NEW(new); new.name := id; new.class := class; new.next := NIL; new.rdo := FALSE; new.dsc := NIL;
        x.next := new; obj := new
      ELSE obj := x.next; ORS.Mark("mult def")
      END
    ELSE ORS.Mark("predefined identifier")
    END
  END NewObj;

PS: When doing this, the impact on the compiler’s performance is about 5-10%.

-ap


> Andreas:
> 
> what a great feature. It could be really useful in the hands of a creative programmer. I am wondering, what would be the run time behavior of this feature. A crash? 
> 
> How did you find this feature? Would be good to get rid of it.
> 
> Wojtek
________________________________________
From: Oberon [
oberon-bounces at lists.inf.ethz.ch] on behalf of Andreas Pirklbauer [andreas_pirklbauer at yahoo.com
]
Sent: Friday, May 14, 2021 9:29 AM
To: Oberon List
Subject: [EXT] [Oberon] PO 2013 allows one to "override" predefined procedures and functions

Has anyone noticed that the PO 2013 allows the programmer
to “overrride” predefined procedures and functions, e.g.,

  MODULE M;
    VAR
       INC: CHAR;
       i: INTEGER;
  BEGIN
    INC := "a”;
    INC(i)           (*not a procedure*)
  END M.

This should not be allowed..


More information about the Oberon mailing list