Contents | < Browse | Browse >


ISO Modula-2 Standard
_________________________________________________________________________


The best resource for learning to use ISO Modula-2 is an on-line textbook, "Modula-2: Abstractions for Data and Programming Structures - Modula-2 shareware textbook by Rick Sutcliffe". This can be found at "http://www.csc.twu.ca/rsbook/index.html".

ISO Modula-2 Syntax

Implemented Features in Aglet Modula-2 (M68K)

- Termination - FINALLY block.
- Exceptions - EXCEPT block.
- FOR loop semantics.
- LENGTH function.
- CAST() and VAL() differences. Type transfer "functions" removed.
- SYSTEM.ADDADR() and SUBADR().
- Storage module semantics.
- Standard IO modules (mostly)
- Other standard modules: SysClock, Strings, conversion modules


Not Implemented in Aglet Modula-2 (M68K)

- Structured type constructors.
- Multidimensional open arrays.
- COROUTINES module.
- COMPLEX Type.


Module Termination

   As specified in the new ISO standard for Modula-2, any module now can have a code section
   to be executed on program termination, in addition to the one for initialization.

The module body code now can be divided into two sections, the first containing the initialization code and the second the termination code. A new language symbol, "FINALLY", was introduced to mark the beginning of the termination code.
Termination code will be called at program exit no matter what the reason for it: end of main module body, a HALT, or a trapped exception.
Different module's termination codes are specified to be called in the opposite order in which their initialization codes were called.
Termination code is called only once. A HALT or exception within a module's termination code will end that one and continue with the next module's termination code.
If program exit occurs during initialization before the main module is reached, modules whose initialization code has not been entered will not be terminated. This implementation will always call termination code, if any, for modules that have no initialization code at all.
NOTE: THE CURRENT IMPLEMENTATION TREATS (NON-DYNAMIC) LOCAL MODULES AS IF THEY WERE PART OF THEIR MAIN MODULE. THUS, THEY WILL HAVE TERMINATION CALLED IF THE INIT CODE OF THEIR MAIN MODULE IS ENTERED.
The standard system module TERMINATION is supported. Its definition module is "built in" to the compiler and its two procedures are built in to the OBM file for module System. They are
PROCEDURE IsTerminating():BOOLEAN; PROCEDURE HasHalted():BOOLEAN;
NOTE: THE CURRENT IMPLEMENTATION RETURNS TRUE FOR HasHalted() IF EITHER A HALT WAS EXECUTED OR A TRAPPED EXCEPTION CAUSED PROGRAM TERMINATION.

Exceptions Support
   The general exception model allows an EXCEPT section at the end of Module init bodies,
   Module term bodies, and Procedure bodies.

Upon an exception, control transfers to the start of the EXCEPT block.
A RETRY statement within the exception block will restart its normal execution body from the beginning.
A RETURN statement within the exception block will clear the exception and exit from the procedure or module body.
IF neither statement is executed within the exception block, the exception state remains raised and the previous active exception block is entered. If there is none, the program ends via the system default exception handler.
M2EXCEPTION defines an enumeration of language exceptions, "M2Exception", that are always trapped:
(indexException, rangeException, caseSelectException, invalidLocation, functionException, wholeValueException, wholeDivException, realValueException, realDivException, complexValueException, complexDivException, protException, sysException, coException, exException)
It also contains two procedures:
PROCEDURE IsM2Exception():BOOLEAN;
returns TRUE if the program is in the "exceptional execution state" because of one of the above language exceptions.
PROCEDURE M2Exception():M2Exceptions;
if the program is not in the "exceptional execution state" because of one of the above language exceptions, this proc raises the "exException". otherwise, it returns which M2Exception is active.
NOTE: Because the Amiga OS4 Pre-release M68K Emulator does not support the TRAP instruction, some exceptions as implemented in the M68K interim compiler cannot be intercepted, such as invalidLocation, and will result in a GrimReaper instead. The compiler switches "-v" and "-r" still determine whether most of these exception situations will be detected at run time.
.