On Sun, Nov 05, 2006 at 05:41:12PM +0100, Leopold Toetsch wrote:
> Am Sonntag, 5. November 2006 15:22 schrieb Patrick R. Michaud:
> > So, I can create the missing cases, but what do I put for the body
> > of the method to get to the corresponding method of Capture?
> >
> > .namespace [ 'Match' ]
> > .sub set_integer_keyed_int :vtable
> > .param int key
> > .param int value
> >
> > # ... how to do set_integer_keyed_int method of Capture?
> >
> > .end
>
> A subclass of a PMC delegates to that PMC (via deleg_pmc.pmc). The PMC is the
> first attribute of that class named '__value'. Your code would look like:
>
> .local pmc capt
> capt = getattribute SELF, '__value'
> capt[key] = value
>
> But this is all clumsy, and might/should change.
>
> Therefore I've ci'ed in r15111 another workaround in parrotobject.pmc, which
> checks, if the parent isa PMC and in that case calls the deleg_pmc method
> instead of the default.
Alas, this seems to work only for immediate subclasses of a PMC.
If we have a sub-subclass, then we're apparently back to the
same problem as before:
$ cat zz.pir
.sub main :main
$P0 = new .Capture # create Capture object
$P0['alpha'] = 1 # store value in hash component
$P0[0] = 2 # store value in array component
$I0 = elements $P0 # display size of array (should be 1)
print $I0
print "\n"
# create a 'Match' subclass of Capture
$P99 = subclass 'Capture', 'Match'
$P1 = new 'Match' # create Match object
$P1['alpha'] = 1 # store value in hash component
$P1[0] = 2 # store value in array component
$I1 = elements $P1 # display size of array (should be 1)
print $I1
print "\n"
# create a 'Exp' subclass of Match
$P99 = subclass 'Match', 'Exp'
$P2 = new 'Exp' # create Exp object
$P2['alpha'] = 1 # store value in hash component
$P2[0] = 2 # store value in array component
$I2 = elements $P2 # display size of array (should be 1)
print $I2
print "\n"
.end
$ ./parrot zz.pir
1
1
0
$
Looking at the above, it seems to me that the crux of the problem
(short of an overall saner design) is that deleg_pmc is occuring
after default.pmc. That seems backwards. Perhaps any deleg_pmc
methods should be taking place before falling back to the PMC defaults.
We also have a similar problem currently taking place with PMC
methods -- methods defined in a PMC aren't being properly inherited
or re-delegated in ParrotObject subclasses. For capture.pmc I've
put some workarounds for this into Capture's 'get_array' and 'get_hash'
methods (r15129), but it again points to something fundamentally
wrong with the way that method inheritance/delegation is being
handled in ParrotObjects.
Pm