diff --git a/__pkginfo__.py b/__pkginfo__.py index 97b42ee3..02701df6 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -31,7 +31,7 @@ classifiers = ['Development Status :: 4 - Beta', author = "Rocky Bernstein, Hartmut Goebel, John Aycock, and others" author_email = "rb@dustyfeet.com" ftp_url = None -install_requires = ['spark-parser >= 1.1.1'] +install_requires = ['spark-parser >= 1.2.0'] license = 'MIT' mailing_list = 'python-debugger@googlegroups.com' modname = 'uncompyle6' diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index e2712b70..fac0a69d 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -84,6 +84,7 @@ class Python2Parser(PythonParser): _stmts ::= _stmts stmt _stmts ::= stmt + # statements with continue c_stmts ::= _stmts c_stmts ::= _stmts lastc_stmt c_stmts ::= lastc_stmt diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index fcb91d59..d3733928 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -76,6 +76,7 @@ class Python3Parser(PythonParser): _stmts ::= _stmts stmt _stmts ::= stmt + # statements with continue c_stmts ::= _stmts c_stmts ::= _stmts lastc_stmt c_stmts ::= lastc_stmt @@ -144,7 +145,7 @@ class Python3Parser(PythonParser): return_if_stmts ::= return_if_stmt return_if_stmts ::= _stmts return_if_stmt - return_if_stmt ::= ret_expr RETURN_END_IF + return_if_stmt ::= ret_expr RETURN_VALUE stmt ::= break_stmt break_stmt ::= BREAK_LOOP @@ -241,7 +242,7 @@ class Python3Parser(PythonParser): testtrue ::= expr jmp_true _ifstmts_jump ::= return_if_stmts - _ifstmts_jump ::= c_stmts_opt JUMP_FORWARD _come_from _come_from + _ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM _ifstmts_jump ::= c_stmts_opt iflaststmt ::= testexpr c_stmts_opt JUMP_ABSOLUTE diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index 042c21b5..c6ba6971 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -47,6 +47,8 @@ class Scanner3(scan.Scanner): The below is based on (an older version?) of Python dis.disassemble_bytes(). """ + + # dis.disassemble(co) # DEBUG # Container for tokens tokens = [] customize = {} @@ -211,13 +213,33 @@ class Scanner3(scan.Scanner): op_name = 'CONTINUE' else: op_name = 'JUMP_BACK' - + pass + pass + elif target > offset: + # Python 3.5 will use JUMP_FORWARD where 3.2 may + # use JUMP_ABSOLUTE. Which direction we move + # simplifies grammar rules working with both 3.2 + # and 3.5. So optimize the way Python 3.5 does it. + # + # We may however want to consider whether we do + # this in 3.5 or not. + op_name = 'JUMP_FORWARD' + oparg -= offset + pass + pass + elif op_name == 'JUMP_FORWARD': + # Python 3.5 will optimize out a JUMP_FORWARD to the + # next instruction while Python 3.2 won't. Smplify + # grammar rules working with both 3.2 and 3.5, + # by optimizing the way Python 3.5 does it. + # + # We may however want to consider whether we do + # this in 3.5 or not. + if oparg == 0: + continue elif op_name == 'LOAD_GLOBAL': if offset in self.load_asserts: op_name = 'LOAD_ASSERT' - elif op_name == 'RETURN_VALUE': - if offset in self.return_end_ifs: - op_name = 'RETURN_END_IF' if offset in self.linestarts: linestart = self.linestarts[offset] @@ -229,6 +251,10 @@ class Scanner3(scan.Scanner): else: tokens.append(Token(replace[offset], oparg, pattr, offset, linestart)) pass + + # debug: + # for t in tokens: + # print(t) return tokens, customize def build_lines_data(self, code_obj): diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index 02053312..9a1280c4 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -1372,7 +1372,9 @@ def deparse_code(version, co, out=StringIO(), showasm=False, showast=False, print(t) debug_parser = dict(PARSER_DEFAULT_DEBUG) - debug_parser['reduce'] = showgrammar + if showgrammar: + debug_parser['reduce'] = showgrammar + debug_parser['errorstack'] = True # Build AST from disassembly. # deparsed = pysource.FragmentsWalker(out, scanner, showast=showast) diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index d9166c99..d55fc148 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1800,7 +1800,9 @@ def deparse_code(version, co, out=sys.stdout, showasm=False, showast=False, print(t) debug_parser = dict(PARSER_DEFAULT_DEBUG) - debug_parser['reduce'] = showgrammar + if showgrammar: + debug_parser['reduce'] = showgrammar + debug_parser['errorstack'] = True # Build AST from disassembly. deparsed = SourceWalker(version, out, scanner, showast=showast,