Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[HOWTO] call a method on a PMC in PIR

5 views
Skip to first unread message

Karl Forner

unread,
Sep 28, 2006, 6:47:41 AM9/28/06
to Internals List
I suppose that again it is a trivial question, but I did not manage to find
the answer by myself in the documentation.
So I want for example to call diretly the "elements" method on a
FixedBooleanArray

I tried

pmc.elements()
pmc."elements"()
pmc._elements()
pmc.__elements()

But it did not work...

In fact, what I really want to do, for debugging purposes, is to add a
custom method in the FixedBooleanArray.pmc (e.g get_allocated_size() ) and
be able to call it
from PIR test code.

Thanks
Karl Forner

Leopold Toetsch

unread,
Sep 28, 2006, 7:11:53 AM9/28/06
to perl6-i...@perl.org
Am Donnerstag, 28. September 2006 12:47 schrieb Karl Forner:
> I suppose that again it is a trivial question, but I did not manage to find
> the answer by myself in the documentation.
> So I want for example to call diretly the "elements" method on a
> FixedBooleanArray
>
> I tried
>
> pmc.elements()
> pmc."elements"()
> pmc._elements()
> pmc.__elements()
>
> But it did not work...

Exactly. Due to asymmetry of methods and vtables, the latter are not
accessible as methods. You have to use the equivalent opcode:

$I0 = elements ar_pmc

But you can code a PIR wrapper for it:

.namespace ['FixedBooleanArray']
.sub 'elements' :method
$I0 = elements self
.return ($I0)
.end

usable as:

$I0 = ar_pmc.'elements'()

> In fact, what I really want to do, for debugging purposes, is to add a
> custom method in the FixedBooleanArray.pmc (e.g get_allocated_size() ) and
> be able to call it
> from PIR test code.

As you need PMC internals for this, you'd have to add it to the .pmc itself
(temporarely):

METHOD INTVAL get_allocated_size() {
return PMC_int_val2(SELF); /* or whatever */
}

> Thanks
> Karl Forner

HTH,
leo

Karl Forner

unread,
Sep 28, 2006, 6:22:28 PM9/28/06
to Leopold Toetsch, perl6-i...@perl.org
>
> METHOD INTVAL get_allocated_size() {
> return PMC_int_val2(SELF); /* or whatever */
> }


great, exactly what I needed
thanks
karl

0 new messages