Skip to content

Commit

Permalink
hard code RESUME. Make sure opmaps are sorted by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Aug 16, 2023
1 parent 5543e7c commit d39233e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

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

2 changes: 1 addition & 1 deletion Lib/_opcode_metadata.py

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

14 changes: 10 additions & 4 deletions Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ def map_op(op, name):
# 17 is reserved as it is the initial value for the specializing counter.
# This helps catch cases where we attempt to execute a cache.
map_op(17, 'RESERVED')

# 166 is RESUME - it is hard coded as such in Tools/build/deepfreeze.py
map_op(166, 'RESUME')

next_opcode = 1

for has_arg, name in sorted(ops):
Expand Down Expand Up @@ -340,8 +344,9 @@ def define(name, opcode):
self.out.emit(f"#define {name:<38} {opcode:>3}")

all_pairs = []
all_pairs.extend((i, 0, name) for (name, i) in self.markers.items())
all_pairs.extend((i, 1, name) for (name, i) in self.opmap.items())
# the second item in the tuple sorts the markers before the ops
all_pairs.extend((i, 1, name) for (name, i) in self.markers.items())
all_pairs.extend((i, 2, name) for (name, i) in self.opmap.items())
for i, _, name in sorted(all_pairs):
assert name is not None
define(name, i)
Expand Down Expand Up @@ -578,17 +583,18 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
)
specialized_ops.add("BINARY_OP_INPLACE_ADD_UNICODE")

ops = sorted((id, name) for (name, id) in self.opmap.items())
# emit specialized opmap
self.out.emit("")
with self.out.block("_specialized_opmap ="):
for name, op in self.opmap.items():
for op, name in ops:
if name in specialized_ops:
self.out.emit(f"'{name}': {op},")

# emit opmap
self.out.emit("")
with self.out.block("opmap ="):
for name, op in self.opmap.items():
for op, name in ops:
if name not in specialized_ops:
self.out.emit(f"'{name}': {op},")

Expand Down

0 comments on commit d39233e

Please sign in to comment.