Skip to content

Conversation

@LunaStev
Copy link
Member

@LunaStev LunaStev commented Jan 3, 2026

Following the modularization of expression handling, this PR decomposes the massive statement.rs file into specialized submodules within llvm_temporary/src/llvm_temporary/statement/. This structural refactor significantly improves code readability, reduces cognitive load when navigating the backend, and provides a cleaner foundation for future language features.

Key Changes

1. Module Reorganization

The monolithic generate_statement_ir function has been broken down into the following logical components:

  • mod.rs: Serves as the main entry point and orchestrator for statement generation.
  • variable.rs: Handles variable declarations and complex initializations (including arrays and structs).
  • assign.rs: Manages variable assignments and dereference-based stores.
  • control.rs: Consolidates logic for control flow structures, including if chains, while loops, and jump statements (break, continue, return).
  • io.rs: Encapsulates standard I/O logic for print, println, and the recently added input statement.
  • asm.rs: Dedicated logic for processing and emitting inline assembly blocks.
  • expr_stmt.rs: Handles statements that consist of a single expression.

2. Logic Migration & Cleanup

  • Function Extraction: Logic previously nested deep within a single match arm has been extracted into descriptive functions like gen_variable_ir, gen_if_ir, and gen_io_ir.
  • Helper Consolidation: Shared internal helpers, such as truthy_to_i1 (for boolean coercion) and make_global_cstr (for string literal management), are now managed within their relevant modules or shared via mod.rs.

3. Behavioral Consistency

  • This is a pure refactor. All existing logic, including type coercion, BasicBlock termination, and error handling, remains identical to the previous implementation.
  • The generate_statement_ir signature remains stable to ensure zero impact on the rest of the compiler's pipeline.

Break down the massive `statement.rs` file into logical submodules,
greatly improving code organization and maintainability.

Changes:
- New Directory Structure `llvm_temporary/statement/`:
  - `mod.rs`: Main entry point for `generate_statement_ir`.
  - `variable.rs`: Variable declaration and initialization (`ASTNode::Variable`).
  - `assign.rs`: Assignment (`ASTNode::Assign`).
  - `control.rs`: Control flow (`If`, `While`, `Break`, `Continue`, `Return`).
  - `io.rs`: Output/Input (`Print`, `Println`, `Input`).
  - `asm.rs`: Inline assembly blocks (`AsmBlock`).
  - `expr_stmt.rs`: Expression statements (`Expression`).
- Migration:
  - Moved logic from the single `generate_statement_ir` function into
    specialized functions within each module (e.g., `gen_variable_ir`,
    `gen_if_ir`).
  - Extracted helper functions like `truthy_to_i1` and `make_global_cstr`
    to appropriate modules.
- Functionality:
  - Preserved all existing logic.
  - No behavioral changes, purely structural refactoring.

This prepares the statement generation logic for future extensions and
makes the codebase easier to navigate.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev self-assigned this Jan 3, 2026
@LunaStev LunaStev merged commit 6030073 into wavefnd:master Jan 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant