[comp.lang.modula2] one pass, ADT initialization problems.

afd@k.cc.purdue.edu.UUCP (02/02/87)

(* This is reposted; my apologies to anyone who receives this twice. *)

   First, I recall from some time ago a discussion on forward references 
   in a one pass Modula-2 compiler being impossible.  Last semester we
   implemented Aho, Sethi, and Ullman's unification algorithm with type 
   variables (pg. 366, 376) and it worked quite well.  I see no problem in
   implementing forward references for types or procedures in a one pass
   Modula-2 compiler.

   Second, concerns the initialization problems with Modula-2 ADTs.
   When a procedure is called with an uninitialized ADT, a test for
   undefined is impossible, and a simple test for nil is obviously
   insufficient.  One solution is to maintain a list of pointers
   to initialized variables of an opaquely exported type.  A simple test 
   at the beginning of each procedure which accesses that type could
   generate an error message or provide automatic initialization.  One
   problem with this solution is Modula-2's inability to control assignment
   of ADTs.  Declaring ADT's as pointers to headers, and keeping a list of
   pointers to these headers would help, but I'm hoping someone will post
   a better solution (if anyone sees problems with this approach, please 
   let me know too). 

   Also, does anyone know of a method to provide automatic cleanup upon 
   termination of an ADT's environment?

				     Bob Hathaway
				     afd@k.cc.purdue.edu