[Oberon] Interfacing with Foreign Systems (was: Negative integer literals in Oberon)

Guy T. turgu666 at gmail.com
Wed Apr 29 14:44:52 CEST 2020

The approach I’ve taken so far is very similar to the "Oberon-2 Programming with Windows”. Here is the modifications to the language I’ve done (from the syntax definition of Oberon-07):

Module           = OberonModule | CModule.
OberonModule     = MODULE ident ";" [ImportList] DeclarationSequence
                   [BEGIN StatementSequence] END ident "." .           (* No change here *)
CModule          = MODULE "[" CDECL "]" ident ";" [ImportList]
                   CDeclarationSequence END ident "." .
CDeclarationSequence = DeclarationSequence =
                           [CONST {ConstDeclaration ";"}]
                           [TYPE {TypeDeclaration ";"}]
                           [VAR {VariableDeclaration ";"}]
                           {CProcedureDeclaration ";"}.

ArrayType        = ARRAY     ["[" CDECL "]"] length {"," length} OF type.
PointerType      = POINTER   ["[" CDECL "]"] TO type.
ProcedureType    = PROCEDURE ["[" CDECL "]"] [FormalParameters].

ProcedureDeclaration = OberonProcedureDeclaration | CProcedureDeclaration.
OberonProcedureDeclaration = ProcedureHeading ";" ProcedureBody ident. (* No change here *)
CProcedureDeclaration = CProcedureHeading ";" .
CProcedureHeading = PROCEDURE ["[" CDECL "]"] identdef [FormalParameters].

RecordType       = OberonRecordType | CRecordType.
OberonRecordType = RECORD ["(" BaseType ")"] [FieldListSequence] END.  (* No change here *)
CRecordType      = RECORD    ["[" CDECL "]"]   [FieldListSequence] END.


The only change to the syntax is the use of a "[CDECL]” for elements that need to be internally managed as C elements. Internally, new forms are created for module, pointer, array procedure and record declared with "[CDECL]”. All basic Oberon types (CHAR, BYTE, BOOLEAN, SHORTINT (16 bits), INTEGER (32 bits), LONGINT (64 bits)) are the same as their equivalent in C. SET is mapped to C 32bits integer for bit-wise manipulations (0: LSB, 31: MSB). The ESP32 is using little-endian for memory addressing.

A CModule is the equivalent of a header file in C. No code is produced so no statements are allowed in a CModule. All elements in a CModule are C related, so the use of [CDECL] for array, record, pointer and procedure is induced. A CModule can import other CModules.

A CRecordType is the equivalent of a C struc. No RECORD extension is allowed.

C Pointers can be declared to point to any simple types and C array, C record, C pointer and C procedure. They cannot be initialized through NEW() but can be initialized through assignation.

C Array can be declared to point to any simple types and C array, C record, C pointer and C procedure.

C Procedures don’t generate name mangling as for GCC and accept only parameters that are compatible (so no Oberon array, record, pointers and procedures but their [CDECL] equivalent).


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

More information about the Oberon mailing list