Copyright © 1996, 1997 Lucent Technologies Inc. All rights reserved.

6.5 Module declarations

A module declaration collects and packages declarations of adt, functions, constants and simple types, and creates an interface with a name that serves to identify the type of the module. The syntax is


module-declaration: identifier : module { mod-member-listopt } ; mod-member-list: mod-member mod-member-list mod-member mod-member: identifier-list : function-type ; identifier-list : data-type ; adt-declaration ; identifier-list : con expression ; identifier-list : type type ;
After a module declaration, the named identifier becomes the name of the type of that module. For example, the declaration
Linear: module {
	setflags: fn (flag: int);
	TRUNCATE: con 1;
	Vector: adt {
		v: array of real;
		add: fn (v1: self Vector, v2: Vector): Vector;
		cross: fn (v1: self Vector, v2: Vector): Vector;
		dot: fn (v1: self Vector, v2: Vector);
		make: fn (a: array of real): Vector;
	};
	Matrix: adt {
		m: array of array of real;
		add: fn (m1: self Matrix, m2: Matrix): Matrix;
		mul: fn (m1: self Matrix, m2: Matrix): Matrix;
		make: fn (a: array of array of real): Matrix;
	};
};
is a module declaration for a linear algebra package that implements two adt, namely Vector and Matrix, a constant, and a function setflags. The name Linear is the type name for the module, and it may be used to declare an object referring to an instance of the module:
	linearmodule:  Linear;
Before the module can be used, it must be loaded, for example in the style:
	linearmodule = load Linear "/usr/dmr/limbo/linear.dis";
	if (linearmodule == nil) {
		sys->print("Can't load Linear\n");
		exit;
	}
The load operator is discussed more fully in §8.4.5 below.

To initialize data declared as part of a module declaration, an assignment expression may be used at the top level. For example:

	implement testmod;
	testmod: module {
		num:	int;
	};
	. . .
	num = 5;
The right side of the assignment must be a constant expression (§8.5).

05/Jun/97