Article View: comp.lang.modula2
Article #3598Unsafe ADT in Modula-2
From: HABERNOL
Date: Thu, 05 Feb 1987 16:58
Date: Thu, 05 Feb 1987 16:58
47 lines
2986 bytes
2986 bytes
> 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 [...]
> [...]
> 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
It is impossible to implement a "safe" ADT in Modula-2. It would
require some modifications of the language. You would need full
control over the objects of this type. The exporting module must be
informed on allocation and deallocation of this object (i.e. at
scope entry and scope exit). Furthermore you must have control over
all operations on these objects. You may write an init, fin, assign
routine, but this is very unsafe (because it requires that the user
applies *only* your operations in the *correct* order. I haven't seen
such a user :-) Such calls had to be generated automatically
by the compiler (block entry, block exit, explicit assignation (":="),
implicit assignation (parameter passing)). You may protect your
implementation of the ADT (by keeping a list of pointers to objects of
this type, or by magic numbers). This will result in additional overhead,
but it doesn't garuantee integrity of data.
Problem with list of pointers mentioned above: Because you can't catch the
assignations you have no chance to decide how many valid references to an
object exists. Another problem comes from the missing signals
on scope exit. No chance for your internal bookkeeping.
It wouldn't be very hard to modify Modula to allow safe implementations
of abstract data types (some procedures must be bound to the type declaration,
calls are generated by the compiler for allocation/deallocation/assignment).
I have implemented such a system for an extended Pascal dialect
several years ago.
After you have done these modifications you would have a nice language but
you will have to find a new name for it because it wouldn't be Modula-2
any longer.
Thomas Habernoll - HABERNOL@DB0TUI11.BITNET - ...!mcvax!unido!tub!thh
Technical Details
Message-ID:
<8702051645.AA05408@Cayuga.cs.Rochester.Edu>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ucbvax!DB0TUI11.arpa!HABERNOLShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbatt!ucbvax!DB0TUI11.arpa!HABERNOL From: HABERNOL@DB0TUI11.arpa.UUCP Newsgroups: comp.lang.modula2 Subject: Unsafe ADT in Modula-2 Message-ID: <8702051645.AA05408@Cayuga.cs.Rochester.Edu> Date: Thu, 5-Feb-87 11:58:05 EST Article-I.D.: Cayuga.8702051645.AA05408 Posted: Thu Feb 5 11:58:05 1987 Date-Received: Sat, 7-Feb-87 12:33:50 EST Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet Lines: 47