You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Handle long 2.x bytecode literals more efficiently
This commit is contained in:
@@ -312,6 +312,14 @@ class Python2Parser(PythonParser):
|
||||
|
||||
opname_base = opname[: opname.rfind("_")]
|
||||
|
||||
if opname in ("BUILD_CONST_LIST", "BUILD_CONST_SET"):
|
||||
rule = """
|
||||
add_consts ::= ADD_VALUE*
|
||||
const_list ::= COLLECTION_START add_consts %s
|
||||
expr ::= const_list
|
||||
""" % opname
|
||||
self.addRule(rule, nop_func)
|
||||
|
||||
# The order of opname listed is roughly sorted below
|
||||
if opname_base in ("BUILD_LIST", "BUILD_SET", "BUILD_TUPLE"):
|
||||
# We do this complicated test to speed up parsing of
|
||||
|
@@ -748,18 +748,37 @@ class Python3Parser(PythonParser):
|
||||
kvlist_n = "expr " * (token.attr)
|
||||
rule = "dict ::= %sLOAD_CONST %s" % (kvlist_n, opname)
|
||||
self.addRule(rule, nop_func)
|
||||
|
||||
elif opname in ("BUILD_CONST_LIST", "BUILD_CONST_DICT", "BUILD_CONST_SET"):
|
||||
if opname == "BUILD_CONST_DICT":
|
||||
rule = """
|
||||
add_consts ::= ADD_VALUE*
|
||||
const_list ::= COLLECTION_START add_consts %s
|
||||
dict ::= const_list
|
||||
expr ::= dict
|
||||
""" % opname
|
||||
else:
|
||||
rule = """
|
||||
add_consts ::= ADD_VALUE*
|
||||
const_list ::= COLLECTION_START add_consts %s
|
||||
expr ::= const_list
|
||||
""" % opname
|
||||
self.addRule(rule, nop_func)
|
||||
|
||||
elif opname.startswith("BUILD_DICT_OLDER"):
|
||||
rule = """dict ::= COLLECTION_START key_value_pairs BUILD_DICT_OLDER
|
||||
key_value_pairs ::= key_value_pair+
|
||||
key_value_pair ::= ADD_KEY ADD_VALUE
|
||||
"""
|
||||
self.addRule(rule, nop_func)
|
||||
|
||||
elif opname.startswith("BUILD_LIST_UNPACK"):
|
||||
v = token.attr
|
||||
rule = "build_list_unpack ::= %s%s" % ("expr " * v, opname)
|
||||
self.addRule(rule, nop_func)
|
||||
rule = "expr ::= build_list_unpack"
|
||||
self.addRule(rule, nop_func)
|
||||
|
||||
elif opname_base in ("BUILD_MAP", "BUILD_MAP_UNPACK"):
|
||||
kvlist_n = "kvlist_%s" % token.attr
|
||||
if opname == "BUILD_MAP_n":
|
||||
|
Reference in New Issue
Block a user