-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Description
Enable variables to be declared with struct types by introducing a lightweight StructType reference that resolves to a previously defined struct.
This phase allows declaring struct variables, but does not introduce value semantics, copying, or passing structs by value.
Background
- Phase 1 introduces named struct types in LLVM IR Add LLVM IR codegen for
StructDefStmt(struct type definitions) #143 - Variables need a way to reference these types at the AST level
- Struct variables are pointer-based and are allocated on the stack
- Struct layout follows LLVM target data layout rules and is opaque at the language level
Tasks
1. Add StructType
- Create
StructTypeinsrc/irx/system.py - Inherit from
astx.DataType - Store only:
struct_name: str
StructType acts purely as a symbolic reference.
Struct definitions are resolved during code generation.
2. Update variable declaration codegen
Update visit(astx.VariableDeclaration) in llvmliteir.py:
- Detect when
type_isStructType - Look up the corresponding LLVM struct type using
struct_name - Allocate the struct using
ir_builder.alloca(llvm_struct_type) - Register the variable as holding a pointer to the struct
Error Handling (Required)
Raise a compile-time error if:
- The referenced struct name is not defined
Example Usage
# Reference a previously defined struct
point_type = StructType(struct_name="Point")
# Declare a struct variable
point_var = astx.VariableDeclaration(name="p", type_=point_type)Metadata
Metadata
Assignees
Labels
No labels