[Oberon] Clarifying type compatibility in Oberon-07

Jörg joerg.straube at iaeth.ch
Wed Oct 4 18:11:03 CEST 2017


In my point of view Appendix A for Oberon-07 would look like this.

Joerg

 

 

Appendix A: Definition of terms

 

Integer types  BYTE, INTEGER, LONGINT (not official but compiler allows as
if LONGINT = INTEGER) 

Real types     REAL, LONGREAL

Numeric types  integer types, real types

 

Same types

Two variables a and b with types Ta and Tb are of the same type if

1.  Ta and Tb are both denoted by the same type identifier, or

2.  Ta is declared to equal Tb in a type declaration of the form Ta = Tb, or

3.  a and b appear in the same identifier list in a variable, record field,
or formal parameter declaration and are not open arrays.

 

Equal types

Two types Ta and Tb are equal if

1.  Ta and Tb are the same type,  or

2.  Ta and Tb are open array types with equal element types, or

3.  Ta and Tb are procedure types whose formal parameter lists match.

 

Type inclusion

Integer types include (the values of) smaller numeric types according to the
following hierarchy:

LONGREAL >= REAL >= LONGINT = INTEGER >= BYTE

 

Type extension (base type)

Given a type declaration Tb = RECORD (Ta) ... END, Tb is a direct extension
of Ta, and Ta is a direct base type of Tb. A type Tb is an extension of a
type Ta (Ta is a base type of Tb) if

1.  Ta and Tb are the same types, or

2.  Tb is a direct extension of an extension of Ta

If Pa = POINTER TO Ta and Pb = POINTER TO Tb, Pb is an extension of Pa (Pa
is a base type of Pb) if Tb is an extension of Ta.

 

Assignment compatible

An expression e of type Te is assignment compatible with a variable v of
type Tv if one of the following conditions hold:

1.  Te and Tv are the same type;

2.  Te and Tv are integer types and Tv includes Te;

3.  Te and Tv are record types and Te is an extension of Tv and the dynamic
type of v is Tv ;

4.  Te and Tv are pointer types and Te is an extension of Tv;

5.  Tv is a pointer or a procedure type and e is NIL;

6.  Tv is ARRAY n OF CHAR, e is a string constant with m characters, and m <
n;

7.  Tv is a procedure type and e is the name of a procedure whose formal
parameters match those of Tv.

 

Array compatible

An actual parameter a of type Ta is array compatible with a formal parameter
f of type Tf if

1.  Tf and Ta are the same type, or

2.  Tf is an open array, Ta is any array, and their element types are array
compatible, or

3.  Tf is ARRAY OF CHAR and a is a string.

4.  Tf is ARRAY n OF BYTE and Ta has length n.

 

Expression compatible

For a given operator, the types of its operands are expression compatible if
they conform to the following table (which shows  also  the  result  type
of  the  expression).  Character  arrays  that  are  to  be  compared  must
contain  0X  as a terminator. Type T1 must be an extension of type T0:

 

operator      1st op                     2nd op                     result
type

+ – *         numeric type               numeric type               numeric
type

/             real type                  real type                  real
type

+ – * /       SET                        SET                        SET

DIV MOD       integer type               integer type               integer
type

OR & ~        BOOLEAN                    BOOLEAN                    BOOLEAN

= # < <= > >= numeric                    numeric                    BOOLEAN

              CHAR                       CHAR                       BOOLEAN

              character array, string    character array, string    BOOLEAN

= #           BOOLEAN                    BOOLEAN                    BOOLEAN

              SET                        SET                        BOOLEAN

              NIL, pointer type T0 or T1 NIL, pointer type T0 or T1 BOOLEAN

              procedure type T, NIL      procedure type T, NIL      BOOLEAN

IN            integer type               SET                        BOOLEAN

IS            type T0                    type T1                    BOOLEAN

 

Matching formal parameter lists

Two formal parameter lists match if

1.  they have the same number of parameters, and

2.  they have either the same function result type or none, and

3.  parameters at corresponding positions have equal types, and

4.  parameters at corresponding positions are both either value or variable
parameters.

 

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


More information about the Oberon mailing list