Wednesday, January 2, 2008

Maybe someday I'll have time to read on Python Bytecode

Maybe someday I'll get a chance to fully digestExploring Python Bytecode.

For the past month or so, I’ve been trying to understand what appears to be a black art mostly because of lacking documentation - Python bytecode generation and peephole optimization. Some notes from the study for the benefit of IRC-mate ‘jstatm’ and anyone else living on similar planes of insanity.

Although bytecode applies to objects other than functions such as tracebacks, dictionaries and strings, I am only interested in optimization and flow analysis of class methods, functions and lambdas. Lets get to the action straight away with an example. Here is a small python program to disassemble and display the bytecode of a function in human readable form.

No comments: