summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2022-12-28 01:11:03 (GMT)
committerGitHub <noreply@github.com>2022-12-28 01:11:03 (GMT)
commit08e5594cf3d42391a48e0311f6b9393ec2e00e1e (patch)
treea8a2c632a5222c4299313bb1ddb6d817ac7cd639 /Tools
parent3dc48dabd48864039951715816e07986a4828d80 (diff)
downloadcpython-08e5594cf3d42391a48e0311f6b9393ec2e00e1e.zip
cpython-08e5594cf3d42391a48e0311f6b9393ec2e00e1e.tar.gz
cpython-08e5594cf3d42391a48e0311f6b9393ec2e00e1e.tar.bz2
GH-98831: Modernize a ton of simpler instructions (#100545)
* load_const and load_fast aren't families for now * Don't decref unmoved names * Modernize GET_ANEXT * Modernize GET_AWAITABLE * Modernize ASYNC_GEN_WRAP * Modernize YIELD_VALUE * Modernize POP_EXCEPT (in more than one way) * Modernize PREP_RERAISE_STAR * Modernize LOAD_ASSERTION_ERROR * Modernize LOAD_BUILD_CLASS * Modernize STORE_NAME * Modernize LOAD_NAME * Modernize LOAD_CLASSDEREF * Modernize LOAD_DEREF * Modernize STORE_DEREF * Modernize COPY_FREE_VARS (mark it as done) * Modernize LIST_TO_TUPLE * Modernize LIST_EXTEND * Modernize SET_UPDATE * Modernize SETUP_ANNOTATIONS * Modernize DICT_UPDATE * Modernize DICT_MERGE * Modernize MAP_ADD * Modernize IS_OP * Modernize CONTAINS_OP * Modernize CHECK_EXC_MATCH * Modernize IMPORT_NAME * Modernize IMPORT_STAR * Modernize IMPORT_FROM * Modernize JUMP_FORWARD (mark it as done) * Modernize JUMP_BACKWARD (mark it as done)
Diffstat (limited to 'Tools')
-rw-r--r--Tools/cases_generator/generate_cases.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/Tools/cases_generator/generate_cases.py b/Tools/cases_generator/generate_cases.py
index 85a7c60..5eed74c 100644
--- a/Tools/cases_generator/generate_cases.py
+++ b/Tools/cases_generator/generate_cases.py
@@ -125,6 +125,7 @@ class Instruction:
# Set later
family: parser.Family | None = None
predicted: bool = False
+ unmoved_names: frozenset[str] = frozenset()
def __init__(self, inst: parser.InstDef):
self.inst = inst
@@ -141,6 +142,13 @@ class Instruction:
effect for effect in inst.inputs if isinstance(effect, StackEffect)
]
self.output_effects = inst.outputs # For consistency/completeness
+ unmoved_names: set[str] = set()
+ for ieffect, oeffect in zip(self.input_effects, self.output_effects):
+ if ieffect.name == oeffect.name:
+ unmoved_names.add(ieffect.name)
+ else:
+ break
+ self.unmoved_names = frozenset(unmoved_names)
def write(self, out: Formatter) -> None:
"""Write one instruction, sans prologue and epilogue."""
@@ -175,12 +183,8 @@ class Instruction:
out.stack_adjust(diff)
# Write output stack effect assignments
- unmoved_names: set[str] = set()
- for ieffect, oeffect in zip(self.input_effects, self.output_effects):
- if ieffect.name == oeffect.name:
- unmoved_names.add(ieffect.name)
for i, oeffect in enumerate(reversed(self.output_effects), 1):
- if oeffect.name not in unmoved_names:
+ if oeffect.name not in self.unmoved_names:
dst = StackEffect(f"PEEK({i})", "")
out.assign(dst, oeffect)
@@ -235,7 +239,8 @@ class Instruction:
elif m := re.match(r"(\s*)DECREF_INPUTS\(\);\s*$", line):
space = m.group(1)
for ieff in self.input_effects:
- out.write_raw(f"{extra}{space}Py_DECREF({ieff.name});\n")
+ if ieff.name not in self.unmoved_names:
+ out.write_raw(f"{extra}{space}Py_DECREF({ieff.name});\n")
else:
out.write_raw(extra + line)
@@ -533,7 +538,7 @@ class Analyzer:
) -> tuple[list[StackEffect], int]:
"""Analyze a super-instruction or macro.
- Print an error if there's a cache effect (which we don't support yet).
+ Ignore cache effects.
Return the list of variable names and the initial stack pointer.
"""