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

2 comments:

The Daily Reviewer said...

Hi!

Congratulations! Your readers have submitted and voted for your blog at The Daily Reviewer. We compiled an exclusive list of the Top 100 python Blogs, and we are glad to let you know that your blog was included! You can see it at http://thedailyreviewer.com/top/python/2

You can claim your Top 100 Blogs Award here : http://thedailyreviewer.com/pages/badges/python

P.S. This is a one-time notice to let you know your blog was included in one of our Top 100 Blog categories. You might get notices if you are listed in two or more categories.

P.P.S. If for some reason you want your blog removed from our list, just send an email to angelina@thedailyreviewer.com with the subject line "REMOVE" and the link to your blog in the body of the message.

Cheers!

Angelina Mizaki
Selection Committee President
The Daily Reviewer
http://thedailyreviewer.com

Doktor said...

Jeff,
This sounds great. I would like to do what I can to help build a team to enable it to go from Python to Scala.
Doktor Stovall Foundation