Contents Menu Expand Light mode Dark mode Auto light/dark mode
The GNU Modula-2 Compiler 13.0.1 (experimental 20220101) documentation
Logo
The GNU Modula-2 Compiler 13.0.1 (experimental 20220101) documentation
  • Overview of GNU Modula-2
    • What is GNU Modula-2
    • Why use GNU Modula-2
    • Release map
    • News
    • How to get source code using git
    • GNU Modula-2 Features
    • Documentation
    • Regression tests for gm2 in the repository
    • Limitations
    • Objectives
    • FAQ
      • Why use the C++ exception mechanism in GCC, rather than a bespoke Modula-2 mechanism?
    • Community
    • Other languages for GCC
    • Papers and talks
  • Using GNU Modula-2
    • Example compile and link
    • Compiler options
    • GNU Modula-2 related environment variables
    • Elementary data types
    • Permanently accessible base procedures.
      • Standard procedures and functions common to PIM and ISO
      • ISO specific standard procedures and functions
    • GNU Modula-2 supported dialects
      • Integer division, remainder and modulus
    • Exception implementation
    • How to detect runtime problems at compile time
    • GNU Modula-2 language extensions
      • Optional procedure parameter
    • Type compatibility
      • Expression compatibility
      • Assignment compatibility
      • Parameter compatibility
    • Unbounded by reference
    • Building a shared library
    • How to produce swig interface files
      • Limitations of automatic generated of Swig files
    • How to produce a Python module
    • Interfacing GNU Modula-2 to C
    • Interface to assembly language
    • Data type alignment
    • Packing data types
    • Accessing GNU Modula-2 Built-ins
    • The PIM system module
    • The ISO system module
  • Licence of GNU Modula-2
  • EBNF of GNU Modula-2
  • PIM and ISO library definitions
    • Base libraries
      • gm2-libs/ASCII
      • gm2-libs/Args
      • gm2-libs/Assertion
      • gm2-libs/Break
      • gm2-libs/Builtins
      • gm2-libs/COROUTINES
      • gm2-libs/CmdArgs
      • gm2-libs/Debug
      • gm2-libs/DynamicStrings
      • gm2-libs/Environment
      • gm2-libs/FIO
      • gm2-libs/FormatStrings
      • gm2-libs/FpuIO
      • gm2-libs/GetOpt
      • gm2-libs/IO
      • gm2-libs/Indexing
      • gm2-libs/LMathLib0
      • gm2-libs/LegacyReal
      • gm2-libs/M2Dependent
      • gm2-libs/M2EXCEPTION
      • gm2-libs/M2LINK
      • gm2-libs/M2RTS
      • gm2-libs/MathLib0
      • gm2-libs/MemUtils
      • gm2-libs/NumberIO
      • gm2-libs/OptLib
      • gm2-libs/PushBackInput
      • gm2-libs/RTExceptions
      • gm2-libs/RTint
      • gm2-libs/SArgs
      • gm2-libs/SCmdArgs
      • gm2-libs/SEnvironment
      • gm2-libs/SFIO
      • gm2-libs/SMathLib0
      • gm2-libs/SYSTEM
      • gm2-libs/Scan
      • gm2-libs/Selective
      • gm2-libs/StdIO
      • gm2-libs/Storage
      • gm2-libs/StrCase
      • gm2-libs/StrIO
      • gm2-libs/StrLib
      • gm2-libs/StringConvert
      • gm2-libs/SysExceptions
      • gm2-libs/SysStorage
      • gm2-libs/TimeString
      • gm2-libs/UnixArgs
      • gm2-libs/cbuiltin
      • gm2-libs/cgetopt
      • gm2-libs/cxxabi
      • gm2-libs/dtoa
      • gm2-libs/errno
      • gm2-libs/gdbif
      • gm2-libs/ldtoa
      • gm2-libs/libc
      • gm2-libs/libm
      • gm2-libs/sckt
      • gm2-libs/termios
      • gm2-libs/wrapc
    • PIM coroutine support
      • gm2-libs-coroutines/Debug
      • gm2-libs-coroutines/Executive
      • gm2-libs-coroutines/KeyBoardLEDs
      • gm2-libs-coroutines/SYSTEM
      • gm2-libs-coroutines/TimerHandler
    • M2 ISO Libraries
      • gm2-libs-iso/COROUTINES
      • gm2-libs-iso/ChanConsts
      • gm2-libs-iso/CharClass
      • gm2-libs-iso/ClientSocket
      • gm2-libs-iso/ComplexMath
      • gm2-libs-iso/ConvStringLong
      • gm2-libs-iso/ConvStringReal
      • gm2-libs-iso/ConvTypes
      • gm2-libs-iso/EXCEPTIONS
      • gm2-libs-iso/ErrnoCategory
      • gm2-libs-iso/GeneralUserExceptions
      • gm2-libs-iso/IOChan
      • gm2-libs-iso/IOConsts
      • gm2-libs-iso/IOLink
      • gm2-libs-iso/IOResult
      • gm2-libs-iso/LongComplexMath
      • gm2-libs-iso/LongConv
      • gm2-libs-iso/LongIO
      • gm2-libs-iso/LongMath
      • gm2-libs-iso/LongStr
      • gm2-libs-iso/LongWholeIO
      • gm2-libs-iso/LowLong
      • gm2-libs-iso/LowReal
      • gm2-libs-iso/LowShort
      • gm2-libs-iso/M2EXCEPTION
      • gm2-libs-iso/M2RTS
      • gm2-libs-iso/MemStream
      • gm2-libs-iso/Preemptive
      • gm2-libs-iso/Processes
      • gm2-libs-iso/ProgramArgs
      • gm2-libs-iso/RTco
      • gm2-libs-iso/RTdata
      • gm2-libs-iso/RTentity
      • gm2-libs-iso/RTfio
      • gm2-libs-iso/RTgen
      • gm2-libs-iso/RTgenif
      • gm2-libs-iso/RTio
      • gm2-libs-iso/RandomNumber
      • gm2-libs-iso/RawIO
      • gm2-libs-iso/RealConv
      • gm2-libs-iso/RealIO
      • gm2-libs-iso/RealMath
      • gm2-libs-iso/RealStr
      • gm2-libs-iso/RndFile
      • gm2-libs-iso/SIOResult
      • gm2-libs-iso/SLongIO
      • gm2-libs-iso/SLongWholeIO
      • gm2-libs-iso/SRawIO
      • gm2-libs-iso/SRealIO
      • gm2-libs-iso/SShortIO
      • gm2-libs-iso/SShortWholeIO
      • gm2-libs-iso/STextIO
      • gm2-libs-iso/SWholeIO
      • gm2-libs-iso/SYSTEM
      • gm2-libs-iso/Semaphores
      • gm2-libs-iso/SeqFile
      • gm2-libs-iso/ServerSocket
      • gm2-libs-iso/ShortComplexMath
      • gm2-libs-iso/ShortIO
      • gm2-libs-iso/ShortWholeIO
      • gm2-libs-iso/SimpleCipher
      • gm2-libs-iso/StdChans
      • gm2-libs-iso/Storage
      • gm2-libs-iso/StreamFile
      • gm2-libs-iso/StringChan
      • gm2-libs-iso/Strings
      • gm2-libs-iso/SysClock
      • gm2-libs-iso/TERMINATION
      • gm2-libs-iso/TermFile
      • gm2-libs-iso/TextIO
      • gm2-libs-iso/WholeConv
      • gm2-libs-iso/WholeIO
      • gm2-libs-iso/WholeStr
      • gm2-libs-iso/wrapsock
      • gm2-libs-iso/wraptime
    • PIM and Logitech 3.0 Compatible
      • gm2-libs-pim/BitBlockOps
      • gm2-libs-pim/BitByteOps
      • gm2-libs-pim/BitWordOps
      • gm2-libs-pim/BlockOps
      • gm2-libs-pim/Break
      • gm2-libs-pim/CardinalIO
      • gm2-libs-pim/Conversions
      • gm2-libs-pim/DebugPMD
      • gm2-libs-pim/DebugTrace
      • gm2-libs-pim/Delay
      • gm2-libs-pim/Display
      • gm2-libs-pim/ErrorCode
      • gm2-libs-pim/FileSystem
      • gm2-libs-pim/FloatingUtilities
      • gm2-libs-pim/InOut
      • gm2-libs-pim/Keyboard
      • gm2-libs-pim/LongIO
      • gm2-libs-pim/NumberConversion
      • gm2-libs-pim/Random
      • gm2-libs-pim/RealConversions
      • gm2-libs-pim/RealInOut
      • gm2-libs-pim/Strings
      • gm2-libs-pim/Termbase
      • gm2-libs-pim/Terminal
      • gm2-libs-pim/TimeDate
    • Indices
