@@ -18,7 +18,7 @@ def recursive_dereferencer(var, builder):
18
18
raise TypeError (f"Unsupported type for dereferencing: { var .type } " )
19
19
20
20
21
- def get_operand_value (operand , builder , local_sym_tab ):
21
+ def get_operand_value (operand , module , builder , local_sym_tab ):
22
22
"""Extract the value from an operand, handling variables and constants."""
23
23
if isinstance (operand , ast .Name ):
24
24
if operand .id in local_sym_tab :
@@ -28,13 +28,15 @@ def get_operand_value(operand, builder, local_sym_tab):
28
28
if isinstance (operand .value , int ):
29
29
return ir .Constant (ir .IntType (64 ), operand .value )
30
30
raise TypeError (f"Unsupported constant type: { type (operand .value )} " )
31
+ elif isinstance (operand , ast .BinOp ):
32
+ return handle_binary_op_impl (operand , module , builder , local_sym_tab )
31
33
raise TypeError (f"Unsupported operand type: { type (operand )} " )
32
34
33
35
34
- def handle_binary_op (rval , module , builder , var_name , local_sym_tab , map_sym_tab , func ):
36
+ def handle_binary_op_impl (rval , module , builder , local_sym_tab ):
35
37
op = rval .op
36
- left = get_operand_value (rval .left , builder , local_sym_tab )
37
- right = get_operand_value (rval .right , builder , local_sym_tab )
38
+ left = get_operand_value (rval .left , module , builder , local_sym_tab )
39
+ right = get_operand_value (rval .right , module , builder , local_sym_tab )
38
40
logger .info (f"left is { left } , right is { right } , op is { op } " )
39
41
40
42
# Map AST operation nodes to LLVM IR builder methods
@@ -54,6 +56,11 @@ def handle_binary_op(rval, module, builder, var_name, local_sym_tab, map_sym_tab
54
56
55
57
if type (op ) in op_map :
56
58
result = op_map [type (op )](left , right )
57
- builder . store ( result , local_sym_tab [ var_name ]. var )
59
+ return result
58
60
else :
59
61
raise SyntaxError ("Unsupported binary operation" )
62
+
63
+
64
+ def handle_binary_op (rval , module , builder , var_name , local_sym_tab ):
65
+ result = handle_binary_op_impl (rval , module , builder , local_sym_tab )
66
+ builder .store (result , local_sym_tab [var_name ].var )
0 commit comments