update globals test and todos.

This commit is contained in:
2025-10-04 06:36:26 +05:30
parent 130d8a9edc
commit 5f2df57e64
2 changed files with 6 additions and 6 deletions

View File

@ -10,13 +10,13 @@ logger: Logger = logging.getLogger(__name__)
def emit_global(module: ir.Module, node, name):
logger.info(f"global identifier {name} processing")
# TODO: below part is LLM generated check logic.
# deduce LLVM type from the annotated return
if not isinstance(node.returns, ast.Name):
raise ValueError(f"Unsupported return annotation {ast.dump(node.returns)}")
ty = ctypes_to_ir(node.returns.id)
# extract the return expression
# TODO: turn this return extractor into a generic function I can use everywhere.
ret_stmt = node.body[0]
if not isinstance(ret_stmt, ast.Return) or ret_stmt.value is None:
raise ValueError(f"Global '{name}' has no valid return")
@ -29,7 +29,7 @@ def emit_global(module: ir.Module, node, name):
# variable reference like "return SOME_CONST"
elif isinstance(init_val, ast.Name):
# you may need symbol resolution here, stub as 0 for now
# need symbol resolution here, stub as 0 for now
raise ValueError(f"Name reference {init_val.id} not yet supported")
# constructor call like "return c_int64(0)" or dataclass(...)

View File

@ -6,17 +6,17 @@ from ctypes import c_void_p, c_int64, c_int32
@bpf
@bpfglobal
def somevalue() -> c_int32:
return c_int32(0)
return c_int32(42)
@bpf
@bpfglobal
def somevalue2() -> c_int64:
return c_int64(0)
return c_int64(69)
@bpf
@bpfglobal
def somevalue1() -> c_int32:
return c_int32(0)
return c_int32(42)
# --- Passing examples ---
@ -31,7 +31,7 @@ def g1() -> c_int64:
@bpf
@bpfglobal
def g2() -> c_int64:
return c_int64(0)
return c_int64(69)
# --- Failing examples ---