From 38eed14b4154a24b4ce206c701f5e1b5ed1ae3bb Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 10 Dec 2016 06:36:22 -0500 Subject: [PATCH] Another python 3 ELSE fixes and ... Makefile: - test python 3.0 bytecode - turn full --verify back on Python 3.x --- test/Makefile | 14 +++++++------- uncompyle6/parsers/parse3.py | 10 ++++++++-- uncompyle6/scanners/scanner3.py | 7 ++++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/test/Makefile b/test/Makefile index 0a5e7df8..70a847bc 100644 --- a/test/Makefile +++ b/test/Makefile @@ -22,29 +22,29 @@ check: #: Run working tests from Python 2.6 or 2.7 check-2.6 check-2.7: check-bytecode-2 check-bytecode-3 check-bytecode-1 check-2.7-ok -#: Run working tests from Python 3.1 +#: Run working tests from Python 3.0 check-3.0: check-bytecode - @echo Python 3.0 testing not done yet + $(PYTHON) test_pythonlib.py --bytecode-3.0 --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 --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 --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 --verify $(COMPILE) #: Run working tests from Python 3.4 check-3.4: check-bytecode check-3.4-ok check-2.7-ok - $(PYTHON) test_pythonlib.py --bytecode-3.4 --weak-verify $(COMPILE) + $(PYTHON) test_pythonlib.py --bytecode-3.4 --verify $(COMPILE) #: 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 --verify $(COMPILE) #: Run working tests from Python 3.6 check-3.6: check-bytecode diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index e82a2abc..0340c3f1 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -142,6 +142,10 @@ class Python3Parser(PythonParser): jf_else ::= JUMP_FORWARD ELSE ja_else ::= JUMP_ABSOLUTE ELSE + # Note: in if/else kinds of statements, we err on the side + # of missing "else" clauses. Therefore we include grammar + # rules with and without ELSE. + ifelsestmt ::= testexpr c_stmts_opt JUMP_FORWARD else_suite COME_FROM ifelsestmt ::= testexpr c_stmts_opt jf_else else_suite _come_from @@ -152,7 +156,6 @@ class Python3Parser(PythonParser): ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel - # FIXME: this feels like a hack. Is it just 1 or two # COME_FROMs? the parsed tree for this and even with just the # one COME_FROM for Python 2.7 seems to associate the @@ -373,7 +376,10 @@ class Python3Parser(PythonParser): def p_expr3(self, args): """ - conditional ::= expr jmp_false expr jf_else expr COME_FROM + conditional ::= expr jmp_false expr jf_else expr COME_FROM + conditionalnot ::= expr jmp_true expr jf_else expr COME_FROM + + expr ::= LOAD_CLASSNAME # Python 3.4+ diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index e29bfab4..ab324225 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -799,9 +799,10 @@ class Scanner3(Scanner): self.not_continue.add(prev_op[rtarget]) if rtarget < end and ( - code[rtarget] != self.opc.END_FINALLY - and code[prev_op[rrtarget]] not in (self.opc.POP_EXCEPT, - self.opc.END_FINALLY)): + code[rtarget] not in (self.opc.END_FINALLY, + self.opc.JUMP_ABSOLUTE) and + code[prev_op[rrtarget]] not in (self.opc.POP_EXCEPT, + self.opc.END_FINALLY)): self.structs.append({'type': 'else', 'start': rtarget, 'end': end})