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

IO Handlers For Generic READ And WRITE

WiP.IOHandlersForGenericREADAndWRITE History

Hide minor edits - Show changes to output

2010-01-13 18:01 by benjk -
Changed lines 10-11 from:
   Builtin = ( BOOLEAN, CHAR, UNICHAR, CARDINAL, LONGCARD, INTEGER, LONGINT,
             
REAL, LONGREAL );
to:
   Builtin = ( BOOLEAN, CHAR, UNICHAR, CARDINAL, LONGCARD, INTEGER, LONGINT, REAL, LONGREAL );
2010-01-13 18:00 by benjk -
Changed line 3 from:
A possible way to implement this facility would be to maintain a table of pointers to R/W handler procedures in the runtime system. At compile time, any invocation of READ or WRITE is translated into a call to the respective pointers to R/W handlers. A procedure that allows the installation of I/O procedures as handlers is provided either by module SYSTEM or by a new system module.
to:
A possible way to implement this facility would be to maintain a table of pointers to R/W handler procedures in the runtime system. At compile time, any invocation of READ or WRITE is translated into a respective call into the R/W handler table. A procedure that allows the installation of I/O procedures as handlers is provided either by module SYSTEM or by a new system module.
2010-01-13 17:59 by benjk -
Changed line 28 from:
FROM M2RTL IMPORT Builtin, InstallRWHandlers;
to:
FROM M2RTS IMPORT Builtin, InstallRWHandlers;
2010-01-13 17:58 by benjk -
Changed line 3 from:
A possible way to implement this facility would be to maintain a table of pointers to R/W handler procedures in the runtime system. At compile time, any invocation of READ or WRITE is translated into a call to the respective pointers to R/W handlers. A procedure that allows the installation of I/O procedures as handlers is provided either by module SYSTEM or by a new system module, e.g. M2RTS.
to:
A possible way to implement this facility would be to maintain a table of pointers to R/W handler procedures in the runtime system. At compile time, any invocation of READ or WRITE is translated into a call to the respective pointers to R/W handlers. A procedure that allows the installation of I/O procedures as handlers is provided either by module SYSTEM or by a new system module.
2010-01-13 17:58 by benjk - new file by benjk
Added lines 1-45:
One of the design objectives is to provide a universal I/O facility through two pervasive generic macros READ and WRITE.

A possible way to implement this facility would be to maintain a table of pointers to R/W handler procedures in the runtime system. At compile time, any invocation of READ or WRITE is translated into a call to the respective pointers to R/W handlers. A procedure that allows the installation of I/O procedures as handlers is provided either by module SYSTEM or by a new system module, e.g. M2RTS.

[@DEFINITION MODULE M2RTS;

(* Modula-2 Run Time System Interface *)

TYPE
    Builtin = ( BOOLEAN, CHAR, UNICHAR, CARDINAL, LONGCARD, INTEGER, LONGINT,
                REAL, LONGREAL );

    ReadHandler = PROCEDURE ( File; VAR <PervasiveType> );

    WriteHandler = PROCEDURE ( File; <PervasiveType> );


PROCEDURE InstallRWHandlers( type : Builtin;
                              rh : ReadHandler;
                              wh : WriteHandler );

END M2RTS.@]

A library that implements I/O procedures then imports the handler installation procedure and installs its I/O procedures as handlers in the runtime system's handler table.

[@IMPLEMENTATION MODULE PervasiveIO;

FROM M2RTL IMPORT Builtin, InstallRWHandlers;

(* implementation of I/O procedures: ReadBool, WriteBool,
  ReadChar, WriteChar, ReadUChar, WriteUChar, ReadCard, WriteCard,
  ReadInt, WriteInt, ReadLInt, WriteLInt, ReadReal, WriteLReal *)

(* installing I/O procedures as R/W handlers *)
BEGIN
    InstallRWHandlers(Builtin.BOOLEAN, ReadBool, WriteBool);
    InstallRWHandlers(Builtin.CHAR, ReadChar, WriteChar);
    InstallRWHandlers(Builtin.UNICHAR, ReadUChar, WriteUChar);
    InstallRWHandlers(Builtin.CARDINAL, ReadCard, WriteCard);
    InstallRWHandlers(Builtin.LONGCARD, ReadLCard, WriteLCard);
    InstallRWHandlers(Builtin.INTEGER, ReadInt, WriteInt);
    InstallRWHandlers(Builtin.LONGINT, ReadLInt, WriteLInt);
    InstallRWHandlers(Builtin.REAL, ReadReal, WriteReal);
    InstallRWHandlers(Builtin.LONGREAL, ReadLReal, WriteLReal);
END PervasiveIO.@]