The ModulaTor logo 7KB

The ModulaTor

Oberon-2 and Modula-2 Technical Publication

The ModulaTor Erlangen's First Independent Modula-2 Journal! Nr.

The ISO/IEC JTC1/SC22 D106/N336 

Modula-2 Language Changes according to the Third Working Draft Standard 

by Guenter Dotzel, ModulaWare 

This article lists only those language changes that affect our VAX/VMS
Modula-2 Compiler MVR. For space  reasons, the list will be more detailed in a
future issue of The ModulaTor, especially concerning the library  modules. 

For more information: The 3rd Working Draft 10941 ISO/DP 10514 (Modula-2) has
about 550 pages and a  copy is available for DM 274.- + sales tax (MwSt.),
from the Beuth Verlag GmbH, Burggrafenstr. 6, D-1000  Berlin 30. In U.S.A.
please contact ISO/IEC JTC1/SC22 Secretariat, 140 O'Connor St., Ottawa, Ont., 
Canada K1A 0R5. 

I. Requirements 

1. FORWARD must be accepted and correctly processed. 

2. All required standard library modules must be provided without extensions. 

3. Module SYSTEM may be extended but not reduced. 

4. All mandatory language exceptions must be detected when compiled with the
[default] /check qualifier.  Most exceptions listed below are mandatory. Those
that aren't mandatory are marked by DNM (detection not  mandatory) in the work
items below. 

5. All language extensions must be detected. 

6. The documentation will address all issues required by a conforming

7.1. Set size will be min. 256. 

7.2. Minimal length of identifiers is 32. 

7.3. Min. number of exportable identifiers is 16. 

II. Lexis 

8*. Alternate symbols, e.g. ":)" for "}", "(:" for "}", "(!" for "[", "!)" for
"]", "@" for "^". 

9. Allow national alphanumeric characters in identifiers. 

10. REM operator. 

11. Real number literals allow only [optional] scale factor designator "E",
but not "D", "G", or "H". [?] 

12. Character and string literals allow national characters. 

III. Programs and Compilation Units 

13. Allow empty definition module but implementation module for initialisation

14. This is a question concerning the meaning of a program in terms of
input/output behaviour. 

15. This is a question whether module identifier components of a program
module shall be identical. 

16. Definition modules don't syntactically have a protection, only
implemenation and program modules.  Protection was previously known as

17. Control variables of the for-statement shall not be imported and shall be
simple variable in declaration. 

18. Opaque types in implementation modules may be declared either as pointer
type or opaque types, but  can't be scalar type. 

19. Procedure parameter's types shall match in definition and implementation
modules, but same names of  parameters aren't enforced. Also identifiers to
denote the types need not be the same. 

20. Defined initialization order of modules: first all modules imported in the
own definition module and then  the imported modules of the implementation
module and then the own body. 

21. Protected modules call initialization of separate modules before entering
the entry procedure of the  implementation module. 

22. It is an exception to reference an uninitialized or unassigned variable.

IV. Definitions and Declarations 

23. Differentiation between definition in definition modules and declaration

24. Static semantic of CONST declaration doesn't allow the occurence of
variable's names in constant  expression, e.g. it doesn't allow SIZE
(variable_id), LENGTH (variable_id). But see more on SIZE below. 

25. SYSTEM.MACHINEADDRESS must be imported to allow declaration of variables
at fixed addresses,  e.g.: VAR variable_at_fixed_address [const_expr]:
TypeName; The fixed address feature is not supported  under VMS. 

26. For identitifiers declared in procedures as formal parameters and local
data: formal overwrites local  identifiers. 

27. This is a typing error in the Standard S6.2. 

28. Function procedure body should be at least contain one return-statement
and can't be null, i.e.: must  have "BEGIN statement_sequence END" 

29. This is an error in the Standard S6.2: the term FUNCTION should be

30. No restrictions on the type of the returned value in function procedures. 

V. Types 

31. Operations imported from module SYSTEM are not allowed on empty records. 

32. Syntax of case-Statement: CASE [tag_identifier] ":" tag_type "OF" ...
instead of CASE [tag_identifier ":"]  tag_type "OF" ... . 

