summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/dis.py
diff options
context:
space:
mode:
authorshadchin <[email protected]>2024-02-12 07:53:52 +0300
committerDaniil Cherednik <[email protected]>2024-02-14 14:26:16 +0000
commit31f2a419764a8ba77c2a970cfc80056c6cd06756 (patch)
treec1995d239eba8571cefc640f6648e1d5dd4ce9e2 /contrib/tools/python3/src/Lib/dis.py
parentfe2ef02b38d9c85d80060963b265a1df9f38c3bb (diff)
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Lib/dis.py')
-rw-r--r--contrib/tools/python3/src/Lib/dis.py65
1 files changed, 48 insertions, 17 deletions
diff --git a/contrib/tools/python3/src/Lib/dis.py b/contrib/tools/python3/src/Lib/dis.py
index 196c886f785..320dec03d25 100644
--- a/contrib/tools/python3/src/Lib/dis.py
+++ b/contrib/tools/python3/src/Lib/dis.py
@@ -11,6 +11,8 @@ from opcode import (
_cache_format,
_inline_cache_entries,
_nb_ops,
+ _intrinsic_1_descs,
+ _intrinsic_2_descs,
_specializations,
_specialized_instructions,
)
@@ -34,9 +36,16 @@ MAKE_FUNCTION = opmap['MAKE_FUNCTION']
MAKE_FUNCTION_FLAGS = ('defaults', 'kwdefaults', 'annotations', 'closure')
LOAD_CONST = opmap['LOAD_CONST']
+RETURN_CONST = opmap['RETURN_CONST']
LOAD_GLOBAL = opmap['LOAD_GLOBAL']
BINARY_OP = opmap['BINARY_OP']
JUMP_BACKWARD = opmap['JUMP_BACKWARD']
+FOR_ITER = opmap['FOR_ITER']
+SEND = opmap['SEND']
+LOAD_ATTR = opmap['LOAD_ATTR']
+LOAD_SUPER_ATTR = opmap['LOAD_SUPER_ATTR']
+CALL_INTRINSIC_1 = opmap['CALL_INTRINSIC_1']
+CALL_INTRINSIC_2 = opmap['CALL_INTRINSIC_2']
CACHE = opmap["CACHE"]
@@ -60,10 +69,10 @@ def _try_compile(source, name):
expect code objects
"""
try:
- c = compile(source, name, 'eval')
+ return compile(source, name, 'eval')
except SyntaxError:
- c = compile(source, name, 'exec')
- return c
+ pass
+ return compile(source, name, 'exec')
def dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False):
"""Disassemble classes, methods, functions, and other compiled objects.
@@ -114,7 +123,10 @@ def distb(tb=None, *, file=None, show_caches=False, adaptive=False):
"""Disassemble a traceback (default: last traceback)."""
if tb is None:
try:
- tb = sys.last_traceback
+ if hasattr(sys, 'last_exc'):
+ tb = sys.last_exc.__traceback__
+ else:
+ tb = sys.last_traceback
except AttributeError:
raise RuntimeError("no last traceback to disassemble") from None
while tb.tb_next: tb = tb.tb_next
@@ -361,9 +373,8 @@ def _get_const_value(op, arg, co_consts):
assert op in hasconst
argval = UNKNOWN
- if op == LOAD_CONST:
- if co_consts is not None:
- argval = co_consts[arg]
+ if co_consts is not None:
+ argval = co_consts[arg]
return argval
def _get_const_info(op, arg, co_consts):
@@ -450,6 +461,7 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
argrepr = ''
positions = Positions(*next(co_positions, ()))
deop = _deoptop(op)
+ caches = _inline_cache_entries[deop]
if arg is not None:
# Set argval to the dereferenced value of the argument when
# available, and argrepr to the string representation of argval.
@@ -463,6 +475,14 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
argval, argrepr = _get_name_info(arg//2, get_name)
if (arg & 1) and argrepr:
argrepr = "NULL + " + argrepr
+ elif deop == LOAD_ATTR:
+ argval, argrepr = _get_name_info(arg//2, get_name)
+ if (arg & 1) and argrepr:
+ argrepr = "NULL|self + " + argrepr
+ elif deop == LOAD_SUPER_ATTR:
+ argval, argrepr = _get_name_info(arg//4, get_name)
+ if (arg & 1) and argrepr:
+ argrepr = "NULL|self + " + argrepr
else:
argval, argrepr = _get_name_info(arg, get_name)
elif deop in hasjabs:
@@ -471,11 +491,12 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
elif deop in hasjrel:
signed_arg = -arg if _is_backward_jump(deop) else arg
argval = offset + 2 + signed_arg*2
+ argval += 2 * caches
argrepr = "to " + repr(argval)
elif deop in haslocal or deop in hasfree:
argval, argrepr = _get_name_info(arg, varname_from_oparg)
elif deop in hascompare:
- argval = cmp_op[arg]
+ argval = cmp_op[arg>>4]
argrepr = argval
elif deop == FORMAT_VALUE:
argval, argrepr = FORMAT_VALUE_CONVERTERS[arg & 0x3]
@@ -489,6 +510,10 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
if arg & (1<<i))
elif deop == BINARY_OP:
_, argrepr = _nb_ops[arg]
+ elif deop == CALL_INTRINSIC_1:
+ argrepr = _intrinsic_1_descs[arg]
+ elif deop == CALL_INTRINSIC_2:
+ argrepr = _intrinsic_2_descs[arg]
yield Instruction(_all_opname[op], op,
arg, argval, argrepr,
offset, starts_line, is_jump_target, positions)
@@ -504,9 +529,8 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
for i in range(size):
offset += 2
# Only show the fancy argrepr for a CACHE instruction when it's
- # the first entry for a particular cache value and the
- # instruction using it is actually quickened:
- if i == 0 and op != deop:
+ # the first entry for a particular cache value:
+ if i == 0:
data = code[offset: offset + 2 * size]
argrepr = f"{name}: {int.from_bytes(data, sys.byteorder)}"
else:
@@ -569,7 +593,12 @@ def _disassemble_bytes(code, lasti=-1, varname_from_oparg=None,
instr.offset > 0)
if new_source_line:
print(file=file)
- is_current_instr = instr.offset == lasti
+ if show_caches:
+ is_current_instr = instr.offset == lasti
+ else:
+ # Each CACHE takes 2 bytes
+ is_current_instr = instr.offset <= lasti \
+ <= instr.offset + 2 * _inline_cache_entries[_deoptop(instr.opcode)]
print(instr._disassemble(lineno_width, is_current_instr, offset_width),
file=file)
if exception_entries:
@@ -602,7 +631,7 @@ def _unpack_opargs(code):
op = code[i]
deop = _deoptop(op)
caches = _inline_cache_entries[deop]
- if deop >= HAVE_ARGUMENT:
+ if deop in hasarg:
arg = code[i+1] | extended_arg
extended_arg = (arg << 8) if deop == EXTENDED_ARG else 0
# The oparg is stored as a signed integer
@@ -624,11 +653,14 @@ def findlabels(code):
labels = []
for offset, op, arg in _unpack_opargs(code):
if arg is not None:
- if op in hasjrel:
- if _is_backward_jump(op):
+ deop = _deoptop(op)
+ caches = _inline_cache_entries[deop]
+ if deop in hasjrel:
+ if _is_backward_jump(deop):
arg = -arg
label = offset + 2 + arg*2
- elif op in hasjabs:
+ label += 2 * caches
+ elif deop in hasjabs:
label = arg*2
else:
continue
@@ -656,7 +688,6 @@ def _find_imports(co):
the corresponding args to __import__.
"""
IMPORT_NAME = opmap['IMPORT_NAME']
- LOAD_CONST = opmap['LOAD_CONST']
consts = co.co_consts
names = co.co_names