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 markup

2010-01-16 11:55 by benjk -
Added line 3:
2010-01-14 12:36 by benjk -
Changed line 3 from:
to:
2010-01-14 08:44 by benjk -
Added line 4:
2010-01-14 08:37 by benjk -
Changed lines 3-12 from:
to:
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 Pervasive IO? 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.

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 Pervasive IO? IMPORT Read Char?, Write Char?;

<*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 File IO? IMPORT File;

FROM Pervasive IO? IMPORT Read Char?, Write Char?;

<*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:
    Read Char?( 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 Pervasive IO? can be provided to serve this function.

[@MODULE Example2;

FROM File IO? IMPORT File;

IMPORT Pervasive IO?; (* implicit import of all pervasive type I/O modules *)

VAR file : File; ch : CHAR;

Changed lines 43-48 from:
    Write Char?( 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 Pervasive IO.Write Char?( 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 Pervasive IO?. 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 Pervasive IO?. 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 Pervasive IO.Write Char?( file, ch ); because the Write procedure is declared with the <*INLINE*> pragma.