From c58481a9ebf7d1c0204381b8097aac36f17a3148 Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 5 May 2016 20:56:41 -0400 Subject: [PATCH] More Python 2 and 3 deparsing bugs fixed * while + if break * try + finall /pass --- test/bytecode_2.7/05_try_finally_pass.pyc | Bin 0 -> 143 bytes test/bytecode_2.7/10_if_break_finally.pyc | Bin 0 -> 175 bytes test/bytecode_3.5/05_try_finally_pass.pyc | Bin 0 -> 139 bytes test/bytecode_3.5/10_if_break_finally.pyc | Bin 0 -> 162 bytes test/simple_source/stmts/05_try_finally_pass.py | 10 ++++++++++ test/simple_source/stmts/10_if_break_finally.py | 10 ++++++++++ uncompyle6/opcodes/opcode_27.py | 3 +-- uncompyle6/parser.py | 2 +- uncompyle6/parsers/parse2.py | 5 ++++- uncompyle6/parsers/parse3.py | 2 +- 10 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 test/bytecode_2.7/05_try_finally_pass.pyc create mode 100644 test/bytecode_2.7/10_if_break_finally.pyc create mode 100644 test/bytecode_3.5/05_try_finally_pass.pyc create mode 100644 test/bytecode_3.5/10_if_break_finally.pyc create mode 100644 test/simple_source/stmts/05_try_finally_pass.py create mode 100644 test/simple_source/stmts/10_if_break_finally.py diff --git a/test/bytecode_2.7/05_try_finally_pass.pyc b/test/bytecode_2.7/05_try_finally_pass.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6be3d50b8fe3ab9d47603ffa10fb195c734cbe0e GIT binary patch literal 143 zcmZSn%*(a+k#=}80~9a=X$K%K<^d8_EDYf(3=9!K9IU|z6!6mk5)5cWu@+FQI5W2( zCpEq}zqBYhRlm3-x1?C#z%;(3s4_k+GcPeGr!u}EvA9^Tpt6JmsN5zuKczG$)s79M N6+|#IvM@0+0svez9S8sb literal 0 HcmV?d00001 diff --git a/test/bytecode_2.7/10_if_break_finally.pyc b/test/bytecode_2.7/10_if_break_finally.pyc new file mode 100644 index 0000000000000000000000000000000000000000..457e93b40d2daa2b8c8bd9a92a9ef1f635bb01f4 GIT binary patch literal 175 zcmZSn%*!SIT010Lm5Tmlh?b>KB*fmK5t78pLO&#U~Y| oCT0V5<|XFjRO%H}f{n7t%}*)KNws4IX$6_h%*f2h#>m420McY4>Hq)$ literal 0 HcmV?d00001 diff --git a/test/bytecode_3.5/05_try_finally_pass.pyc b/test/bytecode_3.5/05_try_finally_pass.pyc new file mode 100644 index 0000000000000000000000000000000000000000..41aad59a79562a220b8dd2a32e5836d70f4530ad GIT binary patch literal 139 zcmWgR<>lJ@NIU!@0|UcjAcg}@Aj<)Wi+O-V6$?Xn3Ijs~5C>~A`mJOrVg!mJh+kU8 znYjfysqw}6rA5i9`o$%=CB^y%rtu|3mGNnrd5JkWmGK3M#l?CBmA5!-a`RJ4b5iZt OK*oazW=0k!Mn(X_xgXpB literal 0 HcmV?d00001 diff --git a/test/bytecode_3.5/10_if_break_finally.pyc b/test/bytecode_3.5/10_if_break_finally.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ebf42bbdacdd13069147b4a0d3b36093b6df83ed GIT binary patch literal 162 zcmWgR<>eB8tsQ=ufq~&M5W@i{kmUfx#Zo|`N{FF?n<15fp@@wkppcCrJUoSgAp(el zH5vUh8EaIhA?^mA5!-a`RJ4b5iYCL3VNg31&uSMm9!HCIE`)C0hUh literal 0 HcmV?d00001 diff --git a/test/simple_source/stmts/05_try_finally_pass.py b/test/simple_source/stmts/05_try_finally_pass.py new file mode 100644 index 00000000..c4f213e0 --- /dev/null +++ b/test/simple_source/stmts/05_try_finally_pass.py @@ -0,0 +1,10 @@ +# Tests and empty finally section +# tryfinallystmt ::= SETUP_FINALLY e_suite_stmts_opt +# POP_BLOCK LOAD_CONST COME_FROM e_suite_stmts_opt END_FINALLY +# + +try: + pass +finally: + pass +pass diff --git a/test/simple_source/stmts/10_if_break_finally.py b/test/simple_source/stmts/10_if_break_finally.py new file mode 100644 index 00000000..4a1486df --- /dev/null +++ b/test/simple_source/stmts/10_if_break_finally.py @@ -0,0 +1,10 @@ +# Tests +# while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK COME_FROM +# tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK + +try: + while 1: + if __file__: + break +finally: + pass diff --git a/uncompyle6/opcodes/opcode_27.py b/uncompyle6/opcodes/opcode_27.py index b4dbba3f..1fb748aa 100755 --- a/uncompyle6/opcodes/opcode_27.py +++ b/uncompyle6/opcodes/opcode_27.py @@ -215,6 +215,5 @@ del def_op, name_op, jrel_op, jabs_op from uncompyle6 import PYTHON_VERSION if PYTHON_VERSION == 2.7: import dis - # print(dis.opmap.items()) - print(set(dis.opmap.items()) - set(opmap.items())) + # print(set(dis.opmap.items()) - set(opmap.items())) assert all(item in opmap.items() for item in dis.opmap.items()) diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 44d0d189..a12720e6 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -448,7 +448,7 @@ def python_parser(version, co, out=sys.stdout, showasm=False, print(t) # For heavy grammar debugging - # parser_debug = {'rules': True, 'transition': True, 'reduce' : True} + parser_debug = {'rules': True, 'transition': True, 'reduce' : True} p = get_python_parser(version, parser_debug) return parse(p, tokens, customize) diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index 9484500c..49bac881 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -268,7 +268,7 @@ class Python2Parser(PythonParser): try_middle COME_FROM # this is nested inside a trystmt - tryfinallystmt ::= SETUP_FINALLY suite_stmts + tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM suite_stmts_opt END_FINALLY @@ -328,7 +328,10 @@ class Python2Parser(PythonParser): return_stmts POP_BLOCK COME_FROM + while1stmt_pre ::= SETUP_LOOP l_stmts JUMP_BACK while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM + while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK COME_FROM + while1stmt ::= SETUP_LOOP return_stmts COME_FROM while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 8424b26c..0533e499 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -263,7 +263,7 @@ class Python3Parser(PythonParser): try_middle _come_from _come_from # this is nested inside a trystmt - tryfinallystmt ::= SETUP_FINALLY suite_stmts + tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM suite_stmts_opt END_FINALLY