Issue #26647: Python interpreter now uses 16-bit wordcode instead of … · pythoncapi/cpython@b0f80b0 · GitHub
Skip to content

Commit b0f80b0

Browse files
Issue python#26647: Python interpreter now uses 16-bit wordcode instead of bytecode.
Patch by Demur Rumed.
1 parent c35f491 commit b0f80b0

18 files changed

Lines changed: 4752 additions & 5027 deletions

Doc/library/dis.rst

Lines changed: 4 additions & 5 deletions

Lib/ctypes/test/test_values.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class struct_frozen(Structure):
7979
continue
8080
items.append((entry.name.decode("ascii"), entry.size))
8181

82-
expected = [("__hello__", 161),
83-
("__phello__", -161),
84-
("__phello__.spam", 161),
82+
expected = [("__hello__", 139),
83+
("__phello__", -139),
84+
("__phello__.spam", 139),
8585
]
8686
self.assertEqual(items, expected, "PyImport_FrozenModules example "
8787
"in Doc/library/ctypes.rst may be out of date")

Lib/dis.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
285285
"""
286286
labels = findlabels(code)
287287
starts_line = None
288-
free = None
289288
for offset, op, arg in _unpack_opargs(code):
290289
if linestarts is not None:
291290
starts_line = linestarts.get(offset, None)
@@ -296,7 +295,7 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
296295
argrepr = ''
297296
if arg is not None:
298297
# Set argval to the dereferenced value of the argument when
299-
# availabe, and argrepr to the string representation of argval.
298+
# available, and argrepr to the string representation of argval.
300299
# _disassemble_bytes needs the string repr of the
301300
# raw name index for LOAD_GLOBAL, LOAD_CONST, etc.
302301
argval = arg
@@ -305,7 +304,7 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
305304
elif op in hasname:
306305
argval, argrepr = _get_name_info(arg, names)
307306
elif op in hasjrel:
308-
argval = offset + 3 + arg
307+
argval = offset + 2 + arg
309308
argrepr = "to " + repr(argval)
310309
elif op in haslocal:
311310
argval, argrepr = _get_name_info(arg, varnames)
@@ -352,23 +351,15 @@ def _disassemble_str(source, *, file=None):
352351
disco = disassemble # XXX For backwards compatibility
353352

354353
def _unpack_opargs(code):
355-
# enumerate() is not an option, since we sometimes process
356-
# multiple elements on a single pass through the loop
357354
extended_arg = 0
358-
n = len(code)
359-
i = 0
360-
while i < n:
355+
for i in range(0, len(code), 2):
361356
op = code[i]
362-
offset = i
363-
i = i+1
364-
arg = None
365357
if op >= HAVE_ARGUMENT:
366-
arg = code[i] + code[i+1]*256 + extended_arg
367-
extended_arg = 0
368-
i = i+2
369-
if op == EXTENDED_ARG:
370-
extended_arg = arg*65536
371-
yield (offset, op, arg)
358+
arg = code[i+1] | extended_arg
359+
extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
360+
else:
361+
arg = None
362+
yield (i, op, arg)
372363

373364
def findlabels(code):
374365
"""Detect all offsets in a byte code which are jump targets.
@@ -379,14 +370,14 @@ def findlabels(code):
379370
labels = []
380371
for offset, op, arg in _unpack_opargs(code):
381372
if arg is not None:
382-
label = -1
383373
if op in hasjrel:
384-
label = offset + 3 + arg
374+
label = offset + 2 + arg
385375
elif op in hasjabs:
386376
label = arg
387-
if label >= 0:
388-
if label not in labels:
389-
labels.append(label)
377+
else:
378+
continue
379+
if label not in labels:
380+
labels.append(label)
390381
return labels
391382

392383
def findlinestarts(code):

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 1 deletion

0 commit comments

Comments
 (0)