Appendix 7--ISO Required System Modules

All the modules in this section are pseudo-modules. that is, they behave as if they had the definitions given, but are not actually separate library modules because their implementation is generally sufficiently low-level that they need to be part of the compiler itself. Only the contents of SYSTEM may vary to suit the needs of an implementation; all the others are to be supplied as is by ISO conforming implementations.

A7.1 SYSTEM

DEFINITION MODULE SYSTEM;

  (* Gives access to system programming facilities that are probably non
portable. *)

  (* The constants and types define underlying properties of storage *)

CONST
  BITSPERLOC    = <implementation-defined constant> ;
  LOCSPERWORD   = <implementation-defined constant> ;

TYPE
  LOC; (* A system basic type. Values are the uninterpreted contents of the
smallest addressable unit of storage *)
  ADDRESS = POINTER TO LOC;
  WORD = ARRAY [0 .. LOCSPERWORD-1] OF LOC;

  (* BYTE and LOCSPERBYTE are provided if appropriate for machine *)
CONST
  LOCSPERBYTE = --<--><implementation-defined constant> ;

TYPE
  BYTE = ARRAY [0 .. LOCSPERBYTE-1] OF LOC;

PROCEDURE ADDADR (addr: ADDRESS; offset: CARDINAL): ADDRESS;
  (* Returns address given by (addr + offset), or may raise an exception if
this address is not valid. *)

PROCEDURE SUBADR (addr: ADDRESS; offset: CARDINAL): ADDRESS;
  (* Returns address given by (addr - offset), or may raise an exception if this address is not valid. *)

PROCEDURE DIFADR (addr1, addr2: ADDRESS): INTEGER;
  (* Returns the difference between addresses (addr1 - addr2), or may raise an exception if the arguments are invalid or address space is non-contiguous. *)

PROCEDURE MAKEADR (val: ; ... ): ADDRESS;
  (* Returns an address constructed from a list of values whose types are implementation-defined, or may raise an exception if this address is not valid. *)

PROCEDURE ADR (VAR v: <anytype>): ADDRESS;
  (* Returns the address of variable v. *)

PROCEDURE ROTATE (val: <a packedset type>; num: INTEGER): <type of first parameter>;
  (* Returns a bit sequence obtained from val by rotating up or down (left or right) by the absolute value of num.  The direction is down if the sign of num is negative, otherwise the direction is up. *)

PROCEDURE SHIFT (val: <a packedset type>; num: INTEGER): <type of first parameter>;
  (* Returns a bit sequence obtained from val by shifting up or down (left or right) by the absolute value of num, introducing zeros as necessary.  The direction is down if the sign of num is negative, otherwise the direction is up. *)

PROCEDURE CAST (<targettype>; val: <anytype>): <targettype>;
  (* CAST is a type transfer function.  Given the expression denoted by val, it returns a value of the type <targettype>.  An invalid value for the target value or a physical address alignment problem may raise an exception. *)

PROCEDURE TSIZE (<type>; ... ): CARDINAL;
  (* Returns the number of LOCS used to store a value of the specified <type>.  
The extra parameters, if present, are used to distinguish variants in a variant record. *)

END SYSTEM.

A7.2 COROUTINES

DEFINITION MODULE COROUTINES;

(* Facilities for coroutines and the handling of interrupts *)

IMPORT SYSTEM;

TYPE
  COROUTINE; (* Values of this type are created dynamically by NEWCOROUTINE  and identify the coroutine in subsequent operations *)
  INTERRUPTSOURCE = <implementation-defined>;

PROCEDURE NEWCOROUTINE (procBody: PROC; workspace: SYSTEM.ADDRESS; size: CARDINAL; VAR cr: COROUTINE[; initProtection: PROTECTION]);
  (* Creates a new coroutine whose body is given by procBody, and returns the identity of the coroutine in cr.  workspace is a pointer to the work space allocated to the coroutine; size specifies the size of this workspace in terms of SYSTEM.LOC.
     initProtection is an optional parameter that specifies the initial protection level of the coroutine. *)

PROCEDURE TRANSFER (VAR from: COROUTINE; to: COROUTINE);
  (* Returns the identity of the calling coroutine in from, and transfers control to the coroutine specified by to. *)

PROCEDURE IOTRANSFER (VAR from: COROUTINE; to: COROUTINE);
  (* Returns the identity of the calling coroutine in from and transfers control to the coroutine specified by to.  On occurrence of an interrupt, associated with the caller, control is transferred back to the caller, and the identity of the interrupted coroutine is returned in from.  The calling coroutine must be associated with a source of interrupts. *)
    
PROCEDURE ATTACH (source: INTERRUPTSOURCE);
  (* Associates the specified source of interrupts with the calling coroutine. *)

PROCEDURE DETACH (source: INTERRUPTSOURCE);
  (* Dissociates the specified source of interrupts from the calling coroutine. *)

PROCEDURE IsATTACHED (source: INTERRUPTSOURCE): BOOLEAN;
  (* Returns TRUE if and only if the specified source of interrupts is
currently associated with a coroutine; otherwise returns FALSE. *)

PROCEDURE HANDLER (source: INTERRUPTSOURCE): COROUTINE;
  (* Returns the coroutine, if any, that is associated with the source of interrupts. The result is undefined if IsATTACHED(source) = FALSE. *)

PROCEDURE CURRENT (): COROUTINE;
  (* Returns the identity of the calling coroutine. *)

PROCEDURE LISTEN (p: PROTECTION);
  (* Momentarily changes the protection of the calling coroutine to p. *)

PROCEDURE PROT (): PROTECTION;
  (* Returns the protection of the calling coroutine. *)

END COROUTINES.

A7.3 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.

A7.4 TERMINATION

DEFINITION MODULE TERMINATION;

(* Provides facilities for enquiries concerning the occurrence of termination events. *)

PROCEDURE IsTerminating (): BOOLEAN ;
  (* Returns true if any coroutine has started  program termination and false otherwise. *)

PROCEDURE HasHalted (): BOOLEAN ;
  (* Returns true if a call to HALT has been made and false otherwise. *)

END TERMINATION.

A7.5 M2EXCEPTION

DEFINITION MODULE M2EXCEPTION;

 (* Provides facilities for identifying language exceptions *)
TYPE
  M2Exceptions = 
    (indexException, rangeException, caseSelectException,
    invalidLocation, functionException, wholeValueException,
    wholeDivException, realValueException, realDivException,
    complexValueException, complexDivException, protException,
    sysException, coException, exException *)

PROCEDURE M2Exception () : M2Exceptions;
(* If the current coroutine is in the exceptional execution state because of a language exception, returns the corresponding enumeration value, and otherwise raises an exception *)

PROCEDURE IsM2Exception () : BOOLEAN;
(* If the current coroutine is in the exceptional execution state because of a language exception, returns TRUE, and otherwise returns FALSE *)

END M2EXCEPTION.

Contents