VI. Compatibility 

33. Assignment compatibility rules allow cardinal_variable := -1; (constant
expression out of range of target!).  Check! 

34. Assignment of empty character literal is allowed, e.g.: ch := ""; 

35. Any array of character [n..m], not only those with a lower bound of 0
[0..n] are assignment compatible with  string constants. 

36. Clarification: arrays of the form ARRAY OF SYSTEM.BYTE, SHORTWORD, ...
OCTAWORD are called  open arrays of module SYSTEM's storage types. 

37. CHAR is not parameter compatible with an open parameter of type ARRAY OF

38. For a PROCEDURE p(a: A), where TYPE A = ARRAY [0..n] OF any SYSTEM's
storage types: the  compatibilty rules for ARRAY OF any SYSTEM's storage types
apply. The term LOC is introduced as the  smallest addressable element with a
SIZE=1. See module SYSTEM below. 

39. Type LOC needs further explanations, since the type LOC is explained later
in the Standard. 

40. The notation for formal parameters in S6.4 "ARRAY OF ARRAY [0..n-1] OF
LOC" is not allowed in the  syntax. 

41. Number constants can't be passed to open arrays of LOC, e.g.: P(177B)
can't call PROCEDURE P (a:  ARRAY OF LOC). 

VII. Statements 

42. The meaning of "Assignment to variant tag variable doesn't change the
associated variant" is unclear. 

43. Exception in assignments of elementary variables: "assignment value out of
range of target". [now, but  error message text has to be changed] 

44.1. Exception "out-of-range" has to be generated for array and record
elements, since array and record  assigments are defined to be processed in a
component-by-component fashion? 

44.2. Exception (DNM) when assigning tag fields of variant records, where no
variant is selected: "tag value  out of range". 

45. Exception in return-statement: "result of function is out of range" 

45.1. Exception when "missing return statement in function procedure" 

46. Differentiation between variable and value record designator with
mandatory evaluation of constant  expression in the latter case. 

47. Assigment compatibility only necessary for control variable and initial
expression in for-statement. The  final expression shall be identical to the
type of the control variable or the host type of the control variable. 

48. Step in for-statement is a non-zero constant expression. 

49. Control variables should be declared in the block that contains the
for-statement in procedures, function  procedures or module. 

50. Termination of a while- and repeat-loop by EXIT within an outer LOOP
should be further clarified (as with  for-statement). 

51. Control variables in for-statement can neither be used in actual VAR
parameter, nor can it be imported,  exported or threatened by a statement of
the statement sequence of the for-statement. The threatening of  for-control
variables takes more than 10 pages in the Standard. 

VIII. Designators 

52. Exception when indexing an array: "array indexed out of range". [now, but
error message text has to be  changed] 

53. Exception (DNM) when selected designator belongs to a variant that has a
tag field and the variant is not  currently active: "access to inactive
component of variant record". 

54. Variant records have explicit or implicit tag fields. This needs further
explanation S6.6.3 (set implicit tag  field to select fields? Needs storage?) 

55. Exception of NIL-pointer reference: "attempt to dereference NIL or other
illegal address values" and  (DNM) "attempt to access non-existing variables".
[now, but error message text has to be changed] 

IX. Expressions 

56. New factors in expression S6.7: "REM" and "/" for integer operations, see

57. Arithmetic on variables of type address is no longer allowed, except via
functions imported from  SYSTEM. [implement these functions in module SYSTEM] 

58. Real number infix operators S6.7.1.1, e.g.: VAR r: REAL; lr: LONGREAL;
2.*r has type of r, 2.*lr has type  of lr, 2.*4. has type RR, 1./3. has type
RR evaluated with real-const-approximation always with at least  double
precision. A non-decreasing accuracy is defined in the Standard in the order:
real-approx.,  long-real-approx., real-const-approx. 

