From f3d86e070817068293ab5d761338a5d086dc88b7 Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 10 Apr 2019 07:22:43 -0400 Subject: [PATCH] Bang on Python 3.8 --- test/Makefile | 38 ++++++++++++++++----------- test/add-test.py | 13 ++++++--- test/bytecode_3.3/10_for.pyc | Bin 221 -> 0 bytes test/bytecode_3.3_run/10_for.pyc | Bin 0 -> 316 bytes test/bytecode_3.4/10_for.pyc | Bin 195 -> 0 bytes test/bytecode_3.4_run/10_for.pyc | Bin 0 -> 289 bytes test/bytecode_3.5/10_for.pyc | Bin 197 -> 0 bytes test/bytecode_3.5_run/10_for.pyc | Bin 0 -> 289 bytes test/bytecode_3.8/09_yield_from.pyc | Bin 0 -> 466 bytes test/bytecode_3.8_run/10_for.pyc | Bin 0 -> 259 bytes test/simple_source/looping/10_for.py | 13 ++++++--- test/test_pythonlib.py | 2 +- uncompyle6/parsers/parse3.py | 4 ++- uncompyle6/parsers/parse36.py | 15 +++++++++-- uncompyle6/parsers/parse38.py | 2 ++ 15 files changed, 60 insertions(+), 27 deletions(-) delete mode 100644 test/bytecode_3.3/10_for.pyc create mode 100644 test/bytecode_3.3_run/10_for.pyc delete mode 100644 test/bytecode_3.4/10_for.pyc create mode 100644 test/bytecode_3.4_run/10_for.pyc delete mode 100644 test/bytecode_3.5/10_for.pyc create mode 100644 test/bytecode_3.5_run/10_for.pyc create mode 100644 test/bytecode_3.8/09_yield_from.pyc create mode 100644 test/bytecode_3.8_run/10_for.pyc 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 3379248ff9c15db21f33e7954d3f5fef7532f4d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 221 zcmbQo!^_neRT(y$fq@|zh~a<<$Z`PUVrw8#AvK1v#nl#rdU0$*KA|`S}HzdFlFw2Jvb6MS2C5r5r$2Ho5sJr8%i~EI@WK N8;}rS`LhQx$6IjJKH@6vkA#%m=r_<=WVOwf9Xv XGujyG3pEZGxi+Ig3B}YE9g4*dy!tma literal 0 HcmV?d00001 diff --git a/test/bytecode_3.4/10_for.pyc b/test/bytecode_3.4/10_for.pyc deleted file mode 100644 index 26c63996bc670690971dec026b6c7e887cfd7591..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 195 zcmaFI!^@RWUlBH&fq~&M5W@izkmUfx#nwQgLYyImfgzod!6lZ5A&P+^g^?kOk)e=_ zA-qD0A(aWlZ$_6?X9!PWVhGk`e#r$fh-3gF0KR;DGUrz3=9?03@MBZ>5L36u>uTHj0~v^ z45^F^=0KT30fulO4=9_>#87O*P{IU~Y-VI=Vq~b0V@PFYNMQnTF*SNZG%|xVmZE4( zVPOc?WPJ&=p5Y}UhyXe1B@2-7(`32Dn0$*d@fM$BadB! zl?+9kKxJU!mwa(%Zb43Jd~tqhQF5w&PJVttW?s6!p+S6Fevw{55cz{tla!6eMc#{>W)zdft~ literal 0 HcmV?d00001 diff --git a/test/bytecode_3.5/10_for.pyc b/test/bytecode_3.5/10_for.pyc deleted file mode 100644 index 82d6433788f293db0d19328404b5275432685eee..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 197 zcmWgR<>gAKuLzsXz`*brh~a<<$Z`PUVrw8#Av88U$+uXG67$kiS27f_0foWD zFGW55;>_HFoYeT@{L-T2RQ;U%{DRE9bbUjE__X{Yy@JYH95%W6DWy57b}T?$#UQN$ Jj9g5@i~x4rDGLAq 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 0000000000000000000000000000000000000000..e669db77acb447129cc5c13868fc893dd79f6dd0 GIT binary patch literal 289 zcmWgV<>k6|W^K$N1_p-5Knw@WK$Zg#7gqv_6b6PU28If0h7?AIbVdf3SOJD8Mut=d zhEzrdbD&J207E#C2b9fbVkov@C}9FgHZw9bF)~!hF{Cmxq%eWFm>NAH8kxZwOHnkY zurLH`vc3db&+w8FM1Y+1k_AZkX|mj6OuogKc#F@mxHz?_Br`wHwWuh+=oV{HVqSXc zN`@j%pfWJ=OTIWWw;(4qzBs?MC^=O>CqKU+GcR4=&>%i7zeum3@)n0pZhlH>PO2R% WP){)rkYHmJVB}+zU=n8JV*&s&89dei literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..8da7c6ad8cd768d4caa9fcb989a4c2878acf3fff GIT binary patch literal 466 zcmZ8eO-lnY5S>Z3wI5VGi1-I8?8SN!6hu5I+DkzNEejHsoh+=~b!&Eu7PhDMDjxh5 z{-wS8FFZL((Ss8v^Ipg#?f0DM{U8x zTkxBs$ZoS?tH&8}x|R|usF3hYTmZopAkW+)Mn2XaQDV5Z)k~O8lqIs3T4RMLsi;9_ZJp(M6HuPlJPFHBWR(DmHnxKb;%)09`A<0zk(jhnZS+ zZBD1~h(U!FEb)C0S?MF3!^7@ERALDWSxJIP+iX?xj&(n8-NPYV!wrnr9&qg;EJNR` zy+WsPusJNX2}@RWISUO18%e1%qvP6hz#4IGOp{UFQi_+2Qub{N_XpVF(Zm)SOMSjV WIQfpQTmK(&lI1i@_35AEPWJ~*L0ljJ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..38a345ee98bf7862af676210aad21fdaf11ccb10 GIT binary patch literal 259 zcmea|<>g`kf@^2i#vB6Dk3k$5Ugy`3o`T4^$iW;)AEb-3My}L*yQG?l;)(`u>zGB^8g7JMh-?UMgb-s HMlL1*2$njy literal 0 HcmV?d00001 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