Digest module and Q:PIR blocks

Will Coleda will at coleda.com
Wed Jun 9 01:52:03 UTC 2010


On Mon, Jun 7, 2010 at 5:56 AM, Cosimo Streppone <cosimo at streppone.it> wrote:
> On Mon, 07 Jun 2010 02:11:05 +0200, Patrick R. Michaud <pmichaud at pobox.com>
> wrote:
>
>> On Sun, Jun 06, 2010 at 11:06:07PM +0200, Cosimo Streppone wrote:
>>>
>>> Hi all,
>>>
>>> Just for fun, I'm trying to write a Digest::MD5 module for Rakudo.
>>> Right now I'm stuck with something like:
>>> [...]
>>
>> The MD5.pbc module loads into a different HLL namespace from
>> Rakudo ('parrot' instead of 'perl6').  So, you probably want
>> 'get_root_namespace' here.
>>
>>    sub test($text) {
>>        Q:PIR {
>>            load_bytecode 'Digest/MD5.pbc'
>>            $P0 = find_lex '$text'
>>            $P1 = get_root_global ['parrot'], '_md5sum'
>>            $P2 = $P1($P0)
>>            $P1 = get_root_global ['parrot'], '_md5_hex'
>>            $S2 = $P1($P2)
>>            say $S0
>>        }
>>    }
>>
>>    test('hello world');
>
> I guess you meant 'say $S2'.
>
>> Running this program for me (with --trace=1) results in a
>> segmentation fault somewhere in the _md5sum function.
>
> Interesting, because it doesn't segfault for me. I get:
>
>  NULL PMC access in find_method('signature')
>    in 'test' at line 2:test.pl
>    in main program body at line 15:test.pl
>
> My ignorant guess is that the signature() method is
> available in the 'parrot' namespace, but not in my
> current namespace.
>
> This makes me think I'd prefer avoiding the globals business
> and using the functions in their natural package (Digest?),
> but I don't know how to do that.
>
> I tried:
>
>  - find_method ['Digest'], '_md5sum'
>  - get_hll_global ['Digest'], '_md5sum'
>  - other futile attempts...
>
> with no luck.
>
> --
> Cosimo
>

Here's my best guess:


sub test (Str $test) {
    my $result = Q:PIR {
        # This loads into the /current/ HLL, but should probably load into
        # the /parrot/ HLL.
        load_bytecode 'Digest/MD5.pbc'
        .local pmc md5sum, md5hex, test
        md5sum = get_root_global ['parrot'; 'Digest'], '_md5sum'
        md5hex = get_root_global ['parrot'; 'Digest'], '_md5hex'
        test = find_lex '$test'
        %r = md5sum(test)
        %r = md5hex(%r)
    };
    return $result;
}

test('hi');


... but this also fails with the 'signature' issue - note that Digest
doesn't have anything called 'signature'

I think this is related to the recent dynop issues - recent changes in
parrot moved a lot of opcodes into dynamic opcode libraries - stepping
through this, it dies in the invocation of the 'rot' opcode, which is
recently moved to the dynamic 'bit' ops. I'm guessing that when this
is invoked, it's actually invoking some perl6 opcode and going south.

Once this bug is fixed (it's related to loading opcode libraries in a
different order in the perl6 and Digest PBCs), this should work.

Regards.

-- 
Will "Coke" Coleda


More information about the parrot-dev mailing list