58.1. The method 58. works for LONGREALs. The Standard only defines REAL and
LONGREAL. But what  about G_ and H_Floating constant expressions? Evaluate all
using H_Floating arithmetic? What if CONST  x=1./3.; is defined in a
definition module, exported and used by a client in a H_Floating expression?
We end  up using constant reals as H_Floatings everywhere in the compiler and
symbol files. [?] 

59. Exception with real arithmetic: "real overflow". [now, but error message
text has to be changed] 

60. Exception with real arithmetic: "real division by zero". Reason of
overflow has to be determined, since  VAX-11 delivers only overflow
information. [?] 

61. Exception (DNM) with whole number arithmetic in S6.7.1.2: "whole number
overflow". This is currently  not detected. 

62. Operators "/" and "REM" are what is now "DIV" and "MOD", e.g.: -31/10
equals -3, whereas -31 DIV 10  shall equal to -4. 

62.1. Exceptions with whole number arithmetic: "whole number division ("/") by
zero", "whole number  remainder by zero", "whole number division ("DIV") by
zero or negative", "whole number modulus by zero or  negative". In contrast to
whole number overflow, the detection of these exceptions is mandatory. 

63. Clarification: Assume VAR p,q: BOOLEAN, then p <= q means p implies q. 

64. Values of structural identical procedure types can be compared by the
relational operators "<>" and "=".  They are equal if both values denote the
same procedure text. 

65. Values of pointer and opaque types can be compared with the operators "<>"
and "=". 

66. The prefix "-" shall not be applied to a value of unsigned type, e.g.:
with VAR a,b: CARDINAL; the  assignment a := -b is illegal. The expression
(-a+b) is illegal. 

67. Exception when the prefix "-" is applied to an expression with the value
MIN(INTEGER), since  non-symetric integer range (overflow). 

68. Exceptions with value designators: only structured objects can have
components which may be  undefined: (DNM) "value of variable is undefined",
"array indexed out-of-range", (DNM) "access to  non-active variant", "attempt
to dereference NIL" , (DNM) "attempt to access a non-existing variable". 

69. Differentiation between standard-function designator and system-function

70. Value constructors: Notation for arrays, records and sets is
"type_identifier { ... }" which is never  anonymous. Untyped value
constructors can be used as elements of value constructors. An array 
constructor does not give a value for an open array. (Notation change from
current form "type_identifier [ ... ]"  ) 

71. Exception when evaluating a value array constructor where a value is not
of component type. 

72. Repeated elements are denoted with "BY constant_expression" in array

73. This is an error in the Standard S6.7.5.2. The sentence beginning with
"The elements shall specify..." is  wrong and appears on the next page too at
record definitions. 

74. Variant records are allowed in record definition and constructor. Tag
fields must be constant expressions.  Six text pages on variants, tags and
record constructors. 

75. Set constructors require type identifier. The is no implicit use of type
BITSET (which is now in module  SYSTEM). 

76. NIL can be redefined, see S6.7.6 

77. Implementation defined maximum real value for real literals. This value
must be at least as large as the  maximum value of any real type, on VAX-11:

78. String constants can't be indexed in character expressions. S6.7.6.3. 

79*. String catenate symbol is likely to be "+". S6.7.6.3. 

80. Syntax change: "single-string = char-string | string-identifier."
"string-literal = single-string,  {catenate-symbol, single-string}." S6.7.6.3. 

81. Empty string is compatible with the type denoted by the pervasive
indentifier CHAR. 

82. Syntax change: A sequence of octal digits followed by "C" denote a
character literal. 

83. Constant expressions: References to variables only in standard functions
that are allowed in constant  expressions. S6.7.7. These standard functions
(e.g.: SIZE) should be listed somewhere, but I didn't yet find a  complete

84. Evaluation of constant expressions of real/whole number type: Error when
greater than maximum real  value for real/whole number literals. 

85. Rule for evaluation of constant expressions: The value of a constant
expression must be the same as the  equivalent non-constant expression. 

86. The constant expression "TRUE OR (1/0 = 1) is legal and TRUE since the
right part is not evaluated. 

87. Constant expressions may denote [partly now]

- a constant, procedure or function procedure value, structured value of
procedure value,

- a component selection for constant array or record (index value or
designator must be constant  expression),