Back to top
Edit this page

gm2-libs-iso/IOLink#

DEFINITION MODULE IOLink;

(* Types and procedures for the standard implementation of channels *)

IMPORT IOChan, IOConsts, ChanConsts, SYSTEM;

TYPE
  DeviceId;
    (* Values of this type are used to identify new device modules,
       and are normally obtained by them during their initialization.
    *)

AllocateDeviceId
PROCEDURE AllocateDeviceId (VAR did: DeviceId);
  (* Allocates a unique value of type DeviceId, and assigns this
     value to did. *)

MakeChan
PROCEDURE MakeChan (did: DeviceId; VAR cid: IOChan.ChanId);
  (* Attempts to make a new channel for the device module identified
     by did. If no more channels can be made, the identity of
     the invalid channel is assigned to cid.  Otherwise, the identity
     of a new channel is assigned to cid.
  *)

UnMakeChan
PROCEDURE UnMakeChan (did: DeviceId; VAR cid: IOChan.ChanId);
  (* If the device module identified by did is not the module that
     made the channel identified by cid, the exception wrongDevice is
     raised; otherwise the channel is deallocated, and the value
     identifying the invalid channel is assigned to cid.
  *)

TYPE
DeviceTablePtr (type)
  DeviceTablePtr = POINTER TO DeviceTable;
    (* Values of this type are used to refer to device tables *)

