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).

The tricky bit is reusing a PMC header for a high-level object, whether it's in the 'morph' opcode or some other opcode. Not impossible, though.

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'.

Allison

Reply via email to