diff --git a/test/Makefile b/test/Makefile index 6d12cf0a..f948cb03 100644 --- a/test/Makefile +++ b/test/Makefile @@ -33,23 +33,23 @@ check-2.6 check-2.7: check-bytecode-2 check-bytecode-3 check-bytecode-1 check-na #: Run working tests from Python 3.0 check-3.0: check-bytecode - $(PYTHON) test_pythonlib.py --bytecode-3.0 --weak-verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-3.0-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.0 --weak-verify $(COMPILE) #: Run working tests from Python 3.1 check-3.1: check-bytecode - $(PYTHON) test_pythonlib.py --bytecode-3.1 --weak-verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-3.1-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.1 --weak-verify $(COMPILE) #: Run working tests from Python 3.2 check-3.2: check-bytecode - $(PYTHON) test_pythonlib.py --bytecode-3.2 --weak-verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-3.2-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.2 --weak-verify $(COMPILE) #: Run working tests from Python 3.3 check-3.3: check-bytecode - $(PYTHON) test_pythonlib.py --bytecode-3.3 --weak-verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-3.3-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.3 --weak-verify $(COMPILE) #: Run working tests from Python 3.4 check-3.4: check-bytecode check-3.4-ok check-2.7-ok @@ -58,18 +58,23 @@ check-3.4: check-bytecode check-3.4-ok check-2.7-ok #: Run working tests from Python 3.5 check-3.5: check-bytecode - $(PYTHON) test_pythonlib.py --bytecode-3.5 --weak-verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-3.5-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.5 --weak-verify $(COMPILE) #: Run working tests from Python 3.6 check-3.6: check-bytecode - $(PYTHON) test_pythonlib.py --bytecode-3.6 --weak-verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-3.6-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.6 --weak-verify $(COMPILE) #: Run working tests from Python 3.7 check-3.7: check-bytecode - $(PYTHON) test_pythonlib.py --bytecode-3.7 --weak-verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-3.7-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.7 --weak-verify $(COMPILE) + +#: Run working tests from Python 3.8 +check-3.8: check-bytecode + $(PYTHON) test_pythonlib.py --bytecode-3.8-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.8 --weak-verify $(COMPILE) # FIXME #: this is called when running under pypy3.5-5.8.0 or pypy2-5.6.0 @@ -92,7 +97,8 @@ check-bytecode-2: check-bytecode-3: $(PYTHON) test_pythonlib.py --bytecode-3.0 \ --bytecode-3.1 --bytecode-3.2 --bytecode-3.3 \ - --bytecode-3.4 --bytecode-3.5 --bytecode-3.6 --bytecode-3.7 \ + --bytecode-3.4 --bytecode-3.5 --bytecode-3.6 \ + --bytecode-3.7 --bytecode-3.8 \ --bytecode-pypy3.2 #: Check deparsing on selected bytecode 3.x @@ -217,43 +223,43 @@ grammar-coverage-3.6: #: Check deparsing Python 2.6 check-bytecode-2.6: - $(PYTHON) test_pythonlib.py --bytecode-2.6 --weak-verify $(PYTHON) test_pythonlib.py --bytecode-2.6-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-2.6 --weak-verify #: Check deparsing Python 2.7 check-bytecode-2.7: - $(PYTHON) test_pythonlib.py --bytecode-2.7 --weak-verify $(PYTHON) test_pythonlib.py --bytecode-2.7-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-2.7 --weak-verify #: Check deparsing Python 3.0 check-bytecode-3.0: - $(PYTHON) test_pythonlib.py --bytecode-3.0 --weak-verify $(PYTHON) test_pythonlib.py --bytecode-3.0-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.0 --weak-verify #: Check deparsing Python 3.1 check-bytecode-3.1: - $(PYTHON) test_pythonlib.py --bytecode-3.1 --weak-verify $(PYTHON) test_pythonlib.py --bytecode-3.1-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.1 --weak-verify #: Check deparsing Python 3.2 check-bytecode-3.2: - $(PYTHON) test_pythonlib.py --bytecode-3.2 --weak-verify $(PYTHON) test_pythonlib.py --bytecode-3.2-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.2 --weak-verify #: Check deparsing Python 3.3 check-bytecode-3.3: - $(PYTHON) test_pythonlib.py --bytecode-3.3 --weak-verify $(PYTHON) test_pythonlib.py --bytecode-3.3-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.3 --weak-verify #: Check deparsing Python 3.4 check-bytecode-3.4: - $(PYTHON) test_pythonlib.py --bytecode-3.4 --weak-verify $(PYTHON) test_pythonlib.py --bytecode-3.4-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.4 --weak-verify #: Check deparsing Python 3.5 check-bytecode-3.5: - $(PYTHON) test_pythonlib.py --bytecode-3.5 --weak-verify $(PYTHON) test_pythonlib.py --bytecode-3.5-run --verify-run + $(PYTHON) test_pythonlib.py --bytecode-3.5 --weak-verify #: Check deparsing Python 3.6 check-bytecode-3.6: diff --git a/test/add-test.py b/test/add-test.py index 905323d5..a5ea9ac6 100755 --- a/test/add-test.py +++ b/test/add-test.py @@ -4,12 +4,19 @@ import os, sys, py_compile assert len(sys.argv) >= 2 version = sys.version[0:3] -for path in sys.argv[1:]: +if sys.argv[1] == '--run': + suffix = '_run' + py_source = sys.argv[2:] +else: + suffix = '' + py_source = sys.argv[1:] + +for path in py_source: short = os.path.basename(path) if hasattr(sys, 'pypy_version_info'): - cfile = "bytecode_pypy%s/%s" % (version, short) + 'c' + cfile = "bytecode_pypy%s%s/%s" % (version, suffix, short) + 'c' else: - cfile = "bytecode_%s/%s" % (version, short) + 'c' + cfile = "bytecode_%s%s/%s" % (version, suffix, short) + 'c' print("byte-compiling %s to %s" % (path, cfile)) py_compile.compile(path, cfile) if isinstance(version, str) or version >= (2, 6, 0): diff --git a/test/bytecode_3.3/10_for.pyc b/test/bytecode_3.3/10_for.pyc deleted file mode 100644 index 3379248f..00000000 Binary files a/test/bytecode_3.3/10_for.pyc and /dev/null differ diff --git a/test/bytecode_3.3_run/10_for.pyc b/test/bytecode_3.3_run/10_for.pyc new file mode 100644 index 00000000..f528dfb8 Binary files /dev/null and b/test/bytecode_3.3_run/10_for.pyc differ diff --git a/test/bytecode_3.4/10_for.pyc b/test/bytecode_3.4/10_for.pyc deleted file mode 100644 index 26c63996..00000000 Binary files a/test/bytecode_3.4/10_for.pyc and /dev/null differ diff --git a/test/bytecode_3.4_run/10_for.pyc b/test/bytecode_3.4_run/10_for.pyc new file mode 100644 index 00000000..ee588b94 Binary files /dev/null and b/test/bytecode_3.4_run/10_for.pyc differ diff --git a/test/bytecode_3.5/10_for.pyc b/test/bytecode_3.5/10_for.pyc deleted file mode 100644 index 82d64337..00000000 Binary files a/test/bytecode_3.5/10_for.pyc and /dev/null differ diff --git a/test/bytecode_3.5_run/10_for.pyc b/test/bytecode_3.5_run/10_for.pyc new file mode 100644 index 00000000..e669db77 Binary files /dev/null and b/test/bytecode_3.5_run/10_for.pyc differ diff --git a/test/bytecode_3.8/09_yield_from.pyc b/test/bytecode_3.8/09_yield_from.pyc new file mode 100644 index 00000000..8da7c6ad Binary files /dev/null and b/test/bytecode_3.8/09_yield_from.pyc differ diff --git a/test/bytecode_3.8_run/10_for.pyc b/test/bytecode_3.8_run/10_for.pyc new file mode 100644 index 00000000..38a345ee Binary files /dev/null and b/test/bytecode_3.8_run/10_for.pyc differ diff --git a/test/simple_source/looping/10_for.py b/test/simple_source/looping/10_for.py index eb85f549..3a37c4cf 100644 --- a/test/simple_source/looping/10_for.py +++ b/test/simple_source/looping/10_for.py @@ -1,8 +1,13 @@ # Tests: # forstmt ::= SETUP_LOOP expr _for store # for_block POP_BLOCK COME_FROM -for a in [1]: - c = 2 -for a in range(2): - c = 2 +c = 0 +for a in [1]: + c += a +assert c == 1, c + +for a in range(3): + c += a + +assert c == 4, c diff --git a/test/test_pythonlib.py b/test/test_pythonlib.py index e74d9d46..df05fcf5 100755 --- a/test/test_pythonlib.py +++ b/test/test_pythonlib.py @@ -81,7 +81,7 @@ for vers in (2.7, 3.4, 3.5, 3.6): for vers in (1.3, 1.4, 1.5, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, - 3.4, 3.5, 3.6, 3.7, 'pypy3.2', 'pypy2.7'): + 3.4, 3.5, 3.6, 3.7, 3.8, 'pypy3.2', 'pypy2.7'): bytecode = "bytecode_%s" % vers key = "bytecode-%s" % vers test_options[key] = (bytecode, PYC, bytecode, vers) diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index eacabdcd..98321047 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -1190,7 +1190,9 @@ class Python3Parser(PythonParser): last += 1 if last == n: return False - return tokens[first].attr > tokens[last].offset + # 3.8+ Doesn't have SETUP_LOOP + return self.version < 3.8 and tokens[first].attr > tokens[last].offset + elif rule == ('try_except', ('SETUP_EXCEPT', 'suite_stmts_opt', 'POP_BLOCK', 'except_handler', 'opt_come_from_except')): diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index 84a696b0..05ab5829 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -231,8 +231,6 @@ class Python36Parser(Python35Parser): self.addRule(rule, nop_func) elif opname == 'SETUP_WITH': rules_str = """ - withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST - WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt COME_FROM_WITH WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY @@ -240,6 +238,19 @@ class Python36Parser(Python35Parser): withasstmt ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY """ + if self.version < 3.8: + rules_str += """ + withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK + LOAD_CONST + WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY + """ + else: + rules_str += """ + withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK + BEGIN_FINALLY COME_FROM_WITH + WITH_CLEANUP_START WITH_CLEANUP_FINISH + END_FINALLY + """ self.addRule(rules_str, nop_func) pass pass diff --git a/uncompyle6/parsers/parse38.py b/uncompyle6/parsers/parse38.py index fb0d5e6e..014d1cc5 100644 --- a/uncompyle6/parsers/parse38.py +++ b/uncompyle6/parsers/parse38.py @@ -26,8 +26,10 @@ class Python38Parser(Python37Parser): def p_38misc(self, args): """ stmt ::= for38 + 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