[PEAK] Patch: Update RuleDispatch for python-2.7

P.J. Eby pje at telecommunity.com
Mon Aug 2 04:11:16 EDT 2010

At 02:33 AM 8/2/2010 -0400, P.J. Eby wrote:
>Hm.  I suppose I could always implement the old opcodes as a macro 
>that sticks in a DUP_TOP and then uses the unconditional POP 
>forms...  That would be evil, performance-wise on 2.7, but it'd make 
>those weird cases easier and transparently support old 
>code.  Hm...  I actually kinda like that.  Anybody else using 
>BytecodeAssembler will then get 2.7-compatibility for free, at the 
>expense of a little slowdown on conditional jumps; if they want the 
>performance, they can upgrade to one of the newer opcodes (and still 
>have it work with older Pythons).

This approach seems to have worked; the svn versions of 
BytecodeAssembler and PEAK-Rules now have only shallow test failures 
on 2.7, i.e. ones that are caused by differences in 2.7's hashing of 
dictionaries (and therefore the repr's used in tests), or in the 
assembly listings that results from emulating older opcodes.

To fix these failures, I'll have to do some additional work, and even 
more to actually properly clean things up and document them, but at 
least it appears feasible.

Two more opcode changes in 2.7 that I found along the way:

* LIST_APPEND now takes an argument to point to the list on the 
stack, so it doesn't need a temporary variable (I hacked around this 
for now, but it should be done more cleanly)

* SETUP_WITH is a new opcode that's not properly supported

So, what I've done for now is release an 0.5.2 "compatibility 
release" of BytecodeAssembler with just the quick workarounds, then 
later I'll release an 0.6 with a more "symbolic" disassembler that 
can handle the emulations transparently for testing purposes.  (And 
with support for SETUP_WITH and some improved LIST_APPEND handling.)

Meanwhile, PEAK-Rules's svn version now appears to have only cosmetic 
test failures on 2.7, when used with BytecodeAssembler 0.5.2.  It's 
not perfect by any means, but then, it looks like most of those 
shallow failures were happening with 2.6 anyway.  ;-)

Please let me know whether this is sufficient for you to be able to 
offer PEAK-Rules on 2.7 for now.

More information about the PEAK mailing list