2nd ed., 13-Aug-1992
3rd ed., 01-Sep-1992 (extended example TestSeq)
4th ed., 05-Mar-1993 (modules LowLong and LowReal added)
5th ed., 09-Apr-1994 (general update for minor changes in 2nd committee draft
ISO 10154 (Dec-1992), last updated by sc22.wg13 in Feb-1993)
6th ed., 17-Jun-1994 (S_, T_FLOATING and _COMPLEX as well for MaX AXP/OpenVMS
Modula-2 implementation; G_COMPLEX support added for both MaX and MVR).
7th ed., 22-Dec-1996: TestSCopy redirection example added.
Compared to the ISO Modula-2 I/O-Library of the 3rd and 4th Interim Working Draft, the main changes of the 4WD resulted from renaming of module, procedure and parameter names. This paper serves as a reference of the "final" version which I am currently implementing for the next major release of MVR and H2O (ModulaWare's Modula-2 and Oberon-2 compiler for DEC VAX/VMS). [Ed. note: the M2 Std Lib implementation for MVR was first released Mar-92.] Where our current implementation (for MVR V3.20) deviates from the 4WD because of compiler restrictions, this is indicated by an additional comment "temporary for MVR". These are only two modules: ConvTypes (modified type ScanType) and RndFiles (modified type FilePos).
In the collection below, the so-called simple I/O modules with the prefix "S" (SRawIO, STextIO, SRealIO, SLongIO, SLongGIO*, SWholeIO, SIOResult) were omitted, because their definition is identical to the corresponding modules without the prefix "S", except that always the parameter cid of type IOChan.ChanId is missing (i.e. implicit, see module StdChans).
To be complete, I've also included all auxiliary string conversion definition modules *_Str (which are equivalent to the *Str modules of the 4WD), because in ModulaWare's library implementation, the modules WholeIO, RealIO, LongGIO and LongIO of the I/O-Library are based on these modules.
Also the ISO M2 Std Lib modules SysClock, Processes, Semaphores, RealMath, LongMath, LongGMath*, ComplexMath, LongComplexMath, LongComplexGMath, LowReal, LowLong, LowLongG*, Storage and Strings are included.
* The G_FLOATING low-level real, [complex] math, I/O- and string conversion modules which are ModulaWare's (AXP|VAX)/OpenVMS specific non-standard extension to the ISO M2 Std Lib are also included. The type SYSTEM.G_COMPLEX is used Long[Complex]GMath; this new type and associated operations are available in both MVR and MaX since V4.05d. Corresponding S_FLOATING and T_FLOATING modules are available for MaX, ModulaWare's AXP/VMS Modula-2 compiler (first version was released in Jul-94); these modules are similar to the corresponding G_FLOATING and G_COMPLEX modules and are not listed here. The modules for S_FLOATING and S_COMPLEX are called RealSIO, SRealSIO, LowRealS, RealSStr, RealS_Str, RealSConv, RealSMath, ComplexSMath and the modules for T_FLOATING and T_COMPLEX are called LongTIO, SLongTIO, LowLongT, LongTStr, LongT_Str, LongTConv, LongTMath, LongComplexTMath. MaX supports 64 bit whole number types and associated operations.
The I/O and number/string conversion modules modules for SYSTEM.[UN]SIGNED_64 are called WholeLIO, SWholeLIO, WholeLStr, WholeL_Str, WholeLConv. Since they are similar to the Whole* modules, their definition is not listed below.
The extended set of library module for (S | T)_(FLOATING | COMPLEX) and [UN]SIGNED_64 are only available on AXP with MaX.
The library definitions are based on the 4th Interim WD and the minutes from the 6th WG-meeting in Tuebingen. (See also summary of changes in Report from the 6th ISO SC22/WG13 Modula-2 WG Meeting in [1, 7.1]. For the 5th ed. of this article, the electronic distribution of sc22.wg13 of Feb-1993 was used as a reference.)
No warranty for correctness is given and no guarantee can be given that this set of definitions exactly matches those of the soon-to-be-released ISO Modula-2 Standard. Some minor changes concerning the exception handling enumeration values and procedures were already agreed at the ISO meeting in Delft Sep-92.
These changes were not yet included in the 4th ed. of this article, since the resulting 2nd CD of ISO 10154 (Modula-2) was published in late Dec-1992 and was not available to the national bodies before Jan-1993.
ModulaWare apologizes for these changes and for the inconveniences this might imply, but the ISO committee changed their mind virtually with every release of a working or committee draft. Even the simplest renamings of identifiers creates a lot of uncreative maintainance work. The Draft International Standard (DIS) was finally released in 1994 and approved (by majority vote) in Jan-1995.
In summary here are the most important changes introduced with the 2nd CD together with some migration hints for existing application programs using the previous version of the ISO M2 Std Lib:
Further test and example programs are contained in The ModulaTor, Mar-1992 (mdlt20). The Oberon-2 interfaces to this Modula-2 implementation of the OSO M2 Std Lib is contained in The ModulaTor, Sep-92 (mdlt26). Implementation specific extensions are marked with an *
The comment description contained in the definition modules uses wide margins lines with more than 80 characters; this is the original format of the DIS.
________________________________________________________________________
IOConsts
DEFINITION MODULE IOConsts;
(* Types and constants for input/output modules *)
TYPE
ReadResults = (* This type is used to classify the result of an input operation *)
(
notKnown, (* no read result is set *)
allRight, (* data is as expected or as required *)
outOfRange, (* data cannot be represented *)
wrongFormat, (* data not in expected format *)
endOfLine, (* end of line seen before expected data *)
endOfInput (* end of input seen before expected data *)
);
END IOConsts.
________________________________________________________________________
ChanConsts
DEFINITION MODULE ChanConsts;
(* Common types and values for channel open requests and results *)
TYPE
ChanFlags = (* Request flags possibly given when a channel is opened *)
( readFlag, (* input operations are requested/available *)
writeFlag, (* output operations are requested/available *)
oldFlag, (* a file may/must/did exist before the channel is opened *)
textFlag, (* text operations are requested/available *)
rawFlag, (* raw operations are requested/available *)
interactiveFlag, (* interactive use is requested/applies *)
echoFlag (* echoing by interactive device on removal of characters from input
stream requested/applies *)
);
FlagSet = SET OF ChanFlags;
(* Singleton values of FlagSet, to allow for example, read + write *)
CONST
read = FlagSet{readFlag}; (* input operations are requested/available *)
write = FlagSet{writeFlag}; (* output operations are requested/available *)
old = FlagSet{oldFlag}; (* a file may/must/did exist before the channel is opened *)
text = FlagSet{textFlag}; (* text operations are requested/available *)
raw = FlagSet{rawFlag}; (* raw operations are requested/available *)
interactive = FlagSet{interactiveFlag}; (* interactive use is requested/applies *)
echo = FlagSet{echoFlag}; (* echoing by interactive device on removal of characters from
input stream requested/applies *)
TYPE
OpenResults = (* Possible results of open requests *)
(opened, (* the open succeeded as requested *)
wrongNameFormat, (* given name is in the wrong format for the implementation *)
wrongFlags, (* given flags include a value that does not apply to the device *)
tooManyOpen, (* this device cannot support any more open channels *)
outOfChans, (* no more channels can be allocated *)
wrongPermissions, (* file or directory permissions do not allow request *)
noRoomOnDevice, (* storage limits on the device prevent the open *)
noSuchFile, (* a needed file does not exist *)
fileExists, (* a file of the given name already exists when a new one is required *)
wrongFileType, (* the file is of the wrong type to support the required operations *)
noTextOperations, (* text operations have been requested, but are not supported *)
noRawOperations, (* raw operations have been requested, but are not supported *)
noMixedOperations,(* text and raw operations have been requested, but they
are not supported in combination *)
alreadyOpen, (* the source/destination is already open for operations not supported
in combination with the requested operations *)
otherProblem (* open failed for some other reason *)
);
END ChanConsts.
________________________________________________________________________
IOChan
DEFINITION MODULE IOChan;
(* Types and procedures forming the interface to channels for device-independent data
transfer modules
*)
IMPORT IOConsts, ChanConsts, SYSTEM;
TYPE
ChanId; (* Values of this type are used to identify channels *)
(* There is one pre-defined value identifying an invalid channel on which no data transfer
operations are available. It may be used to initialize variables of type ChanId.
*)
PROCEDURE InvalidChan (): ChanId;
(* Returns the value identifying the invalid channel. *)
(* For each of the following operations, if the device supports the operation on the
channel, the behaviour of the procedure conforms with the description below. The full
behaviour is defined for each device module. If the device does not support the
operation on the channel, the behaviour of the procedure is to raise the exception
notAvailable.
*)
(* Text operations - these perform any required translation between the internal and
external representation of text.
*)
PROCEDURE Look (cid: ChanId; VAR ch: CHAR; VAR res: IOConsts.ReadResults);
(* If there is a character as the next item in the input stream cid, assigns its value to
ch without removing it from the stream; otherwise the value of ch is not defined. res
(and the stored read result) are set to the value allRight, endOfLine, or endOfInput.
*)
PROCEDURE Skip (cid: ChanId);
(* If the input stream cid has ended, the exception skipAtEnd is raised; otherwise the
next character or line mark in cid is removed, and the stored read result is set to the
value allRight.
*)
PROCEDURE SkipLook (cid: ChanId; VAR ch: CHAR; VAR res: IOConsts.ReadResults);
(* If the input stream cid has ended, the exception skipAtEnd is raised; otherwise the
next character or line mark in cid is removed. If there is a character as the next
item in cid stream, assigns its value to ch without removing it from the stream.
Otherwise, the value of ch is not defined. res (and the stored read result) are set to
the value allRight, endOfLine, or endOfInput.
*)
PROCEDURE WriteLn (cid: ChanId);
(* Writes a line mark over the channel cid. *)
PROCEDURE TextRead (cid: ChanId; to: SYSTEM.ADDRESS; maxChars: CARDINAL;
VAR charsRead: CARDINAL);
(* Reads at most maxChars characters from the current line in cid, and assigns
corresponding values to successive components of an ARRAY OF CHAR variable for which
the address of the first component is to. The number of characters read is assigned
to charsRead. The stored read result is set to allRight, endOfLine, or endOfInput.
*)
PROCEDURE TextWrite (cid: ChanId; from: SYSTEM.ADDRESS; charsToWrite: CARDINAL);
(* Writes a number of characters given by the value of charsToWrite, from successive
components of an ARRAY OF CHAR variable for which the address of the first component
is from, to the channel cid.
*)
(* Direct raw operations - these do not effect translation between the internal and
external representation of data
*)
PROCEDURE RawRead (cid: ChanId; to: SYSTEM.ADDRESS; maxLocs: CARDINAL;
VAR locsRead: CARDINAL);
(* Reads at most maxLocs items from cid, and assigns corresponding values to successive
components of an ARRAY OF LOC variable for which the address of the first component
is to. The number of characters read is assigned to charsRead. The stored read result
is set to the value allRight, or endOfInput.
*)
PROCEDURE RawWrite (cid: ChanId; from: SYSTEM.ADDRESS; locsToWrite: CARDINAL);
(* Writes a number of items given by the value of charsToWrite, from successive
components of an ARRAY OF LOC variable for which the address of the first component
is from, to the channel cid.
*)
(* Common operations *)
PROCEDURE GetName (cid: ChanId; VAR s: ARRAY OF CHAR);
(* Copies to s a name associated with the channel cid, possibly truncated
(depending on the capacity of s).
*)
PROCEDURE Reset (cid: ChanId);
(* Resets the channel cid to a state defined by the device module. *)
PROCEDURE Flush (cid: ChanId);
(* Flushes any data buffered by the device module out to the channel cid. *)
(* Access to read results *)
PROCEDURE SetReadResult (cid: ChanId; res: IOConsts.ReadResults);
(* Sets the read result value for the channel cid to the value res. *)
PROCEDURE ReadResult (cid: ChanId): IOConsts.ReadResults;
(* Returns the stored read result value for the channel cid. (This is initially the value
notKnown).
*)
(* Users can discover which flags actually apply to a channel *)
PROCEDURE CurrentFlags (cid: ChanId): ChanConsts.FlagSet;
(* Returns the set of flags that currently apply to the channel cid. *)
(* The following exceptions are defined for this module and its clients *)
TYPE
ChanExceptions =
(wrongDevice, (* device specific operation on wrong device *)
notAvailable, (* operation attempted that is not available on that channel *)
skipAtEnd, (* attempt to skip data from a stream that has ended *)
softDeviceError, (* device specific recoverable error *)
hardDeviceError, (* device specific non-recoverable error *)
textParseError, (* input data does not correspond to a character or line mark -
optional detection *)
notAChannel (* given value does not identify a channel - optional detection *)
);
PROCEDURE IsChanException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception from ChanExceptions;
otherwise returns FALSE.
*)
PROCEDURE ChanException (): ChanExceptions;
(* If the current coroutine is in the exceptional execution state because of the
raising of an exception from ChanExceptions, returns the corresponding
enumeration value, and otherwise raises an exception.
*)
(* When a device procedure detects a device error, it raises the exception softDeviceError
or hardDeviceError. If these exceptions are handled, the following facilities may be
used to discover an implementation-defined error number for the channel.
*)
TYPE
DeviceErrNum = INTEGER;
PROCEDURE DeviceError (cid: ChanId): DeviceErrNum;
(* If a device error exception has been raised for the channel cid, returns the error
number stored by the device module.
*)
END IOChan.
________________________________________________________________________
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.
*)
PROCEDURE AllocateDeviceId (VAR did: DeviceId);
(* Allocates a unique value of type DeviceId, and assigns this value to did. *)
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.
*)
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 = POINTER TO DeviceTable;
(* Values of this type are used to refer to device tables *)
TYPE
LookProc = PROCEDURE (DeviceTablePtr, VAR CHAR, VAR IOConsts.ReadResults);
SkipProc = PROCEDURE (DeviceTablePtr);
SkipLookProc = PROCEDURE (DeviceTablePtr, VAR CHAR, VAR IOConsts.ReadResults);
WriteLnProc = PROCEDURE (DeviceTablePtr);
TextReadProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL, VAR CARDINAL);
TextWriteProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL);
RawReadProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL, VAR CARDINAL);
RawWriteProc = PROCEDURE (DeviceTablePtr, SYSTEM.ADDRESS, CARDINAL);
GetNameProc = PROCEDURE (DeviceTablePtr, VAR ARRAY OF CHAR);
ResetProc = PROCEDURE (DeviceTablePtr);
FlushProc = PROCEDURE (DeviceTablePtr);
FreeProc = PROCEDURE (DeviceTablePtr);
(* Carry out the operations involved in closing the corresponding channel, including
flushing buffers, but do not unmake the channel.
*)
TYPE
DeviceData = SYSTEM.ADDRESS;
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: *)
TYPE
DevExceptionRange = [IOChan.notAvailable .. IOChan.textParseError];
PROCEDURE DeviceTablePtrValue (cid: IOChan.ChanId; did: DeviceId;
x: DevExceptionRange; s: ARRAY OF CHAR): DeviceTablePtr;
(* 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.
*)
PROCEDURE IsDevice (cid: IOChan.ChanId; did: DeviceId) : BOOLEAN;
(* Tests if the device module identified by did is the module that made the channel
identified by cid.
*)
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.
*)
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.
*)
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.
________________________________________________________________________
RawIO
DEFINITION MODULE RawIO;
(* Reading and writing data over specified channels using raw operations, that is, with no
conversion or interpretation. The read result is of the type IOConsts.ReadResults.
*)
IMPORT IOChan, SYSTEM;
PROCEDURE Read (cid: IOChan.ChanId; VAR to: ARRAY OF SYSTEM.LOC);
(* Reads storage units from cid, and assigns them to successive components of to. The read
result is set to the value allRight, wrongFormat, or endOfInput.
*)
PROCEDURE Write (cid: IOChan.ChanId; from: ARRAY OF SYSTEM.LOC);
(* Writes storage units to cid from successive components of from. *)
END RawIO.
________________________________________________________________________
TextIO
DEFINITION MODULE TextIO;
(* Input and output of character and string types over specified channels.
The read result is of the type IOConsts.ReadResults.
*)
IMPORT IOChan;
(* The following procedures do not read past line marks *)
PROCEDURE ReadChar (cid: IOChan.ChanId; VAR ch: CHAR);
(* If possible, removes a character from the input stream cid and assigns the
corresponding value to ch. The read result is set to the value allRight, endOfLine, or
endOfInput.
*)
PROCEDURE ReadRestLine (cid: IOChan.ChanId; VAR s: ARRAY OF CHAR);
(* Removes any remaining characters from the input stream cid before the next line mark,
copying to s as many as can be accommodated as a string value. The read result is set
to the value allRight, outOfRange, endOfLine, or endOfInput.
*)
PROCEDURE ReadString (cid: IOChan.ChanId; VAR s: ARRAY OF CHAR);
(* Removes only those characters from the input stream cid before the next line mark that
can be accommodated in s as a string value, and copies them to s. The read result is
set to the value allRight, endOfLine, or endOfInput.
*)
PROCEDURE ReadToken (cid: IOChan.ChanId; VAR s: ARRAY OF CHAR);
(* Skips leading spaces, and then removes characters from the input stream cid before the
next space or line mark, copying to s as many as can be accommodated as a string value.
The read result is set to the value allRight, outOfRange, endOfLine, or endOfInput.
*)
(* The following procedure reads past the next line mark *)
PROCEDURE SkipLine (cid: IOChan.ChanId);
(* Removes successive items from the input stream cid up to and including the next line
mark, or until the end of input is reached. The read result is set to the value
allRight, or endOfInput.
*)
(* Output procedures *)
PROCEDURE WriteChar (cid: IOChan.ChanId; ch: CHAR);
(* Writes the value of ch to the output stream cid. *)
PROCEDURE WriteLn (cid: IOChan.ChanId);
(* Writes a line mark to the output stream cid. *)
PROCEDURE WriteString (cid: IOChan.ChanId; s: ARRAY OF CHAR);
(* Writes the string value in s to the output stream cid. *)
END TextIO.
________________________________________________________________________
RealIO
DEFINITION MODULE RealIO;
(* Input and output of real numbers in decimal text form over specified channels.
The read result is of the type IOConsts.ReadResults.
*)
IMPORT IOChan;
(* The text form of a signed fixed-point real number is
["+" | "-"], decimal digit, {decimal digit},
[".", {decimal digit}]
The text form of a signed floating-point real number is
signed fixed-point real number,
"E", ["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE ReadReal (cid: IOChan.ChanId; VAR real: REAL);
(* Skips leading spaces, and removes any remaining characters from cid that form part of a
signed fixed or floating point number. The value of this number is assigned to real.
The read result is set to the value allRight, outOfRange, wrongFormat, endOfLine, or
endOfInput.
*)
PROCEDURE WriteFloat (cid: IOChan.ChanId; real: REAL; sigFigs: CARDINAL; width:
CARDINAL);
(* Writes the value of real to cid in floating-point text form, with sigFigs significant
figures, in a field of the given minimum width.
*)
PROCEDURE WriteEng (cid: IOChan.ChanId; real: REAL; sigFigs: CARDINAL; width: CARDINAL);
(* As for WriteFloat, except that the number is scaled with one to three digits in the
whole number part, and with an exponent that is a multiple of three.
*)
PROCEDURE WriteFixed (cid: IOChan.ChanId; real: REAL; place: INTEGER; width: CARDINAL);
(* Writes the value of real to cid in fixed-point text form, rounded to the given place
relative to the decimal point, in a field of the given minimum width.
*)
PROCEDURE WriteReal (cid: IOChan.ChanId; real: REAL; width: CARDINAL);
(* Writes the value of real to cid, as WriteFixed if the sign and magnitude can be shown
in the given width, or otherwise as WriteFloat. The number of places or significant
digits depends on the given width.
*)
END RealIO.
________________________________________________________________________
LongIO
DEFINITION MODULE LongIO;
(* Input and output of long real numbers in decimal text form over specified channels.
The read result is of the type IOConsts.ReadResults.
*)
IMPORT IOChan;
(* The text form of a signed fixed-point real number is
["+" | "-"], decimal digit, {decimal digit}, [".", {decimal digit}]
The text form of a signed floating-point real number is
signed fixed-point real number,
"E", ["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE ReadReal (cid: IOChan.ChanId; VAR real: LONGREAL);
(* Skips leading spaces, and removes any remaining characters from cid that form part of a
signed fixed or floating point number. The value of this number is assigned to real.
The read result is set to the value allRight, outOfRange, wrongFormat, endOfLine, or
endOfInput.
*)
PROCEDURE WriteFloat (cid: IOChan.ChanId; real: LONGREAL; sigFigs: CARDINAL; width: CARDINAL);
(* Writes the value of real to cid in floating-point text form, with sigFigs significant
figures, in a field of the given minimum width.
*)
PROCEDURE WriteEng (cid: IOChan.ChanId; real: LONGREAL; sigFigs: CARDINAL; width: CARDINAL);
(* As for WriteFloat, except that the number is scaled with one to three digits in the
whole number part, and with an exponent that is a multiple of three.
*)
PROCEDURE WriteFixed (cid: IOChan.ChanId; real: LONGREAL; place: INTEGER; width: CARDINAL);
(* Writes the value of real to cid in fixed-point text form, rounded to the given place
relative to the decimal point, in a field of the given minimum width.
*)
PROCEDURE WriteReal (cid: IOChan.ChanId; real: LONGREAL; width: CARDINAL);
(* Writes the value of real to cid, as WriteFixed if the sign and magnitude can be shown
in the given width, or otherwise as WriteFloat. The number of places or significant
digits depends on the given width.
*)
END LongIO.
________________________________________________________________________
LongGIO
DEFINITION MODULE LongGIO;
(* ISO Modula-2 Standard Library extension,
(AXP | VAX) / OpenVMS implementation
Based on LongIO
(C) 1994 by ModulaWare GmbH,
CS/09-Mar-1994
*)
IMPORT IOChan;
IMPORT SYSTEM;
TYPE LONGREAL = SYSTEM.G_FLOATING;
(* The text form of a signed fixed-point real number is
["+" | "-"], decimal digit, {decimal digit}, [".", {decimal digit}]
The text form of a signed floating-point real number is
signed fixed-point real number,
"E", ["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE ReadReal (cid: IOChan.ChanId; VAR real: LONGREAL);
(* Skips leading spaces, and removes any remaining characters from cid that form part of a
signed fixed or floating point number. The value of this number is assigned to real.
The read result is set to the value allRight, outOfRange, wrongFormat, endOfLine, or
endOfInput.
*)
PROCEDURE WriteFloat (cid: IOChan.ChanId; real: LONGREAL; sigFigs: CARDINAL; width: CARDINAL);
(* Writes the value of real to cid in floating-point text form, with sigFigs significant
figures, in a field of the given minimum width.
*)
PROCEDURE WriteEng (cid: IOChan.ChanId; real: LONGREAL; sigFigs: CARDINAL; width: CARDINAL);
(* As for WriteFloat, except that the number is scaled with one to three digits in the
whole number part, and with an exponent that is a multiple of three.
*)
PROCEDURE WriteFixed (cid: IOChan.ChanId; real: LONGREAL; place: INTEGER; width: CARDINAL);
(* Writes the value of real to cid in fixed-point text form, rounded to the given place
relative to the decimal point, in a field of the given minimum width.
*)
PROCEDURE WriteReal (cid: IOChan.ChanId; real: LONGREAL; width: CARDINAL);
(* Writes the value of real to cid, as WriteFixed if the sign and magnitude can be shown
in the given width, or otherwise as WriteFloat. The number of places or significant
digits depends on the given width.
*)
END LongGIO.
________________________________________________________________________
WholeIO
DEFINITION MODULE WholeIO;
(* Input and output of whole numbers in decimal text form over specified channels.
The read result is of the type IOConsts.ReadResults.
*)
IMPORT IOChan;
(* The text form of a signed whole number is
["+" | "-"], decimal digit, {decimal digit}
The text form of an unsigned whole number is
decimal digit, {decimal digit}
*)
PROCEDURE ReadInt (cid: IOChan.ChanId; VAR int: INTEGER);
(* Skips leading spaces, and removes any remaining characters from cid that form part of a
signed whole number. The value of this number is assigned to int. The read result is
set to the value allRight, outOfRange, wrongFormat, endOfLine, or endOfInput.
*)
PROCEDURE WriteInt (cid: IOChan.ChanId; int: INTEGER; width: CARDINAL);
(* Writes the value of int to cid in text form, in a field of the given minimum width. *)
PROCEDURE ReadCard (cid: IOChan.ChanId; VAR card: CARDINAL);
(* Skips leading spaces, and removes any remaining characters from cid that form part of
an unsigned whole number. The value of this number is assigned to card. The read
result is set to the value allRight, outOfRange, wrongFormat, endOfLine, or endOfInput.
*)
PROCEDURE WriteCard (cid: IOChan.ChanId; card: CARDINAL; width: CARDINAL);
(* Writes the value of card to cid in text form, in a field of the given minimum width. *)
END WholeIO.
________________________________________________________________________
IOResult
DEFINITION MODULE IOResult;
(* Read results for specified channels *)
IMPORT IOConsts, IOChan;
TYPE
ReadResults = IOConsts.ReadResults;
(*
ReadResults = (* This type is used to classify the result of an input operation *)
(
notKnown, (* no read result is set *)
allRight, (* data is as expected or as required *)
outOfRange, (* data cannot be represented *)
wrongFormat, (* data not in expected format *)
endOfLine, (* end of line seen before expected data *)
endOfInput (* end of input seen before expected data *)
);
*)
PROCEDURE ReadResult (cid: IOChan.ChanId): ReadResults;
(* Returns the result for the last read operation on the channel cid. *)
END IOResult.
________________________________________________________________________
TermFile
DEFINITION MODULE TermFile;
(* Access to the terminal device *)
(* Channels opened by this module are connected to a single terminal device; typed
characters are distributed between channels according to the sequence of read requests.
*)
IMPORT IOChan, ChanConsts;
TYPE
ChanId = IOChan.ChanId;
FlagSet = ChanConsts.FlagSet;
OpenResults = ChanConsts.OpenResults;
(* Accepted singleton values of FlagSet *)
CONST
read = FlagSet{ChanConsts.readFlag}; (* input operations are requested/available *)
write = FlagSet{ChanConsts.writeFlag}; (* output operations are requested/available *)
text = FlagSet{ChanConsts.textFlag}; (* text operations are requested/available *)
raw = FlagSet{ChanConsts.rawFlag}; (* raw operations are requested/available *)
echo = FlagSet{ChanConsts.echoFlag}; (* echoing by interactive device on reading of
characters from input stream requested/applies
*)
PROCEDURE Open (VAR cid: ChanId; flags: FlagSet; VAR res: OpenResults);
(* Attempts to obtain and open a channel connected to the terminal.
Without the raw flag, text is implied.
Without the echo flag, line mode is requested, otherwise single character mode is
requested.
If successful, assigns to cid the identity of the opened channel, and assigns the value
opened to res.
If a channel cannot be opened as required, the value of res indicates the reason, and
cid identifies the invalid channel.
*)
PROCEDURE IsTermFile (cid: ChanId): BOOLEAN;
(* Tests if the channel identified by cid is open to the terminal. *)
PROCEDURE Close (VAR cid: ChanId);
(* If the channel identified by cid is not open to the terminal, the exception wrongDevice
is raised; otherwise closes the channel and assigns the value identifying the invalid
channel to cid.
*)
END TermFile.
________________________________________________________________________
RndFile
DEFINITION MODULE RndFile;
(* Random access files *)
IMPORT IOChan, ChanConsts, SYSTEM;
TYPE
ChanId = IOChan.ChanId;
FlagSet = ChanConsts.FlagSet;
OpenResults = ChanConsts.OpenResults;
(* Accepted singleton values of FlagSet *)
CONST
read = FlagSet{ChanConsts.readFlag}; (* input operations are requested/available *)
write = FlagSet{ChanConsts.writeFlag}; (* output operations are requested/available *)
old = FlagSet{ChanConsts.oldFlag}; (* a file may/must/did exist before the channel is
opened *)
text = FlagSet{ChanConsts.textFlag}; (* text operations are requested/available *)
raw = FlagSet{ChanConsts.rawFlag}; (* raw operations are requested/available *)
PROCEDURE OpenOld (VAR cid: ChanId; name: ARRAY OF CHAR; flags: FlagSet;
VAR res: OpenResults);
(* Attempts to obtain and open a channel connected to a stored random access file of the
given name.
The old flag is implied; without the write flag, read is implied; without the text
flag, raw is implied.
If successful, assigns to cid the identity of the opened channel, assigns the value
opened to res, and sets the read/write position to the start of the file.
If a channel cannot be opened as required, the value of res indicates the reason, and
cid identifies the invalid channel.
*)
PROCEDURE OpenClean (VAR cid: ChanId; name: ARRAY OF CHAR; flags: FlagSet;
VAR res: OpenResults);
(* Attempts to obtain and open a channel connected to a stored random access file of the
given name.
The write flag is implied; without the text flag, raw is implied.
If successful, assigns to cid the identity of the opened channel, assigns the value
opened to res, and truncates the file to zero length.
If a channel cannot be opened as required, the value of res indicates the reason, and
cid identifies the invalid channel.
*)
PROCEDURE IsRndFile (cid: ChanId): BOOLEAN;
(* Tests if the channel identified by cid is open to a random access file. *)
PROCEDURE IsRndFileException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state because
of the raising of a RndFile exception; otherwise returns FALSE.
*)
(* ISO-Definition:
CONST
FilePosSize = <implementation-defined whole number greater than zero>;
TYPE
FilePos = ARRAY [1 .. FilePosSize] OF SYSTEM.LOC;
*)
(*temporary definition for MVR V3: *)
CONST
FilePosSize = SYSTEM.TSIZE(SYSTEM.QUADWORD);
TYPE
FilePos = SYSTEM.QUADWORD; (*ARRAY[1..FilePosSize] OF SYSTEM.LOC;*)
PROCEDURE StartPos (cid: ChanId): FilePos;
(* If the channel identified by cid is not open to a random access file, the exception
wrongDevice is raised; otherwise returns the position of the start of the file.
*)
PROCEDURE CurrentPos (cid: ChanId): FilePos;
(* If the channel identified by cid is not open to a random access file, the exception
wrongDevice is raised; otherwise returns the position of the current read/write
position.
*)
PROCEDURE EndPos (cid: ChanId): FilePos;
(* If the channel identified by cid is not open to a random access file, the exception
wrongDevice is raised; otherwise returns the first position after which there have been
no writes.
*)
PROCEDURE NewPos (cid: ChanId; chunks: INTEGER; chunkSize: CARDINAL; from: FilePos): FilePos;
(* If the channel identified by cid is not open to a random access file, the exception
wrongDevice is raised; otherwise returns the position (chunks * chunkSize) relative to
the position given by from, or raises the exception posRange if the required position
cannot be represented as a value of type FilePos.
*)
PROCEDURE SetPos (cid: ChanId; pos: FilePos);
(* If the channel identified by cid is not open to a random access file, the exception
wrongDevice is raised; otherwise sets the read/write position to the value given by
pos.
*)
PROCEDURE Close (VAR cid: ChanId);
(* If the channel identified by cid is not open to a random access file, the exception
wrongDevice is raised; otherwise closes the channel, and assigns the value identifying
the invalid channel to cid.
*)
END RndFile.
________________________________________________________________________
SeqFile
DEFINITION MODULE SeqFile;
(* Rewindable sequential files *)
IMPORT IOChan, ChanConsts;
TYPE
ChanId = IOChan.ChanId;
FlagSet = ChanConsts.FlagSet;
OpenResults = ChanConsts.OpenResults;
(* Accepted singleton values of FlagSet *)
CONST
read = FlagSet{ChanConsts.readFlag}; (* input operations are requested/available *)
write = FlagSet{ChanConsts.writeFlag}; (* output operations are requested/available *)
old = FlagSet{ChanConsts.oldFlag}; (* a file may/must/did exist before the channel is
opened *)
text = FlagSet{ChanConsts.textFlag}; (* text operations are requested/available *)
raw = FlagSet{ChanConsts.rawFlag}; (* raw operations are requested/available *)
PROCEDURE OpenWrite (VAR cid: ChanId; name: ARRAY OF CHAR; flags: FlagSet;
VAR res: OpenResults);
(* Attempts to obtain and open a channel connected to a stored rewindable file of the
given name.
The write flag is implied; without the raw flag, text is implied.
If successful, assigns to cid the identity of the opened channel, assigns the value
opened to res, and selects output mode, with the write position at the start of the
file (i.e. the file is of zero length).
If a channel cannot be opened as required, the value of res indicates the reason, and
cid identifies the invalid channel.
*)
PROCEDURE OpenAppend (VAR cid: ChanId; name: ARRAY OF CHAR; flags: FlagSet;
VAR res: OpenResults);
(* Attempts to obtain and open a channel connected to a stored rewindable file of the
given name.
The write and old flags are implied; without the raw flag, text is implied.
If successful, assigns to cid the identity of the opened channel, assigns the value
opened to res, and selects output mode, with the write position corresponding to the
length of the file.
If a channel cannot be opened as required, the value of res indicates the reason, and
cid identifies the invalid channel.
*)
PROCEDURE OpenRead (VAR cid: ChanId; name: ARRAY OF CHAR; flags: FlagSet;
VAR res: OpenResults);
(* Attempts to obtain and open a channel connected to a stored rewindable file of the
given name.
The read and old flags are implied; without the raw flag, text is implied.
If successful, assigns to cid the identity of the opened channel, assigns the value
opened to res, and selects input mode, with the read position corresponding to the
start of the file.
If a channel cannot be opened as required, the value of res indicates the reason, and
cid identifies the invalid channel.
*)
PROCEDURE IsSeqFile (cid: ChanId): BOOLEAN;
(* Tests if the channel identified by cid is open to a rewindable sequential file. *)
PROCEDURE Reread (cid: ChanId);
(* If the channel identified by cid is not open to a rewindable sequential file, the
exception wrongDevice is raised; otherwise attempts to set the read position to the
start of the file, and to select input mode.
If the operation cannot be performed (perhaps because of insufficient permissions)
neither input mode nor output mode is selected.
*)
PROCEDURE Rewrite (cid: ChanId);
(* If the channel identified by cid is not open to a rewindable sequential file, the
exception wrongDevice is raised; otherwise, attempts to truncate the file to zero
length, and to select output mode.
If the operation cannot be performed (perhaps because of insufficient permissions)
neither input mode nor output mode is selected.
*)
PROCEDURE Close (VAR cid: ChanId);
(* If the channel identified by cid is not open to a rewindable sequential file, the
exception wrongDevice is raised; otherwise closes the channel, and assigns the value
identifying the invalid channel to cid.
*)
END SeqFile.
________________________________________________________________________
StreamFile
DEFINITION MODULE StreamFile;
(* Independent sequential data streams *)
IMPORT IOChan, ChanConsts;
TYPE
ChanId = IOChan.ChanId;
FlagSet = ChanConsts.FlagSet;
OpenResults = ChanConsts.OpenResults;
(* Accepted singleton values of FlagSet *)
CONST
read = FlagSet{ChanConsts.readFlag}; (* input operations are requested/available *)
write = FlagSet{ChanConsts.writeFlag}; (* output operations are requested/available *)
old = FlagSet{ChanConsts.oldFlag}; (* a file may/must/did exist before the channel is
opened *)
text = FlagSet{ChanConsts.textFlag}; (* text operations are requested/available *)
raw = FlagSet{ChanConsts.rawFlag}; (* raw operations are requested/available *)
PROCEDURE Open (VAR cid: ChanId; name: ARRAY OF CHAR; flags: FlagSet; VAR res: OpenResults);
(* Attempts to obtain and open a channel connected to a sequential stream of the given
name.
The read flag implies old; without the raw flag, text is implied.
If successful, assigns to cid the identity of the opened channel, and assigns the value
opened to res.
If a channel cannot be opened as required, the value of res indicates the reason, and
cid identifies the invalid channel.
*)
PROCEDURE IsStreamFile (cid: ChanId): BOOLEAN;
(* Tests if the channel identified by cid is open to a sequential stream. *)
PROCEDURE Close (VAR cid: ChanId);
(* If the channel identified by cid is not open to a sequential stream, the exception
wrongDevice is raised; otherwise closes the channel, and assigns the value identifying
the invalid channel to cid.
*)
END StreamFile.
________________________________________________________________________
ProgramArgs
DEFINITION MODULE ProgramArgs;
(* Access to program arguments *)
IMPORT IOChan;
TYPE
ChanId = IOChan.ChanId;
PROCEDURE ArgChan (): ChanId;
(* Returns a value that identifies a channel for reading program arguments *)
PROCEDURE IsArgPresent (): BOOLEAN;
(* Tests if there is a current argument to read from. If not, read <=
IOChan.CurrentFlags() will be FALSE, and attempting to read from the argument channel
will raise the exception notAvailable.
*)
PROCEDURE NextArg ();
(* If there is another argument, causes subsequent input from the argument device to come
from the start of the next argument. Otherwise there is no argument to read from, and
a call of IsArgPresent will return FALSE.
*)
END ProgramArgs.
________________________________________________________________________
StdChans
DEFINITION MODULE StdChans;
(* Access to standard and default channels *)
IMPORT IOChan;
TYPE
ChanId = IOChan.ChanId;
(* Values of this type are used to identify channels *)
(* The following functions return the standard channel values.
These channels cannot be closed.
*)
PROCEDURE StdInChan (): ChanId;
(* Returns the identity of the implementation-defined standard source for program
input.
*)
PROCEDURE StdOutChan (): ChanId;
(* Returns the identity of the implementation-defined standard source for program
output.
*)
PROCEDURE StdErrChan (): ChanId;
(* Returns the identity of the implementation-defined standard destination for program
error messages.
*)
PROCEDURE NullChan (): ChanId;
(* Returns the identity of a channel open to the null device. *)
(* The following functions return the default channel values *)
PROCEDURE InChan (): ChanId;
(* Returns the identity of the current default input channel. *)
PROCEDURE OutChan (): ChanId;
(* Returns the identity of the current default output channel. *)
PROCEDURE ErrChan (): ChanId;
(* Returns the identity of the current default error message channel. *)
(* The following procedures allow for redirection of the default channels *)
PROCEDURE SetInChan (cid: ChanId);
(* Sets the current default input channel to that identified by cid. *)
PROCEDURE SetOutChan (cid: ChanId);
(* Sets the current default output channel to that identified by cid. *)
PROCEDURE SetErrChan (cid: ChanId);
(* Sets the current default error channel to that identified by cid. *)
END StdChans.
________________________________________________________________________
String Conversions Library
________________________________________________________________________
WholeConv
DEFINITION MODULE WholeConv;
(* Low-level whole-number/string conversions *)
IMPORT
ConvTypes;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
PROCEDURE ScanInt (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
VAR nextState: ConvTypes.ScanState);
(* Represents the start state of a finite state scanner for signed whole numbers -
assigns class of inputCh to chClass and a procedure representing the next state to
nextState.
*)
PROCEDURE FormatInt (str: ARRAY OF CHAR): ConvResults;
(* Returns the format of the string value for conversion to INTEGER. *)
PROCEDURE ValueInt (str: ARRAY OF CHAR): INTEGER;
(* Returns the value corresponding to the signed whole number string value str if str
is well-formed; otherwise raises the WholeConv exception.
*)
PROCEDURE LengthInt (int: INTEGER): CARDINAL;
(* Returns the number of characters in the string representation of int. *)
PROCEDURE ScanCard (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
VAR nextState: ConvTypes.ScanState);
(* Represents the start state of a finite state scanner for unsigned whole numbers -
assigns class of inputCh to chClass and a procedure representing the next state to
nextState.
*)
PROCEDURE FormatCard (str: ARRAY OF CHAR): ConvResults;
(* Returns the format of the string value for conversion to CARDINAL. *)
PROCEDURE ValueCard (str: ARRAY OF CHAR): CARDINAL;
(* Returns the value corresponding to the unsigned whole number string value str if
str is well-formed; otherwise raises the WholeConv exception.
*)
PROCEDURE LengthCard (card: CARDINAL): CARDINAL;
(* Returns the number of characters in the string representation of card. *)
PROCEDURE IsWholeConvException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state because
of the raising of an exception in a routine from this module; otherwise returns
FALSE.
*)
END WholeConv.
________________________________________________________________________
RealConv
DEFINITION MODULE RealConv;
(* Low-level REAL/string conversions *)
IMPORT
ConvTypes;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
PROCEDURE ScanReal (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
VAR nextState: ConvTypes.ScanState);
(* Represents the start state of a finite state scanner for real numbers - assigns
class of inputCh to chClass and a procedure representing the next state to
nextState.
*)
PROCEDURE FormatReal (str: ARRAY OF CHAR): ConvResults;
(* Returns the format of the string value for conversion to REAL. *)
PROCEDURE ValueReal (str: ARRAY OF CHAR): REAL;
(* Returns the value corresponding to the real number string value str if str is
well-formed; otherwise raises the RealConv exception.
*)
PROCEDURE LengthFloatReal (real: REAL; sigFigs: CARDINAL): CARDINAL;
(* Returns the number of characters in the floating-point string representation of
real with sigFigs significant figures.
*)
PROCEDURE LengthEngReal (real: REAL; sigFigs: CARDINAL): CARDINAL;
(* Returns the number of characters in the floating-point engineering string
representation of real with sigFigs significant figures.
*)
PROCEDURE LengthFixedReal (real: REAL; place: INTEGER): CARDINAL;
(* Returns the number of characters in the fixed-point string representation of real
rounded to the given place relative to the decimal point.
*)
PROCEDURE IsRConvException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state because
of the raising of an exception in a routine from this module; otherwise returns
FALSE.
*)
END RealConv.
________________________________________________________________________
LongConv
DEFINITION MODULE LongConv;
(* Low-level LONGREAL/string conversions *)
IMPORT
ConvTypes;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
PROCEDURE ScanReal (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
VAR nextState: ConvTypes.ScanState);
(* Represents the start state of a finite state scanner for real numbers - assigns
class of inputCh to chClass and a procedure representing the next state to
nextState.
*)
PROCEDURE FormatReal (str: ARRAY OF CHAR): ConvResults;
(* Returns the format of the string value for conversion to LONGREAL. *)
PROCEDURE ValueReal (str: ARRAY OF CHAR): LONGREAL;
(* Returns the value corresponding to the real number string value str if str is
well-formed; otherwise raises the LongConv exception.
*)
PROCEDURE LengthFloatReal (real: LONGREAL; sigFigs: CARDINAL): CARDINAL;
(* Returns the number of characters in the floating-point string representation of
real with sigFigs significant figures.
*)
PROCEDURE LengthEngReal (real: LONGREAL; sigFigs: CARDINAL): CARDINAL;
(* Returns the number of characters in the floating-point engineering string
representation of real with sigFigs significant figures.
*)
PROCEDURE LengthFixedReal (real: LONGREAL; place: INTEGER): CARDINAL;
(* Returns the number of characters in the fixed-point string representation of real
rounded to the given place relative to the decimal point.
*)
PROCEDURE IsRConvException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state because
of the raising of an exception in a routine from this module; otherwise returns
FALSE.
*)
END LongConv.
________________________________________________________________________
LongGConv
DEFINITION MODULE LongGConv;
(* ISO Modula-2 Standard Library extension,
(AXP | VAX) / OpenVMS implementation
Based on LongConv
(C) 1994 by ModulaWare GmbH,
CS/09-Mar-1994
*)
IMPORT ConvTypes;
IMPORT SYSTEM;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
LONGREAL = SYSTEM.G_FLOATING;
PROCEDURE ScanReal (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
VAR nextState: ConvTypes.ScanState);
(* Represents the start state of a finite state scanner for real numbers - assigns
class of inputCh to chClass and a procedure representing the next state to
nextState.
*)
PROCEDURE FormatReal (str: ARRAY OF CHAR): ConvResults;
(* Returns the format of the string value for conversion to LONGREAL. *)
PROCEDURE ValueReal (str: ARRAY OF CHAR): LONGREAL;
(* Returns the value corresponding to the real number string value str if str is
well-formed; otherwise raises the LongConv exception.
*)
PROCEDURE LengthFloatReal (real: LONGREAL; sigFigs: CARDINAL): CARDINAL;
(* Returns the number of characters in the floating-point string representation of
real with sigFigs significant figures.
*)
PROCEDURE LengthEngReal (real: LONGREAL; sigFigs: CARDINAL): CARDINAL;
(* Returns the number of characters in the floating-point engineering string
representation of real with sigFigs significant figures.
*)
PROCEDURE LengthFixedReal (real: LONGREAL; place: INTEGER): CARDINAL;
(* Returns the number of characters in the fixed-point string representation of real
rounded to the given place relative to the decimal point.
*)
PROCEDURE IsRConvException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state because
of the raising of an exception in a routine from this module; otherwise returns
FALSE.
*)
END LongGConv.
________________________________________________________________________
ConvTypes
DEFINITION MODULE ConvTypes;
(* Common types used in the string conversion modules *)
IMPORT SYSTEM;
TYPE
ConvResults = (* Values of this type are used to express the format of a string *)
(
strAllRight, (* the string format is correct for the corresponding conversion *)
strOutOfRange, (* the string is well-formed but the value cannot be represented *)
strWrongFormat, (* the string is in the wrong format for the conversion *)
strEmpty (* the given string is empty *)
);
ScanClass = (* Values of this type are used to classify input to finite state scanners *)
(
padding, (* a leading or padding character at this point in the scan - ignore it *)
valid, (* a valid character at this point in the scan - accept it *)
invalid, (* an invalid character at this point in the scan - reject it *)
terminator (* a terminating character at this point in the scan (not part of token) *)
);
(*
ScanState = (* The type of lexical scanning control procedures *)
PROCEDURE (CHAR, VAR ScanClass, VAR ScanState);
*)
(* temporary for MVR: *)
ScanState = PROCEDURE(CHAR, VAR ScanClass, VAR SYSTEM.WORD (*ScanState*));
END ConvTypes.
________________________________________________________________________
WholeStr
DEFINITION MODULE WholeStr;
(* Whole-number/string conversions *)
IMPORT
ConvTypes;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
(* the string form of a signed whole number is
["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE StrToInt (str: ARRAY OF CHAR; VAR int: INTEGER; VAR res: ConvResults);
(* Ignores any leading spaces in str. If the subsequent characters in str are in the
format of a signed whole number, assigns a corresponding value to int. Assigns a
value indicating the format of str to res.
*)
PROCEDURE IntToStr (int: INTEGER; VAR str: ARRAY OF CHAR);
(* Converts the value of int to string form and copies the possibly truncated result to str. *)
(* the string form of an unsigned whole number is
decimal digit, {decimal digit}
*)
PROCEDURE StrToCard (str: ARRAY OF CHAR; VAR card: CARDINAL; VAR res: ConvResults);
(* Ignores any leading spaces in str. If the subsequent characters in str are in the
format of an unsigned whole number, assigns a corresponding value to card.
Assigns a value indicating the format of str to res.
*)
PROCEDURE CardToStr (card: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of card to string form and copies the possibly truncated result to str. *)
END WholeStr.
________________________________________________________________________
Whole_Str
DEFINITION MODULE Whole_Str;
(* ISO Modula-2 Standard Library extension,
(AXP | VAX) / OpenVMS implementation
Whole-number/string conversions
(C) 1994 by ModulaWare GmbH,
CS/17-Mar-1994
*)
IMPORT
ConvTypes;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
(* the string form of a signed whole number is
["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE StrToInt (str: ARRAY OF CHAR; VAR int: INTEGER; VAR res: ConvResults);
(* Ignores any leading spaces in str. If the subsequent characters in str are in the
format of a signed whole number, assigns a corresponding value to int. Assigns a
value indicating the format of str to res.
*)
PROCEDURE IntToStr (int: INTEGER; width: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of int to string form, using the requested field width,
and copies the possibly truncated result to str.
*)
(* the string form of an unsigned whole number is
decimal digit, {decimal digit}
*)
PROCEDURE StrToCard (str: ARRAY OF CHAR; VAR card: CARDINAL; VAR res: ConvResults);
(* Ignores any leading spaces in str. If the subsequent characters in str are in the
format of an unsigned whole number, assigns a corresponding value to card.
Assigns a value indicating the format of str to res.
*)
PROCEDURE CardToStr (card: CARDINAL; width: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of card to string form, using the requested field width,
and copies the possibly truncated result to str.
*)
END Whole_Str.
________________________________________________________________________
RealStr
DEFINITION MODULE RealStr;
(* REAL/string conversions *)
IMPORT
ConvTypes;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
(* the string form of a signed fixed-point real number is
["+" | "-"], decimal digit, {decimal digit}, [".", {decimal digit}]
*)
(* the string form of a signed floating-point real number is
signed fixed-point real number, "E", ["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: REAL; VAR res: ConvResults);
(* Ignores any leading spaces in str. If the subsequent characters in str are in the
format of a signed real number, assigns a corresponding value to real.
Assigns a value indicating the format of str to res.
*)
PROCEDURE RealToFloat (real: REAL; sigFigs: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, and copies the possibly truncated result to str.
*)
PROCEDURE RealToEng (real: REAL; sigFigs: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, and copies the possibly truncated result to str. The number is scaled with
one to three digits in the whole number part and with an exponent that is a
multiple of three.
*)
PROCEDURE RealToFixed (real: REAL; place: INTEGER; VAR str: ARRAY OF CHAR);
(* Converts the value of real to fixed-point string form, rounded to the given place
relative to the decimal point, and copies the possibly truncated result to str.
*)
PROCEDURE RealToStr (real: REAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real as RealToFixed if the sign and magnitude can be shown
within the capacity of str, or otherwise as RealToFloat, and copies the possibly
truncated result to str. The number of places or significant digits are
implementation-defined.
*)
END RealStr.
________________________________________________________________________
Real_Str
DEFINITION MODULE Real_Str;
(* ISO Modula-2 Standard Library extension,
(AXP | VAX) / OpenVMS implementation
REAL/string conversions
(C) 1994 by ModulaWare GmbH,
CS/09-Mar-1994
*)
IMPORT
ConvTypes;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
(* the string form of a signed fixed-point real number is
["+" | "-"], decimal digit, {decimal digit}, [".", {decimal digit}]
*)
(* the string form of a signed floating-point real number is
signed fixed-point real number, "E", ["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: REAL; VAR res: ConvResults);
(* Ignores any leading spaces in str. If the subsequent characters in str are in the
format of a signed real number, assigns a corresponding value to real.
Assigns a value indicating the format of str to res.
*)
PROCEDURE RealToFloat (real: REAL; sigFigs: CARDINAL; width: CARDINAL;
VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, using the requested field width, and copies the possibly truncated
result to str.
*)
PROCEDURE RealToEng (real: REAL; sigFigs: CARDINAL; width: CARDINAL;
VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, using the requested field width, and copies the possibly truncated
result to str. The number is scaled with one to three digits in the whole number
part and with an exponent that is a multiple of three.
*)
PROCEDURE RealToFixed (real: REAL; place: INTEGER; width: CARDINAL;
VAR str: ARRAY OF CHAR);
(* Converts the value of real to fixed-point string form, rounded to the given place
relative to the decimal point, using the requested field width, and copies the
possibly truncated result to str.
*)
PROCEDURE RealToStr (real: REAL; width: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real as RealToFixed if the sign and magnitude can be shown
in the given width, or otherwise as RealToFloat, and copies the possibly truncated
result to str. The number of places or significant digits depend on the given width.
*)
END Real_Str.
________________________________________________________________________
LongStr
DEFINITION MODULE LongStr;
(* LONGREAL/string conversions *)
IMPORT
ConvTypes;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
(* the string form of a signed fixed-point real number is
["+" | "-"], decimal digit, {decimal digit}, [".", {decimal digit}]
*)
(* the string form of a signed floating-point real number is
signed fixed-point real number, "E", ["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: LONGREAL; VAR res: ConvResults);
(* Ignores any leading spaces in str. If the subsequent characters in str are in the
format of a signed real number, assigns a corresponding value to real.
Assigns a value indicating the format of str to res.
*)
PROCEDURE RealToFloat (real: LONGREAL; sigFigs: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, and copies the possibly truncated result to str.
*)
PROCEDURE RealToEng (real: LONGREAL; sigFigs: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, and copies the possibly truncated result to str. The number is scaled with
one to three digits in the whole number part and with an exponent that is a
multiple of three.
*)
PROCEDURE RealToFixed (real: LONGREAL; place: INTEGER; VAR str: ARRAY OF CHAR);
(* Converts the value of real to fixed-point string form, rounded to the given place
relative to the decimal point, and copies the possibly truncated result to str.
*)
PROCEDURE RealToStr (real: LONGREAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real as RealToFixed if the sign and magnitude can be shown
within the capacity of str, or otherwise as RealToFloat, and copies the possibly
truncated result to str. The number of places or significant digits depend on the
capacity of str.
*)
END LongStr.
________________________________________________________________________
Long_Str
DEFINITION MODULE Long_Str;
(* ISO Modula-2 Standard Library extension,
(AXP | VAX) / OpenVMS implementation
LONGREAL/string conversions
(C) 1994 by ModulaWare GmbH,
CS/17-Mar-1994
*)
IMPORT
ConvTypes;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
(* the string form of a signed fixed-point real number is
["+" | "-"], decimal digit, {decimal digit}, [".", {decimal digit}]
*)
(* the string form of a signed floating-point real number is
signed fixed-point real number, "E", ["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: LONGREAL; VAR res: ConvResults);
(* Ignores any leading spaces in str. If the subsequent characters in str are in the
format of a signed real number, assigns a corresponding value to real.
Assigns a value indicating the format of str to res.
*)
PROCEDURE RealToFloat (real: LONGREAL; sigFigs: CARDINAL; width: CARDINAL;
VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, using the requested field width, and copies the possibly truncated
result to str.
*)
PROCEDURE RealToEng (real: LONGREAL; sigFigs: CARDINAL; width: CARDINAL;
VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, using the requested field width, and copies the possibly truncated
result to str. The number is scaled with one to three digits in the whole number
part and with an exponent that is a multiple of three.
*)
PROCEDURE RealToFixed (real: LONGREAL; place: INTEGER; width: CARDINAL;
VAR str: ARRAY OF CHAR);
(* Converts the value of real to fixed-point string form, rounded to the given place
relative to the decimal point, using the requested field width, and copies the
possibly truncated result to str.
*)
PROCEDURE RealToStr (real: LONGREAL; width: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real as RealToFixed if the sign and magnitude can be shown
in the given width, or otherwise as RealToFloat, and copies the possibly truncated
result to str. The number of places or significant digits depend on the given width.
*)
END Long_Str.
________________________________________________________________________
LongGStr
DEFINITION MODULE LongGStr;
(* ISO Modula-2 Standard Library extension,
(AXP | VAX) / OpenVMS implementation
Based on LongStr
(C) 1994 by ModulaWare GmbH,
CS/17-Mar-1994
*)
IMPORT
ConvTypes, SYSTEM;
TYPE
LONGREAL = SYSTEM.G_FLOATING;
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
(* the string form of a signed fixed-point real number is
["+" | "-"], decimal digit, {decimal digit}, [".", {decimal digit}]
*)
(* the string form of a signed floating-point real number is
signed fixed-point real number, "E", ["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: LONGREAL; VAR res: ConvResults);
(* Ignores any leading spaces in str. If the subsequent characters in str are in the
format of a signed real number, assigns a corresponding value to real.
Assigns a value indicating the format of str to res.
*)
PROCEDURE RealToFloat (real: LONGREAL; sigFigs: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, and copies the possibly truncated result to str.
*)
PROCEDURE RealToEng (real: LONGREAL; sigFigs: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, and copies the possibly truncated result to str. The number is scaled with
one to three digits in the whole number part and with an exponent that is a
multiple of three.
*)
PROCEDURE RealToFixed (real: LONGREAL; place: INTEGER; VAR str: ARRAY OF CHAR);
(* Converts the value of real to fixed-point string form, rounded to the given place
relative to the decimal point, and copies the possibly truncated result to str.
*)
PROCEDURE RealToStr (real: LONGREAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real as RealToFixed if the sign and magnitude can be shown
within the capacity of str, or otherwise as RealToFloat, and copies the possibly
truncated result to str. The number of places or significant digits depend on the
capacity of str.
*)
END LongGStr.
________________________________________________________________________
LongG_Str
DEFINITION MODULE LongG_Str;
(* ISO Modula-2 Standard Library extension,
(AXP | VAX) / OpenVMS implementation
Based on Long_Str
(C) 1994 by ModulaWare GmbH,
CS/09-Mar-1994
*)
IMPORT
ConvTypes, SYSTEM;
TYPE
ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
LONGREAL = SYSTEM.G_FLOATING;
(* the string form of a signed fixed-point real number is
["+" | "-"], decimal digit, {decimal digit}, [".", {decimal digit}]
*)
(* the string form of a signed floating-point real number is
signed fixed-point real number, "E", ["+" | "-"], decimal digit, {decimal digit}
*)
PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: LONGREAL; VAR res: ConvResults);
(* Ignores any leading spaces in str. If the subsequent characters in str are in the
format of a signed real number, assigns a corresponding value to real.
Assigns a value indicating the format of str to res.
*)
PROCEDURE RealToFloat (real: LONGREAL; sigFigs: CARDINAL; width: CARDINAL;
VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, using the requested field width, and copies the possibly truncated
result to str.
*)
PROCEDURE RealToEng (real: LONGREAL; sigFigs: CARDINAL; width: CARDINAL;
VAR str: ARRAY OF CHAR);
(* Converts the value of real to floating-point string form, with sigFigs significant
figures, using the requested field width, and copies the possibly truncated
result to str. The number is scaled with one to three digits in the whole number
part and with an exponent that is a multiple of three.
*)
PROCEDURE RealToFixed (real: LONGREAL; place: INTEGER; width: CARDINAL;
VAR str: ARRAY OF CHAR);
(* Converts the value of real to fixed-point string form, rounded to the given place
relative to the decimal point, using the requested field width, and copies the
possibly truncated result to str.
*)
PROCEDURE RealToStr (real: LONGREAL; width: CARDINAL; VAR str: ARRAY OF CHAR);
(* Converts the value of real as RealToFixed if the sign and magnitude can be shown
in the given width, or otherwise as RealToFloat, and copies the possibly truncated
result to str. The number of places or significant digits depend on the given width.
*)
END LongG_Str.
________________________________________________________________________
CharClass
DEFINITION MODULE CharClass;
(* Classification of values of the type CHAR *)
PROCEDURE IsNumeric (ch: CHAR): BOOLEAN;
(* Returns TRUE if and only if ch is classified as a numeric character *)
PROCEDURE IsLetter (ch: CHAR): BOOLEAN;
(* Returns TRUE if and only if ch is classified as a letter *)
PROCEDURE IsUpper (ch: CHAR): BOOLEAN;
(* Returns TRUE if and only if ch is classified as an upper case letter *)
PROCEDURE IsLower (ch: CHAR): BOOLEAN;
(* Returns TRUE if and only if ch is classified as a lower case letter *)
PROCEDURE IsControl (ch: CHAR): BOOLEAN;
(* Returns TRUE if and only if ch represents a control function *)
PROCEDURE IsWhiteSpace (ch: CHAR): BOOLEAN;
(* Returns TRUE if and only if ch represents a space character or a format effector *)
END CharClass.
________________________________________________________________________
________________________________________________________________________
TestCopy
MODULE TestCopy;
(* Copy a textfile with ISO-Modula-2 I/O-Library
reading the in- and out-file specification
as parameter from the command line.
Example: The OpenVMS command
$ run testcopy
$_ x.lis y.lis
copies file x.lis to file y.lis.
When installed as a foreign command, the arguments
can be specified in the command line:
$ testcopy :== $dev:[dir]testcopy.exe
$ testcopy x.lis y.lis
Copyright (1993-1996) by Guenter Dotzel
http://www.modulaware.com/
GD/1993
*)
FROM ProgramArgs IMPORT IsArgPresent, ArgChan;
FROM IOResult IMPORT ReadResults, ReadResult;
FROM SeqFile IMPORT OpenRead, OpenWrite, OpenResults,
Close, ChanId, read, write;
FROM TextIO IMPORT ReadRestLine, SkipLine, ReadToken,
WriteLn, WriteString;
IMPORT STextIO, SWholeIO;
TYPE fnam= ARRAY [0..254] OF CHAR;
VAR in,out: fnam;
ores: OpenResults;
input, output: ChanId;
line: ARRAY[0..8191] OF CHAR;
lines: INTEGER;
PROCEDURE usage;
BEGIN
STextIO.WriteString("TestCopy usage: 'testcopy IN.EXT OUT.EXT'");
STextIO.WriteLn;
END usage;
BEGIN
lines:=0;
IF IsArgPresent() THEN
ReadToken(ArgChan(), in);
IF IsArgPresent() THEN
ReadToken(ArgChan(), out);
OpenRead(input, in, read, ores);
IF ores=opened THEN
OpenWrite(output, out, write, ores);
IF ores=opened THEN
ReadRestLine(input, line);
WHILE ReadResult(input) <> endOfInput DO
IF ReadResult(input) = allRight THEN
WriteString(output, line); WriteLn(output);
INC(lines);
ELSIF ReadResult(input) = endOfLine THEN
WriteLn(output);
INC(lines);
ELSE
STextIO.WriteString("TestCopy error reading infile");
STextIO.WriteLn;
HALT;
END;
SkipLine(input); ReadRestLine(input, line);
END;
Close(input);
ELSE
STextIO.WriteString("TestCopy can't create outfile");
STextIO.WriteLn;
END;
Close(output);
STextIO.WriteString("TestCopy: endOfInput reached, lines copied=");
SWholeIO.WriteInt(lines,0);
STextIO.WriteLn;
ELSE
STextIO.WriteString("TestCopy can't open infile");
STextIO.WriteLn;
END;
ELSE usage;
END;
ELSE usage;
END;
END TestCopy.
________________________________________________________________________
________________________________________________________________________
TestSCopy
MODULE TestSCopy;
(* Same as TestCopy.mod, but copies a textfile
via redirection using the ISO-Modula-2 I/O-Library
StdChans.SetIn/OutChan
Example: The OpenVMS command
$ run testscopy
$_ x.lis y.lis
copies file x.lis to file y.lis.
When installed as a foreign command, the arguments
can be specified in the command line:
$ testscopy :== $dev:[dir]testscopy.exe
$ testscopy x.lis y.lis
Copyright (1993-1996) by Guenter Dotzel
http://www.modulaware.com/
GD/22-Nov-1996
*)
FROM ProgramArgs IMPORT IsArgPresent, ArgChan;
FROM SIOResult IMPORT ReadResults, ReadResult;
FROM SeqFile IMPORT OpenRead, OpenWrite, OpenResults,
Close, ChanId, read, write;
IMPORT STextIO, SWholeIO, SIOResult, StdChans;
FROM STextIO IMPORT ReadRestLine, SkipLine,
ReadToken, WriteLn, WriteString;
TYPE fnam= ARRAY [0..254] OF CHAR;
VAR in,out: fnam;
ores: OpenResults;
input, output: ChanId;
line: ARRAY[0..8191] OF CHAR;
lines: INTEGER;
PROCEDURE usage;
BEGIN
STextIO.WriteString("TestSCopy usage: 'testscopy IN.EXT OUT.EXT'");
STextIO.WriteLn;
END usage;
BEGIN
lines:=0;
IF IsArgPresent() THEN
StdChans.SetInChan(ArgChan());
ReadToken(in);
IF IsArgPresent() THEN
ReadToken(out);
OpenRead(input, in, read, ores);
IF ores=opened THEN
OpenWrite(output, out, write-read, ores);
StdChans.SetOutChan(output);
IF ores=opened THEN
StdChans.SetInChan(input);
ReadRestLine(line);
WHILE ReadResult() <> endOfInput DO
IF ReadResult() = allRight THEN
WriteString(line); WriteLn;
INC(lines);
ELSIF ReadResult() = endOfLine THEN
WriteLn;
INC(lines);
ELSE
StdChans.SetOutChan(StdChans.StdOutChan());
STextIO.WriteString("TestSCopy error reading infile");
STextIO.WriteLn;
HALT;
END;
SkipLine; ReadRestLine(line);
END;
Close(input);
ELSE
StdChans.SetOutChan(StdChans.StdOutChan());
STextIO.WriteString("TestSCopy can't create outfile");
STextIO.WriteLn;
END;
Close(output);
StdChans.SetOutChan(StdChans.StdOutChan());
STextIO.WriteString("TestSCopy: endOfInput reached, lines copied=");
SWholeIO.WriteInt(lines,0);
STextIO.WriteLn;
ELSE
StdChans.SetOutChan(StdChans.StdOutChan());
STextIO.WriteString("TestSCopy can't open infile");
STextIO.WriteLn;
END;
ELSE usage;
END;
ELSE usage;
END;
END TestSCopy.
________________________________________________________________________
In addition to some ISO M2 Std Lib modules, module TestSeq imports three auxiliary, private modules GetConvTime, Measures and EXCEPTIONS. Their definitions are listed below. Note, the functionality of GetConvTime and Measures could not be provided by the ISO M2 Std Lib module SysClock, since Testseq evaluates not only the elapsed time but also the cpu-time and or other information also available from Measures.GetTimer.
In MaX | MVR, Module EXCEPTIONS is not yet a pseudo module such as SYSTEM, (SYSTEM is a compiler known (built-in) module in ISO M2), although it's definition is compatible with ISO M2's EXCEPTIONS module.
Module TestSeq is followed by the command trace for compilation, linking and image execution with the output listing that it generates. The timings are actual values measured on a (relatively slow) VAXStation3100/VMS as well as on an AXP/OpenVMS system. If the performance on the VAX looks poor to you, this is due to the slow machine used and is not an indicator for a poor library implementation. Actually, except for number-to-string conversions, MaX and MVR have identical source code. From the architectural viewpoint, ModulaWare's ISO M2 Std Lib is efficiently implemented (although all run-time checks are still enabled for subranges, enumerations, and array indices).
________________________________________________________________________
GetConvTime
DEFINITION MODULE GetConvTime;
(* same as [mrkit]DateTime, but with Hundredths of a second.
(C) 1992 Guenter Dotzel, http://www.modulaware.com
*)
IMPORT SYSTEM;
TYPE TimeType= SYSTEM.QUADWORD;
(*
* Procedures Time and Date return the current time
* in system format or as a string.
*)
PROCEDURE Time(
VAR time: TimeType
);
PROCEDURE Date(
VAR date: ARRAY OF CHAR
);
(*
* The conversion procedures convert a time value from
* system format to string and vice versa.
*)
PROCEDURE ConvertTime(
time: TimeType;
VAR date: ARRAY OF CHAR
);
PROCEDURE ConvertDate(
date: ARRAY OF CHAR;
VAR time: TimeType
);
(*
* The following procedures return portions of a
* time value in system format as a cardinal
*)
PROCEDURE Year(
time: TimeType
): CARDINAL;
PROCEDURE Month(
time: TimeType
): CARDINAL;
PROCEDURE Day(
time: TimeType
): CARDINAL;
PROCEDURE Hours(
time: TimeType
): CARDINAL;
PROCEDURE Minutes(
time: TimeType
): CARDINAL;
PROCEDURE Seconds(
time: TimeType
): CARDINAL;
PROCEDURE Hundredths(
time: TimeType
): CARDINAL;
END GetConvTime.
________________________________________________________________________
Measures
DEFINITION MODULE Measures;
FROM DateTime IMPORT TimeType;
PROCEDURE InitTimer;
PROCEDURE FreeTimer;
PROCEDURE GetTimer(
VAR elapsed: TimeType;
VAR cputime: CARDINAL;
VAR bufio: CARDINAL;
VAR dirio: CARDINAL;
VAR pagefault: CARDINAL );
PROCEDURE ShowTimer;
END Measures.
________________________________________________________________________
EXCEPTIONS
DEFINITION MODULE EXCEPTIONS;
(* Provides facilities for raising user exceptions
and for making enquiries concerning the current execution state.
*)
TYPE
ExceptionSource; (* values of this type are used within library modules to
identify the source of raised exceptions
*)
ExceptionNumber = CARDINAL;
PROCEDURE AllocateSource(VAR newSource: ExceptionSource);
(* Allocates a unique value of type ExceptionSource *)
PROCEDURE RAISE (source: ExceptionSource; number: ExceptionNumber; message: ARRAY OF CHAR);
(* Associates the given values of source, number and message with the current context
and raises an exception.
*)
PROCEDURE CurrentNumber (source: ExceptionSource): ExceptionNumber;
(* If the current coroutine is in the exceptional execution state because of the raising
of an exception from source, returns the corresponding number, and otherwise
raises an exception.
*)
PROCEDURE GetMessage (VAR text: ARRAY OF CHAR);
(* If the current coroutine is in the exceptional execution state, returns the possibly
truncated string associated with the current context.
Otherwise, in normal execution state, returns the empty string.
*)
PROCEDURE IsCurrentSource (source: ExceptionSource): BOOLEAN;
(* If the current coroutine is in the exceptional execution state because of the raising
of an exception from source, returns TRUE, and otherwise returns FALSE.
*)
PROCEDURE IsExceptionalExecution (): BOOLEAN;
(* If the current coroutine is in the exceptional execution state because of the raising
of an exception, returns TRUE, and otherwise returns FALSE.
*)
END EXCEPTIONS.
________________________________________________________________________
TestSeq
MODULE TestSeq;
(*
Test program for
ISO 10154 Modula-2 Standard Library [Extension] of
MaX|MVR V4 Modula-2 Compiler for AXP|VAX/OpenVMS
Distribution Kit
Copyright (1994) Guenter Dotzel, ModulaWare,
http://www.modulaware.com/
This software source code constitutes intellectual property
rights of Guenter Dotzel, ModulaWare and is furnished under a
Non-Disclosure Agreement and may only be used, processed
and stored according to the terms and conditions of this agreement.
All rights reserved.
This is an extended performance test program written in Oberon-2 for the ISO Modula-2 Std I/O-Lib. TestSeq reads/writes whole data structures and single bytes from/to binary and text files and evaluates the individual data transfer speed in Bytes/Second (elapsed- and CPU-time). The actual timings when run on a VAX and AXP workstations are also provided below. when comparing the speed with other libs, note that run-time checks are still enabled in our ISO M2 Std library implementation. Also, the elapsed time is varying and depends heavily on the server activities.
TestSeq creates two temporary files: BINA.LIS and TEXT.LIS which are truncated to zero size ad the end.
An Oberon-2 version of TestSeq is also available on request.
Written by Elmar Baumgart, 01-Sep-1992.
Revised by GD/27-May-1994:
- variable parameters for check procedures,
- upper limit increased for performance test (timer resolution is too low)
- increased repeat count
*)
IMPORT IOResult, SeqFile, TextIO, SRealIO, SWholeIO, STextIO, RawIO,
GetConvTime, Measures, SYSTEM;
CONST
Check = TRUE; (* enable/disable io read checks *)
BigBlocks = 1;
Blocks = 1;
Bytes = 1;
lenB = ((BigBlocks * 63 + Blocks) * 512 + Bytes);
lenT = 8190;
TYPE(*
CARDINAL = LONGINT;
INTEGER = LONGINT;*)
DataB = ARRAY [0..lenB-1] OF CHAR;
DataT = ARRAY [0..lenT-1] OF CHAR;
CONST
bin = 'BINA.LIS';
tex = 'TEXT.LIS';
F = 8;
RepeatI = F*17000; (* integers written binary *)
RepeatB = F*2; (* binary fields *)
RepeatT = F*8; (* text fields *)
(* approx. F*64K for each test*)
SizeI = SYSTEM.TSIZE(INTEGER) * RepeatI;
SizeB = SYSTEM.TSIZE(DataB) * RepeatB;
SizeT = SYSTEM.TSIZE(DataT) * RepeatT;
VAR
f: SeqFile.ChanId; ores: SeqFile.OpenResults;
i,j: INTEGER;
ch, chRead: CHAR; eq: BOOLEAN;
elapsed: GetConvTime.TimeType;
cputime: CARDINAL;
bufio: CARDINAL;
dirio: CARDINAL;
pagefault: CARDINAL;
fieldB, lastB: DataB;
fieldT, lastLine: DataT;
PROCEDURE InitFields(VAR t: DataT; VAR b: DataB);
VAR ch: CHAR; i: INTEGER;
BEGIN
FOR i:= 0 TO lenB-1 DO b[i]:= CHR(i MOD 256);
END;
ch:= ' ';
FOR i:= 0 TO lenT-1 DO
t[i]:= ch; ch:= CHR(ORD(ch) + 1);
IF ch = CHR(255) THEN ch:= ' ';
END;
END;
END InitFields;
PROCEDURE IsCorrectB((**)VAR(**) a: DataB): BOOLEAN;
VAR i: INTEGER; eq: BOOLEAN;
BEGIN
i:= 0;
eq:= a[i] = CHR(i MOD 256);
WHILE eq & (i < lenB-1) DO
INC(i); eq:= a[i] = CHR(i MOD 256);
END;
RETURN eq;
END IsCorrectB;
PROCEDURE IsCorrectT((**)VAR(**)a: DataT): BOOLEAN;
VAR ch: CHAR; i: INTEGER; eq: BOOLEAN;
BEGIN
ch:= ' '; i:= 0;
eq:= a[i] = ch;
WHILE eq & (i < lenT-1) DO
INC(i); ch:= CHR(ORD(ch) + 1);
IF ch = CHR(255) THEN ch:= ' ';
END;
eq:= a[i] = ch;
END;
RETURN eq;
END IsCorrectT;
PROCEDURE Float(i: INTEGER): REAL;
BEGIN RETURN FLOAT(i);
END Float;
PROCEDURE Header;
BEGIN (* ' ' *)
STextIO.WriteLn;
STextIO.WriteLn;
STextIO.WriteString(' ');
STextIO.WriteString(' Kbytes/sec Kbytes/cpusec');
STextIO.WriteLn;
STextIO.WriteString(' ');
STextIO.WriteString('transfer rate transfer rate bufio dirio pagefaults');
STextIO.WriteLn; STextIO.WriteLn;
END Header;
PROCEDURE InitTimer;
VAR i: INTEGER;
BEGIN Measures.InitTimer;
END InitTimer;
PROCEDURE Info(a: ARRAY OF CHAR; Size: CARDINAL);
VAR t: CARDINAL;
BEGIN (* cputime is in 10 ms units *)
Measures.GetTimer(elapsed, cputime, bufio, dirio, pagefault);
cputime := cputime*10; (* convert to 1 ms units *)
t:= 10*GetConvTime.Hundredths(elapsed)+1000*GetConvTime.Seconds(elapsed)
+60000*GetConvTime.Minutes(elapsed); (* t is in 1 ms units *)
STextIO.WriteString(a); STextIO.WriteString(' ');
IF t > 0 THEN
SRealIO.WriteFixed(Float(Size)/Float(t), 0, 11);
ELSE (* assume it took up-to 10 ms *)
(* resolution of timer is not sufficient; avoid div by zero *)
STextIO.WriteChar(">");
SRealIO.WriteFixed(Float(Size), 0, 10);
END;
STextIO.WriteString(' ');
IF cputime > 0 THEN
SRealIO.WriteFixed(Float(Size)/Float(cputime), 0, 13);
ELSE (* assume it took up-to 10 ms *)
STextIO.WriteChar(">"); (*div by zero*)
SRealIO.WriteFixed(Float(Size), 0, 12);
END;
SWholeIO.WriteInt(bufio, 7);
SWholeIO.WriteInt(dirio, 7);
SWholeIO.WriteInt(pagefault,12);
STextIO.WriteLn;
END Info;
BEGIN
STextIO.WriteLn;
STextIO.WriteString('test of SeqFile, binary and text'); STextIO.WriteLn;
STextIO.WriteString('-init fields-'); STextIO.WriteLn;
InitFields(fieldT, fieldB);
Header;
SeqFile.OpenWrite(f, tex, SeqFile.read + SeqFile.text, ores);
IF ores = SeqFile.opened THEN
InitTimer;
FOR i:= 1 TO RepeatT DO
TextIO.WriteString(f, fieldT); TextIO.WriteLn(f);
END;
Info(' writing text ', SizeT);
SeqFile.Rewrite(f);
InitTimer;
FOR i:= 1 TO RepeatT DO
TextIO.WriteString(f, fieldT); TextIO.WriteLn(f);
END;
Info(' writing text ', SizeT);
SeqFile.Rewrite(f);
InitTimer;
FOR i:= 1 TO RepeatT DO
FOR j:=0 TO lenT-1 DO
TextIO.WriteChar(f, fieldT[j]);
END;
TextIO.WriteLn(f);
END;
Info('write text bytewise ', SizeT);
STextIO.WriteLn;
SeqFile.Reread(f);
i:= 0;
InitTimer;
TextIO.ReadRestLine(f, fieldT);
WHILE (IOResult.ReadResult(f) # IOResult.endOfInput) DO
INC(i); TextIO.SkipLine(f);
IF Check THEN lastLine:= fieldT;
END;
TextIO.ReadRestLine(f, fieldT);
END;
Info(' reading text ', SizeT);
IF Check & (~ IsCorrectT(lastLine) OR (i # RepeatT)) THEN
SWholeIO.WriteInt(i, 5); STextIO.WriteString(' lines read'); STextIO.WriteLn;
STextIO.WriteString('TestSeq-err: read text failed'); HALT;
END;
SeqFile.Reread(f);
i:=0; ch:= ' '; eq:= TRUE;
InitTimer;
TextIO.ReadChar(f, chRead);
WHILE eq & (IOResult.ReadResult(f) # IOResult.endOfInput) DO
IF (IOResult.ReadResult(f) = IOResult.endOfLine) THEN
INC(i); TextIO.SkipLine(f); ch:= CHR(254);
ELSE
eq:= ch = chRead;
END;
ch:= CHR(ORD(ch) + 1);
IF ch = CHR(255) THEN ch:= ' ';
END;
TextIO.ReadChar(f, chRead);
END;
Info(' read text bytewise ', SizeT);
IF Check & (~ eq OR (i # RepeatT)) THEN
SWholeIO.WriteInt(i, 5); STextIO.WriteString(' lines read'); STextIO.WriteLn;
STextIO.WriteString('TestSeq-err: read text failed'); HALT;
END;
STextIO.WriteLn;
SeqFile.Rewrite(f); (* dealloc disk space *)
SeqFile.Close(f);
ELSE STextIO.WriteString('TestSeq-err: OPENWRITE text failed'); HALT;
END;
SeqFile.OpenWrite(f, bin, SeqFile.read + SeqFile.raw, ores);
IF ores = SeqFile.opened THEN
InitTimer;
FOR i:= 1 TO RepeatB DO
RawIO.Write(f, fieldB);
END;
Info(' writing binary ', SizeB);
SeqFile.Rewrite(f);
InitTimer;
FOR i:= 1 TO RepeatB DO
RawIO.Write(f, fieldB);
END;
Info(' writing binary ', SizeB);
SeqFile.Rewrite(f);
InitTimer;
FOR i:= 1 TO RepeatB DO
FOR j:=0 TO lenB-1 DO
RawIO.Write(f, fieldB[j]);
END;
END;
Info(' write bin bytewise ', SizeB);
STextIO.WriteLn;
SeqFile.Reread(f);
i:= 0;
InitTimer;
RawIO.Read(f, fieldB);
WHILE (IOResult.ReadResult(f) # IOResult.endOfInput) DO
INC(i);
IF Check THEN lastB:= fieldB;
END;
RawIO.Read(f, fieldB);
END;
Info(' reading binary ', SizeB);
IF Check & (~ IsCorrectB(lastB) OR (i # RepeatB)) THEN
STextIO.WriteString('TestSeq-err: read binary failed'); HALT;
END;
SeqFile.Reread(f);
i:=0; eq:= TRUE;
RawIO.Read(f, chRead);
InitTimer;
WHILE eq & (IOResult.ReadResult(f) # IOResult.endOfInput) DO
eq:= chRead = CHR(i MOD 256);
RawIO.Read(f, chRead);
i:= (i + 1) MOD lenB; (* must be 0 on eof *)
END;
Info(' read bin bytewise ', SizeB);
IF Check & (~ eq OR (i # 0)) THEN
STextIO.WriteString('TestSeq-err: read binary failed'); HALT;
END;
SeqFile.Rewrite(f);
InitTimer;
FOR i:= 1 TO RepeatI DO RawIO.Write(f, i);
END;
STextIO.WriteLn;
Info(' write bin integers ', SizeI);
SeqFile.Reread(f);
i:= 1;
RawIO.Read(f, j);
WHILE (IOResult.ReadResult(f) # IOResult.endOfInput) DO
IF Check & (i # j) THEN
STextIO.WriteString('TestSeq-err: read binary integers failed'); HALT;
END;
RawIO.Read(f, i); INC(j);
END;
Info(' read bin integers ', SizeI);
SeqFile.Rewrite(f);
SeqFile.Close(f);
ELSE STextIO.WriteString('TestSeq-err: OPENWRITE binary failed'); HALT;
END;
END TestSeq.
________________________________________________________________________
$mod testseq/iso=4
VMS ISO-Modula-2 MVR V4.05d(C)1994 by ModulaWare GmbH, D-91054 Erlangen/FRG
compiling _PSLAVE$DKA0:[EDISON.ISO]TESTSEQ.MOD;20/DEBUG/NORELATIONAL/ISO=4/NAME_SEPA
RATOR='.'
Syntax analysis
IOResult: _PSLAVE$DKA0:[EDISON.ISO]IORESULT.SYM;8
SeqFile: _PSLAVE$DKA0:[EDISON.ISO]SEQFILE.SYM;9
TextIO: _PSLAVE$DKA0:[EDISON.ISO]TEXTIO.SYM;8
SRealIO: _PSLAVE$DKA0:[EDISON.ISO]SREALIO.SYM;8
SWholeIO: _PSLAVE$DKA0:[EDISON.ISO]SWHOLEIO.SYM;8
STextIO: _PSLAVE$DKA0:[EDISON.ISO]STEXTIO.SYM;8
RawIO: _PSLAVE$DKA0:[EDISON.ISO]RAWIO.SYM;9
GetConvTime: _PSLAVE$DKA0:[MVR3_20]GETCONVTIME.SYM;5
Measures: _PSLAVE$DKA0:[MVR3_20]MEASURES.SYM;6
EXCEPTIONS: _PSLAVE$DKA0:[EDISON.ISO]EXCEPTIONS.SYM;6
Declaration analysis
Body analysis
Code generation
End of compilation, source file: _PSLAVE$DKA0:[EDISON.ISO]TESTSEQ.MOD;20
$ link testseq,io/lib
$ run
test of SeqFile, binary and text
-init fields-
Kbytes/sec Kbytes/cpusec
transfer rate transfer rate bufio dirio pagefaults
writing text 55. 406. 32 301 15
writing text 148. 738. 0 64 0
write text bytewise 10. 10. 0 64 0
reading text 107. 214. 0 64 15
read text bytewise 7. 7. 0 64 0
writing binary 80. 783. 9 211 48
writing binary 186. 1808. 0 32 0
write bin bytewise 7. 9. 0 1024 0
reading binary 215. 2017. 0 33 63
read bin bytewise 5. 5. 0 1024 0
write bin integers 15. 27. 2 1062 0
read bin integers 8. 11. 13 2127 0
The above measurement was done on VAX/VMS V5.4 (VAXstation 3100/30).
The below measurment was done on AXP/OpenVMS V1.5H1 (DEC 3000-300LX/125 MHz).
Both compilations were with run-time array index checks enabled.
test of SeqFile, binary and text
-init fields-
Kbytes/sec Kbytes/cpusec
transfer rate transfer rate bufio dirio pagefaults
writing text 173. 1638. 32 151 0
writing text 472. 4765. 0 64 0
write text bytewise 93. 123. 0 64 0
reading text 1028. 1542. 0 1 0
read text bytewise 60. 61. 0 0 0
writing binary 324. 6554. 9 76 3
writing binary 718. 13108. 0 32 0
write bin bytewise 23. 52. 0 1024 0
reading binary 8738. 7490. 0 1 3
read bin bytewise 35. 36. 0 0 0
write bin integers 45. 151. 2 1062 0
read bin integers 32. 68. 13 1065 0
$
________________________________________________________________________
Strings Library
Strings
DEFINITION MODULE Strings;
(* Facilities for manipulating strings *)
TYPE
String1 = ARRAY [0..0] OF CHAR;
(* String1 is provided for constructing a value of a single-character string type from a
single character value in order to pass CHAR values to ARRAY OF CHAR parameters.
*)
PROCEDURE Length (stringVal: ARRAY OF CHAR): CARDINAL;
(* Returns the length of stringVal (the same value as would be returned by the
pervasive function LENGTH).
*)
(* The following seven procedures construct a string value, and attempt to assign it to a
variable parameter. They all have the property that if the length of the constructed string
value exceeds the capacity of the variable parameter, a truncated value is assigned, while
if the length of the constructed string value is less than the capacity of the variable
parameter, a string terminator is appended before assignment is performed.
*)
PROCEDURE Assign (source: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR);
(* Copies source to destination *)
PROCEDURE Extract (source: ARRAY OF CHAR; startIndex, numberToExtract: CARDINAL;
VAR destination: ARRAY OF CHAR);
(* Copies at most numberToExtract characters from source to destination, starting at position
startIndex in source.
*)
PROCEDURE Delete (VAR stringVar: ARRAY OF CHAR; startIndex, numberToDelete:
CARDINAL);
(* Deletes at most numberToDelete characters from stringVar, starting at position
startIndex.
*)
PROCEDURE Insert (source: ARRAY OF CHAR; startIndex: CARDINAL;
VAR destination: ARRAY OF CHAR);
(* Inserts source into destination at position startIndex *)
PROCEDURE Replace (source: ARRAY OF CHAR; startIndex: CARDINAL;
VAR destination: ARRAY OF CHAR);
(* Copies source into destination, starting at position startIndex. Copying stops when
all of source has been copied, or when the last character of the string value in
destination has been replaced.
*)
PROCEDURE Append (source: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR);
(* Appends source to destination. *)
PROCEDURE Concat (source1, source2: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR);
(* Concatenates source2 onto source1 and copies the result into destination. *)
(* The following predicates provide for pre-testing of the operation-completion
conditions for the procedures above.
*)
PROCEDURE CanAssignAll (sourceLength: CARDINAL; VAR destination: ARRAY OF CHAR): BOOLEAN;
(* Returns TRUE if a number of characters, indicated by sourceLength, will fit into
destination; otherwise returns FALSE.
*)
PROCEDURE CanExtractAll (sourceLength, startIndex, numberToExtract: CARDINAL;
VAR destination: ARRAY OF CHAR): BOOLEAN;
(* Returns TRUE if there are numberToExtract characters starting at startIndex and
within the sourceLength of some string, and if the capacity of destination is
sufficient to hold numberToExtract characters; otherwise returns FALSE.
*)
PROCEDURE CanDeleteAll (stringLength, startIndex, numberToDelete: CARDINAL): BOOLEAN;
(* Returns TRUE if there are numberToDelete characters starting at startIndex and
within the stringLength of some string; otherwise returns FALSE.
*)
PROCEDURE CanInsertAll (sourceLength, startIndex: CARDINAL;
VAR destination: ARRAY OF CHAR): BOOLEAN;
(* Returns TRUE if there is room for the insertion of sourceLength characters from
some string into destination starting at startIndex; otherwise returns FALSE.
*)
PROCEDURE CanReplaceAll (sourceLength, startIndex: CARDINAL;
VAR destination: ARRAY OF CHAR): BOOLEAN;
(* Returns TRUE if there is room for the replacement of sourceLength characters in
destination starting at startIndex; otherwise returns FALSE.
*)
PROCEDURE CanAppendAll (sourceLength: CARDINAL; VAR destination: ARRAY OF CHAR): BOOLEAN;
(* Returns TRUE if there is sufficient room in destination to append a string of
length sourceLength to the string in destination; otherwise returns FALSE.
*)
PROCEDURE CanConcatAll (source1Length, source2Length: CARDINAL;
VAR destination: ARRAY OF CHAR): BOOLEAN;
(* Returns TRUE if there is sufficient room in destination for a two strings of
lengths source1Length and source2Length; otherwise returns FALSE.
*)
(* The following type and procedures provide for the comparison of string values, and for the
location of substrings within strings.
*)
TYPE
CompareResults = (less, equal, greater);
PROCEDURE Compare (stringVal1, stringVal2: ARRAY OF CHAR): CompareResults;
(* Returns less, equal, or greater, according as stringVal1 is lexically less than,
equal to, or greater than stringVal2.
*)
PROCEDURE Equal (stringVal1, stringVal2: ARRAY OF CHAR): BOOLEAN;
(* Returns Strings.Compare(stringVal1, stringVal2) = Strings.equal *)
PROCEDURE FindNext (pattern, stringToSearch: ARRAY OF CHAR; startIndex: CARDINAL;
VAR patternFound: BOOLEAN; VAR posOfPattern: CARDINAL);
(* Looks forward for next occurrence of pattern in stringToSearch, starting the search at
position startIndex. If startIndex < LENGTH(stringToSearch) and pattern is found,
patternFound is returned as TRUE, and posOfPattern contains the start position in
stringToSearch of pattern. Otherwise patternFound is returned as FALSE, and posOfPattern
is unchanged.
*)
PROCEDURE FindPrev (pattern, stringToSearch: ARRAY OF CHAR; startIndex: CARDINAL;
VAR patternFound: BOOLEAN; VAR posOfPattern: CARDINAL);
(* Looks backward for the previous occurrence of pattern in stringToSearch and returns the
position of the first character of the pattern if found. The search for the pattern
begins at startIndex. If pattern is found, patternFound is returned as TRUE, and
posOfPattern contains the start position in stringToSearch of pattern in the range
[0..startIndex]. Otherwise patternFound is returned as FALSE, and posOfPattern is unchanged.
*)
PROCEDURE FindDiff (stringVal1, stringVal2: ARRAY OF CHAR;
VAR differenceFound: BOOLEAN; VAR posOfDifference: CARDINAL);
(* Compares the string values in stringVal1 and stringVal2 for differences. If they
are equal, differenceFound is returned as FALSE, and TRUE otherwise. If
differenceFound is TRUE, posOfDifference is set to the position of the first
difference; otherwise posOfDifference is unchanged.
*)
PROCEDURE Capitalize (VAR stringVar: ARRAY OF CHAR);
(* Applies the function CAP to each character of the string value in stringVar. *)
END Strings.
________________________________________________________________________
Storage Library
________________________________________________________________________
Storage
DEFINITION MODULE Storage;
(* Facilities for dynamically allocating and deallocating storage *)
IMPORT SYSTEM;
PROCEDURE ALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL);
(* Allocates storage for a variable of size amount and assigns the address of this
variable to addr. If there is insufficient unallocated storage to do this, the
value NIL is assigned to addr.
*)
PROCEDURE DEALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL);
(* Deallocates amount locations allocated by ALLOCATE for the storage of the variable
addressed by addr and assigns the value NIL to addr.
*)
TYPE
StorageExceptions = (
nilDeallocation, (* first argument to DEALLOCATE is NIL *)
pointerToUnallocatedStorage, (* storage to deallocate not allocated by ALLOCATE *)
wrongStorageToUnallocate (* amount to deallocate is not amount allocated *)
);
PROCEDURE IsStorageException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception from StorageExceptions;
otherwise returns FALSE.
*)
PROCEDURE StorageException (): StorageExceptions;
(* If the current coroutine is in the exceptional execution state because of the
raising of an exception from StorageExceptions, returns the corresponding
enumeration value, and otherwise raises an exception.
*)
END Storage.
________________________________________________________________________
Mathematical Library
________________________________________________________________________
RealMath
DEFINITION MODULE RealMath;
(* Mathematical functions for the type REAL *)
CONST
pi = 3.1415926535897932384626433832795028841972;
exp1 = 2.7182818284590452353602874713526624977572;
PROCEDURE sqrt (x: REAL): REAL;
(* Returns the positive square root of x *)
PROCEDURE exp (x: REAL): REAL;
(* Returns the exponential of x *)
PROCEDURE ln (x: REAL): REAL;
(* Returns the natural logarithm of x *)
(* The angle in all trigonometric functions is measured in radians *)
PROCEDURE sin (x: REAL): REAL;
(* Returns the sine of x *)
PROCEDURE cos (x: REAL): REAL;
(* Returns the cosine of x *)
PROCEDURE tan (x: REAL): REAL;
(* Returns the tangent of x *)
PROCEDURE arcsin (x: REAL): REAL;
(* Returns the arcsine of x *)
PROCEDURE arccos (x: REAL): REAL;
(* Returns the arccosine of x *)
PROCEDURE arctan (x: REAL): REAL;
(* Returns the arctangent of x *)
PROCEDURE power (base, exponent: REAL): REAL;
(* Returns the value of the number base raised to the power exponent *)
PROCEDURE round (x: REAL): INTEGER;
(* Returns the value of x rounded to the nearest integer *)
PROCEDURE IsRMathException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception in a routine from this module; otherwise
returns FALSE.
*)
(* not yet impl. on MVR | MAX *)
END RealMath.
________________________________________________________________________
LongMath
DEFINITION MODULE LongMath;
(* Mathematical functions for the type LONGREAL *)
CONST
pi = 3.1415926535897932384626433832795028841972;
exp1 = 2.7182818284590452353602874713526624977572;
PROCEDURE sqrt (x: LONGREAL): LONGREAL;
(* Returns the positive square root of x *)
PROCEDURE exp (x: LONGREAL): LONGREAL;
(* Returns the exponential of x *)
PROCEDURE ln (x: LONGREAL): LONGREAL;
(* Returns the natural logarithm of x *)
(* The angle in all trigonometric functions is measured in radians *)
PROCEDURE sin (x: LONGREAL): LONGREAL;
(* Returns the sine of x *)
PROCEDURE cos (x: LONGREAL): LONGREAL;
(* Returns the cosine of x *)
PROCEDURE tan (x: LONGREAL): LONGREAL;
(* Returns the tangent of x *)
PROCEDURE arcsin (x: LONGREAL): LONGREAL;
(* Returns the arcsine of x *)
PROCEDURE arccos (x: LONGREAL): LONGREAL;
(* Returns the arccosine of x *)
PROCEDURE arctan (x: LONGREAL): LONGREAL;
(* Returns the arctangent of x *)
PROCEDURE power (base, exponent: LONGREAL): LONGREAL;
(* Returns the value of the number base raised to the power exponent *)
PROCEDURE round (x: LONGREAL): INTEGER;
(* Returns the value of x rounded to the nearest integer *)
PROCEDURE IsRMathException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception in a routine from this module; otherwise
returns FALSE.
*)
(* not yet impl. on MVR | MAX *)
END LongMath.
________________________________________________________________________
LongGMath
DEFINITION MODULE LongGMath;
(* ISO Modula-2 Standard Library extension,
(AXP | VAX) / OpenVMS implementation
Based on LongMath
(C) 1994 by ModulaWare GmbH,
CS/09-Mar-1994
*)
IMPORT SYSTEM;
TYPE LONGREAL = SYSTEM.G_FLOATING;
CONST
pi = VAL(LONGREAL, 3.1415926535897932384626433832795028841972);
exp1 = VAL(LONGREAL, 2.7182818284590452353602874713526624977572);
PROCEDURE sqrt (x: LONGREAL): LONGREAL;
(* Returns the positive square root of x *)
PROCEDURE exp (x: LONGREAL): LONGREAL;
(* Returns the exponential of x *)
PROCEDURE ln (x: LONGREAL): LONGREAL;
(* Returns the natural logarithm of x *)
(* The angle in all trigonometric functions is measured in radians *)
PROCEDURE sin (x: LONGREAL): LONGREAL;
(* Returns the sine of x *)
PROCEDURE cos (x: LONGREAL): LONGREAL;
(* Returns the cosine of x *)
PROCEDURE tan (x: LONGREAL): LONGREAL;
(* Returns the tangent of x *)
PROCEDURE arcsin (x: LONGREAL): LONGREAL;
(* Returns the arcsine of x *)
PROCEDURE arccos (x: LONGREAL): LONGREAL;
(* Returns the arccosine of x *)
PROCEDURE arctan (x: LONGREAL): LONGREAL;
(* Returns the arctangent of x *)
PROCEDURE power (base, exponent: LONGREAL): LONGREAL;
(* Returns the value of the number base raised to the power exponent *)
PROCEDURE round (x: LONGREAL): INTEGER;
(* Returns the value of x rounded to the nearest integer *)
PROCEDURE IsRMathException (): BOOLEAN; (* not yet impl. on MVR | MAX *)
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception in a routine from this module;
otherwise returns FALSE.
*)
END LongGMath.
________________________________________________________________________
Complex Library
________________________________________________________________________
ComplexMath
DEFINITION MODULE ComplexMath;
(* Mathematical functions for the type COMPLEX *)
CONST
i = CMPLX (0.0, 1.0);
one = CMPLX (1.0, 0.0);
zero = CMPLX (0.0, 0.0);
PROCEDURE abs (z: COMPLEX): REAL;
(* Returns the length of z *)
PROCEDURE arg (z: COMPLEX): REAL;
(* Returns the angle that z subtends to the positive real axis *)
PROCEDURE conj (z: COMPLEX): COMPLEX;
(* Returns the complex conjugate of z *)
PROCEDURE power (base: COMPLEX; exponent: REAL): COMPLEX;
(* Returns the value of the number base raised to the power exponent *)
PROCEDURE sqrt (z: COMPLEX): COMPLEX;
(* Returns the principal square root of z *)
PROCEDURE exp (z: COMPLEX): COMPLEX;
(* Returns the complex exponential of z *)
PROCEDURE ln (z: COMPLEX): COMPLEX;
(* Returns the principal value of the natural logarithm of z *)
PROCEDURE sin (z: COMPLEX): COMPLEX;
(* Returns the sine of z *)
PROCEDURE cos (z: COMPLEX): COMPLEX;
(* Returns the cosine of z *)
PROCEDURE tan (z: COMPLEX): COMPLEX;
(* Returns the tangent of z *)
PROCEDURE arcsin (z: COMPLEX): COMPLEX;
(* Returns the arcsine of z *)
PROCEDURE arccos (z: COMPLEX): COMPLEX;
(* Returns the arccosine of z *)
PROCEDURE arctan (z: COMPLEX): COMPLEX;
(* Returns the arctangent of z *)
PROCEDURE polarToComplex (abs, arg: REAL): COMPLEX;
(* Returns the complex number with the specified polar coordinates *)
PROCEDURE scalarMult (scalar: REAL; z: COMPLEX): COMPLEX;
(* Returns the scalar product of scalar with z *)
PROCEDURE IsCMathException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception in a routine from this module; otherwise
returns FALSE.
*)
(* not yet impl. on MVR | MAX *)
END ComplexMath.
________________________________________________________________________
LongComplexMath
DEFINITION MODULE LongComplexMath;
(* Mathematical functions for the type LONGCOMPLEX *)
CONST
i = CMPLX (0.0, 1.0);
one = CMPLX (1.0, 0.0);
zero = CMPLX (0.0, 0.0);
PROCEDURE abs (z: LONGCOMPLEX): LONGREAL;
(* Returns the length of z *)
PROCEDURE arg (z: LONGCOMPLEX): LONGREAL;
(* Returns the angle that z subtends to the positive real axis *)
PROCEDURE conj (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the complex conjugate of z *)
PROCEDURE power (base: LONGCOMPLEX; exponent: LONGREAL): LONGCOMPLEX;
(* Returns the value of the number base raised to the power exponent *)
PROCEDURE sqrt (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the principal square root of z *)
PROCEDURE exp (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the complex exponential of z *)
PROCEDURE ln (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the principal value of the natural logarithm of z *)
PROCEDURE sin (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the sine of z *)
PROCEDURE cos (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the cosine of z *)
PROCEDURE tan (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the tangent of z *)
PROCEDURE arcsin (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the arcsine of z *)
PROCEDURE arccos (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the arccosine of z *)
PROCEDURE arctan (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the arctangent of z *)
PROCEDURE polarToComplex (abs, arg: LONGREAL): LONGCOMPLEX;
(* Returns the complex number with the specified polar coordinates *)
PROCEDURE scalarMult (scalar: LONGREAL; z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the scalar product of scalar with z *)
PROCEDURE IsCMathException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception in a routine from this module; otherwise
returns FALSE.
*)
(* not yet impl. on MVR | MAX *)
END LongComplexMath.
________________________________________________________________________
LongComplexGMath
DEFINITION MODULE LongComplexGMath;
(* ISO Modula-2 Standard Library extension,
(AXP | VAX) / OpenVMS implementation
Based on LongComplexMath
(C) 1994 by ModulaWare GmbH,
CS/30-May-1994
*)
IMPORT SYSTEM;
TYPE
LONGREAL = SYSTEM.G_FLOATING;
LONGCOMPLEX = SYSTEM.G_COMPLEX;
VAR
i, one, zero: LONGCOMPLEX; (* read only *)
PROCEDURE abs (z: LONGCOMPLEX): LONGREAL;
(* Returns the length of z *)
PROCEDURE arg (z: LONGCOMPLEX): LONGREAL;
(* Returns the angle that z subtends to the positive real axis *)
PROCEDURE conj (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the complex conjugate of z *)
PROCEDURE power (base: LONGCOMPLEX; exponent: LONGREAL): LONGCOMPLEX;
(* Returns the value of the number base raised to the power exponent *)
PROCEDURE sqrt (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the principal square root of z *)
PROCEDURE exp (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the complex exponential of z *)
PROCEDURE ln (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the principal value of the natural logarithm of z *)
PROCEDURE sin (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the sine of z *)
PROCEDURE cos (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the cosine of z *)
PROCEDURE tan (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the tangent of z *)
PROCEDURE arcsin (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the arcsine of z *)
PROCEDURE arccos (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the arccosine of z *)
PROCEDURE arctan (z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the arctangent of z *)
PROCEDURE polarToComplex (abs, arg: LONGREAL): LONGCOMPLEX;
(* Returns the complex number with the specified polar coordinates *)
PROCEDURE scalarMult (scalar: LONGREAL; z: LONGCOMPLEX): LONGCOMPLEX;
(* Returns the scalar product of scalar with z *)
PROCEDURE IsCMathException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception in a routine from this module;
otherwise returns FALSE.
*)
(* not yet impl. on MVR | MAX *)
END LongComplexGMath.
________________________________________________________________________
Low-level Real-number Representation Support
________________________________________________________________________
LowReal
DEFINITION MODULE LowReal;
(* Access to underlying properties of the type REAL *)
CONST
radix = 2;
places = 23;
expoMin = -127;
expoMax = 127;
large = MAX(REAL);
small = 2.938736E-39;
IEEE = FALSE;
ISO = FALSE;
rounds = FALSE;
gUnderflow = FALSE;
exception = FALSE;
extend = FALSE;
nModes = 1;
TYPE
Modes = SET OF [0 .. nModes-1];
PROCEDURE exponent (x: REAL): INTEGER;
(* Returns the exponent value of x *)
PROCEDURE fraction (x: REAL): REAL;
(* Returns the significand (or significant part) of x *)
PROCEDURE sign (x: REAL): REAL;
(* Returns the signum of x *)
PROCEDURE succ (x: REAL): REAL;
(* Returns the next value of the type REAL greater than x *)
PROCEDURE ulp (x: REAL): REAL;
(* Returns the value of a unit in the last place of x *)
PROCEDURE pred (x: REAL): REAL;
(* Returns the previous value of the type REAL less than x *)
PROCEDURE intpart (x: REAL): REAL;
(* Returns the integer part of x *)
PROCEDURE fractpart (x: REAL): REAL;
(* Returns the fractional part of x *)
PROCEDURE scale (x: REAL; n: INTEGER): REAL;
(* Returns the value of x * radix ** n *)
PROCEDURE trunc (x: REAL; n: INTEGER): REAL;
(* Returns the value of the first n places of x *)
PROCEDURE round (x: REAL; n: INTEGER): REAL;
(* Returns the value of x rounded to the first n places *)
PROCEDURE synthesize (expart: INTEGER; frapart: REAL): REAL;
(* Returns a value of the type REAL constructed from the given expart and frapart *)
PROCEDURE setMode (m: Modes); (* not yet impl. on MVR | MAX *)
(* Sets status flags appropriate to the underlying implementation of the type REAL *)
PROCEDURE currentMode (): Modes; (* not yet impl. on MVR | MAX *)
(* Returns the current status flags in the form set by setMode *)
PROCEDURE IsLowException (): BOOLEAN; (* not yet impl. on MVR | MAX *)
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception in a routine from this module; otherwise
returns FALSE.
*)
END LowReal.
________________________________________________________________________
LowLong
DEFINITION MODULE LowLong;
(* Access to underlying properties of the type LONGREAL *)
CONST
radix = 2;
places = 23 + 32;
expoMin = -127;
expoMax = 127;
large = MAX (LONGREAL);
small = 2.93873587705571878E-39;
(*temporary for MVR,
adjusted for MVR scanner to produce exactly 000000000000080H *)
IEEE = FALSE;
ISO = FALSE;
rounds = FALSE;
gUnderflow = FALSE;
exception = FALSE;
extend = FALSE;
nModes = 1;
TYPE
Modes = SET OF [0 .. nModes-1];
PROCEDURE exponent (x: LONGREAL): INTEGER;
(* Returns the exponent value of x *)
PROCEDURE fraction (x: LONGREAL): LONGREAL;
(* Returns the significand (or significant part) of x *)
PROCEDURE sign (x: LONGREAL): LONGREAL;
(* Returns the signum of x *)
PROCEDURE succ (x: LONGREAL): LONGREAL;
(* Returns the next value of the type LONGREAL greater than x *)
PROCEDURE ulp (x: LONGREAL): LONGREAL;
(* Returns the value of a unit in the last place of x *)
PROCEDURE pred (x: LONGREAL): LONGREAL;
(* Returns the previous value of the type LONGREAL less than x *)
PROCEDURE intpart (x: LONGREAL): LONGREAL;
(* Returns the integer part of x *)
PROCEDURE fractpart (x: LONGREAL): LONGREAL;
(* Returns the fractional part of x *)
PROCEDURE scale (x: LONGREAL; n: INTEGER): LONGREAL;
(* Returns the value of x * radix ** n *)
PROCEDURE trunc (x: LONGREAL; n: INTEGER): LONGREAL;
(* Returns the value of the first n places of x *)
PROCEDURE round (x: LONGREAL; n: INTEGER): LONGREAL;
(* Returns the value of x rounded to the first n places *)
PROCEDURE synthesize (expart: INTEGER; frapart: LONGREAL): LONGREAL;
(* Returns a value of the type LONGREAL constructed from the given expart and frapart *)
PROCEDURE setMode (m: Modes); (* not yet impl. on MVR | MAX *)
(* Sets status flags appropriate to the underlying implementation of the type LONGREAL *)
PROCEDURE currentMode (): Modes; (* not yet impl. on MVR | MAX *)
(* Returns the current status flags in the form set by setMode *)
PROCEDURE IsLowException (): BOOLEAN; (* not yet impl. on MVR | MAX *)
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception in a routine from this module; otherwise
returns FALSE.
*)
END LowLong.
________________________________________________________________________
LowLongG
DEFINITION MODULE LowLongG;
(* ISO Modula-2 Standard Library extension,
(AXP | VAX) / OpenVMS implementation
Based on LowLong
(C) 1994 by ModulaWare GmbH,
CS/16-Mar-1994
*)
IMPORT SYSTEM;
TYPE LONGREAL = SYSTEM.G_FLOATING;
CONST
radix = 2;
places = 20 + 32;
expoMin = -1023;
expoMax = 1023;
large = MAX (LONGREAL);
(*small = VAL(LONGREAL,5.562684646268003E-309);
(*= CAST(LONGREAL,0000000000000010H)*) *)
(*temporary adjusted for MVR scanner to produce exactly the above pattern: *)
n = VAL(LONGREAL,1.0E-30); (* n is for internal use only *)
small = VAL(LONGREAL,5.562684646267999)* n*n*n*n*n*n*n*n*n*n
*VAL(LONGREAL,1.0E-9);
IEEE = FALSE;
ISO = FALSE;
rounds = FALSE;
gUnderflow = FALSE;
exception = FALSE;
extend = FALSE;
nModes = 1;
TYPE
Modes = SET OF [0 .. nModes-1];
PROCEDURE exponent (x: LONGREAL): INTEGER;
(* Returns the exponent value of x *)
PROCEDURE fraction (x: LONGREAL): LONGREAL;
(* Returns the significand (or significant part) of x *)
PROCEDURE sign (x: LONGREAL): LONGREAL;
(* Returns the signum of x *)
PROCEDURE succ (x: LONGREAL): LONGREAL;
(* Returns the next value of the type LONGREAL greater than x *)
PROCEDURE ulp (x: LONGREAL): LONGREAL;
(* Returns the value of a unit in the last place of x *)
PROCEDURE pred (x: LONGREAL): LONGREAL;
(* Returns the previous value of the type LONGREAL less than x *)
PROCEDURE intpart (x: LONGREAL): LONGREAL;
(* Returns the integer part of x *)
PROCEDURE fractpart (x: LONGREAL): LONGREAL;
(* Returns the fractional part of x *)
PROCEDURE scale (x: LONGREAL; n: INTEGER): LONGREAL;
(* Returns the value of x * radix ** n *)
PROCEDURE trunc (x: LONGREAL; n: INTEGER): LONGREAL;
(* Returns the value of the first n places of x *)
PROCEDURE round (x: LONGREAL; n: INTEGER): LONGREAL;
(* Returns the value of x rounded to the first n places *)
PROCEDURE synthesize (expart: INTEGER; frapart: LONGREAL): LONGREAL;
(* Returns a value of the type LONGREAL constructed from the given expart and frapart *)
PROCEDURE setMode (m: Modes); (* not yet impl. on MVR | MAX *)
(* Sets status flags appropriate to the underlying implementation of the type LONGREAL *)
PROCEDURE currentMode (): Modes; (* not yet impl. on MVR | MAX *)
(* Returns the current status flags in the form set by setMode *)
PROCEDURE IsLowException (): BOOLEAN; (* not yet impl. on MVR | MAX *)
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception in a routine from this module; otherwise
returns FALSE.
*)
END LowLongG.
________________________________________________________________________
Concurrent Processes Library
________________________________________________________________________
Processes
DEFINITION MODULE Processes;
(* This module allows concurrent algorithms to be expressed using processes. A process is
a unit of a program that has the potential to run in parallel with other processes.
*)
IMPORT SYSTEM;
TYPE
ProcessId; (* Used to identify processes *)
Parameter = SYSTEM.ADDRESS; (* Used to pass data between processes *)
Body = PROC; (* Used as the type of a process body *)
Urgency = INTEGER; (* Used by the internal scheduler *)
Sources = CARDINAL; (* Used to identify event sources *)
ProcessesExceptions = (* Exceptions raised by this module *)
(passiveProgram, processError);
(* The following procedures create processes and switch control between them. *)
PROCEDURE Create (procBody: Body; extraSpace: CARDINAL; procUrg: Urgency;
procParams: Parameter; VAR procId: ProcessId);
(* Creates a new process with procBody as its body, and with urgency and parameters
given by procUrg and procParams. At least as much workspace (in units of
SYSTEM.LOC) as is specified by extraSpace is allocated to the process.
An identity for the new process is returned in procId.
The process is created in the passive state; it will not run until activated.
*)
PROCEDURE Start (procBody: Body; extraSpace: CARDINAL; procUrg: Urgency;
procParams: Parameter; VAR procId: ProcessId);
(* Creates a new process, with parameters as for Create.
The process is created in the ready state; it is eligible to run immediately.
*)
PROCEDURE StopMe ();
(* Terminates the calling process.
The process must not be associated with a source of events.
*)
PROCEDURE SuspendMe ();
(* Causes the calling process to enter the passive state. The procedure only returns
when the calling process is again activated by another process.
*)
PROCEDURE Activate (procId: ProcessId);
(* Causes the process identified by procId to enter the ready state, and thus to become
eligible to run again.
*)
PROCEDURE SuspendMeAndActivate (procId: ProcessId);
(* Executes an atomic sequence of SuspendMe() and Activate(procId). *)
PROCEDURE Switch (procId: ProcessId; VAR info: Parameter);
(* Causes the calling process to enter the passive state; the process identified by procId
becomes the currently executing process.
info is used to pass parameter information from the calling to the activated process.
On return, info will contain information from the process that chooses to switch back to
this one (or will be NIL if Activate or SuspendMeAndActivate are used instead of
Switch).
*)
PROCEDURE Wait ();
(* Causes the calling process to enter the waiting state. The procedure will return when
the calling process is activated by another process, or when one of its associated
eventSources has generated an event.
*)
(* The following procedures allow the association of processes with sources of external
events.
*)
PROCEDURE Attach (eventSource: Sources);
(* Associates the specified eventSource with the calling process. *)
PROCEDURE Detach (eventSource: Sources);
(* Dissociates the specified eventSource from the program. *)
PROCEDURE IsAttached (eventSource: Sources): BOOLEAN;
(* Returns TRUE if and only if the specified eventSource is currently associated with
one of the processes of the program.
*)
PROCEDURE Handler (eventSource: Sources): ProcessId;
(* Returns the identity of the process, if any, that is associated with the specified
eventSource.
*)
(* The following procedures allow processes to obtain their identity, parameters, and
urgency.
*)
PROCEDURE Me (): ProcessId;
(* Returns the identity of the calling process (as assigned when the process was first
created).
*)
PROCEDURE MyParam (): Parameter;
(* Returns the value specified as procParams when the calling process was created. *)
PROCEDURE UrgencyOf (procId: ProcessId): Urgency;
(* Returns the urgency established when the process identified by procId was first
created.
*)
(* The following procedure provides facilities for exception handlers. *)
PROCEDURE ProcessesException (): ProcessesExceptions;
(* If the current coroutine is in the exceptional execution state because of the raising
of a language exception, returns the corresponding enumeration value, and
otherwise raises an exception.
*)
PROCEDURE IsProcessesException (): BOOLEAN;
(* Returns TRUE if the current coroutine is in the exceptional execution state
because of the raising of an exception in a routine from this module; otherwise
returns FALSE.
*)
END Processes.
________________________________________________________________________
Semaphores
DEFINITION MODULE Semaphores;
(* Provides mutual exclusion facilities for use by processes. *)
TYPE
SEMAPHORE;
PROCEDURE Create (VAR s: SEMAPHORE; initialCount: CARDINAL );
(* Creates and returns s as the identity of a new semaphore that has its associated count
initialized to initialCount, and has no processes yet waiting on it.
*)
PROCEDURE Destroy (VAR s: SEMAPHORE);
(* Recovers the resources used to implement the semaphore s, provided that no process is
waiting for s to become free.
*)
PROCEDURE Claim (s: SEMAPHORE);
(* If the count associated with the semaphore s is non-zero, decrements this count and
allows the calling process to continue; otherwise suspends the calling process until
s is released.
*)
PROCEDURE Release (s: SEMAPHORE);
(* If there are any processes waiting on the semaphore s, allows one of them
to enter the ready state; otherwise increments the count associated with s.
*)
PROCEDURE CondClaim (s: SEMAPHORE): BOOLEAN;
(* Returns TRUE if the call Claim(s) would cause the calling process to be suspended;
in this case the count associated with s is not changed. Otherwise returns TRUE and
the associated count is decremented.
*)
END Semaphores.
________________________________________________________________________
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 Günter Dotzel; he can be reached at mailto:[email deleted due to spam]
Home | Site_index | Legal | OpenVMS_compiler | Alpha_Oberon_System | ModulaTor | Bibliography | Oberon[-2]_links | Modula-2_links |