- a standard function that is defined to be a constant standard function,

- an array, record or set definition with all elements or set members
constructed from constant expressions,

- a real/whole number or string constant expression. 

87.1. A constant expression can't be dereferenced. 

88. This is an error in S6.7/p221 in "Array definition", since
"Array-constructor" is repeatedly used. 

89. This point deleted, since it is already covered in point 87. 

X. Procedure Activation 

90. Formal array type parameter: actual parameter must be a value designator
that designates an array.  S6.8.3. 

XI. Pervasive Identifiers 

91. List of all pervasive identifiers (91.1, ... 91.3) 

91.1*. Elementary data types: INTEGER, CARDINAL, BOOLEAN, FALSE, TRUE, CHAR,
UNINTERRUPTIBLE.  (Here is an error in the Standard S6.9.1./p230: it
erroneously spells INTERRUPTABLE) 

91.2*. Standard functions: ABS, CAP, CHR, CMPLX, FLOAT, HIGH, IM, INT, LFLOAT,

91.3. Standard procedures: DEC, DISPOSE, ENTER, EXCL, HALT, INC, INCL, LEAVE,

91.4 New standard functions INT, PROT, and SIZE which was moved out of module
SYSTEM. New standard  procedures ENTER, LEAVE. See below. 

91.5. New standard function INT (is equivalent to the old TRUNC which is now
defined to return an unsigned  value, see 91.8.): INT (x) = VAL(INTEGER, x). 

91.6. LENGTH of a string. 

91.7. SIZE must no longer be imported from SYSTEM and it's parameter can't be
a component of an array or  record, or the variable referenced by a pointer
variable. The value returned by a call of SIZE shall be a whole  number

91.8. The value returned by a call of TRUNC shall be of the unsigned type. 

91.9. PROT, ENTER and LEAVE deal with protection codes and priorities. These
features that deal with  interrupts aren't available under VMS. 

92. This is an error in S6.9.2 last line/p231: standard-function-procedure
should spell standard-procedure. 

93. INC/DEC only for ordinal types, not for reals (VAX-11 extension). If the
first parameter is signed, then the  second parameter shall be <= MAX(INTEGER)
otherwise, the second parameter shall be >= 0. 

94. Exception if INC/DEC overflows or underflows. Signed arithmetic, if first
parameter is signed, unsigned  otherwise. (DNM?) 

95. The S6.9.3.2./p235 and S6.9.3.9/p242 (description of DISPOSE and NEW) uses
TSIZE (see module  SYSTEM below) and tsize (not found in index) which is still
undefined. Also doubt that <expression-list> is  defined anywhere. 

96. New type PROTECTION used with ENTER/LEAVE. 

97. Exception for EXCL/INCL (x, expr) if expr is not a value of the base type
of the type of the set variable.  "value to be excluded does not belong to
base type". S6.9.3.4 and S6.9.3.7 

98. ABS(s) where s: subrange; TYPE subrange = T [...]; has host type of the
subrange. Host type needs  further clarification. 

99. Exception for ABS(x) outside the range of the type of x, e.g.:
ABS(MIN(INTEGER)) is an exception.  ABS(unsigned_variable) is allowed. 

100. CAP only modifies lower-case letters, otherwise unmodified for all other

101. Exception for CHR(x) when (x<0) OR (x>ORD(MAX(CHAR))). CHAR(x) is
equivalent to VAL (CHAR,  x). 

102. Exception for FLOAT(x), where MIN(REAL) < x < MAX(REAL). FLOAT (x) is
equivalent to VAL (REAL,  x). 

103. FLOAT(x): x of is-number-type which includes whole-number-type and
real-number-type. S6.9.4.4. 

104. This point was deleted. 

105. HIGH is only allowed for open array parameter, i.e.: not for ordinary
variables of array type. S6.9.4.5. 

106. HIGH is not allowed in constant-expression. 

107. INT(x), with x of ordinal-number-type or real number-type returns a the
signed type. INT(x) is equivalent  to VAL (INTEGER, x). 

