A Python bytecode assember?

Dean Hall dean.hall at computer.org
Mon Dec 3 10:26:14 EST 2001


Daniel Yoo <dyoo at hkn.eecs.berkeley.edu> wrote in message news:<9uf0kd$1r4r$1 at agate.berkeley.edu>...
> Hi everyone,
> 
> I'm planning to do a small project with Python's bytecode, and I'd
> like to know if anyone's written a bytecode assember for it?
> 
> I've taken a look at Michael Hudson's 'bytecodehacks' package at:
> 
>     http://bytecodehacks.sourceforge.net/
> 
> but the code looks like it hasn't been touched since March 2000.  Can
> anyone talk about their experiences with bytecodehacks?  I need a
> bytecode assember that supports jumps, so if someone's hacked up
> bytecodehacks to support this, I'll be a very happy person.

I wrote a tool that helps study code objects; it doesn't assemble, but it will
help you look in and around a code string. See:

    http://sourceforge.net/project/showfiles.php?group_id=32525
    The file dismantle.py and the doc co_info.pdf might be helpful to you.

It seems like it wouldn't be too difficult to make an assembler using dis.
Just make a reverse dict from dis.opname for the translator.
Python has the bytecodes 113 JUMP_ABSOLUTE and 110 JUMP_FORWARD that you want.

I've searched for ways to take a Python code object and substitue the co_code
string; but the code object is static, so I didn't get far.  The simple hack
would happen in the .pyc file.

!!Dean



More information about the Python-list mailing list