I just want to add a reminder here that the whole reason PCT,
PAST-pm, and Tcl use morph in the first place is because Parrot
doesn't provide a usable "replace pmc with clone" opcode, and
using morph+assign is a workaround.

In other words, if a "replace pmc" opcode exists, then morph 
suddenly becomes _much_ less important.

Ideally I'd like to have a keyed version also (choose your
own better opcode name):

    replace $P0, $P1        # replace $P0 with a clone of $P1

    replace $P0[key], $P1   # replace pmc at $P0[key] with a clone
                            #   of $P1 (creating $P0[key] if needed)

Pm


On Fri, Nov 23, 2007 at 12:05:08PM +0200, Allison Randal wrote:
> A better fix is to update pmc_reuse in src/pmc.c so it correctly handles 
> morphing to object types. See pmc_new in the same file for an example of 
> instantiating an object from a type ID (by looking up the class object). 
> As Jonathan started to ponder in his message "Morphing to high level 
> classes", this may mean having the 'instantiate' vtable function check 
> the hash parameter for a 'reuse' key, a PMC header to reuse. (50/50 on 
> whether we want to expose that as an option from the PIR-level interface 
> or block it.)
> 
> Allison
> 
> [EMAIL PROTECTED] wrote:
> >Author: chromatic
> >Date: Tue Nov 20 20:42:22 2007
> >New Revision: 22924
> >
> >Modified:
> >   trunk/src/pmc/undef.pmc
> >
> >Log:
> >[PMC] assign $P0, $P1 failed with badness when $P0 was an Undef PMC and 
> >$P1 was
> >an Object, because the assign_pmc vtable entry first morphed the Undef PMC 
> >into
> >a like Object and then tried to instantiate it with the init vtable entry.
> >
> >This does not work on Objects, as you must instantiate them from their 
> >Classes.
> >
> >Now there's no morph into an Object; the Undef PMC morphs into a Ref and 
> >points to the Object instead.
> >
> >Modified: trunk/src/pmc/undef.pmc
> >==============================================================================
> >--- trunk/src/pmc/undef.pmc  (original)
> >+++ trunk/src/pmc/undef.pmc  Tue Nov 20 20:42:22 2007
> >@@ -48,7 +48,7 @@
> > 
> > =item C<void assign_pmc(PMC *other)>
> > 
> >-Assigns the PMC to the value of C<*other>by first changing the PMC to the
> >+Assigns the PMC to the value of C<*other> by first changing the PMC to the
> > appropriate type.
> > 
> > =cut
> >@@ -56,7 +56,8 @@
> > */
> > 
> >     void assign_pmc(PMC *other) {
> >-        VTABLE_morph(INTERP, SELF, other->vtable->base_type);
> >+        if (!PObj_is_object_TEST(other))
> >+            VTABLE_morph(INTERP, SELF, other->vtable->base_type);
> > 
> >         /* don't want to call set_pmc if we're assigning an Undef to an 
> >         Undef */
> >         if (other->vtable->base_type != enum_class_Undef)
> >
> >

Reply via email to