At revision 9000. - fun with constant PMCs

Skip to first unread message

Leopold Toetsch

Aug 19, 2005, 11:33:39 AM8/19/05
to Perl 6 Internals
First I'd like to thank all contributors for the steady stream of
patches that made this round revision number possible.

Rev 9000 happened to hit leo-ctx5. It is a test and looks like this:

$ cat cobj.pir
.sub make_obj @IMMEDIATE, @ANON
.local pmc cl, o
cl = newclass "Foo"
addattribute cl, 'x'
o = new 'Foo'
$P0 = new String
$P0 = "ok 1\n"
setattribute o, 'x', $P0
.return (o)

.sub main @MAIN
.const .Sub o = "make_obj"
$P0 = getattribute o, 'x'
print $P0

$ parrot -o cobj.pbc cobj.pir

During compilation the code of the subroutine 'make_obj' is run due to
it's @IMMEDIATE flag and an instance of Foo is returned. This PMC
replaces now the entry of the Sub PMC in the constant table. PMCs in the
constant table are serialized as frozen images in the PBC.

At runtime ...

$ parrot cobj.pir
ok 1

... first the PBC is unpacked, which thaws the object (and it's class).
Only 'main' is executed. The constant definition line, which is actually

set_p_pc Px, PMC_CONST(n)

fetches an already created object from the constant table.

Have fun,

Reply all
Reply to author
0 new messages