Skip to content

Commit

Permalink
Track recent xdis changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Aug 26, 2023
1 parent 20c58e2 commit 803678e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
16 changes: 9 additions & 7 deletions uncompyle6/scanners/scanner26.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,25 @@ def __init__(self, show_asm=False):
return

def ingest(self, co, classname=None, code_objects={}, show_asm=None):
"""
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
easier.
returning a list of uncompyle6 Token's.
Some transformations are made to assist the deparsing grammar:
- various types of LOAD_CONST's are categorized in terms of what they load
- COME_FROM instructions are added to assist parsing control structures
- operands with stack argument counts or flag masks are appended to the opcode name, e.g.:
- operands with stack argument counts or flag masks are appended to the
opcode name, e.g.:
* BUILD_LIST, BUILD_SET
* MAKE_FUNCTION and FUNCTION_CALLS append the number of positional arguments
* MAKE_FUNCTION and FUNCTION_CALLS append the number of positional
arguments
- EXTENDED_ARGS instructions are removed
Also, when we encounter certain tokens, we add them to a set which will cause custom
grammar rules. Specifically, variable arg tokens like MAKE_FUNCTION or BUILD_LIST
cause specific rules for the specific number of arguments they take.
Also, when we encounter certain tokens, we add them to a set
which will cause custom grammar rules. Specifically, variable
arg tokens like MAKE_FUNCTION or BUILD_LIST cause specific
rules for the specific number of arguments they take.
"""

if not show_asm:
Expand Down
13 changes: 9 additions & 4 deletions uncompyle6/scanners/scanner37base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,17 @@ def tokens_append(j, token):

if show_asm in ("both", "before"):
print("\n# ---- before tokenization:")
bytecode.disassemble_bytes(
self.insts = bytecode.disassemble_bytes(
co.co_code,
varnames=co.co_varnames,
names=co.co_names,
constants=co.co_consts,
cells=bytecode._cell_names,
linestarts=bytecode._linestarts,
asm_format="extended",
filename=co.co_filename,
show_source=True,
first_line_number=co.co_firstlineno,
)

# "customize" is in the process of going away here
Expand Down Expand Up @@ -302,6 +305,8 @@ def tokens_append(j, token):
inst.starts_line,
inst.is_jump_target,
inst.has_extended_arg,
None,
None,
)

# Get jump targets
Expand Down Expand Up @@ -348,9 +353,9 @@ def tokens_append(j, token):
j = tokens_append(
j,
Token(
come_from_name,
jump_offset,
repr(jump_offset),
opname=come_from_name,
attr=jump_offset,
pattr=repr(jump_offset),
offset="%s_%s" % (inst.offset, jump_idx),
has_arg=True,
opc=self.opc,
Expand Down
2 changes: 1 addition & 1 deletion uncompyle6/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# More could be done here though.

from math import copysign
from xdis.codetype import UnicodeForPython3
from xdis.cross_types import UnicodeForPython3
from xdis.version_info import PYTHON_VERSION_TRIPLE

def get_code_name(code) -> str:
Expand Down

0 comments on commit 803678e

Please sign in to comment.