Re: PDD16 details
On Monday 03 December 2007 14:09:26 pancake wrote: > I have been looking a bit inside PDDs and parrot source and find no way to > load a pointer to a function as a PMC inside the VM. > > What I want to do is to embed parrot into a C program and make some of the > functions of this C program available via NCI to the vm. > > I have achieved this by using the tip noted in docs/compiler_faq.pod > (thanks kjs!) which says I need to pass a null string to loadlib and > compile the parent C program with -export-dynamic which is GCC specific... > So imho looks like an ugly system- dependant 'hack'. > > I have found some interesting funcs in src/inter_misc.c but seems not to > fix the problem, can anybody give me an appoint? I know that the NCI part > is not yet finished, but IMHO these functions should follow the Parrot_ > name convention and make them available from the Parrot API. Is there any reason you're not using the NCI opcodes from within PIR? That's the easy way to do it. -- c
Re: PDD16 details
Uh... ping? On Mon, Dec 03, 2007 at 11:09:26PM +0100, pancake wrote: > I have been looking a bit inside PDDs and parrot source and find no way to > load a pointer to a function as a PMC inside the VM. > > What I want to do is to embed parrot into a C program and make some of the > functions of this C program available via NCI to the vm. > > I have achieved this by using the tip noted in docs/compiler_faq.pod (thanks > kjs!) > which says I need to pass a null string to loadlib and compile the parent C > program > with -export-dynamic which is GCC specific... So imho looks like an ugly > system- > dependant 'hack'. > > I have found some interesting funcs in src/inter_misc.c but seems not to fix > the problem, > can anybody give me an appoint? I know that the NCI part is not yet finished, > but IMHO > these functions should follow the Parrot_ name convention and make them > available from > the Parrot API. > > Here's the source: > > #include > > void func() > { > printf("Hello World!\n"); > } > > int main(int argc, char **argv) > { > PMC *method; > Parrot_Interp pvm = Parrot_new(NULL); > > register_nci_method(pvm, enum_class_NCI, &func, "func", "v"); > > Parrot_PackFile pf = Parrot_readbc(pvm, "hello.pbc"); > if (pf == NULL) { > fprintf(stderr, "Oops. Cannot open hello.pbc\n"); > return 1; > } > > > /* */ > Parrot_loadbc(pvm, pf); > > Parrot_runcode(pvm, argc, argv); > > Parrot_destroy(pvm); > } > > $ cat hello.pir > > .sub main :main > func() > say "Hello World" > .end > > > $ cat Makefile > > all: > parrot -o hello.pbc hello.pir > gcc main.c `pkg-config --cflags --libs parrot` -export-dynamic > > > Thanks! > > --pancake >
PDD16 details
I have been looking a bit inside PDDs and parrot source and find no way to load a pointer to a function as a PMC inside the VM. What I want to do is to embed parrot into a C program and make some of the functions of this C program available via NCI to the vm. I have achieved this by using the tip noted in docs/compiler_faq.pod (thanks kjs!) which says I need to pass a null string to loadlib and compile the parent C program with -export-dynamic which is GCC specific... So imho looks like an ugly system- dependant 'hack'. I have found some interesting funcs in src/inter_misc.c but seems not to fix the problem, can anybody give me an appoint? I know that the NCI part is not yet finished, but IMHO these functions should follow the Parrot_ name convention and make them available from the Parrot API. Here's the source: #include void func() { printf("Hello World!\n"); } int main(int argc, char **argv) { PMC *method; Parrot_Interp pvm = Parrot_new(NULL); register_nci_method(pvm, enum_class_NCI, &func, "func", "v"); Parrot_PackFile pf = Parrot_readbc(pvm, "hello.pbc"); if (pf == NULL) { fprintf(stderr, "Oops. Cannot open hello.pbc\n"); return 1; } /* */ Parrot_loadbc(pvm, pf); Parrot_runcode(pvm, argc, argv); Parrot_destroy(pvm); } $ cat hello.pir .sub main :main func() say "Hello World" .end $ cat Makefile all: parrot -o hello.pbc hello.pir gcc main.c `pkg-config --cflags --libs parrot` -export-dynamic Thanks! --pancake
Re: [PATCH] PDD16 NCI update with simple example
On Friday 23 February 2007 05:16, Klaas-Jan Stol wrote: > As a result, I added a simple example to PDD16. I didnt' put too much > work in it (there are many more places that could be improved), because > I didn't know if updating this doc is desirable at this moment (any big > changes pending?). > If desired, I'd be happy to do more updates. Please let me know. > At least there's full working code to do a simple NCI invocation. Please do. There are no big changes pending. Thanks, applied as r17164. -- c
[PATCH] PDD16 NCI update with simple example
hi, I've been playing with NCI calls and more fun (embedding a Parrot, that runs a PIR program, which invokes a C function, that then invokes a PIR callback function). As a result, I added a simple example to PDD16. I didnt' put too much work in it (there are many more places that could be improved), because I didn't know if updating this doc is desirable at this moment (any big changes pending?). If desired, I'd be happy to do more updates. Please let me know. At least there's full working code to do a simple NCI invocation. regards, klaas-jan Index: docs/pdds/draft/pdd16_native_call.pod === --- docs/pdds/draft/pdd16_native_call.pod (revision 17146) +++ docs/pdds/draft/pdd16_native_call.pod (working copy) @@ -126,8 +126,48 @@ =head2 Examples Most of the function parameters are reasonably self-evident. Some, however, -merit additional explanation. The {{ ??? }} +merit additional explanation. +This section describes the simplest example for NCI possible. To every NCI +invocation, there are two parts: the native function to be invoked, and the +PIR code to do the invocation. + +First the native function, to be written in C. +On Windows, it is necessary to do a DLL export specification of the NCI function: + + /* foo.c */ + + /* specify the function prototype */ + + void foo(void); + + /* or on Windows using Microsoft Visual Studio: */ + + __declspec(dllexport) void foo(void); + + void foo(void) { +printf("Hello Parrot!\n"); + } + +Then, after having compiled the file as a shared library, the PIR code looks +like this: + + .sub main :main + .local pmc lib, func + + # load the shared library + lib = loadlib "hello" # no extension, .so or .dll is assumed + + # get a reference to the function from the library just + # loaded, called "foo", and signature "void" (and no arguments) + func = dlfunc lib, "foo", "v" + + # invoke + func() + + .end + + =head2 Callbacks Some libraries, particularly ones implementing more complex functionality such @@ -224,9 +264,9 @@ Maintainer: Dan Sugalski Class: Internals PDD Number: 16 -Version: 1.1 +Version: 1.2 Status: Developing -Last Modified: Oct 12, 2004 +Last Modified: Feb 23, 2007 PDD Format: 1 Language: English @@ -234,6 +274,10 @@ =over 4 +=item version 1.2 + +Updated with basic example. + =item version 1.1 Changed callback section to reflect current status. @@ -248,6 +292,10 @@ =over 4 +=item version 1.2 + +Updated with basic example. + =item version 1.1 Changed callback section to reflect current status.
[perl #33172] Missing examples subsection in PDD16
# New Ticket Created by Simon Glover # Please include the string: [perl #33172] # in the subject line of all future correspondence about this issue. # http://rt.perl.org:80/rt3/Ticket/Display.html?id=33172 > In PDD16 (NCI conventions and definitions), the examples subsection contains very little text and stops in the middle of a line, i.e.: - =head2 Examples Most of the function parameters are reasonably self-evident. Some, however, merit additional explanation. The - This section should either be completed (by someone who understands NCI, which rules me out...) or removed, as it's useless as it stands. Simon
[perl #31607] [TODO] Update PDD16 to reflect current state
# New Ticket Created by Will Coleda # Please include the string: [perl #31607] # in the subject line of all future correspondence about this issue. # http://rt.perl.org:80/rt3/Ticket/Display.html?id=31607 > Leo says: >The docs aren't yet updated, sorry. Have a look at t/pmc/nci.t for examples >of working syntax.
Re: pdd16
At 10:19 PM -0500 12/30/03, Dan Sugalski wrote: At 2:28 AM + 12/31/03, Harry Jackson wrote: I might be going mad here and maybe I have been up too long but, does: http://dev.x.perl.org/perl6/pdd/pdd16_native_call.html have two identical Parrot_callback_C and Parrot_callback_D function signatures. Possibly, though they're supposed to have their parameters reversed. I'll go fix as soon as I can. Yeah, it was definitely wrong. I've a checkin pending reasonable CVS access. -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: pdd16
At 2:28 AM + 12/31/03, Harry Jackson wrote: I might be going mad here and maybe I have been up too long but, does: http://dev.x.perl.org/perl6/pdd/pdd16_native_call.html have two identical Parrot_callback_C and Parrot_callback_D function signatures. Possibly, though they're supposed to have their parameters reversed. I'll go fix as soon as I can. -- Dan --"it's like this"--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
pdd16
I might be going mad here and maybe I have been up too long but, does: http://dev.x.perl.org/perl6/pdd/pdd16_native_call.html have two identical Parrot_callback_C and Parrot_callback_D function signatures. Harry Jackson