[New-bugs-announce] [issue27236] Add CHAINED_COMPARE_OP opcode

Serhiy Storchaka report at bugs.python.org
Sun Jun 5 15:43:25 EDT 2016


New submission from Serhiy Storchaka:

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

----------
components: Interpreter Core
files: chained_compare_op.patch
keywords: patch
messages: 267466
nosy: Demur Rumed, Mark.Shannon, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Add CHAINED_COMPARE_OP opcode
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file43247/chained_compare_op.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27236>
_______________________________________


More information about the New-bugs-announce mailing list