mirror of
https://github.com/python/cpython
synced 2024-07-21 10:15:53 +00:00
gh-109287: fix overrides in cases generator (#110419)
This commit is contained in:
parent
bb057b3370
commit
3c0f65ebce
|
@ -598,6 +598,41 @@ def test_macro_push_push(self):
|
|||
"""
|
||||
self.run_cases_test(input, output)
|
||||
|
||||
def test_override_inst(self):
|
||||
input = """
|
||||
inst(OP, (--)) {
|
||||
spam();
|
||||
}
|
||||
override inst(OP, (--)) {
|
||||
ham();
|
||||
}
|
||||
"""
|
||||
output = """
|
||||
TARGET(OP) {
|
||||
ham();
|
||||
DISPATCH();
|
||||
}
|
||||
"""
|
||||
self.run_cases_test(input, output)
|
||||
|
||||
def test_override_op(self):
|
||||
input = """
|
||||
op(OP, (--)) {
|
||||
spam();
|
||||
}
|
||||
macro(M) = OP;
|
||||
override op(OP, (--)) {
|
||||
ham();
|
||||
}
|
||||
"""
|
||||
output = """
|
||||
TARGET(M) {
|
||||
ham();
|
||||
DISPATCH();
|
||||
}
|
||||
"""
|
||||
self.run_cases_test(input, output)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
InstructionOrCacheEffect,
|
||||
MacroInstruction,
|
||||
MacroParts,
|
||||
OverriddenInstructionPlaceHolder,
|
||||
PseudoInstruction,
|
||||
)
|
||||
import parsing
|
||||
|
@ -66,7 +65,6 @@ def note(self, msg: str, node: parsing.Node) -> None:
|
|||
parsing.InstDef
|
||||
| parsing.Macro
|
||||
| parsing.Pseudo
|
||||
| OverriddenInstructionPlaceHolder
|
||||
]
|
||||
instrs: dict[str, Instruction] # Includes ops
|
||||
macros: dict[str, parsing.Macro]
|
||||
|
@ -141,7 +139,7 @@ def parse_file(self, filename: str, instrs_idx: dict[str, int]) -> None:
|
|||
match thing:
|
||||
case parsing.InstDef(name=name):
|
||||
macro: parsing.Macro | None = None
|
||||
if thing.kind == "inst":
|
||||
if thing.kind == "inst" and not thing.override:
|
||||
macro = parsing.Macro(name, [parsing.OpName(name)])
|
||||
if name in self.instrs:
|
||||
if not thing.override:
|
||||
|
@ -150,12 +148,7 @@ def parse_file(self, filename: str, instrs_idx: dict[str, int]) -> None:
|
|||
f"previous definition @ {self.instrs[name].inst.context}",
|
||||
thing_first_token,
|
||||
)
|
||||
placeholder = OverriddenInstructionPlaceHolder(name=name)
|
||||
self.everything[instrs_idx[name]] = placeholder
|
||||
if macro is not None:
|
||||
self.warning(
|
||||
f"Overriding desugared {macro.name} may not work", thing
|
||||
)
|
||||
self.everything[instrs_idx[name]] = thing
|
||||
if name not in self.instrs and thing.override:
|
||||
raise psr.make_syntax_error(
|
||||
f"Definition of '{name}' @ {thing.context} is supposed to be "
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
MacroInstruction,
|
||||
MacroParts,
|
||||
PseudoInstruction,
|
||||
OverriddenInstructionPlaceHolder,
|
||||
TIER_ONE,
|
||||
TIER_TWO,
|
||||
)
|
||||
|
@ -208,8 +207,6 @@ def write_stack_effect_functions(self) -> None:
|
|||
popped_data: list[tuple[AnyInstruction, str]] = []
|
||||
pushed_data: list[tuple[AnyInstruction, str]] = []
|
||||
for thing in self.everything:
|
||||
if isinstance(thing, OverriddenInstructionPlaceHolder):
|
||||
continue
|
||||
if isinstance(thing, parsing.Macro) and thing.name in self.instrs:
|
||||
continue
|
||||
instr, popped, pushed = self.get_stack_effect_info(thing)
|
||||
|
@ -393,8 +390,6 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
|
|||
for thing in self.everything:
|
||||
format: str | None = None
|
||||
match thing:
|
||||
case OverriddenInstructionPlaceHolder():
|
||||
continue
|
||||
case parsing.InstDef():
|
||||
format = self.instrs[thing.name].instr_fmt
|
||||
case parsing.Macro():
|
||||
|
@ -492,8 +487,6 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
|
|||
# Write metadata for each instruction
|
||||
for thing in self.everything:
|
||||
match thing:
|
||||
case OverriddenInstructionPlaceHolder():
|
||||
continue
|
||||
case parsing.InstDef():
|
||||
self.write_metadata_for_inst(self.instrs[thing.name])
|
||||
case parsing.Macro():
|
||||
|
@ -774,8 +767,6 @@ def write_instructions(
|
|||
n_macros = 0
|
||||
for thing in self.everything:
|
||||
match thing:
|
||||
case OverriddenInstructionPlaceHolder():
|
||||
self.write_overridden_instr_place_holder(thing)
|
||||
case parsing.InstDef():
|
||||
pass
|
||||
case parsing.Macro():
|
||||
|
@ -836,14 +827,6 @@ def write_abstract_interpreter_instructions(
|
|||
file=sys.stderr,
|
||||
)
|
||||
|
||||
def write_overridden_instr_place_holder(
|
||||
self, place_holder: OverriddenInstructionPlaceHolder
|
||||
) -> None:
|
||||
self.out.emit("")
|
||||
self.out.emit(
|
||||
f"{self.out.comment} TARGET({place_holder.name}) overridden by later definition"
|
||||
)
|
||||
|
||||
|
||||
def is_super_instruction(mac: MacroInstruction) -> bool:
|
||||
if (
|
||||
|
|
|
@ -295,11 +295,6 @@ class PseudoInstruction:
|
|||
instr_flags: InstructionFlags
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class OverriddenInstructionPlaceHolder:
|
||||
name: str
|
||||
|
||||
|
||||
AnyInstruction = Instruction | MacroInstruction | PseudoInstruction
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue