Patrick R. Michaud <[EMAIL PROTECTED]> wrote:
On Fri, Dec 08, 2006 at 05:05:00PM -0500, Matt Diephouse wrote:
> Patrick R. Michaud <[EMAIL PROTECTED]> wrote:
> >Does anyone have any suggestions about what sort of PIR
> >code and/or PMCs we need to be able to do make the following
> >Perl 6 code work...?
>
> Sure. I think Tcl handles this pretty nicely at the moment (although
> Leo disagrees - he likes the Ref PMC route). The main idea is that
> aliasing/binding enters the same PMC under a different name and that
> assignment morphs the PMC.

Does this basically assume that every PMC knows how to morph into
any other type?  (In the example I gave the PMC would need to be able
to morph from an integer to a list, but in the general case it could
be converting to any type.)

No, it assumes that every PMC knows how to morph into an Undef. Once
you have an Undef, you can safely use assign. Undef's assign morphs to
the type of the second PMC and then calls assign again, so that each
type only needs to handle one type in assign -- itself.

> With this scheme, you'd have to use assign in this last case instead
> of set (with a morph to really make it safe) because you need to reuse
> the same PMC:
>
>     #### @a[4] = [1, 2]
>     $P2 = 'list'(1, 2)
>     find_lex $P3, '@a'
>     $P3 = $P3[4]
>     morph $P3, .Undef
>     assign $P3, $P2
>
> If you're only assigning your own PMCs, you can drop the morph (which
> isn't technically safe anyway).

I don't think I can assume I'm only assigning my own PMCs.  (This is
being handled in PAST-pm, and so it probably needs to work with PMCs
in general.)  And I know that morphing isn't safe, which is why I've
been avoiding it.

Hmm... perhaps what we really need is an opcode or sequence of
opcodes that convert a PMC into a value-based copy (clone?) of
another PMC, but keeping the first PMC as the same PMC so that
other references to it will see the new value and type.

I would like to see some sort of morph opcode that isn't a vtable
function. This fits in to my transparent references proposal (which I
haven't quite finished). I'm not sure what the use case of the morph
vtable function is supposed to be.

Note that using Ref PMCs isn't completely safe either, as they use the
set_pmc vtable function.

--
Matt Diephouse
http://matt.diephouse.com

Reply via email to