Re: Re: p6 variable binding in Parrot

2006-12-09 Thread Patrick R. Michaud
On Sat, Dec 09, 2006 at 12:59:35AM -0500, Matt Diephouse wrote:
> Patrick R. Michaud <[EMAIL PROTECTED]> wrote:
> >On Fri, Dec 08, 2006 at 05:05:00PM -0500, Matt Diephouse wrote:
> >> 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. [...]

A, I get it.  Yes, this sounds good to me.  In fact, it's
pretty much what I asked for -- a "sequence of opcodes that convert
a PMC into a value-based copy of another PMC".

Many thanks, I'll go with that for now.

Pm


Re: Re: p6 variable binding in Parrot

2006-12-08 Thread Matt Diephouse

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


Re: p6 variable binding in Parrot

2006-12-08 Thread Patrick R. Michaud
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.)

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

Pm


Re: p6 variable binding in Parrot

2006-12-08 Thread Leopold Toetsch
Am Freitag, 8. Dezember 2006 22:43 schrieb Patrick R. Michaud:
> 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...?
>
>     my @a;
>     @a[4] = 'Hello';
>
>     my $b := @a[4];
>     say $b;                # says "Hello"
>
>     @a[4] = [1, 2];
>     say $b;                # says "1 2"

Please talk with Jonathan. He has AFAIK implemented this and more in dotnet 
PMCs.

See also

http://groups.google.at/group/perl.perl6.internals/browse_frm/thread/e55c6c4921b728e0/edd57aa9a293f87c?lnk=gst&q=jonathan+reference&rnum=2#edd57aa9a293f87c
http://groups.google.at/group/perl.perl6.internals/browse_frm/thread/645ed07d9527d353/bb4f84dc252b6ea8?lnk=gst&q=jonathan+reference&rnum=1#bb4f84dc252b6ea8

leo


Re: p6 variable binding in Parrot

2006-12-08 Thread Matt Diephouse

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.


my @a;
@a[4] = 'Hello';

my $b := @a[4];
say $b;# says "Hello"

@a[4] = [1, 2];
say $b;# says "1 2"


Here are the pieces I can fill in:

 my @a;
new $P0, .Perl6List
.lex '@a', $P0

 @a[4] = 'Hello';
find_lex $P1, '@a'
# (in general case we autovivify @a here if needed)
set $P1[4], 'Hello'


 my $b := @a[4];
find_lex $P2, '@a'
$P2 = $P2[4]
.lex '$b', $P2
 say $b;# says "Hello"
say $b


 @a[4] = [1, 2]
$P2 = 'list'(1, 2) # create a list
find_lex $P3, '@a'
# (in general case we autovivify @a here if needed)
set $P3[4], $P2


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

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