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

Storing external data in PMCs

19 views
Skip to first unread message

Arthur Bergman

unread,
Oct 27, 2003, 9:56:29 AM10/27/03
to perl6-i...@perl.org, poni...@perl.org
Hi,

So I am currently trying to do a Perl5LVALUE pmc, a stumbling block is
however that I need to pass the PMC the thing that it is lvalueling, I
was planning to use the pmc data field for storing this but I cannot
access it as a extender without violating the API and guessing at
layouts which is kind of bad (Dan says so ;)

Arthur

Melvin Smith

unread,
Oct 27, 2003, 10:26:52 AM10/27/03
to Arthur Bergman, perl6-i...@perl.org, poni...@perl.org

I don't know Perl5 internals enough to know exactly what Perl5LVALUE
does. Do you want a way to pass a value to the PMC and let the PMC type morph
itself based on the data representation?

-Melvin

Arthur Bergman

unread,
Oct 27, 2003, 10:35:42 AM10/27/03
to Melvin Smith, perl6-i...@perl.org, poni...@perl.org


An lvalue holds usually a function, and when set is called that
function is called. So no morthing required at all!

For example:

perl -le '$foo = hi; $bar = \substr($foo,1); print "$bar-$foo"; $$bar =
"b"; print "$bar-$foo"';
LVALUE(0x513ec)-hi
LVALUE(0x513ec)-hb

so the reference points to a lvalue which has a reference to $bar and a
special function on the set to actually execute the substr.

The reason I am starting with this is that it is so obscure that it is
hardly used anywhere and is limited to a few small areas in the core
making it a good testing ground.

Arthur

Arthur Bergman

unread,
Oct 27, 2003, 12:09:54 PM10/27/03
to Melvin Smith, Melvin Smith, perl6-i...@perl.org, poni...@perl.org

On Monday, October 27, 2003, at 04:44 pm, Melvin Smith wrote:

>
> In this case I assume the function can either be Perl5 or Parrot?
> Sounds like a custom PMC to me. Given the PMC that
> could stash function pointers and correctly dispatch gets/sets
> you have the option of writing a PNI method for setting the stashed
> routine from C or we have to add a call to the extension API to stash a
> raw pointer.
>
> -Melvin
>

The function is a C function. And yes it is a custom PMC which I have
already created.

Dan pointed out the unmanagedstruct.pmc which but I fail to see how
that would help me, I think we need an external API for stashing raw
pointers.

(I don't know what PNI is, but I assume it is to execute bytecode from
C and I do not want to do that).

Arthur

Arthur Bergman

unread,
Oct 27, 2003, 12:39:13 PM10/27/03
to Melvin Smith, Melvin Smith, perl6-i...@perl.org, poni...@perl.org

On Monday, October 27, 2003, at 05:20 pm, Melvin Smith wrote:

> Apologies for the formatting of these replies, I'm at work with Lotus
> Notes.
>
> PNI (Parrot Native Interface) is for writing native extensions in C.
> So, what I meant is you can write a method for stashing a raw pointer
> with
> the API today (probably using char *). I'm not sure if it is your
> preferred method,
> and I understand your wariness of bytecode in this case. I was 1/2
> asleep
> this morning on IRC when I suggested it, not understanding the case
> you were dealing with.
>
> You can see samples that Dan has played with such as ncurses somewhere
> in the examples area. (I'm still not saying you don't need API added
> to extend.h
> though, but I'd have to be very clear on what you are asking for...)
>
> -Melvin
>

I just want to be able to say

Parrot_PMC_attach_data(Parrot, PMC, *void);

so the PMC code can get to it

Arthur

Leopold Toetsch

unread,
Oct 27, 2003, 1:34:31 PM10/27/03
to Arthur Bergman, perl6-i...@perl.org
Arthur Bergman <s...@nanisky.com> wrote:

> The function is a C function. And yes it is a custom PMC which I have
> already created.

The interface for calling C code from PASM is NCI (native call
interface). s. e.g. library/*.pasm or t/pmc/nci.t.
But inside your custom PMC you can do all kinds of things, to stuff a
pointer into e.g. data.

- at init time init_pmc() has an extra pointer argument
- via a customized vtable method:
e.g. set_pmc, set_pmc_keyed or push or whatever

Vtable calls seem still to be missing in the extension interface though.

> Dan pointed out the unmanagedstruct.pmc which but I fail to see how
> that would help me, I think we need an external API for stashing raw
> pointers.

unmanagaged struct isn't finished yet. But extending the switch
statements by an enum_type_ptr case is really simple.
library/libpcre.imc has an example to get match results via an
unmanagedstruct PMC.

> Arthur

leo

0 new messages