On Wed, Aug 09, 2000 at 03:32:41PM -0400, Chaim Frenkel wrote:
> Each sub has a unique number.
> 
> Package A - Has nothing blessed, doesn't need the lookup table
> 
> Package B - Has blessed items, lookup table for all subs that are part
>           of the package, or in the inheritance tree.

Are you thinking of assigning a unique number to every sub seen in
every package?

An alternate method might be:

Each sub is assigned an index.  This index is unique for the package
the sub is in, and all ancestor packages.

For example:

  package Dog;
  sub bark { }        # Index = 0.
  sub bite { }        # Index = 1.

The Dog vtable now looks like this:

  0  Dog::bark
  1  Dog::bite

Define a couple of subclasses of Dog:

  package Corgi;
  sub bark { }       # Overrides base class definition; index = 0.
  sub sleep { }      # New sub; index = 2.

  package Mutt;
  sub bark { }       # Overrides base class definition; index = 0.
  sub read_mail { }  # New sub; index = 2.
  sub sleep { }      # New sub; index = 3.

The Corgi vtable is:

  0  Corgi::bark
  1  Dog::bite
  2  Corgi::sleep

The Mutt vtable is:

  0  Mutt::bark
  1  Dog::bite
  2  Mutt::read_mail
  3  Mutt::sleep


In this fashion, the object vtable never needs to contain more entries
than there are subs in the object package (and all ancestors of this
package).  It doesn't matter that the sleep() method has different
slots in the Corgi and Mutt packages, since these packages do not
inherit this method from a common package.

This all falls apart under multiple inheritance, unfortunately.  Pity
I didn't notice that when I started writing this.

                     - Damien

Reply via email to