[svn:parrot] r33417 - trunk/src/pmc

NotFound julian.notfound at gmail.com
Wed Dec 3 11:14:55 UTC 2008


>> +    VTABLE INTVAL is_same(PMC *value) {
>> +        return PMC_IS_NULL(value);
>> +    }
>> +
>>  }
>
> Since there's only one PMCNULL value, do we really need this
> vtable entry?  And why would it do anything different from the
> default, which is to compare C<value> and C<SELF> ?

If we delete it, this is the generated vtable entry for the null pmc:

PARROT_EXPORT INTVAL
Parrot_Null_is_same(PARROT_INTERP, PMC *pmc, PMC *value)
{
    Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_NULL_REG_ACCESS,
        "Null PMC access in is_same()");
}

Defaults for the null pmc are not taken from the default pmc, they are
handled apart.

> In fact, naively I expect that nearly all PMCs should simply
> use the default "is_same" VTABLE function, which simply returns
> the result of C< value == SELF >.  It's not at all clear to me
> why some of the PMCs override this default behavior.

This is the explanation in string.pmc POD:
------------------------------------------------------------------------
Returns true if this PMC and the one in C<value> are of the same PMC
class and their strings are aliases of the same internal string.

(this can only happen if you use the set_string_native method)
------------------------------------------------------------------------
I don't know the rationale of this intended behavior, nor if there are
any test for it.

> Continuing on with the String PMC, even after the patch in r33417
> we still have the case of:
>
>    $ cat x.pir
>    .sub main
>        $P0 = new 'String'
>        assign $P0, 'foo'
>
>        $P1 = split ' ', 'parrot speaks your language'
>
>        $I0 = issame $P0, $P1
>        say $I0
>    .end
>
>    $ ./parrot x.pir
>    get_string() not implemented in class 'ResizableStringArray'
>    current instr.: 'main' pc 10 (x.pir:7)
>    $

The problem seems to be that the check for the "same PMC class" part
is done after calling get_string on both operands. (Note that this
does not contradict the POD, because it says when to return true but
does not explicitly tell that must return false in any other case).

Fixed this part in r33452. Now it must return true or false except
when both operands are of the same pmc type and get_string throws.

-- 
Salu2


More information about the parrot-dev mailing list