Re: NCI: passing PMCs and using them

2005-08-23 Thread Klaas-Jan Stol

Leopold Toetsch wrote:


Klaas-Jan Stol wrote:



hi,

I'm currently trying to check out the NCI. As my Lua compiler only 
uses PMCs (and not I/N/S registers), calling C functions will only be 
done with PMCs.


I couldn't find info on this matter: suppose I have this string PMC, 
how can I access the actual string in it?


so, when calling:

void print_pmc(void *PMC)
{
   // how to access the string in P?
}



If it's a stringish PMC, then STRING *s = VTABLE_get_string(INTERP, 
p); will do it.


The C code is just in a .c file, it's not like a PMC or something. So, I 
don't think I can use INTERP, or VTABLE_get_string() at all. Or should 
I link to parrotlib.a or something?
Is there some public API for accessing the fields in a PMC (for standard 
PMCs, so accessing the intval for the Integer PMC and its decendents, 
floatval for Float PMC, stringval for String PMCs, etc) ?


You might also consider switching to branches/leo-ctx5. The new 
calling conventions do auto-conversion betwen PMCs and I/S/N in both 
directions for NCI too.


Forgive my ignorance, but I don't really understand. I'm only using 
PMCs, no I/S/N values. Why would using these auto-conversions be 
interesting?



Btw, I also got this leo-ctx5 branch, compiled it, and run it from the 
directory where my lua stuff is, like this:


   $ ../leo-ctx5/parrot a.pir

it says:

   PackFile_FixupTable_unpack: Unknown fixup type 1953066601!
   PackFile_unpack segment 'FIXUP_luaglobals.pir' failed
   Segmentation fault

I got this branch by doing this: (was not sure about the command, but I 
considered this most probable)


   svn checkout http://svn.perl.org/parrot/branches/leo-ctx5

Any idea what's wrong and causing the error?

klaas-jan




Re: NCI: passing PMCs and using them

2005-08-23 Thread Leopold Toetsch


On Aug 23, 2005, at 14:38, Klaas-Jan Stol wrote:



Leopold Toetsch wrote:


Klaas-Jan Stol wrote:


void print_pmc(void *PMC)
{
   // how to access the string in P?
}



If it's a stringish PMC, then STRING *s = VTABLE_get_string(INTERP, 
p); will do it.


The C code is just in a .c file, it's not like a PMC or something. So, 
I don't think I can use INTERP, or VTABLE_get_string() at all. Or 
should I link to parrotlib.a or something?


INTERP is just translated to interpreter (see any classes/.c file). 
VTABLE_get_string is available in the whole Parrot tree, it's a macro 
define in include/parrot/vtable.h. I don't know in what relation your 
plain .c file is to parrot, but you might have a look at 
src/extend.c, which also provides interfaces for such stuff.


Is there some public API for accessing the fields in a PMC (for 
standard PMCs, so accessing the intval for the Integer PMC and its 
decendents, floatval for Float PMC, stringval for String PMCs, etc) ?


Have a look at src/extend.c for the most abstract API.


You might also consider switching to branches/leo-ctx5. The new 
calling conventions do auto-conversion betwen PMCs and I/S/N in both 
directions for NCI too.


Forgive my ignorance, but I don't really understand. I'm only using 
PMCs, no I/S/N values. Why would using these auto-conversions be 
interesting?


If you are calling a NCI method, which takes native types (or returns 
one) from PIR, you can still pass in PMCs (and will get a PMC as 
result, if appropriate).



Btw, I also got this leo-ctx5 branch, compiled it, and run it from the 
directory where my lua stuff is, like this:


   $ ../leo-ctx5/parrot a.pir

it says:

   PackFile_FixupTable_unpack: Unknown fixup type 1953066601!
   PackFile_unpack segment 'FIXUP_luaglobals.pir' failed


$ make realclean and be sure to delete your .pbc files too. You can't 
share PBCs between trunk and leo-ctx5 - run a.pir in distinct 
directories.



klaas-jan


leo



NCI: passing PMCs and using them

2005-08-22 Thread Klaas-Jan Stol

hi,

I'm currently trying to check out the NCI. As my Lua compiler only uses 
PMCs (and not I/N/S registers), calling C functions will only be done 
with PMCs.


I couldn't find info on this matter: suppose I have this string PMC, how 
can I access the actual string in it?


so, when calling:

void print_pmc(void *PMC)
{
   // how to access the string in P?
}

Thanks,
klaas-jan



Re: NCI: passing PMCs and using them

2005-08-22 Thread Leopold Toetsch

Klaas-Jan Stol wrote:


hi,

I'm currently trying to check out the NCI. As my Lua compiler only uses 
PMCs (and not I/N/S registers), calling C functions will only be done 
with PMCs.


I couldn't find info on this matter: suppose I have this string PMC, how 
can I access the actual string in it?


so, when calling:

void print_pmc(void *PMC)
{
   // how to access the string in P?
}


If it's a stringish PMC, then STRING *s = VTABLE_get_string(INTERP, p); 
will do it. You might also consider switching to branches/leo-ctx5. The 
new calling conventions do auto-conversion betwen PMCs and I/S/N in both 
directions for NCI too.



Thanks,
klaas-jan


leo