----- Original Message -----
From: "Leopold Toetsch" <[EMAIL PROTECTED]>
To: "Luke Palmer" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Saturday, June 28, 2003 9:34 AM
Subject: Re: Tentative [PATCH]: valclone


> Luke Palmer <[EMAIL PROTECTED]> wrote:
> > Consider this Perl 6 code:
>
> >     sub refinc($var) {
> >         my $myvar = $var;
> >         $myvar += 1;
> >     }
>
> > If you pass an integer in here, it should do nothing.  However, if you
> > pass an object with an overloaded += in, it should have the
> > side-effect of adding one to that object.  It's just a value/reference
> > semantics thing.
>
> AFAIK no. The default is to pass constant references as arguments. So I
> would expect this throwing an exception.
> When you have:
>
>      sub refinc($var is rw) {
>
> it should increment the object ref.
>
> > If Perl compiles that code with $var and $myvar as PMCs, and it uses
> > C<set> to get $var into $myvar, PerlInt won't work right.  And if it
> > uses C<clone> to get $var into $myvar, an object won't work right.
>
> I think the assignment would translate to:
>
>     $P0 = new PerlUndef
>     assign $P0, $P1
>
> Its now up to the set_pmc() vtable to do the right thing for an object
> reference.
>
> > There are two ways to solve this: make a PerlRef class (which will
> > eventually have to be done anyway) or make a polymorphic assignment
> > which lets the PMC decide whether it has value or reference semantics.
>
> We need both, yes.
>
> > The included tentative patch implements the latter (namely,
> > C<valclone>).
>
> This is AFAIK what C<assign> does anyway.
>
> >>     PMC* valclone () {
> >>         PMC* dest = pmc_new(INTERP, SELF->vtable->base_type);
> >>         memcpy(&dest->cache, &SELF->cache, sizeof(UnionVal));
> >>         return dest;
> >>     }
>
> I'm not sure, if we need this.
>
> leo
>

This same problem I encountered when generating code for my Lua compiler:
passing args by value or reference.
If all vars on Parrot will be represented by PMCs (in many languages they
will, I presume, if no type checking can be done). It really depends on the
language being compiled if args are passed by ref or by value, so wouldn't
it be favourable to have a general "argument" PMC class or something, which
is language independent, and changes its type to whatever was passed in?
Then, the problem is solved for most (all?) languages that are being
compiled to Parrot (and gives Parrot a standard (and abstracted) way of
handling this issue.

Or is this not possible/desired? Just an idea I had.

Klaas-jan


Reply via email to