ModuleGeneration class
Defined in module l0_backend_module (l0_backend_module.py).
Translation-unit order, top-level declarations, and function lifecycle.
Public static attributes
- static StaticInitializers initializers
- static ValueLifetime lifetime
- static Lowering lowering
- static TypeOrdering ordering
- static BackendState state
Constructors, destructors, conversion operators
- _iter_body_stmts(self, Stmt|None stmt) protected
- Yield every statement reachable from stmt, recursing into block-bearing nodes.
Public functions
- auto generate(self) -> str
- Main entry point: generate complete C source for the compilation unit.
Protected functions
- auto _emit_let_declarations(self) -> None
- Emit static global variables for top-level let declarations.
- auto _emit_let_declaration(self, str module_name, LetDecl decl) -> None
- Emit a single top-level let declaration as a static variable.
- auto _emit_function_declarations(self) -> None
- Emit forward declarations for all functions.
- auto _emit_function_declaration(self, str module_name, FuncDecl decl) -> None
- Emit a single function declaration.
- auto _emit_function_definitions(self) -> None
- Emit function definitions (bodies).
- auto _emit_function_definition(self, str module_name, FuncDecl decl) -> None
- Emit a complete function definition with body.
- auto _emit_main_wrapper_if_needed(self) -> None
- If the entry module has a main function, emit a C main() wrapper.
- auto _collect_reassigned_arc_params(self, FuncDecl decl, FuncType func_type) -> set
- Collect the names of ARC-typed parameters reassigned syntactically in the body.
Function documentation
l0_backend_module:: ModuleGeneration:: _iter_body_stmts(self,
Stmt|None stmt) protected
Yield every statement reachable from stmt, recursing into block-bearing nodes.
| Parameters | |
|---|---|
| stmt | The root statement (or None). |
| Returns | An iterator over every Stmt in the sub-tree, including stmt itself. |
str l0_backend_module:: ModuleGeneration:: generate(self)
Main entry point: generate complete C source for the compilation unit.
| Returns | C source code as a string. |
|---|---|
| Exceptions | |
| ValueError | If there is no compilation unit or if there are semantic errors. |
None l0_backend_module:: ModuleGeneration:: _emit_let_declaration(self,
str module_name,
LetDecl decl) protected
Emit a single top-level let declaration as a static variable.
| Parameters | |
|---|---|
| module_name | Name of the module containing the declaration. |
| decl | The LetDecl AST node. |
None l0_backend_module:: ModuleGeneration:: _emit_function_declaration(self,
str module_name,
FuncDecl decl) protected
Emit a single function declaration.
| Parameters | |
|---|---|
| module_name | Name of the module. |
| decl | The FuncDecl AST node. |
| Exceptions | |
| InternalCompilerError | If FuncType is missing. |
None l0_backend_module:: ModuleGeneration:: _emit_function_definition(self,
str module_name,
FuncDecl decl) protected
Emit a complete function definition with body.
| Parameters | |
|---|---|
| module_name | Name of the module. |
| decl | The FuncDecl AST node. |
| Exceptions | |
| InternalCompilerError | If scope is not reset or FuncType is missing. |
None l0_backend_module:: ModuleGeneration:: _emit_main_wrapper_if_needed(self) protected
If the entry module has a main function, emit a C main() wrapper.
This allows us to consistently mangle all L0 functions (including main) while still providing the expected C entry point.
set l0_backend_module:: ModuleGeneration:: _collect_reassigned_arc_params(self,
FuncDecl decl,
FuncType func_type) protected
Collect the names of ARC-typed parameters reassigned syntactically in the body.
| Parameters | |
|---|---|
| decl | The FuncDecl AST node. |
| func_type | The resolved FuncType for the declaration. |
| Returns | Set of parameter names (source names, not mangled) to retain at entry. |
Any function whose body contains an AssignStmt whose target is a bare VarRef naming an ARC-typed parameter needs a defensive retain on that parameter at entry.