MODULE [ HP Pascal/iX Reference Manual ] MPE/iX 5.0 Documentation
HP Pascal/iX Reference Manual
MODULE
A module provides a mechanism for separate compilation of program
segments. It is a program fragment with a completely defined interface
that can be compiled independently and later used to construct programs.
A module usually defines some data types, constants, variables, and some
procedures and functions that operate on this data. Such definitions are
made accessible to users of the module by its export declarations.
Modules can only access data or procedures in other modules and then only
by importing them.
Any module used by a program, whether appearing in the program's globals
or compiled separately, must be named in an import declaration. The
objects that modules export always belong to the global scope of the
importer.
The source text input to a compiler that is the complete unit of
compilation may be a program or a list of modules separated by semicolons
(; ). An implementation may allow only a single module to be compiled at
a time, thus requiring multiple invocations of the compiler to process
several modules. The input text is terminated by a period.
A module cannot be imported before it has been compiled, either as part
of the importing program or by a previous invocation of the compiler.
This prevents construction of mutually-referring modules. Access to
separately compiled modules is discussed below.
Although a module declaration defines data and procedures that become
globals of any program importing the module, not everything declared in
the module becomes known to the importer. A module specifies exactly
what is exported to the "outside world" and lists any other modules on
which it is itself dependent.
The export declaration defines constants and types, declares variables,
and gives the headings of procedures and functions whose complete
specifications appear in the implement part of the module. It is only
the items in the export declaration that become accessible to any other
code that subsequently imports the module.
There need not be any procedures or functions in a module if its purpose
is solely to declare types and variables for other modules.
Any constants, types, and variables declared in the implement part are
not made known to importers of the module; they are only known inside the
module, and outside it they are hidden. Variables of the implement part
of a module have the same life time as global program variables, even
though they are hidden.
Any procedures or functions whose headings are exported by the module
must subsequently be completely specified in its implement part. In this
respect, the headings in the export declaration are like FORWARD
directives, and in fact the parameter list of such procedures need not
be, but may be, repeated in the implement part. Procedures and functions
that are not exported may be declared in the implement part; they are
known only within the module and are hidden from the rest of the program.
Separately compiled modules are called library modules. To use library
modules, a program imports them just as if they had appeared in the
program block. Refer to the HP Pascal/iX Programmer's Guide or the HP
Pascal/HP-UX Programmer's Guide, depending on your implementation, for
further information.
When an import declaration is seen, a module must be found matching each
name in the import declaration. If a module of the required name appears
in the compilation unit before the import declaration, the reference is
to that module. Otherwise, external module libraries must be searched.
See "SEARCH" , and the HP Pascal/iX Programmer's Guide or the HP
Pascal/HP-UX Programmer's Guide, depending on your implementation, for
more information.
In order for a procedure in a module to read from input or write to
output (for example, readln from input or writeln to output), that module
must import the standard modules stdinput or stdoutput, respectively.
On HP-UX the standard modules stdinput, stdoutput, and stderr are
contained in the predefined library /usr/lib/paslib. On MPE/iX the
standard modules stdinput and stdoutput are contained in the predefined
library PASLIB.PUB.SYS.
When a program, either directly or indirectly, imports a module that
imports stdinput or stdoutput, the program must specify input or output,
respectively, in the program parameter. If a program does not specify
input or output and a module imports the standard modules, the program
will not link.
On HP-UX only, if a program, either directly or indirectly, imports a
module that imports stderr, the program must specify stderr in the
program parameter. If a program does not specify stderr and a module
imports the standard module stderr, the program will not link. In
addition, if a procedure in a module writes to stderr, that module must
import the standard module, stderr.
Syntax
Module_declaration:
Example
This example shows a source file that contains definitions for the
modules bit_types and char_info. MODULE bit_types and MODULE char_info
are compiled into an object file called mod1.o. Note that mod1.o is
referenced in the examples in section "IMPORT" .
MODULE bit_types; { Module declaration }
EXPORT { Exported types }
TYPE
bits8 = 0..255; { Exported type }
IMPLEMENT { No implement, part, module }
END; { only provides data types }
MODULE char_info; { Module declaration }
IMPORT
bit_types; { Import other modules needed }
{ to compile this module }
EXPORT { Start of export text }
TYPE
byte = bits8; { Exported type }
VAR
last_byte: byte; { Exported variable }
FUNCTION control (i:byte; flag:BOOLEAN): BOOLEAN; { Exported function }
IMPLEMENT { Start of implementation }
IMPORT stdoutput; { Required for using output }
CONST
error = 'non-ASCII character'; { Non-exported constant }
FUNCTION check (i: byte; flag: BOOLEAN): BOOLEAN; {Non-exported function}
BEGIN
IF i > 127 THEN
BEGIN
check := false;
IF flag THEN writeln (error);
END
ELSE
check := true;
END;
FUNCTION control (i: byte; flag: BOOLEAN): BOOLEAN;{ Exported function }
BEGIN
last_byte := i;
control := check (i,flag) AND (i < 32);
END;
END.
MPE/iX 5.0 Documentation