[Oberon] NEW with anonymous records

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Tue Feb 20 12:13:58 CET 2018


  > I believe this problem was addressed in the 23.9.2017
  > update of Project Oberon with a language restriction
  > implemented in ORP.Mod. If you try to compile the
  > code above you will now get the error message:
  >
  > "Error: must point to named record”
  >

Correct. This is when it happened. It came out of a discussion
about type descriptors and a suggestion I had made back then.

Prior to 23.9.2017 it possible to declare pointers to
*anonymous* records eg: TYPE T = POINTER TO RECORD .. END.

The issue with this was that the compiler did not (and still
does not) create type descriptors for *anonymous* records.
This created a problem if a dynamic variable pointing to
an *anonymous* record type is allocated via the predefined
procedure NEW (which accesses the type descriptor to obtain
the size of the record about to be allocated in the heap).


Solution #1 is to also create type descriptors for *anonymous*
records, which could be accomplished by changing ORP.Type0 to:

    IF type.base.form # ORB.Record THEN ORS.Mark("must point to record”)
    ELSIF type.base.typobj = NIL THEN ORG.BuildTD(type.base, dc)    (*type descriptor; len used as its address*)
    END


Solution #2 is to restrict pointers to *named* records, which is
accomplished by replacing the above IF statement in ORP.Type0 to:

  IF (type.base.form # ORB.Record) OR (type.base.typobj = NIL) THEN
    ORS.Mark("must point to named record”)
  END


Solution #2 was retained. It leads to more readably code, even though
the necessity to declare a pointer type AND its record type my be
perceived as somewhat annoying. But one can certainly live with it.

Andreas

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


More information about the Oberon mailing list