Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

One IO Module Per Pervasive Type

WiP.OneIOModulePerPervasiveType History

Hide minor edits - Show changes to output

2010-01-16 11:55 by benjk -
Added line 3:
*[[Spec/IO Module BITSET]]
2010-01-14 12:38 by benjk -
Changed lines 4-12 from:
*[[IO Module OCTET]]
*[[IO Module CHAR]]
*[[IO Module UNICHAR]]
*[[IO Module CARDINAL]]
*[[IO Module LONGCARD]]
*[[IO Module INTEGER]]
*[[IO Module LONGINT]]
*[[IO Module REAL]]
*[[IO Module LONGREAL]]
to:
*[[Spec/IO Module OCTET]]
*[[Spec/IO Module CHAR]]
*[[Spec/IO Module UNICHAR]]
*[[Spec/IO Module CARDINAL]]
*[[Spec/IO Module LONGCARD]]
*[[Spec/IO Module INTEGER]]
*[[Spec/IO Module LONGINT]]
*[[Spec/IO Module REAL]]
*[[Spec/IO Module LONGREAL]]
2010-01-14 12:36 by benjk -
Changed line 3 from:
*[[IO Module BOOLEAN]]
to:
*[[Spec/IO Module BOOLEAN]]
2010-01-14 08:44 by benjk -
Added line 4:
*[[IO Module OCTET]]
2010-01-14 08:37 by benjk -
Changed lines 3-12 from:
*[[IO Module BOOLEAN]] for type BOOLEAN
*[[IO Module CHAR]] for type CHAR
*[[IO Module UNICHAR]] for type UNICHAR
*[[IO Module CARDINAL]] for type CARDINAL
*[[IO Module LONGCARD]] for type LONGCARD
*[[IO Module INTEGER]] for type INTEGER
*[[IO Module LONGINT]] for type LONGINT
*[[IO Module REAL]] for type REAL
*[[IO Module LONGREAL]] for type LONGREAL

to:
*[[IO Module BOOLEAN]]
*[[IO Module CHAR]]
*[[IO Module UNICHAR]]
*[[IO Module CARDINAL]]
*[[IO Module LONGCARD]]
*[[IO Module INTEGER]]
*[[IO Module LONGINT]]
*[[IO Module REAL]]
*[[IO Module LONGREAL]]
Changed line 32 from:
Since it may be inconvenient to have to import each pervasive type's I/O module explicitly, the standard library should also provide a consolidated module that can serve as an import aggregator if desired. A module named PervasiveIO can be provided to serve this function.
to:
Since it may be inconvenient to have to import each pervasive type's I/O module explicitly, the standard library should also provide a consolidated module that can serve as an import aggregator if desired. A module named `PervasiveIO can be provided to serve this function.
2010-01-14 08:36 by benjk -
Changed lines 1-4 from:
The actual I/O procedures for all pervasive types reside in module `PervasiveIO. In order to accommodate the proper functioning of macros READ and WRITE, a separate wrapper IO module for each pervasive type is provided as follows:

[@DEFINITION MODULE
CHAR;
to:
For each pervasive type the standard library provides one type specific I/O module. In order to facilitate the use of pervasive macros READ and WRITE, the type specific modules are named identical to their respective types.

*[[IO Module BOOLEAN]] for type BOOLEAN
*[[IO Module
CHAR]] for type CHAR
*[[IO Module UNICHAR]] for type UNICHAR
*[[IO Module CARDINAL]] for type CARDINAL
*[[IO Module LONGCARD]] for type LONGCARD
*[[IO Module INTEGER]] for type INTEGER
*[[IO Module LONGINT]] for type LONGINT
*[[IO Module REAL]] for type REAL
*[[IO Module LONGREAL]] for type LONGREAL

The modules have to be imported directly or indirectly in order to use the pervasive macros READ and WRITE.

[@MODULE Example1
;
Changed lines 19-35 from:
FROM PervasiveIO IMPORT ReadChar, WriteChar;

<*INLINE*> PROCEDURE Read( fid : File; VAR ch
: CHAR );

<*INLINE*> PROCEDURE Write( fid : File; ch : CHAR );

END CHAR.@]

The corresponding implementation part is shown below:

[@IMPLEMENTATION MODULE CHAR;

FROM FileIO IMPORT File;

FROM PervasiveIO IMPORT ReadChar, WriteChar;

<*INLINE*> PROCEDURE Read( fid : File; VAR ch : CHAR );
to:
IMPORT CHAR; (* explicit import of CHAR's I/O module *)

VAR file
: File; ch : CHAR;
Changed lines 24-27 from:
   ReadChar( fid, ch );
END Read
;

<*INLINE*> PROCEDURE Write( fid : File; ch :
CHAR );
to:
   ...

 
  READ( file, ch );   (* equivalent to CHAR.Read( file, ch ); *)

    WRITE( file, ch );  (* equivalent to CHAR.Write( file, ch ); *)

END Example1.@]

Since it may be inconvenient to have to import each pervasive type's I/O module explicitly, the standard library should also provide a consolidated module that can serve as an import aggregator if desired. A module named PervasiveIO can be provided to serve this function.

[@MODULE Example2;

FROM FileIO IMPORT File;

IMPORT PervasiveIO; (* implicit import of all pervasive type I/O modules *)

VAR file : File; ch : CHAR;

Changed lines 43-48 from:
   WriteChar( fid, ch );
END Write;

END CHAR.@]

The compiler will first expand a macro invocation such as WRITE( file, char
); to CHAR.Write( file, char ); which in turn is translated into `PervasiveIO.WriteChar( file, char ); because the Write procedure is declared with the <*INLINE*> pragma.
to:
   ...

 
  READ( file, ch );  (* equivalent to CHAR.Read( file, ch ); *)

    WRITE( file, ch );  (* equivalent to CHAR
.Write( file, ch ); *)

