You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
tok.format -> tok.__str__; simplify pypy code
This commit is contained in:
@@ -61,7 +61,7 @@ def disco_loop(disasm, queue, real_out):
|
||||
queue.append(t.pattr)
|
||||
elif iscode(t.attr):
|
||||
queue.append(t.attr)
|
||||
print(t.format(), file=real_out)
|
||||
print(t, file=real_out)
|
||||
pass
|
||||
pass
|
||||
|
||||
|
@@ -252,12 +252,12 @@ class Python2Parser(PythonParser):
|
||||
for opname, v in list(customize.items()):
|
||||
opname_base = opname[:opname.rfind('_')]
|
||||
if opname == 'PyPy':
|
||||
self.add_unique_rules([
|
||||
'stmt ::= assign3_pypy',
|
||||
'stmt ::= assign2_pypy',
|
||||
'assign3_pypy ::= expr expr expr designator designator designator',
|
||||
'assign2_pypy ::= expr expr designator designator'
|
||||
], customize)
|
||||
self.addRule("""
|
||||
stmt ::= assign3_pypy
|
||||
stmt ::= assign2_pypy
|
||||
assign3_pypy ::= expr expr expr designator designator designator
|
||||
assign2_pypy ::= expr expr designator designator
|
||||
""", nop_func)
|
||||
continue
|
||||
elif opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
|
||||
thousands = (v//1024)
|
||||
|
@@ -17,7 +17,7 @@ that a later phase can turn into a sequence of ASCII text.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.parser import PythonParser, PythonParserSingle
|
||||
from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func
|
||||
from uncompyle6.parsers.astnode import AST
|
||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||
from uncompyle6 import PYTHON3
|
||||
@@ -440,7 +440,15 @@ class Python3Parser(PythonParser):
|
||||
opname = token.type
|
||||
opname_base = opname[:opname.rfind('_')]
|
||||
|
||||
if opname in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR',
|
||||
if opname == 'PyPy':
|
||||
self.addRule("""
|
||||
stmt ::= assign3_pypy
|
||||
stmt ::= assign2_pypy
|
||||
assign3_pypy ::= expr expr expr designator designator designator
|
||||
assign2_pypy ::= expr expr designator designator
|
||||
""", nop_func)
|
||||
continue
|
||||
elif opname in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR',
|
||||
'CALL_FUNCTION_VAR_KW', 'CALL_FUNCTION_KW'):
|
||||
self.custom_classfunc_rule(opname, token, customize)
|
||||
elif opname == 'LOAD_DICTCOMP':
|
||||
|
@@ -253,7 +253,7 @@ class Scanner2(scan.Scanner):
|
||||
|
||||
if show_asm in ('both', 'after'):
|
||||
for t in tokens:
|
||||
print(t.format())
|
||||
print(t)
|
||||
print()
|
||||
return tokens, customize
|
||||
|
||||
@@ -865,7 +865,7 @@ if __name__ == "__main__":
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
tokens, customize = Scanner2(PYTHON_VERSION).disassemble(co)
|
||||
for t in tokens:
|
||||
print(t.format())
|
||||
print(t)
|
||||
else:
|
||||
print("Need to be Python 3.2 or greater to demo; I am %s." %
|
||||
PYTHON_VERSION)
|
||||
|
@@ -108,7 +108,7 @@ if __name__ == "__main__":
|
||||
co = inspect.currentframe().f_code
|
||||
tokens, customize = Scanner27().disassemble(co)
|
||||
for t in tokens:
|
||||
print(t.format())
|
||||
print(t)
|
||||
pass
|
||||
else:
|
||||
print("Need to be Python 2.7 to demo; I am %s." %
|
||||
|
@@ -130,10 +130,13 @@ class Scanner3(scan.Scanner):
|
||||
for instr in bytecode.get_instructions(co):
|
||||
print(instr._disassemble())
|
||||
|
||||
customize = {}
|
||||
# Container for tokens
|
||||
tokens = []
|
||||
|
||||
customize = {}
|
||||
if self.is_pypy:
|
||||
customize['PyPy'] = 1;
|
||||
|
||||
self.code = array('B', co.co_code)
|
||||
self.build_lines_data(co)
|
||||
self.build_prev_op()
|
||||
@@ -307,7 +310,7 @@ class Scanner3(scan.Scanner):
|
||||
|
||||
if show_asm in ('both', 'after'):
|
||||
for t in tokens:
|
||||
print(t.format())
|
||||
print(t)
|
||||
print()
|
||||
return tokens, customize
|
||||
|
||||
@@ -801,7 +804,7 @@ if __name__ == "__main__":
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
tokens, customize = Scanner3(PYTHON_VERSION).disassemble(co)
|
||||
for t in tokens:
|
||||
print(t.format())
|
||||
print(t)
|
||||
else:
|
||||
print("Need to be Python 3.2 or greater to demo; I am %s." %
|
||||
PYTHON_VERSION)
|
||||
|
@@ -28,7 +28,7 @@ if __name__ == "__main__":
|
||||
co = inspect.currentframe().f_code
|
||||
tokens, customize = Scanner35().disassemble(co)
|
||||
for t in tokens:
|
||||
print(t.format())
|
||||
print(t)
|
||||
pass
|
||||
else:
|
||||
print("Need to be Python 3.5 to demo; I am %s." %
|
||||
|
@@ -52,7 +52,7 @@ class Token:
|
||||
# return (prefix +
|
||||
# ('%9s %-18s %r' % (self.offset, self.type, pattr)))
|
||||
|
||||
def format(self):
|
||||
def __str__(self):
|
||||
prefix = '\n%4d ' % self.linestart if self.linestart else (' ' * 6)
|
||||
offset_opname = '%6s %-17s' % (self.offset, self.type)
|
||||
if not self.has_arg:
|
||||
@@ -76,8 +76,6 @@ class Token:
|
||||
pattr = ''
|
||||
return "%s%s%s %r" % (prefix, offset_opname, argstr, pattr)
|
||||
|
||||
__str__ = format
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.type)
|
||||
|
||||
|
@@ -14,7 +14,7 @@ def maybe_show_asm(showasm, tokens):
|
||||
if showasm:
|
||||
stream = showasm if hasattr(showasm, 'write') else sys.stdout
|
||||
for t in tokens:
|
||||
stream.write(t.format())
|
||||
stream.write(t)
|
||||
stream.write('\n')
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user