From ddc54600301a2f219eb551236b8da985fa2b8616 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 26 Aug 2016 20:50:08 -0400 Subject: [PATCH] Start to handle Python 3.1 bytecode --- Makefile | 2 +- test/Makefile | 4 ++++ uncompyle6/parser.py | 7 ++++++- uncompyle6/parsers/parse3.py | 12 ++++++++++++ uncompyle6/scanner.py | 3 ++- uncompyle6/scanners/scanner3.py | 10 +++++++--- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 910e17d6..4be5dca5 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ check-2.7 check-3.3 check-3.4: pytest #: Tests for Python 3.2 and 3.5 - pytest doesn't work here # Or rather 3.5 doesn't work not on Travis -check-3.2 check-3.5 check-3.6: +check-3.1 check-3.2 check-3.5 check-3.6: $(MAKE) -C test $@ #:Tests for Python 2.6 (doesn't have pytest) diff --git a/test/Makefile b/test/Makefile index 1579d92c..ea87c7e3 100644 --- a/test/Makefile +++ b/test/Makefile @@ -22,6 +22,10 @@ check: #: Run working tests from Python 2.6 or 2.7 check-2.6 check-2.7: check-bytecode-2 check-bytecode-3 check-2.7-ok +#: Run working tests from Python 3.1 +check-3.2: check-bytecode + $(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 --verify $(COMPILE) diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index aa19a91e..e5c6b12b 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -590,7 +590,12 @@ def get_python_parser( pass else: import uncompyle6.parsers.parse3 as parse3 - if version == 3.2: + if version == 3.1: + if compile_mode == 'exec': + p = parse3.Python31Parser(debug_parser) + else: + p = parse3.Python31ParserSingle(debug_parser) + elif version == 3.2: if compile_mode == 'exec': p = parse3.Python32Parser(debug_parser) else: diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 8c3d844a..8db91a55 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -635,6 +635,15 @@ class Python3Parser(PythonParser): return +class Python31Parser(Python3Parser): + + def p_31(self, args): + """ + # Store locals is only in Python 3.0 to 3.3 + stmt ::= store_locals + store_locals ::= LOAD_FAST STORE_LOCALS + """ + class Python32Parser(Python3Parser): def p_32(self, args): @@ -660,6 +669,9 @@ class Python3ParserSingle(Python3Parser, PythonParserSingle): pass +class Python31ParserSingle(Python31Parser, PythonParserSingle): + pass + class Python32ParserSingle(Python32Parser, PythonParserSingle): pass diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index 3bec4eb2..a78c89a8 100755 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -22,7 +22,8 @@ from uncompyle6 import PYTHON3, IS_PYPY from uncompyle6.scanners.tok import Token # The byte code versions we support -PYTHON_VERSIONS = (2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.2, 3.3, 3.4, 3.5, 3.6) +PYTHON_VERSIONS = (2.2, 2.3, 2.4, 2.5, 2.6, 2.7, + 3.1, 3.2, 3.3, 3.4, 3.5, 3.6) # FIXME: DRY if PYTHON3: diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index d0034afb..9dbee8af 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -52,10 +52,9 @@ class Scanner3(Scanner): # Note: super initilization above initializes self.opc # Opcodes that can start a statement. - self.statement_opcodes = frozenset([ + statement_opcodes = [ self.opc.SETUP_LOOP, self.opc.BREAK_LOOP, self.opc.CONTINUE_LOOP, self.opc.SETUP_FINALLY, self.opc.END_FINALLY, self.opc.SETUP_EXCEPT, - self.opc.SETUP_WITH, self.opc.POP_BLOCK, self.opc.STORE_FAST, self.opc.DELETE_FAST, self.opc.STORE_DEREF, @@ -67,7 +66,12 @@ class Scanner3(Scanner): self.opc.RETURN_VALUE, self.opc.RAISE_VARARGS, self.opc.POP_TOP, self.opc.PRINT_EXPR, self.opc.JUMP_ABSOLUTE - ]) + ] + + if version >= 3.2: + statement_opcodes.append(self.opc.SETUP_WITH) + + self.statement_opcodes = frozenset(statement_opcodes) # Opcodes that can start a designator non-terminal. # FIXME: JUMP_ABSOLUTE is weird. What's up with that?