2003-02-20

Python::Bytecode::SAX Version 0.1 Released

I just released version 0.1 of the Python::ByteCode::SAX Perl Module.

This module leverages earlier work (Python::Bytecode 2.0) by Simon Cozens

You can use this module to generate SAX (version 1 or 2) events from a .pyc file you've generated by compiling a .py file. You can follow the examples in the documentation to turn those SAX events into an XML file, or you can do something more insidious with them, if you like.

I wrote this because I was working on converting Python bytecode to Parrot bytecode as one option for running Python programs via the Parrot interpreter. I discovered that Python's own dis.py didn't disassemble all the bytecode in a .pyc file (some bytecode gets squirrelled away into strings in the constant table for the included primes.py{,c} example). Also, Simon's Python::Bytecode wasn't working right on primes.pyc, either. At first, I just made a private copy of Python::Bytecode and tried to hack it into shape, but I was having trouble visualizing the structure of the bytecode file (and googling for it didn't help, either). So, I made a fresh copy and hacked it into a SAX event generator.

I don't like the output produced by the SAX2 processor XML::SAX::Writer very much, so I tried using the SAX1 processor XML::Handler::YAWriter, which I've used happily enough before. Along the way, I slapped together some handy utility functions to allow me to switch between SAX1 and SAX2 events for the simple cases involved in this module.

Next, I need to go back to translating compiled Python (.pyc files) into Parrot's intermediate code (.imc files). The coolest translation would express the Python program in a stackless idiom, but I would not attack that without getting a simple version that retained the stack execution model running pretty well first.

No comments: