It's a timing issue. Methods are currently loaded into the class from the namespace when the class is created. So, if you call load_bytecode after newclass, it helpfully inserts the methods into the namespace, but the class doesn't pick them up. (This has been on my radar for a while, I just haven't made the change yet.)

I'll work on this today, but if you want the quick fix, just call load_bytecode before newclass. (The quick fix won't work for your eval example.)

Thanks for the good test cases.

Allison

Patrick R. Michaud wrote:
In pdd15oo, there seems to be an issue about using load_bytecode
to load :method subs after a class has been created.

Here's my test code.  The main file is 'foo.pir':

    $ cat foo.pir
    .sub 'main' :main
        $P0 = newclass 'Foo'
        $P1 = new 'Foo'
        $P1.'foo_method'()
load_bytecode 'bar.pir'
        $P1 = new 'Foo'
        $P1.'bar_method'()
    .end
.namespace ['Foo'] .sub 'foo_method' :method
        say 'foo_method'
    .end


Here's 'bar.pir', which is loaded via load_bytecode:
$ cat bar.pir
    .namespace ['Foo']
.sub 'bar_method' :method
        say 'bar_method'
    .end


When I run foo.pir, it doesn't recognize 'bar_method' as being
a valid method for Foo objects:
$ ./parrot foo.pir
    foo_method
    Method 'bar_method' not found
    current instr.: 'main' pc 24 (foo.pir:8)
    $
It works if I move the load_bytecode line above the newclass opcode.

There doesn't seem to be any difference between loading bar.pir
or a pre-compiled bar.pbc .

Pm


Reply via email to