END Example2
.@]
2010-01-13 20:09 by benjk -
Changed line 35 from:
The compiler will first expand a macro invocation such as WRITE( file, char ); to CHAR.Write( file, ch ); which in turn is translated into `PervasiveIO.WriteChar( file, ch ); because the Write procedure is declared with the <*INLINE*> pragma.
to:
The compiler will first expand a macro invocation such as WRITE( file, char ); to CHAR.Write( file, char ); which in turn is translated into `PervasiveIO.WriteChar( file, char ); because the Write procedure is declared with the <*INLINE*> pragma.
2010-01-13 20:09 by benjk -
Changed line 35 from:
The compiler will first expand a macro invocation such as WRITE( file, char ); to CHAR.Write( file, ch ); which in turn is translated into PervasiveIO.WriteChar( file, ch ); because the Write procedure is declared with the <*INLINE*> pragma.
to:
The compiler will first expand a macro invocation such as WRITE( file, char ); to CHAR.Write( file, ch ); which in turn is translated into `PervasiveIO.WriteChar( file, ch ); because the Write procedure is declared with the <*INLINE*> pragma.
2010-01-13 20:09 by benjk -
Changed line 1 from:
The actual I/O procedures for all pervasive types reside in module PervasiveIO. In order to accommodate the proper functioning of macros READ and WRITE, a separate wrapper IO module for each pervasive type is provided as follows:
to:
The actual I/O procedures for all pervasive types reside in module `PervasiveIO. In order to accommodate the proper functioning of macros READ and WRITE, a separate wrapper IO module for each pervasive type is provided as follows:
2010-01-13 20:08 by benjk -
Changed line 15 from:
The implementation module is shown below:
to:
The corresponding implementation part is shown below:
2010-01-13 20:07 by benjk - new file by benjk
Added lines 1-35:
The actual I/O procedures for all pervasive types reside in module PervasiveIO. In order to accommodate the proper functioning of macros READ and WRITE, a separate wrapper IO module for each pervasive type is provided as follows:

[@DEFINITION MODULE CHAR;

FROM FileIO IMPORT File;

FROM PervasiveIO IMPORT ReadChar, WriteChar;

<*INLINE*> PROCEDURE Read( fid : File; VAR ch : CHAR );

<*INLINE*> PROCEDURE Write( fid : File; ch : CHAR );

END CHAR.@]

The implementation module is shown below:

[@IMPLEMENTATION MODULE CHAR;

FROM FileIO IMPORT File;

FROM PervasiveIO IMPORT ReadChar, WriteChar;

<*INLINE*> PROCEDURE Read( fid : File; VAR ch : CHAR );
BEGIN
    ReadChar( fid, ch );
END Read;

<*INLINE*> PROCEDURE Write( fid : File; ch : CHAR );
BEGIN
    WriteChar( fid, ch );
END Write;

END CHAR.@]

The compiler will first expand a macro invocation such as WRITE( file, char ); to CHAR.Write( file, ch ); which in turn is translated into PervasiveIO.WriteChar( file, ch ); because the Write procedure is declared with the <*INLINE*> pragma.