19
19
BEGIN_MARKER = "// BEGIN BYTECODES //"
20
20
END_MARKER = "// END BYTECODES //"
21
21
RE_PREDICTED = r"(?s)(?:PREDICT\(|GO_TO_INSTRUCTION\(|DEOPT_IF\(.*?,\s*)(\w+)\);"
22
+ UNUSED = "unused"
23
+ BITS_PER_CODE_UNIT = 16
22
24
23
25
arg_parser = argparse .ArgumentParser ()
24
26
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:
70
72
# Write cache effect variable declarations
71
73
cache_offset = 0
72
74
for ceffect in self .cache_effects :
73
- if ceffect .name != "unused" :
75
+ if ceffect .name != UNUSED :
74
76
# TODO: if name is 'descr' use PyObject *descr = read_obj(...)
75
- bits = ceffect .size * 16
77
+ bits = ceffect .size * BITS_PER_CODE_UNIT
76
78
f .write (f"{ indent } uint{ bits } _t { ceffect .name } = " )
77
79
if ceffect .size == 1 :
78
80
f .write (f"*(next_instr + { cache_offset } );\n " )
@@ -84,12 +86,12 @@ def write(self, f: typing.TextIO, indent: str, dedent: int = 0) -> None:
84
86
# Write input stack effect variable declarations and initializations
85
87
input_names = [seffect .name for seffect in self .input_effects ]
86
88
for i , seffect in enumerate (reversed (self .input_effects ), 1 ):
87
- if seffect .name != "unused" :
89
+ if seffect .name != UNUSED :
88
90
f .write (f"{ indent } PyObject *{ seffect .name } = PEEK({ i } );\n " )
89
91
90
92
# Write output stack effect variable declarations
91
93
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 :
93
95
f .write (f"{ indent } PyObject *{ seffect .name } ;\n " )
94
96
95
97
self .write_body (f , indent , dedent )
@@ -108,7 +110,7 @@ def write(self, f: typing.TextIO, indent: str, dedent: int = 0) -> None:
108
110
# Write output stack effect assignments
109
111
for i , output in enumerate (reversed (self .output_effects ), 1 ):
110
112
# 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 :
112
114
f .write (f"{ indent } POKE({ i } , { output .name } );\n " )
113
115
114
116
# Write cache effect
@@ -223,7 +225,7 @@ class Analyzer:
223
225
224
226
filename : str
225
227
src : str
226
- errors : int = 0
228
+ errors : int = 0 # TODO: add a method to print an error message
227
229
228
230
def __init__ (self , filename : str ):
229
231
"""Read the input file."""
0 commit comments