TYPE
LookProc (type)
  LookProc      = PROCEDURE (DeviceTablePtr, VAR CHAR, VAR IOConsts.ReadResults) ;
SkipProc (type)
  SkipProc      = PROCEDURE (DeviceTablePtr) ;
SkipLookProc (type)
  SkipLookProc  = PROCEDURE (DeviceTablePtr, VAR CHAR, VAR IOConsts.ReadResults) ;
WriteLnProc (type)
  WriteLnProc   = PROCEDURE (DeviceTablePtr) ;
TextReadProc (type)
  TextReadProc  = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL, VAR CARDINAL) ;
TextWriteProc (type)
  TextWriteProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL) ;
RawReadProc (type)
  RawReadProc   = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL, VAR CARDINAL) ;
RawWriteProc (type)
  RawWriteProc  = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL) ;
GetNameProc (type)
  GetNameProc   = PROCEDURE (DeviceTablePtr, VAR ARRAY OF CHAR) ;
ResetProc (type)
  ResetProc     = PROCEDURE (DeviceTablePtr) ;
FlushProc (type)
  FlushProc     = PROCEDURE (DeviceTablePtr) ;
FreeProc (type)
  FreeProc      = PROCEDURE (DeviceTablePtr) ;
     (* Carry out the operations involved in closing the corresponding
        channel, including flushing buffers, but do not unmake the
        channel.
     *)

TYPE
DeviceData (type)
  DeviceData = SYSTEM.ADDRESS;

DeviceTable (type)
  DeviceTable =
    RECORD                         (* Initialized by MakeChan to: *)
      cd: DeviceData;              (* the value NIL *)
      did: DeviceId;               (* the value given in the call of MakeChan *)
      cid: IOChan.ChanId;          (* the identity of the channel *)
      result: IOConsts.ReadResults;(* the value notKnown *)
      errNum: IOChan.DeviceErrNum; (* undefined *)
      flags: ChanConsts.FlagSet;   (* ChanConsts.FlagSet{} *)
      doLook: LookProc;            (* raise exception notAvailable *)
      doSkip: SkipProc;            (* raise exception notAvailable *)
      doSkipLook: SkipLookProc;    (* raise exception notAvailable *)
      doLnWrite: WriteLnProc;      (* raise exception notAvailable *)
      doTextRead: TextReadProc;    (* raise exception notAvailable *)
      doTextWrite: TextWriteProc;  (* raise exception notAvailable *)
      doRawRead: RawReadProc;      (* raise exception notAvailable *)
      doRawWrite: RawWriteProc;    (* raise exception notAvailable *)
      doGetName: GetNameProc;      (* return the empty string *)
      doReset: ResetProc;          (* do nothing *)
      doFlush: FlushProc;          (* do nothing *)
      doFree: FreeProc;            (* do nothing *)
    END;

  (* The pointer to the device table for a channel is obtained using the
     following procedure: *)

(*
   If the device module identified by did is not the module that made
   the channel identified by cid, the exception wrongDevice is raised.
*)

DeviceTablePtrValue
PROCEDURE DeviceTablePtrValue (cid: IOChan.ChanId; did: DeviceId): DeviceTablePtr;

(*
   Tests if the device module identified by did is the module
   that made the channel identified by cid.
*)

IsDevice
PROCEDURE IsDevice (cid: IOChan.ChanId; did: DeviceId) : BOOLEAN;

TYPE
DevExceptionRange (type)
  DevExceptionRange = IOChan.ChanExceptions;

(*
  ISO standard states defines

  DevExceptionRange = [IOChan.notAvailable ..  IOChan.textParseError];

  however this must be a bug as other modules need to raise
  IOChan.wrongDevice exceptions.
*)

RAISEdevException
PROCEDURE RAISEdevException (cid: IOChan.ChanId; did: DeviceId;
                             x: DevExceptionRange; s: ARRAY OF CHAR);

  (* If the device module identified by did is not the module that made the channel
     identified by cid, the exception wrongDevice is raised; otherwise the given exception
     is raised, and the string value in s is included in the exception message.
  *)

IsIOException
PROCEDURE IsIOException () : BOOLEAN;
  (* Returns TRUE if the current coroutine is in the exceptional execution state
     because of the raising af an exception from ChanExceptions;
     otherwise FALSE.
  *)

IOException
PROCEDURE IOException () : IOChan.ChanExceptions;
  (* If the current coroutine is in the exceptional execution state because of the
     raising af an exception from ChanExceptions, returns the corresponding
     enumeration value, and otherwise raises an exception.
  *)

END IOLink.
Next
gm2-libs-iso/IOResult
Previous
gm2-libs-iso/IOConsts
Copyright © 2022 Free Software Foundation, Inc.
Made with Sphinx and @pradyunsg's Furo
Last updated on Nov 07, 2022