3.7: if <expr> and not <expr> else <expr>

This commit is contained in:
rocky
2019-05-04 22:14:07 -04:00
parent bc49469704
commit 8e9ce0be31
5 changed files with 26 additions and 0 deletions

View File

@@ -268,6 +268,7 @@ check-bytecode-3.6:
#: Check deparsing Python 3.7
check-bytecode-3.7:
$(PYTHON) test_pythonlib.py --bytecode-3.7-run --verify-run
$(PYTHON) test_pythonlib.py --bytecode-3.7 --weak-verify
#: Check deparsing Python 3.8

Binary file not shown.

View File

@@ -0,0 +1,16 @@
# From 3.7.3 base64.py
# Bug was handling "and not" in an
# if/else in the presence of better Python bytecode generatation
# RUNNABLE!
def foo(foldnuls, word):
x = 5 if foldnuls and not word else 6
return x
for expect, foldnuls, word in (
(6, True, True),
(5, True, False),
(6, False, True),
(6, False, False)
):
assert foo(foldnuls, word) == expect

View File

@@ -111,6 +111,12 @@ class Python37Parser(Python36Parser):
ifelsestmt ::= testexpr c_stmts_opt jf_cfs else_suite opt_come_from_except
_ifstmts_jump ::= c_stmts_opt come_froms
and_not ::= expr jmp_false expr POP_JUMP_IF_TRUE
expr ::= conditional37
conditional37 ::= and_not expr JUMP_FORWARD COME_FROM expr COME_FROM
"""
def customize_grammar_rules(self, tokens, customize):

View File

@@ -24,6 +24,8 @@ def customize_for_version37(self, version):
PRECEDENCE['attribute37'] = 2
TABLE_DIRECT.update({
'and_not': ( '%c and not %c',
(0, 'expr'), (2, 'expr') ),
'async_forelse_stmt': (
'%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n',
(7, 'store'), (1, 'expr'), (17, 'for_block'), (25, 'else_suite') ),
@@ -54,5 +56,6 @@ def customize_for_version37(self, version):
(0, 19 ) ),
'compare_chained2c_37': (
'%[3]{pattr.replace("-", " ")} %p %p', (0, 19), (6, 19) ),
'conditional37': ( '%p if %p else %p', (1, 'expr', 27), (0, 27), (4, 'expr', 27) ),
})