Dan Sugalski wrote:

At 9:33 AM -0400 10/15/04, Sam Ruby wrote:

Leopold Toetsch wrote:

Sam Ruby <[EMAIL PROTECTED]> wrote:

Concrete example: should ResizablePMCArray inherit sort from FixedPMCArray?

Yes. But the inheritance should be (and is AFAIK already partially) in the method lookup. But it's not quite finished. Objects derived from PMCs inherit methods of the parent, but one level only. PMC inheritance isn't followed yet IIRC.

I'm puzzled as to what works and what doesn't work. I added a __add__ method to pyobject and I can't access it from pyint... however I can access sort from ResizablePMCArray. Weird.

There are two basic classes of methods here. (And classes of classes, something I'm regretting, and I think we'll redo once I get a handle on metaclasses and just unify it all)[1]


The first is the vtable method stuff. There's a static single inheritance scheme when Parrot's built. These methods are the *C* methods (not NCI or bytecode) and they get filled in at parrot build time. There's no runtime inheritance, lookups, or anything. The fixed method is what's called. (That the fixed method may then delegate to parrot methods confounds things a bit)

The second is the *parrot* method stuff. These generally do a search of the hierarchy, at least if you're making a method call on a thing that's a ParrotObject. If you're making a method call on something else it depends on whether the method invocation code for that thing knows how to traverse the hierarchy.

So basically it's a bit of a muddle, and it needs swamping out.

It still doesn't make sense to me. Try adding the following line to both fixedpmcarray.pmc and perlint.pmc:


  METHOD INTVAL inheritme() { return 42; }

Then try running the following:

  .sub _main @MAIN
      print "test 1\n"
      $P0 = new ResizablePMCArray
      $I1 = $P0."inheritme"()
      print $I1
      print "\n"

      print "test 2\n"
      $P0 = new Boolean
      $I1 = $P0."inheritme"()
      print $I1
      print "\n"
  .end

The output I get is:

  test 1
  42
  test 2
  Method 'inheritme' not found
          in file '(unknown file)' near line -1

Apparently FixedPMCArray and PerlInt are different kinds of classes?

In any case, I would like to create some PMCs to represent Python classes. And I would like to implement as many of the methods as I can in C. And I would like such methods to be inherited.

I'm OK with a temporary solution (like the patch I provided) until a "real" solution can be put in place.

Suggestions welcome.

[1] And yes, I am being dragged deep into objects. Kicking and screaming, but still..

- Sam Ruby

Reply via email to