@@ -99,10 +99,7 @@ def handle_assign(func, module, builder, stmt, map_sym_tab, local_sym_tab):
99
99
print ("Unsupported assignment value type" )
100
100
101
101
102
- def handle_expr (func , module , builder , expr , local_sym_tab , map_sym_tab ):
103
- """Handle expression statements in the function body."""
104
- print (f"Handling expression: { ast .dump (expr )} " )
105
-
102
+ def eval_expr (func , module , builder , expr , local_sym_tab , map_sym_tab ):
106
103
if isinstance (expr , ast .Name ):
107
104
if expr .id in local_sym_tab :
108
105
var = local_sym_tab [expr .id ]
@@ -119,40 +116,30 @@ def handle_expr(func, module, builder, expr, local_sym_tab, map_sym_tab):
119
116
else :
120
117
print ("Unsupported constant type" )
121
118
return None
119
+ elif isinstance (expr , ast .Call ):
120
+ if isinstance (expr .func , ast .Name ):
121
+ # check for helpers first
122
+ if expr .func .id in helper_func_list :
123
+ return handle_helper_call (
124
+ expr , module , builder , func , local_sym_tab , map_sym_tab )
125
+ elif isinstance (expr .func , ast .Attribute ):
126
+ if isinstance (expr .func .value , ast .Call ) and isinstance (expr .func .value .func , ast .Name ):
127
+ method_name = expr .func .attr
128
+ if method_name in helper_func_list :
129
+ return handle_helper_call (
130
+ expr , module , builder , func , local_sym_tab , map_sym_tab )
131
+ print ("Unsupported expression evaluation" )
132
+ return None
133
+
122
134
135
+ def handle_expr (func , module , builder , expr , local_sym_tab , map_sym_tab ):
136
+ """Handle expression statements in the function body."""
137
+ print (f"Handling expression: { ast .dump (expr )} " )
123
138
call = expr .value
124
139
if isinstance (call , ast .Call ):
125
- if isinstance (call .func , ast .Name ):
126
- # check for helpers first
127
- if call .func .id in helper_func_list :
128
- handle_helper_call (
129
- call , module , builder , func , local_sym_tab , map_sym_tab )
130
- return
131
- elif isinstance (call .func , ast .Attribute ):
132
- if isinstance (call .func .value , ast .Call ) and isinstance (call .func .value .func , ast .Name ):
133
- method_name = call .func .attr
134
- if method_name in helper_func_list :
135
- handle_helper_call (
136
- call , module , builder , func , local_sym_tab , map_sym_tab )
137
- return
138
- elif isinstance (call , ast .Name ):
139
- if call .id in local_sym_tab :
140
- var = local_sym_tab [call .id ]
141
- val = builder .load (var )
142
- return val
143
- else :
144
- print (f"Undefined variable { call .id } " )
145
- return None
146
- elif isinstance (call , ast .Constant ):
147
- if isinstance (call .value , int ):
148
- return ir .Constant (ir .IntType (64 ), call .value )
149
- elif isinstance (call .value , bool ):
150
- return ir .Constant (ir .IntType (1 ), int (call .value ))
151
- else :
152
- print ("Unsupported constant type" )
153
- return None
140
+ eval_expr (func , module , builder , call , local_sym_tab , map_sym_tab )
154
141
else :
155
- print ("Unsupported expression statement " )
142
+ print ("Unsupported expression type " )
156
143
157
144
158
145
def handle_cond (func , module , builder , cond , local_sym_tab , map_sym_tab ):
@@ -173,13 +160,13 @@ def handle_cond(func, module, builder, cond, local_sym_tab, map_sym_tab):
173
160
print (f"Undefined variable { cond .id } in condition" )
174
161
return None
175
162
elif isinstance (cond , ast .Compare ):
176
- lhs = handle_expr (func , module , builder , cond .left ,
177
- local_sym_tab , map_sym_tab )
163
+ lhs = eval_expr (func , module , builder , cond .left ,
164
+ local_sym_tab , map_sym_tab )
178
165
if len (cond .ops ) != 1 or len (cond .comparators ) != 1 :
179
166
print ("Unsupported complex comparison" )
180
167
return None
181
- rhs = handle_expr (func , module , builder ,
182
- cond .comparators [0 ], local_sym_tab , map_sym_tab )
168
+ rhs = eval_expr (func , module , builder ,
169
+ cond .comparators [0 ], local_sym_tab , map_sym_tab )
183
170
op = cond .ops [0 ]
184
171
185
172
if lhs .type != rhs .type :
0 commit comments