Misc fixups/cleanups

* parse3.py Had botched if-for-else test by grammar addition
* semantics/*.py: Show errorstack in failed parse when -g (requires sparck 1.2.0)
* some optimization in scanner3
This commit is contained in:
rocky
2016-05-12 09:27:25 -04:00
parent 8d51456f59
commit 6f6f1db576
6 changed files with 41 additions and 9 deletions

View File

@@ -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'

View File

@@ -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

View File

@@ -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

View File

@@ -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):

View File

@@ -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)

View File

@@ -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,