You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Reduce unecessary grammar rules in 2.x
This commit is contained in:
@@ -256,9 +256,8 @@ class Python2Parser(PythonParser):
|
|||||||
|
|
||||||
PyPy adds custom rules here as well
|
PyPy adds custom rules here as well
|
||||||
"""
|
"""
|
||||||
for opname, v in list(customize.items()):
|
if 'PyPy' in customize:
|
||||||
opname_base = opname[:opname.rfind('_')]
|
# PyPy-specific customizations
|
||||||
if opname == 'PyPy':
|
|
||||||
self.addRule("""
|
self.addRule("""
|
||||||
stmt ::= assign3_pypy
|
stmt ::= assign3_pypy
|
||||||
stmt ::= assign2_pypy
|
stmt ::= assign2_pypy
|
||||||
@@ -267,8 +266,15 @@ class Python2Parser(PythonParser):
|
|||||||
list_compr ::= expr BUILD_LIST_FROM_ARG _for designator list_iter
|
list_compr ::= expr BUILD_LIST_FROM_ARG _for designator list_iter
|
||||||
JUMP_BACK
|
JUMP_BACK
|
||||||
""", nop_func)
|
""", nop_func)
|
||||||
|
for i, token in enumerate(tokens):
|
||||||
|
opname = token.kind
|
||||||
|
# FIXME: remove the "v" thing in the code below
|
||||||
|
if opname in customize:
|
||||||
|
v = customize[opname]
|
||||||
|
else:
|
||||||
continue
|
continue
|
||||||
elif opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
|
opname_base = opname[:opname.rfind('_')]
|
||||||
|
if opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
|
||||||
thousands = (v//1024)
|
thousands = (v//1024)
|
||||||
thirty32s = ((v//32) % 32)
|
thirty32s = ((v//32) % 32)
|
||||||
if thirty32s > 0:
|
if thirty32s > 0:
|
||||||
@@ -348,6 +354,7 @@ class Python2Parser(PythonParser):
|
|||||||
# no longer need to add a rule
|
# no longer need to add a rule
|
||||||
continue
|
continue
|
||||||
elif opname_base == 'MAKE_FUNCTION':
|
elif opname_base == 'MAKE_FUNCTION':
|
||||||
|
if i > 0 and tokens[i-1] == 'LOAD_LAMBDA':
|
||||||
self.addRule('mklambda ::= %s LOAD_LAMBDA %s' %
|
self.addRule('mklambda ::= %s LOAD_LAMBDA %s' %
|
||||||
('pos_arg '*v, opname), nop_func)
|
('pos_arg '*v, opname), nop_func)
|
||||||
rule = 'mkfunc ::= %s LOAD_CONST %s' % ('expr '*v, opname)
|
rule = 'mkfunc ::= %s LOAD_CONST %s' % ('expr '*v, opname)
|
||||||
|
@@ -625,20 +625,20 @@ class Python3Parser(PythonParser):
|
|||||||
# Loop over instructions adding custom grammar rules based on
|
# Loop over instructions adding custom grammar rules based on
|
||||||
# a specific instruction seen.
|
# a specific instruction seen.
|
||||||
|
|
||||||
for i, token in enumerate(tokens):
|
if 'PyPy' in customize:
|
||||||
opname = token.kind
|
|
||||||
opname_base = opname[:opname.rfind('_')]
|
|
||||||
|
|
||||||
# The order listed is roughly alphabetic by instruction opcode.
|
|
||||||
if opname == 'PyPy':
|
|
||||||
self.addRule("""
|
self.addRule("""
|
||||||
stmt ::= assign3_pypy
|
stmt ::= assign3_pypy
|
||||||
stmt ::= assign2_pypy
|
stmt ::= assign2_pypy
|
||||||
assign3_pypy ::= expr expr expr designator designator designator
|
assign3_pypy ::= expr expr expr designator designator designator
|
||||||
assign2_pypy ::= expr expr designator designator
|
assign2_pypy ::= expr expr designator designator
|
||||||
""", nop_func)
|
""", nop_func)
|
||||||
continue
|
|
||||||
elif opname_base == 'BUILD_CONST_KEY_MAP':
|
for i, token in enumerate(tokens):
|
||||||
|
opname = token.kind
|
||||||
|
opname_base = opname[:opname.rfind('_')]
|
||||||
|
|
||||||
|
# The order of opname listed is roughly sorted below
|
||||||
|
if opname_base == 'BUILD_CONST_KEY_MAP':
|
||||||
# This is in 3.6+
|
# This is in 3.6+
|
||||||
kvlist_n = 'expr ' * (token.attr)
|
kvlist_n = 'expr ' * (token.attr)
|
||||||
rule = "mapexpr ::= %sLOAD_CONST %s" % (kvlist_n, opname)
|
rule = "mapexpr ::= %sLOAD_CONST %s" % (kvlist_n, opname)
|
||||||
|
Reference in New Issue
Block a user