Skip to content

Commit 598e71a

Browse files
committed
Code review from GH-99526
1 parent 5f757fa commit 598e71a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Tools/cases_generator/generate_cases.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
BEGIN_MARKER = "// BEGIN BYTECODES //"
2020
END_MARKER = "// END BYTECODES //"
2121
RE_PREDICTED = r"(?s)(?:PREDICT\(|GO_TO_INSTRUCTION\(|DEOPT_IF\(.*?,\s*)(\w+)\);"
22+
UNUSED = "unused"
23+
BITS_PER_CODE_UNIT = 16
2224

2325
arg_parser = argparse.ArgumentParser()
2426
arg_parser.add_argument("-i", "--input", type=str, default=DEFAULT_INPUT)
@@ -70,9 +72,9 @@ def write(self, f: typing.TextIO, indent: str, dedent: int = 0) -> None:
7072
# Write cache effect variable declarations
7173
cache_offset = 0
7274
for ceffect in self.cache_effects:
73-
if ceffect.name != "unused":
75+
if ceffect.name != UNUSED:
7476
# TODO: if name is 'descr' use PyObject *descr = read_obj(...)
75-
bits = ceffect.size * 16
77+
bits = ceffect.size * BITS_PER_CODE_UNIT
7678
f.write(f"{indent} uint{bits}_t {ceffect.name} = ")
7779
if ceffect.size == 1:
7880
f.write(f"*(next_instr + {cache_offset});\n")
@@ -84,12 +86,12 @@ def write(self, f: typing.TextIO, indent: str, dedent: int = 0) -> None:
8486
# Write input stack effect variable declarations and initializations
8587
input_names = [seffect.name for seffect in self.input_effects]
8688
for i, seffect in enumerate(reversed(self.input_effects), 1):
87-
if seffect.name != "unused":
89+
if seffect.name != UNUSED:
8890
f.write(f"{indent} PyObject *{seffect.name} = PEEK({i});\n")
8991

9092
# Write output stack effect variable declarations
9193
for seffect in self.output_effects:
92-
if seffect.name not in input_names and seffect.name != "unused":
94+
if seffect.name not in input_names and seffect.name != UNUSED:
9395
f.write(f"{indent} PyObject *{seffect.name};\n")
9496

9597
self.write_body(f, indent, dedent)
@@ -108,7 +110,7 @@ def write(self, f: typing.TextIO, indent: str, dedent: int = 0) -> None:
108110
# Write output stack effect assignments
109111
for i, output in enumerate(reversed(self.output_effects), 1):
110112
# TODO: Only skip if output occurs at same position as input
111-
if output.name not in input_names and output.name != "unused":
113+
if output.name not in input_names and output.name != UNUSED:
112114
f.write(f"{indent} POKE({i}, {output.name});\n")
113115

114116
# Write cache effect
@@ -223,7 +225,7 @@ class Analyzer:
223225

224226
filename: str
225227
src: str
226-
errors: int = 0
228+
errors: int = 0 # TODO: add a method to print an error message
227229

228230
def __init__(self, filename: str):
229231
"""Read the input file."""

Tools/cases_generator/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def inputs(self) -> list[InputEffect]:
9999
return self.header.inputs
100100

101101
@property
102-
def outputs(self) -> list[StackEffect]:
102+
def outputs(self) -> list[OutputEffect]:
103103
return self.header.outputs
104104

105105

0 commit comments

Comments
 (0)