PEP 329 and bytecode hacking

Robert Brewer fumanchu at amor.org
Wed Apr 21 18:58:06 EDT 2004


Phillip J. Eby wrote:
> At 03:07 PM 4/21/04 -0700, Robert Brewer wrote:
> >Raymond's cookbook recipe inspired me to write a generic Visitor for
> >inspecting and rewriting bytecode. Maybe it'll help someone out there
> >with prototyping bytecode hacks.
> 
> For more sophisticated bytecode modifications, you'll want to 
> keep track of 
> things like source line number, the nth instruction and its 
> operand if any 
> (so you can scan *backwards*), the list of locations of a 
> given opcode, 
> etc.  This Pyrex module:
> 
>
http://cvs.eby-sarna.com/PEAK/src/peak/util/_Code.pyx?rev=1.2&content-ty
pe=text/vnd.viewcvs-markup
> provides high-speed dynamic access to bytecode metadata, and is
suitable 
> for use in runtime bytecode hacks, since it does not require Python 
> function call overhead for each instruction.

Good idea! I'll work on including that. It's not as context-sensitive as
visiting each opcode in turn, but sometimes no context is good context.
:) Since it's already available from Pyrex, I'll adapt the functionality
into a codewalk.Visitor subclass.


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org




More information about the Python-list mailing list