Basic 3.8+ "for" loop handling...

More Makefile mangling
This commit is contained in:
rocky 2019-04-10 11:26:58 -04:00
parent 49e354375e
commit 726045a05e
5 changed files with 66 additions and 31 deletions

View File

@ -40,6 +40,9 @@ check-3.0 check-3.1 check-3.2 check-3.6:
check-3.7: pytest
$(MAKE) -C test check
check-3.8:
$(MAKE) -C test check
#:PyPy 2.6.1 PyPy 5.0.1, or PyPy 5.8.0-beta0
# Skip for now
2.6 5.0 5.3 5.6 5.8:

View File

@ -270,6 +270,10 @@ check-bytecode-3.6:
check-bytecode-3.7:
$(PYTHON) test_pythonlib.py --bytecode-3.7 --weak-verify
#: Check deparsing Python 3.8
check-bytecode-3.8:
$(PYTHON) test_pythonlib.py --bytecode-3.8 --weak-verify
#: short tests for bytecodes only for this version of Python
check-native-short:
$(PYTHON) test_pythonlib.py --bytecode-$(PYTHON_VERSION) --weak-verify $(COMPILE)

View File

@ -26,14 +26,17 @@ class Python38Parser(Python37Parser):
def p_38misc(self, args):
"""
stmt ::= for38
stmt ::= forelsestmt38
stmt ::= forelselaststmt38
stmt ::= forelselaststmtl38
for38 ::= expr get_iter store for_block JUMP_BACK
for38 ::= expr for_iter store for_block JUMP_BACK
for38 ::= expr for_iter store for_block JUMP_BACK POP_BLOCK
forelsestmt ::= expr for_iter store for_block POP_BLOCK else_suite
forelselaststmt ::= expr for_iter store for_block POP_BLOCK else_suitec
forelselaststmtl ::= expr for_iter store for_block POP_BLOCK else_suitel
forelsestmt38 ::= expr for_iter store for_block POP_BLOCK else_suite
forelselaststmt38 ::= expr for_iter store for_block POP_BLOCK else_suitec
forelselaststmtl38 ::= expr for_iter store for_block POP_BLOCK else_suitel
whilestmt ::= testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK
whilestmt ::= testexpr l_stmts_opt JUMP_BACK POP_BLOCK
whilestmt ::= testexpr returns POP_BLOCK
@ -54,11 +57,15 @@ class Python38Parser(Python37Parser):
def customize_grammar_rules(self, tokens, customize):
self.remove_rules("""
stmt ::= for
stmt ::= forelsestmt
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
forelsestmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suite
forelselaststmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitec
forelselaststmtl ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitel
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK NOP
for_block ::= l_stmts_opt COME_FROM_LOOP JUMP_BACK
forelsestmt38 ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suite
forelselaststmt38 ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitec
forelselaststmtl38 ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitel
""")
super(Python37Parser, self).customize_grammar_rules(tokens, customize)

View File

@ -1,4 +1,4 @@
# Copyright (c) 2017, 2018 by Rocky Bernstein
# Copyright (c) 2017-2019 by Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -276,6 +276,8 @@ TABLE_DIRECT = {
'while1elsestmt': ( '%|while 1:\n%+%c%-%|else:\n%+%c%-\n\n', 1, -2 ),
'whileelsestmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 2, -2 ),
'whileelselaststmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-', 1, 2, -2 ),
# Note: Python 3.8+ changes this
'for': ( '%|for %c in %c:\n%+%c%-\n\n',
(3, 'store'),
(1, 'expr'),
@ -295,6 +297,7 @@ TABLE_DIRECT = {
(3, 'store'),
(1, 'expr'),
(4, 'for_block'), -2 ),
'try_except': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ),
'tryelsestmt': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-\n\n', 1, 3, 4 ),
'tryelsestmtc': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-', 1, 3, 4 ),

View File

@ -909,7 +909,7 @@ def customize_for_version3(self, version):
if version >= 3.7:
########################
# Python 3.7+ Additions
# Python 3.7+ changes
#######################
PRECEDENCE['attribute37'] = 2
@ -934,13 +934,31 @@ def customize_for_version3(self, version):
})
if version >= 3.8:
########################
# Python 3.8+ Additions
# Python 3.8+ changes
#######################
for lhs in 'for forelsestmt forelselaststmt forelselaststmtl'.split():
del TABLE_DIRECT[lhs]
TABLE_DIRECT.update({
'for38': ( '%|for %c in %c:\n%+%c%-\n\n',
'for38': (
'%|for %c in %c:\n%+%c%-\n\n',
(2, 'store'),
(0, 'expr'),
(3, 'for_block') ),
'forelsestmt38': (
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n',
(2, 'store'),
(0, 'expr'),
(3, 'for_block'), -2 ),
'forelselaststmt38': (
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-',
(2, 'store'),
(0, 'expr'),
(3, 'for_block'), -2 ),
'forelselaststmtl38': (
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n',
(2, 'store'),
(0, 'expr'),
(3, 'for_block'), -2 ),
})
pass
pass