1919BEGIN_MARKER = "// BEGIN BYTECODES //"
2020END_MARKER = "// END BYTECODES //"
2121RE_PREDICTED = r"(?s)(?:PREDICT\(|GO_TO_INSTRUCTION\(|DEOPT_IF\(.*?,\s*)(\w+)\);"
22+ UNUSED = "unused"
23+ BITS_PER_CODE_UNIT = 16
2224
2325arg_parser = argparse .ArgumentParser ()
2426arg_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."""
0 commit comments