Unlike the Generic extensions, those for OOM-2 require some library support. That for exceptions parallels the one in the base language; coroutines requires one additional procedure, and garbage collection also has a library.
OOM-2 extensions to the base language define four new exceptions. Detection of the first three is mandatory, but detection of the last one is optional. They are:
raised whenever an attempt is made to access an object via an empty reference
raised whenever an attempt is made to call an abstract method
raised if there is no match on the list of selections (possibly due to an empty reference) and no ELSE
an implementation may choose to raise this if there is an attempt to change an immutable entity.
In addition, there is a new system module, which behaves as if it had the following definition:
DEFINITION MODULE M2OOEXCEPTION; (* Provides facilities for identifying exceptions of the extended language *) TYPE M2OOExceptions = (emptyException, abstractException, immutableException, guardException); PROCEDURE M2OOException (): M2OOExceptions; (* If the current coroutine is in the exceptional execution state because of the raising of an exception of the language extensions, returns the corresponding enumeration value, and otherwise raises an exception. *) PROCEDURE IsM2OOException (): BOOLEAN; (* If the current coroutine is in the exceptional execution state because of the raising of an exception of the language extensions, returns TRUE, and otherwise returns FALSE. *) END M2OOEXCEPTION.
The entities of this system module behave in exactly the same way as do those of the module M2EXCEPTION described in section 10.2.1 except that they act on the OOM-2 exception enumeration instead of that of the base language.
The module COROUTINES (see the chapter on that subject) in the base standard has one procedure added to provide support for OOM-2. It is
PROCEDURE DISPOSECOROUTINE (VAR cr: COROUTINE); (* Declare that the coroutine identified by cr has reached the end of its lifetime. *)
The procedure DISPOSECOROUTINE is used to inform the garbage collector that the coroutine of the actual parameter has reached the end of its lifetime. The garbage collector takes this to mean that all the traced variables in that coroutine have become defunct and may be collected.
In some implementations it may be possible to turn garbage collection off and on, or to force it to take place at specified points in a program when it is convenient, rather than leave it up to automatic routines. Thus, the procedures of the following module may do something, but only if the implementation allows this. Their semantics are described in the comments and need no further explanation.
DEFINITION MODULE GARBAGECOLLECTION; (* Provides facilities for controlling the garbage collector. *) PROCEDURE IsCollectionEnabled (): BOOLEAN; (* If garbage collection is enabled then returns TRUE and otherwise returns FALSE. *) PROCEDURE CollectionEnable (on: BOOLEAN); (* If on is TRUE then enable garbage collection; otherwise if on is FALSE and garbage collection can be disabled then disable garbage collection. *) PROCEDURE ForceCollection; (* If garbage collection can be forced then force it else do nothing. *) END GARBAGECOLLECTION.