Forwarder

ajh18 at cornell.edu ajh18 at cornell.edu
Wed Jul 25 16:07:04 UTC 2001


Stephen Pair <spair at advantive.com> wrote:
> We must ensure that all references to self in the methods of a forwardee
> object are actually referring back to the instance of the forwarder (thus,
references to the forwardee can be controlled).

I assume your only doing this for identity since obviously the message
sends will come back to the same forwardee.  But what about (Forwarder
on: anObject) == anObject?  It will return false.  Changing identity
just in the delagated method is not good enough.

Instead of trying to maintain references to the forwarder object in
method contexts, I think it would be more complete and simpler to just
redefine the identity (==) bytecode (bytecodePrimEquivalent) and class
bytecode (bytecodePrimClass) to do a normal message lookup if the
receiver or arg is a Forwarder (for #==, switch the receiver and arg if
arg is the Forwarder).  Forwarder instances would understand just one
message: #doesNotUnderstand:, which would forward the message (including
#==, and #class) to the forwardee and if that message returns the
forwardee or uses the forwardee so be it.  Any identity tests between
the forwarder and forwardee will return true.

If you want to free the forwardee and have all its references point to
the forwarder, you can use a become that uses forwarders as described by
Martin McClure's recent email.  object1 fowardBecome: object2 would
change the class of object1 to a Forwarder that points to object2. 
Changing the class of any object to a Forwarder would require a little
trickery (We would need two Forwarder classes: CompactClassForwarder and
NonCompacteClassForwarder.  Both would be variable length to accomodate
any object size.  object2 would be put in the first slot and nil in the
rest.  Empty objects would have to fail (Can't do nil become)).

Of course, when freeing the forwardee, you probably want to free it from
all pointer except the forwarder pointer.  In which case, you would
change the forwarder to point to a new copy of the forwardee before
doing the forwardee become.

Cheers,
Anthony Hannan




More information about the Squeak-dev mailing list