This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients pitrou
Date 2008-12-22.01:49:45
SpamBayes Score 0.0015438234
Marked as misclassified No
Message-id <1229910592.51.0.945951799274.issue4715@psf.upfronthosting.co.za>
In-reply-to
Content
Here is an optional patch which provides the two opcodes I was talking
about (I've called them POP_OR_JUMP and JUMP_OR_POP). Together with a
bit of work on the peepholer they make the bytecode expression of
boolean calculations very concise.

A somewhat contrived example: "f = lambda x,y,z,v: (z if x else y) or v"

Without the patch:

  1           0 LOAD_FAST                0 (x) 
              3 JUMP_IF_FALSE            7 (to 13) 
              6 POP_TOP              
              7 LOAD_FAST                2 (z) 
             10 JUMP_FORWARD             4 (to 17) 
        >>   13 POP_TOP              
             14 LOAD_FAST                1 (y) 
        >>   17 JUMP_IF_TRUE             4 (to 24) 
             20 POP_TOP              
             21 LOAD_FAST                3 (v) 
        >>   24 RETURN_VALUE         

With the patch:

  1           0 LOAD_FAST                0 (x) 
              3 POP_JUMP_IF_FALSE       12 
              6 LOAD_FAST                2 (z) 
              9 JUMP_FORWARD             3 (to 15) 
        >>   12 LOAD_FAST                1 (y) 
        >>   15 JUMP_OR_POP             21 
             18 LOAD_FAST                3 (v) 
        >>   21 RETURN_VALUE
History
Date User Action Args
2008-12-22 01:49:52pitrousetrecipients: + pitrou
2008-12-22 01:49:52pitrousetmessageid: <1229910592.51.0.945951799274.issue4715@psf.upfronthosting.co.za>
2008-12-22 01:49:51pitroulinkissue4715 messages
2008-12-22 01:49:50pitroucreate