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 check-3.7: pytest
$(MAKE) -C test check $(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 #:PyPy 2.6.1 PyPy 5.0.1, or PyPy 5.8.0-beta0
# Skip for now # Skip for now
2.6 5.0 5.3 5.6 5.8: 2.6 5.0 5.3 5.6 5.8:

View File

@@ -270,6 +270,10 @@ check-bytecode-3.6:
check-bytecode-3.7: check-bytecode-3.7:
$(PYTHON) test_pythonlib.py --bytecode-3.7 --weak-verify $(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 #: short tests for bytecodes only for this version of Python
check-native-short: check-native-short:
$(PYTHON) test_pythonlib.py --bytecode-$(PYTHON_VERSION) --weak-verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-$(PYTHON_VERSION) --weak-verify $(COMPILE)

View File

@@ -25,27 +25,30 @@ class Python38Parser(Python37Parser):
def p_38misc(self, args): def p_38misc(self, args):
""" """
stmt ::= for38 stmt ::= for38
stmt ::= forelsestmt38
stmt ::= forelselaststmt38
stmt ::= forelselaststmtl38
for38 ::= expr get_iter store for_block JUMP_BACK 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
for38 ::= expr for_iter store for_block JUMP_BACK POP_BLOCK for38 ::= expr for_iter store for_block JUMP_BACK POP_BLOCK
forelsestmt ::= expr for_iter store for_block POP_BLOCK else_suite forelsestmt38 ::= expr for_iter store for_block POP_BLOCK else_suite
forelselaststmt ::= expr for_iter store for_block POP_BLOCK else_suitec forelselaststmt38 ::= expr for_iter store for_block POP_BLOCK else_suitec
forelselaststmtl ::= expr for_iter store for_block POP_BLOCK else_suitel 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 COME_FROM JUMP_BACK POP_BLOCK
whilestmt ::= testexpr l_stmts_opt JUMP_BACK POP_BLOCK whilestmt ::= testexpr l_stmts_opt JUMP_BACK POP_BLOCK
whilestmt ::= testexpr returns POP_BLOCK whilestmt ::= testexpr returns POP_BLOCK
while1elsestmt ::= l_stmts JUMP_BACK while1elsestmt ::= l_stmts JUMP_BACK
whileelsestmt ::= testexpr l_stmts_opt JUMP_BACK POP_BLOCK whileelsestmt ::= testexpr l_stmts_opt JUMP_BACK POP_BLOCK
whileTruestmt ::= l_stmts_opt JUMP_BACK POP_BLOCK whileTruestmt ::= l_stmts_opt JUMP_BACK POP_BLOCK
while1stmt ::= l_stmts COME_FROM_LOOP while1stmt ::= l_stmts COME_FROM_LOOP
while1stmt ::= l_stmts COME_FROM JUMP_BACK COME_FROM_LOOP while1stmt ::= l_stmts COME_FROM JUMP_BACK COME_FROM_LOOP
while1elsestmt ::= l_stmts JUMP_BACK while1elsestmt ::= l_stmts JUMP_BACK
whileTruestmt ::= l_stmts_opt JUMP_BACK NOP whileTruestmt ::= l_stmts_opt JUMP_BACK NOP
whileTruestmt ::= l_stmts_opt JUMP_BACK POP_BLOCK NOP whileTruestmt ::= l_stmts_opt JUMP_BACK POP_BLOCK NOP
for_block ::= l_stmts_opt _come_from_loops JUMP_BACK for_block ::= l_stmts_opt _come_from_loops JUMP_BACK
""" """
def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG): def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG):
@@ -54,11 +57,15 @@ class Python38Parser(Python37Parser):
def customize_grammar_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):
self.remove_rules(""" self.remove_rules("""
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK stmt ::= for
forelsestmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suite stmt ::= forelsestmt
forelselaststmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitec for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
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 ::= 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) 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 # 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 # 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 ), '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 ), 'whileelsestmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 2, -2 ),
'whileelselaststmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-', 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', 'for': ( '%|for %c in %c:\n%+%c%-\n\n',
(3, 'store'), (3, 'store'),
(1, 'expr'), (1, 'expr'),
@@ -295,6 +297,7 @@ TABLE_DIRECT = {
(3, 'store'), (3, 'store'),
(1, 'expr'), (1, 'expr'),
(4, 'for_block'), -2 ), (4, 'for_block'), -2 ),
'try_except': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ), 'try_except': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ),
'tryelsestmt': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-\n\n', 1, 3, 4 ), 'tryelsestmt': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-\n\n', 1, 3, 4 ),
'tryelsestmtc': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-', 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: if version >= 3.7:
######################## ########################
# Python 3.7+ Additions # Python 3.7+ changes
####################### #######################
PRECEDENCE['attribute37'] = 2 PRECEDENCE['attribute37'] = 2
@@ -934,13 +934,31 @@ def customize_for_version3(self, version):
}) })
if version >= 3.8: 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({ TABLE_DIRECT.update({
'for38': ( '%|for %c in %c:\n%+%c%-\n\n', 'for38': (
(2, 'store'), '%|for %c in %c:\n%+%c%-\n\n',
(0, 'expr'), (2, 'store'),
(3, 'for_block') ), (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
pass pass