108. Exception: INT(x) for x outside the range of signed type. 

109. LENGTH(s), where s is an expression of string type or any array type with
element type of character  (this excludes multidimensional arrays), returns
unsigned type. LENGTH (s) is either the length of the string s  or the
position of the end-of-string-character. [for arrays with lower index bound =
0: now] 

110. This is an error in S6.9.4.7 on p249 (insert a space after LENGTH in
first line) and p250 (the function ... is  new, wrong name used). 

111. LFLOAT for LONGREAL, see FLOAT above. 

111.1. LFLOAT is not in module SYSTEM. 

112. This is an error: MAX is only defined for ordinal-types which do not
include reals. Use scalar-type  S6.10.4.3./p285 which do include real-numbers.
Also for MIN in S6.10.4.5 on p252. 

113. MAX(CARDINAL) and MAX(INTEGER) are of ZZ-type. 

114. Exception with non-symetric signed type: ODD (MIN(INTEGER)), since ODD(x)
is defined implicitely as  ODD(ABS(x)). Error in Standard? 

115. ORD(x) with x of ordinal type, returns unsigned type. ORD(x) is
equivalent to VAL(CARDINAL, x). 

115.1. Exception: ORD(x), where x > MAX(CARDINAL). 

116. PROT() returns current protection. 

117. SIZE(x), with x either an entire designator or qualified identifier which
is a type identifier, but not an open  array parameter. SIZE returns a whole
number literal, e.g.: SIZE (record.field) and SIZE(array[index]) and 
SIZE(pointer^) is not allowed. 

118. SIZE is allowed in constant expressions. 

119. SIZE(a) = SIZE(T) where VAR a:T; SIZE returns the number of LOCs occupied
by a variable of that  type. 

120. SIZE(formal_parameter) = SIZE(Type_of_formal_parameter). 

121. TRUNC (x) returns unsigned type in contrast to INT. x of real-number-type
only. TRUNC(x) =  VAL(CARDINAL, x). 

121.1. Exception with semantically changed TRUNC: if integral part outside the
range of unsigned type. 

122. VAL (T, x), where T ordinal-type or real-type is called result-type T. x
is an expression of either ordinal or  real-type. VAL returns the host type in
case of subranges, otherwise the result-type. 

123. This is an error in insert "in" in "the following table". 

124. Exception with VAL: if value of expression outside the range of result
type. [for exception with  mandatory detection] 

125. VAL (INTEGER or CARDINAL, r): r is truncated, not rounded. 

126.1. VAL(LONGREAL, -2.7) = -2.7; 

126.2. VAR r: REAL; r:=-2.7; then VAL(LONGREAL, r) = -2.7; 

127. Exception with VAL: "expression cannot be converted to the new type". 

128. This is an error in the Standard S6.9.5 in annotation (Return... is ...
is ... is). 

XII. Environment 

129. Implicit tag needs more explanantion (tagged-variable). S6.10.1.9./p270. 

130. Declaration of opaque types and procedures are taken from the
implementation module.  S6.10.2.11./p282. [?] 

131. Short glossary on: elementary Types: procedure, pointer, opaque, set, or
scalar type. 

131.1. Whole-number-type: unsigned-, signed-, or ZZ-type. 

131.2. Ordinal-type is character-, enumerated-, subrange-, or

131.3. Scalar-type is ordinal- or real-number-type. 

131.4. Number-type is real-number- or whole-number-type. 

132. This is an error in the Standard S6.10.1.3/p266: System-storage-type =
loc-type |  machine-address-type | bitnum-type. And in
is-bin-type refers to binnum-type as binary  number type. See 135.2. below
(binnum should spell bitnum?). 

133. New standard identifiers: INTERRUPTIBLE/UNINTERRUPTIBLE of priority-type.

134. The section that deals with exceptions is to be completed in the
Standard. S6.12. 

XIII. The SYSTEM Module 

135. The complete module SYSTEM is given here. S7.1. 

135.1. New constants (LOC means location and was renamed from SAU which was an
acronym for smallest  addressable unit): LOCSPERBYTE, LOCSPERWORD, BITSPERSET;
All have implementation-defined  values. 

