Skip to content

Commit 140a681

Browse files
committed
Restore override behavior
1 parent fde5f18 commit 140a681

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

Lib/test/test_generated_cases.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,50 @@ def test_macro_push_push(self):
666666
"""
667667
self.run_cases_test(input, output)
668668

669+
def test_override_inst(self):
670+
input = """
671+
inst(OP, (--)) {
672+
spam();
673+
}
674+
override inst(OP, (--)) {
675+
ham();
676+
}
677+
"""
678+
output = """
679+
TARGET(OP) {
680+
frame->instr_ptr = next_instr;
681+
next_instr += 1;
682+
INSTRUCTION_STATS(OP);
683+
ham();
684+
DISPATCH();
685+
}
686+
"""
687+
self.run_cases_test(input, output)
688+
689+
def test_override_op(self):
690+
input = """
691+
op(OP, (--)) {
692+
spam();
693+
}
694+
macro(M) = OP;
695+
override op(OP, (--)) {
696+
ham();
697+
}
698+
"""
699+
output = """
700+
TARGET(M) {
701+
frame->instr_ptr = next_instr;
702+
next_instr += 1;
703+
INSTRUCTION_STATS(M);
704+
ham();
705+
DISPATCH();
706+
}
707+
"""
708+
self.run_cases_test(input, output)
709+
669710
def test_annotated_inst(self):
670711
input = """
671-
annotation inst(OP, (--)) {
712+
guard inst(OP, (--)) {
672713
ham();
673714
}
674715
"""
@@ -685,7 +726,7 @@ def test_annotated_inst(self):
685726

686727
def test_annotated_op(self):
687728
input = """
688-
annotation op(OP, (--)) {
729+
guard op(OP, (--)) {
689730
spam();
690731
}
691732
macro(M) = OP;

Python/bytecodes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
/* Annotations */
5454
#define guard
55+
#define override
5556
#define specializing
5657

5758
// Dummy variables for stack effects.

Tools/cases_generator/analysis.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,20 @@ def parse_file(self, filename: str, instrs_idx: dict[str, int]) -> None:
139139
match thing:
140140
case parsing.InstDef(name=name):
141141
macro: parsing.Macro | None = None
142-
if thing.kind == "inst":
142+
if thing.kind == "inst" and not thing.annotation == "override":
143143
macro = parsing.Macro(name, [parsing.OpName(name)])
144144
if name in self.instrs:
145+
if not thing.annotation == "override":
146+
raise psr.make_syntax_error(
147+
f"Duplicate definition of '{name}' @ {thing.context} "
148+
f"previous definition @ {self.instrs[name].inst.context}",
149+
thing_first_token,
150+
)
151+
self.everything[instrs_idx[name]] = thing
152+
if name not in self.instrs and thing.annotation == "override":
145153
raise psr.make_syntax_error(
146-
f"Duplicate definition of '{name}' @ {thing.context} "
147-
f"previous definition @ {self.instrs[name].inst.context}",
154+
f"Definition of '{name}' @ {thing.context} is supposed to be "
155+
"an override but no previous definition exists.",
148156
thing_first_token,
149157
)
150158
self.instrs[name] = Instruction(thing)

Tools/cases_generator/lexer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,19 @@ def choice(*opts: str) -> str:
206206
kwds.append(VOLATILE)
207207
WHILE = "WHILE"
208208
kwds.append(WHILE)
209-
#An instruction in the DSL
209+
# An instruction in the DSL
210210
INST = "INST"
211211
kwds.append(INST)
212-
#A micro-op in the DSL
212+
# A micro-op in the DSL
213213
OP = "OP"
214214
kwds.append(OP)
215-
#A macro in the DSL
215+
# A macro in the DSL
216216
MACRO = "MACRO"
217217
kwds.append(MACRO)
218218
keywords = {name.lower(): name for name in kwds}
219219

220220
ANNOTATION = "ANNOTATION"
221-
annotations = {"specializing", "guard"}
221+
annotations = {"specializing", "guard", "override", "register"}
222222

223223
__all__ = []
224224
__all__.extend(kwds)

0 commit comments

Comments
 (0)