Wednesday, September 19, 2007

Pynie - the Parrot-based Python Interpreter

Some weeks ago the DFW Pythoneers usergroup had a presentation by our own Patrick Michaud about his work getting a Python interpreter on top of the Parrot bytecode VM. Recently I've started playing with it, and found it rather easy to get up and running.

Don't get too excited though - plenty of Python-specific functionality is missing - it basically lacks the standard library and has stubs for most of the Python statements. If there are others into language internals who would like to work on this, I would like to coordinate with them. Here in Dallas we're considering arranging a special event, to meet with Patrick and sprint on Pynie. I'd suggest if you're curious to go download and install it to see if it is something you can get into.

To get you to the good stuff, here are the basic steps:

# mkdir ~/ParrotWork
# cd ~ ParrotWork
# svn co https://svn.perl.org/parrot/trunk parrot
# cd parrot
# perl Configure.pl
# make
# make test (to run the test suite)
# cd languages/pynie
# make
# ../../parrot pynie.pbc yourhellopgm.py

Although there are packages for Debian, Gentoo and so forth, I suggest working with the latest in subversion because of Parrot is rapidly changing in development.

One neat aspect is that you can compile your Python programs into x86 code, using the Parrot JIT:

# ../../parrot --target=PIR -o yourhellopgm.pir yourhellopgm.py
# ../../parrot -o yourhellopgm.pbc yourhellopgm.pir
# ../../parrot -o yourhellopgm.o yourhellopgm.pbc
# cd ../..
# make EXEC=languages/pynie/yourhellopgm exec
# ./yourhellopgm

There is interesting reading about Parrot internals in general in the directory ~/ParrotWork/docs, just use "perldoc intro.pod" to get started. It kept me up all night reading. ;-)

And for the Python-specific portions of the source, check out:

~/ParrotWork/languages/pynie/src/
builtins/ (implementation of Python datatypes)
parser/ (lexer/parser definitions to take apart Python source)
PAST/ (Parrot Abstract Syntax Trees to generate bytecode)

-Jeff