adrian@ru-cs44.UUCP (Adrian Pell) (02/21/84)
There is indeed a problem related to circular references in Modula-2. We have the M2 compiler modified by Univ. of New South Wales for Unix from the original RT-11 compiler written at ETH. It does NOT allow circular references of the first type mentioned, ie. circular references between definition modules. It would appear from the report (section 4, rule 3), that such references ought to be allowed since the scope of the exported identifier extends to all those compilation units that import the identifier. However, consider the following: definition module a; from b import Btype; export qualified Atype; type Atype = record x : Btype; end; end a. definition module b; from a import Atype; export qualified Btype; type Btype = record y : Atype; end; end b. At the time of compiling def mod a, if b has not been compiled, we do not know the size of Btype, nor its components, but if the compilation were to be successful we could proceed to compile a's implementation module, and (presumably) to use the fields of Btype which we don't know! Circular references of the other type, i.e. involving implementation and definition modules present no such problems, since there is no ambiguity or uncertainty in what is meant. Our compiler allows such things and leaves it up to the linker to determine the order of initialisation. The linker, incidentally, has the sense to tell the user what order has been chosen. There is, of course, a problem concerning initialisation of local modules. They must be initialised before their enclosing module's statement part, which can involve circumventing the initialisation in order to reverse the order - especially true where asynchronous processes are started by inner modules! -- Adrian Pell ({vax135,mcvax,edcaad}!ukc!ru-cs44!adrian) Computer Science Dept. University of Reading UK