[Oberon] Bug in Oberon compiler? (no type descriptors created for anonymous record types)

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Sat Sep 23 14:33:24 CEST 2017

Sorry, I meant to say..
(1) does compile under the Original Oberon compiler, but when a variable is declared as POINTER TO RECORD ... END without a preceding type definition, it leads to the runtime problem described in my original post (no type descriptor created)
    On Saturday, September 23, 2017, 2:27:04 PM GMT+2, Andreas Pirklbauer <andreas_pirklbauer at yahoo.com> wrote:  
 The code segment
 List = POINTER TO RECORD item: T; next: List END
(1) does NOT compile under the Original Oberon compiler for RISC (as currently published on the web)(2) does compile under my original suggestion (which creates a type descriptor for the anonymous record type)(3) does NOT compile under the alternative suggestion (which simply disallows pointers to anonymous records)
In my version of the Oberon compiler I have (2) implemented. I was just wondering whether one should in fact restrict the language further to obtain (3).
PS: I don’t think “declaration bloat” is a big issue. After all the *entire* Oberon system is written with pointers to *named* record types, and it really is not all that more verbose, while increasing readability. But it can be debated. Personally I’d be fine with leaving (2), so that your code actually compiles.
$ grep POINTER Oberon/Sources/*.Mod
Oberon/Sources/Checkers.Mod:  TYPE Frame = POINTER TO FrameDesc;
Oberon/Sources/Curves.Mod:    Curve* = POINTER TO CurveDesc;
Oberon/Sources/EBNF.Mod:    Item = POINTER TO ItemDesc;
Oberon/Sources/EBNF.Mod:    Symbol = POINTER TO SymbolDesc;
Oberon/Sources/FileDir.Mod:    FileHd* = POINTER TO FileHeader;
Oberon/Sources/Files.Mod:      File*    = POINTER TO FileDesc;
Oberon/Sources/Files.Mod:      Buffer  = POINTER TO BufferRecord;
Oberon/Sources/Files.Mod:      Index   = POINTER TO IndexRecord;
Oberon/Sources/Fonts.Mod:  TYPE Font* = POINTER TO FontDesc;
Oberon/Sources/Fonts.Mod:    LargeFont = POINTER TO LargeFontDesc;
Oberon/Sources/GraphicFrames.Mod:    Frame* = POINTER TO FrameDesc;
Oberon/Sources/GraphicFrames.Mod:    Location* = POINTER TO LocDesc;
Oberon/Sources/Graphics.Mod:    Graph* = POINTER TO GraphDesc;
Oberon/Sources/Graphics.Mod:    Object* = POINTER TO ObjectDesc;
Oberon/Sources/Graphics.Mod:    Method* = POINTER TO MethodDesc;
Oberon/Sources/Graphics.Mod:    Line* = POINTER TO LineDesc;
Oberon/Sources/Graphics.Mod:    Caption* = POINTER TO CaptionDesc;
Oberon/Sources/Graphics.Mod:    Macro* = POINTER TO MacroDesc;
Oberon/Sources/Graphics.Mod:    MacHead* = POINTER TO MacHeadDesc;
Oberon/Sources/Graphics.Mod:    MacExt* = POINTER TO MacExtDesc;
Oberon/Sources/Graphics.Mod:    Library* = POINTER TO LibraryDesc;
Oberon/Sources/MenuViewers.Mod:  TYPE Viewer* = POINTER TO ViewerDesc;
Oberon/Sources/Modules.Mod:  TYPE Module* = POINTER TO ModDesc;
Oberon/Sources/ORB.Mod:  TYPE Object* = POINTER TO ObjDesc;
Oberon/Sources/ORB.Mod:    Module* = POINTER TO ModDesc;
Oberon/Sources/ORB.Mod:    Type* = POINTER TO TypeDesc;
Oberon/Sources/ORP.Mod:  TYPE PtrBase = POINTER TO PtrBaseDesc;
Oberon/Sources/ORS.Mod:  EnterKW(pointer, "POINTER");
Oberon/Sources/Oberon.Mod:    Task* = POINTER TO TaskDesc;
Oberon/Sources/Rectangles.Mod:    Rectangle* = POINTER TO RectDesc;
Oberon/Sources/Stars.Mod:  TYPE Frame = POINTER TO FrameDesc;
Oberon/Sources/TextFrames.Mod:  TYPE Line = POINTER TO LineDesc;
Oberon/Sources/TextFrames.Mod:    Frame* = POINTER TO FrameDesc;
Oberon/Sources/Texts.Mod:  TYPE Piece = POINTER TO PieceDesc;
Oberon/Sources/Texts.Mod:    Text* = POINTER TO TextDesc;
Oberon/Sources/Texts.Mod:    Buffer* = POINTER TO BufDesc;
Oberon/Sources/Viewers.Mod:    Viewer* = POINTER TO ViewerDesc;
Oberon/Sources/Viewers.Mod:    Track = POINTER TO TrackDesc;

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------August Karlstrom fusionfile at gmail.com  Sat Sep 23 13:22:41 CEST 2017

In most cases we don't need a name for the record type, for instance in
 List = POINTER TO RECORD item: T; next: List END
Forcing the above to be split into two declarations only leads to declaration bloat.
-- August

On 23 Sep 2017, at 10:01, Andreas Pirklbauer <andreas_pirklbauer at yahoo.com> wrote:

No, they don’t need to be exported. Here is an even more minimal program showing the effect:
       PROCEDURE P*;       BEGIN NEW(x); x.i := 0       END P;
     END M.
The compiler compiles this program with no error message. But at runtime, multiple executions of the command M.P will lead to a trap.
I just noticed that nowhere in the Original Oberon system are pointer variables declared as shown above. They all point to *named* record types.
This makes me inclined to actually disallow the above program to be compiled. To achieve that, one would only have to change the language rule from “Pointers must point to records” to “Pointers must point to named records” in the language definition (see the last sentence in https://www.inf.ethz.ch/personal/wirth/Oberon/Oberon07.pdf ) and adjust the proposed change to procedure ORP.Type0 accordingly:
  IF (type.base.form # ORB.Record) OR (type.base.typobj = NIL) THEN ORS.Mark("must point to named record”) END ;
Chris Burrows chris at cfbsoftware.com  Sat Sep 23 06:24:28 CEST 2017

I’m having difficulty understanding the possible intended use of your example. Did you really mean for x and y to be marked for export? If so, can you provide an example client module which would demonstrate how they could be usefully referenced?
Chris BurrowsCFB Software


On 22 Sep 2017, at 16:47, Andreas Pirklbauer <andreas_pirklbauer at yahoo.com> wrote:

It seems that the Oberon 2013 compiler on RISC creates type descriptors only for *named* record types, but not for *anonymous* record types. This creates a problem if a dynamic variable pointing to an anonymous record type is allocated in the heap via the predefined procedure NEW.
For example, in the following test program:
       VAR x*: POINTER TO R;         y*: POINTER TO RECORD x, y, z: INTEGER END;
       PROCEDURE P*;       BEGIN NEW(x)       END P;
       PROCEDURE Q*;       BEGIN NEW(y)       END Q;
     END M.
the pointer variable 'x' points to a dynamic record of *named* record type 'R' for which a type descriptor is created by the compiler when the declaration for 'R' is processed. However, the pointer variable 'y' points to an *anonymous* record type for which *no* type descriptor is created by the compiler. So the command M.Q will crash the system as soon as the garbage collector uses the type tag of ‘y' to access the (non existing) type descriptor of the anonymous record pointed to by ‘y’.
The proposed solution is to also creates a type descriptor for a variable declaration of a pointer variable pointing to an *anonymous* record type. This is achieved by adding a single line to procedure ORP.Type0:
     PROCEDURE Type0(Var type: ORB.Type);       ...     BEGIN       ...       IF sym = ORS.ident THEN ...       ELSIF sym = ORS.array THEN ....       ELSIF sym = ORS.record THEN ...       ELSIF sym = ORS.pointer THEN ....         ...         IF sym = ORS.ident THEN ...         ELSE Type(type.base);           IF type.base.form # ORB.Record THEN ORS.Mark("must point to record”)-->      ELSIF (type.base.typobj = NIL) & (level = 0) THEN ORG.BuildTD(type.base, dc)    (*type descriptor; len used as its address*)           END ;           CheckRecLevel(level)         END       ELSIF sym = ORS.procedure THEN ...       ELSE ...       END     END Type0;
I’d be interested if anyone else has bumped into this issue before and whether there are any comments on the proposed solution. In particular, are there any other cases that should be considered and that people have reported before? Also, I have not tested the proposed solution with record extensions.
Best regards,AP

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

More information about the Oberon mailing list