135.2. New types: TYPE BITNUM; (* = [0..MAX(BITNUM)] *)

TYPE LOC; (* smallest addressable unit of storage with TSIZE(LOC)=1 *)





135.3. New procedures: 



PROCEDURE SETRESULT (resultCode: <impl.def> );


PROCEDURE ADDRESSVALUE (val: <some type>; ...): ADDRESS;


PROCEDURE CAST (<type>; val: <anytype>): <type>;


PROCEDURE MACHINEADDRESS (val: <some type>; ...): machine-address-type; see
25. above.

PROCEDURE ROTATE (val: <bit number set type>; shift: INTEGER): <bit number set

PROCEDURE SHIFT (val: <bit number set type>; shift: INTEGER): <bit number set



135.4. GET-/SETCLEANUP and SETRESULT: systemcleanup procedure handling. Allows
several modules  to set up a chain of procedures to be called on program
termination. Allows individual module termination  code. Eventually SETRESULT
will be replaced by STOP with the same definition as SETRESULT. [?] 

135.4. ADDRESSVALUE converts to an address in an implementation defined

135.5. CAST is used for unsafe type conversion. It maps the bit pattern
representation from val to the return  value. 

135.6. Address operators ADD-, SUB, DIFADR are introduced, since ADDRESS is no
longer expression  compatible with CARDINAL. 

135.7. MACHINEADDRESS is used to construct machine addresses. 


136. The COROUTINES Module is a system module without a definition or
implementation module. S7.2.  There is one type, namely COROUTINE which is the
equivalent to the old type PROCESS. The complete set  of procedures is: 

PROCEDURE ATTACH (source: <impl.def>); (* connect to interrupts *)

PROCEDURE DETACH (source: <impl.def>); (* disconnect from interrupts *)

PROCEDURE HANDLER (source: <impl.def.>): COROUTINE; (* coroutine which is
connected to the source  of interrupts *)


PROCEDURE IsATTACHED (source: <impl.def>): BOOLEAN;


initpriority:  PRIORITY; VAR cr: COROUTINE);

PROCEDURE SELF(): COROUTINE; (* identity of calling coroutine *)


136.1. The first six procedures from 136. will not be available under VMS.
TRANSFER now only specifies the  destination coroutine and NEWCOROUTINE has
been renamed from NEWPROCESS and incorporates a  priority specification. 

XV. Exception Handling 

137. The ReportExceptions module provides means for identifying standard and
user-defined exceptions  and for reporting the detection of these exceptions.
It is not listed here, because there are currently too much  so-called to do
sections in S7.3. See also 138. 

XVI. Separate Modules 

138. Required separate modules (only 138.1, ... 138.4.). 

138.1. Storage (ALLOCATE, DEALLOCATE). 

138.2. HandleExceptions (to do). 

138.3. LowReal (several implementation defined constants specifying exponent's
range, radix and so on  plus some associated low level procedures). 

138.4. LowLong same as 138.3., but for LONGREAL. 

139. Standard Library Modules (mathematical, input/output, conversions,
concurrent programming, string  handling): RealMath, LongMath, Channel,
StdIds, IO, SIO, WholeIO, SWholeIO, RealIO, SRealIO, LongIO,  SLongIO, BaseIO,
SBaseIO, ConvTypes, CardStr, IntStr, RealStr, LongStr, Term, SeqFile, RndFile, 
IOErrors, IOLink, Processes, Semaphores, Strings, Termination, and SysClock. 

IMPRESSUM: The ModulaTor is an unrefereed journal. Technical papers are to be taken as working papers and personal rather than organizational statements. Items are printed at the discretion of the Editor based upon his judgement on the interest and relevancy to the readership. Letters, announcements, and other items of professional interest are selected on the same basis. Office of publication: The Editor of The ModulaTor is Guenter Dotzel; he can be reached by tel/fax: [removed due to abuse] or by mailto:[email deleted due to spam]
  ModulaWare home page   The ModulaTor download    [Any browser]

Webdesign by, 14-Jul-1998