update: see Inline::Parrot for the most current code.
I couldn't find an implementation of Inline::Parrot,
so I thought maybe I could try to write one.
This is a
slow-but-it-works version of the module that can execute
Parrot Intermediate Representation (pir) code using pure Perl.
I tested this in MS Windows, with
Activestate Perl 5.8.0, and a pre-built Parrot obtained from
http://www.jwcs.net/developers/perl/pow/. I installed Inline
using ppm.
It can execute this sample code:
use Inline Parrot;
print "Start Perl\n";
_hello( 'int count' => 5, name => 'test' );
print "End Perl\n";
__END__
__Parrot__
.sub _hello
.param int count
.param string name
print "Hello world\n"
print count
print " "
print name
print "\n"
ret
.end
Output:
Start Perl
Hello world
5 test
End Perl
I've got some ideas on how to improve this, but
I'd like to have some feedback, before I go too far.
There are still a lot of limitations, but most are fixable:
- the Perl parameter 'int count' should be written just
'count', but I'm not parsing the ".param" line yet.
- only 1 subroutine can be defined. This is also a simple parsing problem.
- it doesn't retrieve return values back to Perl.
- it doesn't allow positional parameters to be specified.
- there are no options for specifying the calling mode for pir.
- it doesn't pass data structures back and forth.
- you can't pass a data structure by reference - this is not likely to be fixable,
because the perl and the parrot processes don't share memory.
- the current code uses temporary files for interprocess communication; it doesn't reuse the compiled code between calls; it has problems if two or more processes use the same source code. These problems are all fixable by using proper IPC with Open3 or sockets.
|