Contents | Prev | Next | Index
A text source file is accepted by the compiler as a unit and is called a compilation unit. There a three kinds of compilation units:
A main module constitutes a main program and consists of a so-called program module. In particular, it has no export list. Imported items are defined in other, separately compilable program parts which themselves are subdivided into two units, called definition and implementation module.
A definition module specifies the names and properties of items that are relevant to clients, i.e. other modules which import from it. These items are automatically qualified exported and might consist of constants, types, variables and specifications of procedure headings.
The corresponding implementation module contains local items and statements that need not be known to a client. It also contains the complete procedure declarations, and possibly further declarations of items not exported.
Definition and implementation modules exist in pairs. In this compiler, an implementation module need not be written, if the definition module refers to a foreign Java package. Both definition and implementation modules may contain import lists, and all items defined in the definition module are available in the corresponding implementation module without explicit import.
The definition module evidently represents the interface between the implementation module on one side and its clients on the other side. The definition module contains those declarations which are relevant to the client modules, and presumably no other ones.
Definition modules imply the use of qualified export. Type definitions may consist of the full specification of the (fully transparent) type, or they may consist of the type identifier only. In this case the full specification must appear in the corresponding implementation module, and its export is said to be opaque. The type is known in the importing client modules by its name only, and all its properties are hidden. Therefore, procedures operating on operands of this type, and in particular operating on its components, must be defined in the same implementation module which hides the type's properties. Opaque export in this compiler is restricted to pointers only. Assignment and test for equality are applicable to all opaque types.
As in local modules, the body of an implementation module acts as an initialization facility for its local objects. Before its execution, the imported modules are intialized in the order in which they are listed. If circular references occur among modules, their order of initialization is not defined.
The following syntax shows language extensions in red color.
compilation_unit ::= def_module ::= imp_module ::= program_module
imp_module ::= IMPLEMENTATION program_module |
This compiler maps a Modula-2 main module or a definition/implementation module pair to a Java class. Its variables and procedures become static members of that class. An optional JAVA PACKAGE directive informs the compiler into what subdirectory to place the resulting Java files. The default is that the compiler output goes into the current working directory.
Contents | Prev | Next | Index
Canterbury Modula-2 for Java (Last documentation update
Feb 8, 2000)
Copyright © 1998 Mill Hill &
Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to
mhc@webcom.com