Author serhiy.storchaka
Recipients Demur Rumed, Mark.Shannon, serhiy.storchaka
Date 2016-06-05.19:43:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1465155805.46.0.0768541508675.issue27236@psf.upfronthosting.co.za>
In-reply-to
Content
For now complex code is generated for chained comparing.

$ echo "x = a < b > c < d" | ./python -m dis
  1           0 LOAD_NAME                0 (a)
              2 LOAD_NAME                1 (b)
              4 DUP_TOP
              6 ROT_THREE
              8 COMPARE_OP               0 (<)
             10 JUMP_IF_FALSE_OR_POP    28
             12 LOAD_NAME                2 (c)
             14 DUP_TOP
             16 ROT_THREE
             18 COMPARE_OP               4 (>)
             20 JUMP_IF_FALSE_OR_POP    28
             22 LOAD_NAME                3 (d)
             24 COMPARE_OP               0 (<)
             26 JUMP_FORWARD             4 (to 32)
        >>   28 ROT_TWO
             30 POP_TOP
        >>   32 STORE_NAME               4 (x)
             34 LOAD_CONST               0 (None)
             36 RETURN_VALUE

Proposed patch adds CHAINED_COMPARE_OP opcode that does all necessary stack manipulatios. Using it the generated code is simpler:

$ echo "x = a < b > c < d" | ./python -m dis
  1           0 LOAD_NAME                0 (a)
              2 LOAD_NAME                1 (b)
              4 CHAINED_COMPARE_OP       0 (<)
              6 JUMP_IF_FALSE_OR_POP    18
              8 LOAD_NAME                2 (c)
             10 CHAINED_COMPARE_OP       4 (>)
             12 JUMP_IF_FALSE_OR_POP    18
             14 LOAD_NAME                3 (d)
             16 COMPARE_OP               0 (<)
        >>   18 STORE_NAME               4 (x)
             20 LOAD_CONST               0 (None)
             22 RETURN_VALUE
History
Date User Action Args
2016-06-05 19:43:25serhiy.storchakasetrecipients: + serhiy.storchaka, Mark.Shannon, Demur Rumed
2016-06-05 19:43:25serhiy.storchakasetmessageid: <1465155805.46.0.0768541508675.issue27236@psf.upfronthosting.co.za>
2016-06-05 19:43:25serhiy.storchakalinkissue27236 messages
2016-06-05 19:43:25serhiy.storchakacreate