On Sun, Nov 25, 2007 at 01:56:51PM +0200, Allison Randal wrote: > Patrick R. Michaud wrote: > >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. > > But you do want 'replace' (by whatever name) to reuse the same PMC > header as the original? i.e it's not the same as: > > clone $P2, $P1 > set $P0, $P2 > > (which would simply store a new clone in that register) but equivalent to: > > morph $P0, <type of $P1> > assign $P0, $P1 > > (which reuses the PMC header of $P0, changes its type, and then copies > in the value from $P1). Correct, it's not the same as as clone+set. The difference is in what happens if there are other registers or symbols that point to the target PMC. With clone+set, the bindings of those other registers is lost -- they still point to the original PMC.
> >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) > > Seems reasonable. Agreed it needs some naming work. It's more like > 'rebless' than 'replace', but that's not right either (since we don't > have bless). It may end up as a variant of 'clone', or 'morph', or 'new'. How about 'copy'? Of the above suggestions, 'morph' seems most accurate, and 'new' seems all wrong to me. Of course, if we do it as a variant of 'clone' or 'morph' we might run into trouble when the source operand is itself a class (do we want to copy the class or do we simply want to morph to that type?). Pm