Storing Classes in Bytecode

Patrick R. Michaud pmichaud at pobox.com
Thu Jul 29 09:11:59 UTC 2010


On Wed, Jul 28, 2010 at 08:42:44PM -0700, Peter Lobsinger wrote:
> AFAIK, classes freeze and thaw fine.
> 
> .sub 'FooClass' :anon :immediate
>     $P0 = newclass 'Foo'
>     .return ($P0)
> .end
> 
> .sub 'main' :main
>     # .const 'Sub' $P0 = 'FooClass'
>     $P0 = get_class 'Foo'
>     $S0 = $P0
>     say $S0
> .end

This example oversimplifies a bunch, at least for Rakudo and NQP.
We don't use simple Class PMCs -- we also have to create type objects
(formerly "protoobjects") and do a variety of other compositions
in order to fully create a class.  A more typical code path
might be something like:

.sub '' :anon :load :init
    ##  assume we've already done a load_bytecode 'P6object.pbc'
    $P0 = get_hll_global 'P6metaclass'
    $P1 = $P0.'new_class'('Foo', 'parent'=>'Bar', 'attr' => '$.xyz')
.end

This does more than create a new Parrot class -- it's also responsible 
for initializing a type object and potentially composing other roles 
and methods into the class.  In Rakudo's case, we also have to cast 
them into an entirely new metaclass ("P6opaque").

I'm fairly sure the above doesn't quite work with :immediate, but
would be happy to be proven wrong.

Also, note that there are still open tickets for :immediate --
see TT #1324 and #1374.

Pm


More information about the parrot-dev mailing list