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 ;
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;
};
};
linearmodule: Linear;
linearmodule = load Linear "/usr/dmr/limbo/linear.dis";
if (linearmodule == nil) {
sys->print("Can't load Linear\n");
exit;
}
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;