provide type as weel in eval_expr

This commit is contained in:
Pragyansh Chaturvedi
2025-09-26 00:24:10 +05:30
parent 1517f6e052
commit 4cf284a81f

View File

@ -8,15 +8,15 @@ def eval_expr(func, module, builder, expr, local_sym_tab, map_sym_tab, structs_s
if expr.id in local_sym_tab: if expr.id in local_sym_tab:
var = local_sym_tab[expr.id][0] var = local_sym_tab[expr.id][0]
val = builder.load(var) val = builder.load(var)
return val return val, local_sym_tab[expr.id][1] # return value and type
else: else:
print(f"Undefined variable {expr.id}") print(f"Undefined variable {expr.id}")
return None return None
elif isinstance(expr, ast.Constant): elif isinstance(expr, ast.Constant):
if isinstance(expr.value, int): if isinstance(expr.value, int):
return ir.Constant(ir.IntType(64), expr.value) return ir.Constant(ir.IntType(64), expr.value), ir.IntType(64)
elif isinstance(expr.value, bool): elif isinstance(expr.value, bool):
return ir.Constant(ir.IntType(1), int(expr.value)) return ir.Constant(ir.IntType(1), int(expr.value)), ir.IntType(1)
else: else:
print("Unsupported constant type") print("Unsupported constant type")
return None return None
@ -44,8 +44,9 @@ def eval_expr(func, module, builder, expr, local_sym_tab, map_sym_tab, structs_s
if arg is None: if arg is None:
print("Failed to evaluate deref argument") print("Failed to evaluate deref argument")
return None return None
# Since we are handling only name case, directly take type from sym tab
val = builder.load(arg) val = builder.load(arg)
return val return val, local_sym_tab[expr.args[0].id][1]
# check for helpers # check for helpers
if expr.func.id in helper_func_list: if expr.func.id in helper_func_list: