diff --git a/Makefile b/Makefile index 5fe5d565..21d91675 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/test/Makefile b/test/Makefile index e5111541..91c0a7e4 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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) diff --git a/uncompyle6/parsers/parse38.py b/uncompyle6/parsers/parse38.py index 014d1cc5..5594f2c8 100644 --- a/uncompyle6/parsers/parse38.py +++ b/uncompyle6/parsers/parse38.py @@ -25,27 +25,30 @@ class Python38Parser(Python37Parser): 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 for_iter store for_block JUMP_BACK - for38 ::= expr for_iter store for_block JUMP_BACK POP_BLOCK + 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 - 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 - while1elsestmt ::= l_stmts JUMP_BACK - whileelsestmt ::= testexpr 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 JUMP_BACK COME_FROM_LOOP - while1elsestmt ::= l_stmts JUMP_BACK - whileTruestmt ::= l_stmts_opt JUMP_BACK NOP - whileTruestmt ::= l_stmts_opt JUMP_BACK POP_BLOCK NOP - for_block ::= l_stmts_opt _come_from_loops JUMP_BACK + 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 + while1elsestmt ::= l_stmts JUMP_BACK + whileelsestmt ::= testexpr 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 JUMP_BACK COME_FROM_LOOP + while1elsestmt ::= l_stmts JUMP_BACK + whileTruestmt ::= l_stmts_opt JUMP_BACK NOP + whileTruestmt ::= l_stmts_opt JUMP_BACK POP_BLOCK NOP + for_block ::= l_stmts_opt _come_from_loops JUMP_BACK """ def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG): @@ -54,11 +57,15 @@ class Python38Parser(Python37Parser): def customize_grammar_rules(self, tokens, customize): self.remove_rules(""" - 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 + stmt ::= for + stmt ::= forelsestmt + for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK + 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) diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index f68580c2..d4aed209 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -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 ), diff --git a/uncompyle6/semantics/customize3.py b/uncompyle6/semantics/customize3.py index 326f0beb..6ac0441d 100644 --- a/uncompyle6/semantics/customize3.py +++ b/uncompyle6/semantics/customize3.py @@ -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', - (2, 'store'), - (0, 'expr'), - (3, 'for_block') ), + '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