On Mon, Dec 31, 2007 at 11:17:53PM +0300, Richard Hainsworth wrote: > Not sure whether this should be p6-lan or p6-users. Posted to p6l only.
Since the question is specific to perl6 and Parrot, it probably belongs on perl6-compiler. But I'll answer it here for now, as it may spark a language related discussion. > Given a function implemented in parrot, how can it be called from a > perl6 program? > > Suppose I have a file (in current path) 'myfun.pir' which contains > > .sub myfun > .param pmc passed_variable > .local int an_int > an_int = passed_variable > .local string string_var > #code > .return (string_var) > end # is this necessary? > .end > > how do I create a mymodule.pm so that I can in a perl6 program do > > use mymodule; > > my $parameter = 30; > my $string_var = myfun($parameter); > > ??? > > If this is documented, please just send a pointer. It's not document yet. As far as calling the function is concerned, that part already exists -- perl6 will correctly locate the 'myfun' sub written in PIR and call it with the appropriate arguments. The part we don't have yet is dynamic loading of pir files from perl6. In other words, perl6 currently treats the statement "use mymodule;" as being a request for "mymodule.pm", which it expects to be a Perl 6 source file. My best guess at this point is that we could have something like: use Parrot; Parrot::load_bytecode('myfun.pir'); For the time being we could make the "use Parrot;" step automatic to the perl6 compiler, such that one could do: Parrot::load_bytecode('myfun.pir'); my $parameter = 30; my $string_var = myfun($parameter); Then it's just a matter of deciding what sort of functions/interface we expect the Parrot module to have. Pm