[Python-ideas] PEP 355 (overloading boolean operations) and chained comparisons

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Oct 20 02:30:45 CEST 2011


On 20/10/11 13:16, Raymond Hettinger wrote:

> /* Simplify conditional jump to conditional jump where the
> result of the first test implies the success of a similar
> test or the failure of the opposite test.
> Arises in code like:
> "if a and b:"
> "if a or b:"
> "a and b or c"
> "(a and b) and c"
> x:JUMP_IF_FALSE_OR_POP y y:JUMP_IF_FALSE_OR_POP z
> --> x:JUMP_IF_FALSE_OR_POP z
> x:JUMP_IF_FALSE_OR_POP y y:JUMP_IF_TRUE_OR_POP z
> --> x:POP_JUMP_IF_FALSE y+3
> where y+3 is the instruction following the second test.
> */

While the existing peephole optimisations wouldn't work
as-is, there's no reason that similarly efficient code
couldn't be generated, either by peephole or using a
different compilation strategy to begin with.

There are some comments about this in the draft PEP
update that I'll try to get submitted soon.

-- 
Greg



More information about the Python-ideas mailing list