Skip to content

Commit

Permalink
Code review from pythonGH-99526
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanrossum committed Nov 18, 2022
1 parent fe0d336 commit d84a5c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
BEGIN_MARKER = "// BEGIN BYTECODES //"
END_MARKER = "// END BYTECODES //"
RE_PREDICTED = r"(?s)(?:PREDICT\(|GO_TO_INSTRUCTION\(|DEOPT_IF\(.*?,\s*)(\w+)\);"
UNUSED = "unused"
BITS_PER_CODE_UNIT = 16

arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("-i", "--input", type=str, default=DEFAULT_INPUT)
Expand Down Expand Up @@ -70,9 +72,9 @@ def write(self, f: typing.TextIO, indent: str, dedent: int = 0) -> None:
# Write cache effect variable declarations
cache_offset = 0
for ceffect in self.cache_effects:
if ceffect.name != "unused":
if ceffect.name != UNUSED:
# TODO: if name is 'descr' use PyObject *descr = read_obj(...)
bits = ceffect.size * 16
bits = ceffect.size * BITS_PER_CODE_UNIT
f.write(f"{indent} uint{bits}_t {ceffect.name} = ")
if ceffect.size == 1:
f.write(f"*(next_instr + {cache_offset});\n")
Expand All @@ -84,12 +86,12 @@ def write(self, f: typing.TextIO, indent: str, dedent: int = 0) -> None:
# Write input stack effect variable declarations and initializations
input_names = [seffect.name for seffect in self.input_effects]
for i, seffect in enumerate(reversed(self.input_effects), 1):
if seffect.name != "unused":
if seffect.name != UNUSED:
f.write(f"{indent} PyObject *{seffect.name} = PEEK({i});\n")

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

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

# Write cache effect
Expand Down Expand Up @@ -223,7 +225,7 @@ class Analyzer:

filename: str
src: str
errors: int = 0
errors: int = 0 # TODO: add a method to print an error message

def __init__(self, filename: str):
"""Read the input file."""
Expand Down
2 changes: 1 addition & 1 deletion Tools/cases_generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def inputs(self) -> list[InputEffect]:
return self.header.inputs

@property
def outputs(self) -> list[StackEffect]:
def outputs(self) -> list[OutputEffect]:
return self.header.outputs


Expand Down

0 comments on commit d84a5c3

Please sign in to comment.