Skip to content

Commit

Permalink
pythongh-105481: generate op IDs from bytecode.c instead of hard codi…
Browse files Browse the repository at this point in the history
…ng them in opcode.py (python#107971)
  • Loading branch information
iritkatriel authored Aug 16, 2023
1 parent e88eb37 commit 665a439
Show file tree
Hide file tree
Showing 21 changed files with 1,533 additions and 1,461 deletions.
540 changes: 0 additions & 540 deletions Include/internal/pycore_opcode.h

Large diffs are not rendered by default.

490 changes: 490 additions & 0 deletions Include/internal/pycore_opcode_metadata.h

Large diffs are not rendered by default.

436 changes: 219 additions & 217 deletions Include/opcode_ids.h

Large diffs are not rendered by default.

226 changes: 225 additions & 1 deletion Lib/_opcode_metadata.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
_intrinsic_1_descs,
_intrinsic_2_descs,
_specializations,
_specialized_instructions,
_specialized_opmap,
)

__all__ = ["code_info", "dis", "disassemble", "distb", "disco",
Expand Down Expand Up @@ -49,11 +49,11 @@

_all_opname = list(opname)
_all_opmap = dict(opmap)
_empty_slot = [slot for slot, name in enumerate(_all_opname) if name.startswith("<")]
for spec_op, specialized in zip(_empty_slot, _specialized_instructions):
for name, op in _specialized_opmap.items():
# fill opname and opmap
_all_opname[spec_op] = specialized
_all_opmap[specialized] = spec_op
assert op < len(_all_opname)
_all_opname[op] = name
_all_opmap[name] = op

deoptmap = {
specialized: base for base, family in _specializations.items() for specialized in family
Expand Down
3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.13a1 3556 (Convert LOAD_CLOSURE to a pseudo-op)
# Python 3.13a1 3557 (Make the conversion to boolean in jumps explicit)
# Python 3.13a1 3558 (Reorder the stack items for CALL)
# Python 3.13a1 3559 (Generate opcode IDs from bytecodes.c)

# Python 3.14 will start with 3600

Expand All @@ -470,7 +471,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3558).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3559).to_bytes(2, 'little') + b'\r\n'

_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

Expand Down
Loading

0 comments on commit 665a439

Please sign in to comment.