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
Tasks
1. Add StructType
- Create
StructType in src/irx/system.py
- Inherit from
astx.DataType
- Store only:
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_ is StructType
- 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)
Description
Enable variables to be declared with struct types by introducing a lightweight
StructTypereference 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
StructDefStmt(struct type definitions) #143Tasks
1. Add
StructTypeStructTypeinsrc/irx/system.pyastx.DataTypestruct_name: strStructTypeacts purely as a symbolic reference.Struct definitions are resolved during code generation.
2. Update variable declaration codegen
Update
visit(astx.VariableDeclaration)inllvmliteir.py:type_isStructTypestruct_nameir_builder.alloca(llvm_struct_type)Error Handling (Required)
Raise a compile-time error if:
Example Usage