summaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2023-02-07 20:03:22 -0800
committerGitHub <noreply@github.com>2023-02-07 20:03:22 -0800
commita9f01448a99c6a2ae34d448806176f2df3a5b323 (patch)
tree5447310b44439cb0bf297a39d37ada56d22ea7ff /Tools
parentgh-101446: Change `repr` of `collections.OrderedDict` (#101661) (diff)
downloadcpython-a9f01448a99c6a2ae34d448806176f2df3a5b323.tar.gz
cpython-a9f01448a99c6a2ae34d448806176f2df3a5b323.tar.bz2
cpython-a9f01448a99c6a2ae34d448806176f2df3a5b323.zip
gh-98831: Modernize CALL_FUNCTION_EX (#101627)
New generator feature: Move CHECK_EVAL_BREAKER() call to just before DISPATCH().
Diffstat (limited to 'Tools')
-rw-r--r--Tools/cases_generator/generate_cases.py15
-rw-r--r--Tools/cases_generator/test_generator.py9
2 files changed, 19 insertions, 5 deletions
diff --git a/Tools/cases_generator/generate_cases.py b/Tools/cases_generator/generate_cases.py
index 4f94b48d114..9b5aa914cde 100644
--- a/Tools/cases_generator/generate_cases.py
+++ b/Tools/cases_generator/generate_cases.py
@@ -227,7 +227,8 @@ class Instruction:
self.kind = inst.kind
self.name = inst.name
self.block = inst.block
- self.block_text, self.predictions = extract_block_text(self.block)
+ self.block_text, self.check_eval_breaker, self.predictions = \
+ extract_block_text(self.block)
self.always_exits = always_exits(self.block_text)
self.cache_effects = [
effect for effect in inst.inputs if isinstance(effect, parser.CacheEffect)
@@ -1027,6 +1028,8 @@ class Analyzer:
if not instr.always_exits:
for prediction in instr.predictions:
self.out.emit(f"PREDICT({prediction});")
+ if instr.check_eval_breaker:
+ self.out.emit("CHECK_EVAL_BREAKER();")
self.out.emit(f"DISPATCH();")
def write_super(self, sup: SuperInstruction) -> None:
@@ -1102,7 +1105,7 @@ class Analyzer:
self.out.emit(f"DISPATCH();")
-def extract_block_text(block: parser.Block) -> tuple[list[str], list[str]]:
+def extract_block_text(block: parser.Block) -> tuple[list[str], bool, list[str]]:
# Get lines of text with proper dedent
blocklines = block.text.splitlines(True)
@@ -1122,6 +1125,12 @@ def extract_block_text(block: parser.Block) -> tuple[list[str], list[str]]:
while blocklines and not blocklines[-1].strip():
blocklines.pop()
+ # Separate CHECK_EVAL_BREAKER() macro from end
+ check_eval_breaker = \
+ blocklines != [] and blocklines[-1].strip() == "CHECK_EVAL_BREAKER();"
+ if check_eval_breaker:
+ del blocklines[-1]
+
# Separate PREDICT(...) macros from end
predictions: list[str] = []
while blocklines and (
@@ -1130,7 +1139,7 @@ def extract_block_text(block: parser.Block) -> tuple[list[str], list[str]]:
predictions.insert(0, m.group(1))
blocklines.pop()
- return blocklines, predictions
+ return blocklines, check_eval_breaker, predictions
def always_exits(lines: list[str]) -> bool:
diff --git a/Tools/cases_generator/test_generator.py b/Tools/cases_generator/test_generator.py
index 33bba7ee340..036094ac8ef 100644
--- a/Tools/cases_generator/test_generator.py
+++ b/Tools/cases_generator/test_generator.py
@@ -177,15 +177,16 @@ def test_overlap():
"""
run_cases_test(input, output)
-def test_predictions():
+def test_predictions_and_eval_breaker():
input = """
inst(OP1, (--)) {
}
inst(OP2, (--)) {
}
- inst(OP3, (--)) {
+ inst(OP3, (arg -- res)) {
DEOPT_IF(xxx, OP1);
PREDICT(OP2);
+ CHECK_EVAL_BREAKER();
}
"""
output = """
@@ -200,8 +201,12 @@ def test_predictions():
}
TARGET(OP3) {
+ PyObject *arg = PEEK(1);
+ PyObject *res;
DEOPT_IF(xxx, OP1);
+ POKE(1, res);
PREDICT(OP2);
+ CHECK_EVAL_BREAKER();
DISPATCH();
}
"""