Start to handle Python 3.1 bytecode

This commit is contained in:
rocky
2016-08-26 20:50:08 -04:00
parent 835c4151c3
commit ddc5460030
6 changed files with 32 additions and 6 deletions

View File

@@ -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 #: Tests for Python 3.2 and 3.5 - pytest doesn't work here
# Or rather 3.5 doesn't work not on Travis # 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 $@ $(MAKE) -C test $@
#:Tests for Python 2.6 (doesn't have pytest) #:Tests for Python 2.6 (doesn't have pytest)

View File

@@ -22,6 +22,10 @@ check:
#: Run working tests from Python 2.6 or 2.7 #: 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 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 #: Run working tests from Python 3.2
check-3.2: check-bytecode check-3.2: check-bytecode
$(PYTHON) test_pythonlib.py --bytecode-3.2 --verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-3.2 --verify $(COMPILE)

View File

@@ -590,7 +590,12 @@ def get_python_parser(
pass pass
else: else:
import uncompyle6.parsers.parse3 as parse3 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': if compile_mode == 'exec':
p = parse3.Python32Parser(debug_parser) p = parse3.Python32Parser(debug_parser)
else: else:

View File

@@ -635,6 +635,15 @@ class Python3Parser(PythonParser):
return 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): class Python32Parser(Python3Parser):
def p_32(self, args): def p_32(self, args):
@@ -660,6 +669,9 @@ class Python3ParserSingle(Python3Parser, PythonParserSingle):
pass pass
class Python31ParserSingle(Python31Parser, PythonParserSingle):
pass
class Python32ParserSingle(Python32Parser, PythonParserSingle): class Python32ParserSingle(Python32Parser, PythonParserSingle):
pass pass

View File

@@ -22,7 +22,8 @@ from uncompyle6 import PYTHON3, IS_PYPY
from uncompyle6.scanners.tok import Token from uncompyle6.scanners.tok import Token
# The byte code versions we support # 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 # FIXME: DRY
if PYTHON3: if PYTHON3:

View File

@@ -52,10 +52,9 @@ class Scanner3(Scanner):
# Note: super initilization above initializes self.opc # Note: super initilization above initializes self.opc
# Opcodes that can start a statement. # 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_LOOP, self.opc.BREAK_LOOP, self.opc.CONTINUE_LOOP,
self.opc.SETUP_FINALLY, self.opc.END_FINALLY, self.opc.SETUP_EXCEPT, 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.POP_BLOCK, self.opc.STORE_FAST, self.opc.DELETE_FAST,
self.opc.STORE_DEREF, 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.RETURN_VALUE, self.opc.RAISE_VARARGS, self.opc.POP_TOP,
self.opc.PRINT_EXPR, self.opc.JUMP_ABSOLUTE 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. # Opcodes that can start a designator non-terminal.
# FIXME: JUMP_ABSOLUTE is weird. What's up with that? # FIXME: JUMP_ABSOLUTE is weird. What's up with that?