How does one create a new class with a name determined dynamically
at runtime?

For example, suppose I have a string like 'PGE::Perl6Grammar', and
from that I want to create a ['PGE';'Perl6Grammar'] class.  The code

    $ cat z1.pir
    .sub main :main
        $S0 = 'PGE::Perl6Grammar'
        $P0 = split '::', $S0
        $P1 = newclass $P0
        say $P1
    .end

gives me
    
    $ ./parrot z1.pir
    Invalid namespace key in get_pointer_keyed
    current instr.: 'main' pc 7 (z1.pir:4)

The same problem exists for creating a subclass:

    $ cat z2.pir
    .sub main :main
        $S0 = 'PGE::Perl6Grammar'
        $P0 = split '::', $S0
        $P1 = subclass 'Hash', $P0
        say $P1
    .end
    
    $ ./parrot z2.pir
    Invalid namespace key in get_pointer_keyed
    current instr.: 'main' pc 7 (z2.pir:4)
    $


(Yes, the above can be solved by providing constant keys to the
newclass and subclass opcodes, but I need a solution for the case
where the class names aren't a compile-time constant.)
    
Pm 

Reply via email to