Merge in literal speedups

This commit is contained in:
rocky
2022-04-26 02:45:31 -04:00
parent 2a0a6c904c
commit 3471d11dd5
3 changed files with 13 additions and 20 deletions

View File

@@ -816,18 +816,18 @@ class Python3Parser(PythonParser):
elif opname in ("BUILD_CONST_LIST", "BUILD_CONST_DICT", "BUILD_CONST_SET"): elif opname in ("BUILD_CONST_LIST", "BUILD_CONST_DICT", "BUILD_CONST_SET"):
if opname == "BUILD_CONST_DICT": if opname == "BUILD_CONST_DICT":
rule = f""" rule = """
add_consts ::= ADD_VALUE* add_consts ::= ADD_VALUE*
const_list ::= COLLECTION_START add_consts {opname} const_list ::= COLLECTION_START add_consts %s
dict ::= const_list dict ::= const_list
expr ::= dict expr ::= dict
""" """ % opname
else: else:
rule = f""" rule = """
add_consts ::= ADD_VALUE* add_consts ::= ADD_VALUE*
const_list ::= COLLECTION_START add_consts {opname} const_list ::= COLLECTION_START add_consts %s
expr ::= const_list expr ::= const_list
""" """ % opname
self.addRule(rule, nop_func) self.addRule(rule, nop_func)
elif opname_base in ( elif opname_base in (

View File

@@ -35,8 +35,6 @@ Finally we save token information.
from __future__ import print_function from __future__ import print_function
from typing import Optional, Tuple
from xdis import iscode, instruction_size, Instruction from xdis import iscode, instruction_size, Instruction
from xdis.bytecode import _get_const_info from xdis.bytecode import _get_const_info
@@ -209,7 +207,7 @@ class Scanner3(Scanner):
def bound_collection_from_inst( def bound_collection_from_inst(
self, insts: list, next_tokens: list, inst: Instruction, t: Token, i: int, collection_type: str self, insts: list, next_tokens: list, inst: Instruction, t: Token, i: int, collection_type: str
) -> Optional[list]: ):
count = t.attr count = t.attr
assert isinstance(count, int) assert isinstance(count, int)
@@ -248,7 +246,7 @@ class Scanner3(Scanner):
opname="COLLECTION_START", opname="COLLECTION_START",
attr=collection_enum, attr=collection_enum,
pattr=collection_type, pattr=collection_type,
offset=f"{start_offset}_0", offset= "%s_0" % start_offset,
linestart=False, linestart=False,
has_arg=True, has_arg=True,
has_extended_arg=False, has_extended_arg=False,
@@ -270,7 +268,7 @@ class Scanner3(Scanner):
) )
new_tokens.append( new_tokens.append(
Token( Token(
opname=f"BUILD_{collection_type}", opname="BUILD_%s" % collection_type,
attr=t.attr, attr=t.attr,
pattr=t.pattr, pattr=t.pattr,
offset=t.offset, offset=t.offset,
@@ -283,7 +281,7 @@ class Scanner3(Scanner):
return new_tokens return new_tokens
def ingest(self, co, classname=None, code_objects={}, show_asm=None def ingest(self, co, classname=None, code_objects={}, show_asm=None
) -> Tuple[list, dict]: ):
""" """
Create "tokens" the bytecode of an Python code object. Largely these Create "tokens" the bytecode of an Python code object. Largely these
are the opcode name, but in some cases that has been modified to make parsing are the opcode name, but in some cases that has been modified to make parsing
@@ -403,7 +401,7 @@ class Scanner3(Scanner):
else opname.split("_")[1] else opname.split("_")[1]
) )
try_tokens = self.bound_collection_from_inst( try_tokens = self.bound_collection_from_inst(
self.insts, new_tokens, inst, t, i, f"CONST_{collection_type}" self.insts, new_tokens, inst, t, i, "CONST_%s" % collection_type
) )
if try_tokens is not None: if try_tokens is not None:
new_tokens = try_tokens new_tokens = try_tokens

View File

@@ -22,13 +22,8 @@ This sets up opcodes Python's 3.7 and calls a generalized
scanner routine for Python 3. scanner routine for Python 3.
""" """
<<<<<<< HEAD
=======
from typing import Tuple
from uncompyle6.scanner import CONST_COLLECTIONS from uncompyle6.scanner import CONST_COLLECTIONS
from uncompyle6.scanners.tok import Token from uncompyle6.scanners.tok import Token
>>>>>>> long-collection-python3
from uncompyle6.scanners.scanner37base import Scanner37Base from uncompyle6.scanners.scanner37base import Scanner37Base
# bytecode verification, verify(), uses JUMP_OPs from here # bytecode verification, verify(), uses JUMP_OPs from here
@@ -86,7 +81,7 @@ class Scanner37(Scanner37Base):
opname="COLLECTION_START", opname="COLLECTION_START",
attr=collection_enum, attr=collection_enum,
pattr=collection_type, pattr=collection_type,
offset=f"{start_offset}_0", offset="%s_0" % start_offset,
linestart=False, linestart=False,
has_arg=True, has_arg=True,
has_extended_arg=False, has_extended_arg=False,
@@ -108,7 +103,7 @@ class Scanner37(Scanner37Base):
) )
new_tokens.append( new_tokens.append(
Token( Token(
opname=f"BUILD_{collection_type}", opname="BUILD_%s" % collection_type,
attr=t.attr, attr=t.attr,
pattr=t.pattr, pattr=t.pattr,
offset=t.offset, offset=t.offset,