mirror of
https://github.com/python/cpython.git
synced 2025-08-31 22:18:28 +00:00
Issue #26647: Python interpreter now uses 16-bit wordcode instead of bytecode.
Patch by Demur Rumed.
This commit is contained in:
parent
c35f491a06
commit
b0f80b0312
18 changed files with 4747 additions and 5022 deletions
35
Lib/dis.py
35
Lib/dis.py
|
@ -285,7 +285,6 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
|
|||
"""
|
||||
labels = findlabels(code)
|
||||
starts_line = None
|
||||
free = None
|
||||
for offset, op, arg in _unpack_opargs(code):
|
||||
if linestarts is not None:
|
||||
starts_line = linestarts.get(offset, None)
|
||||
|
@ -296,7 +295,7 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
|
|||
argrepr = ''
|
||||
if arg is not None:
|
||||
# Set argval to the dereferenced value of the argument when
|
||||
# availabe, and argrepr to the string representation of argval.
|
||||
# available, and argrepr to the string representation of argval.
|
||||
# _disassemble_bytes needs the string repr of the
|
||||
# raw name index for LOAD_GLOBAL, LOAD_CONST, etc.
|
||||
argval = arg
|
||||
|
@ -305,7 +304,7 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
|
|||
elif op in hasname:
|
||||
argval, argrepr = _get_name_info(arg, names)
|
||||
elif op in hasjrel:
|
||||
argval = offset + 3 + arg
|
||||
argval = offset + 2 + arg
|
||||
argrepr = "to " + repr(argval)
|
||||
elif op in haslocal:
|
||||
argval, argrepr = _get_name_info(arg, varnames)
|
||||
|
@ -352,23 +351,15 @@ def _disassemble_str(source, *, file=None):
|
|||
disco = disassemble # XXX For backwards compatibility
|
||||
|
||||
def _unpack_opargs(code):
|
||||
# enumerate() is not an option, since we sometimes process
|
||||
# multiple elements on a single pass through the loop
|
||||
extended_arg = 0
|
||||
n = len(code)
|
||||
i = 0
|
||||
while i < n:
|
||||
for i in range(0, len(code), 2):
|
||||
op = code[i]
|
||||
offset = i
|
||||
i = i+1
|
||||
arg = None
|
||||
if op >= HAVE_ARGUMENT:
|
||||
arg = code[i] + code[i+1]*256 + extended_arg
|
||||
extended_arg = 0
|
||||
i = i+2
|
||||
if op == EXTENDED_ARG:
|
||||
extended_arg = arg*65536
|
||||
yield (offset, op, arg)
|
||||
arg = code[i+1] | extended_arg
|
||||
extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
|
||||
else:
|
||||
arg = None
|
||||
yield (i, op, arg)
|
||||
|
||||
def findlabels(code):
|
||||
"""Detect all offsets in a byte code which are jump targets.
|
||||
|
@ -379,14 +370,14 @@ def findlabels(code):
|
|||
labels = []
|
||||
for offset, op, arg in _unpack_opargs(code):
|
||||
if arg is not None:
|
||||
label = -1
|
||||
if op in hasjrel:
|
||||
label = offset + 3 + arg
|
||||
label = offset + 2 + arg
|
||||
elif op in hasjabs:
|
||||
label = arg
|
||||
if label >= 0:
|
||||
if label not in labels:
|
||||
labels.append(label)
|
||||
else:
|
||||
continue
|
||||
if label not in labels:
|
||||
labels.append(label)
|
||||
return labels
|
||||
|
||||
def findlinestarts(code):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue