Skip to content

Conversation

@LunaStev
Copy link
Member

@LunaStev LunaStev commented Jan 2, 2026

This PR focuses on improving the maintainability of the LLVM backend and increasing the reliability of the integration test suite. It decomposes the massive expression.rs file into a modular sub-structure and upgrades the test runner with advanced error detection and interactive input support.


Key Changes

1. Expression Codegen Modularization

The monolithic expression.rs has been broken down into a structured hierarchy within expression/rvalue/. This separation of concerns makes the IR generation logic significantly easier to navigate and extend.

  • Module Breakdown:
    • dispatch.rs: Central routing for all expression types.
    • literals.rs, variables.rs, structs.rs: Handling of data and memory resolution.
    • binary.rs, unary.rs, incdec.rs: Arithmetic and logical operation logic.
    • calls.rs, assign.rs, index.rs: Function execution and complex assignments.
    • pointers.rs, asm.rs: Low-level memory and inline assembly operations.
  • Context Management: Introduced ExprGenEnv in mod.rs to pass LLVM context and builder references consistently across sub-modules.

2. Enhanced Test Runner (run_tests.py)

The integration test script has been upgraded from a simple execution wrapper to a robust diagnostic tool.

  • Heuristic Failure Detection: Added looks_like_fail() logic. Even if a process exits, the script now scans stderr for keywords like WaveError, panicked, or Segfault to catch hidden compiler crashes or semantic errors.
  • Intelligent Classification:
    • PASS (exit=0): Standard success.
    • PASS (non-zero): Marked in Magenta. Indicates the test finished without a compiler crash but returned a non-zero code (useful for testing intentional runtime errors).
    • FAIL: Marked in Red if a crash pattern or exit code indicates a genuine failure.
  • Interactive Input Simulation: The runner now automatically provides mock stdin (e.g., 3\n) for test22.wave, allowing the input() function to be tested in a non-interactive CI environment.
  • Clean Output: Stdout/Stderr are now hidden by default and only displayed when a failure is detected, reducing terminal noise.

LunaStev and others added 2 commits January 2, 2026 17:50
Decompose the monolithic `expression.rs` into modular components to
improve maintainability and readability of the LLVM IR generation logic.

Changes:
- Renaming:
  - `expression.rs` -> `expression/rvalue.rs` (initially) -> modularized structure.
- New Module Structure (`expression/rvalue/`):
  - `mod.rs`: Entry point and `ExprGenEnv` context struct.
  - `dispatch.rs`: Central dispatch logic for expression types.
  - `literals.rs`: Numeric, string, bool, char literals.
  - `variables.rs`: Variable loading and constant resolution.
  - `pointers.rs`: Dereference and AddressOf operations.
  - `calls.rs`: Function and method call generation.
  - `assign.rs`: Assignment and compound assignment operations.
  - `binary.rs`: Binary operations (arithmetic, logical, bitwise).
  - `unary.rs`: Unary operations (logical/bitwise NOT).
  - `incdec.rs`: Increment and decrement operations.
  - `index.rs`: Array and pointer indexing.
  - `structs.rs`: Struct literals and field access.
  - `asm.rs`: Inline assembly block generation.
  - `utils.rs`: Helper functions (e.g., `to_bool`).
- Updates:
  - `expression/mod.rs` now exposes `lvalue` and `rvalue` modules.
  - `expression/rvalue.rs` now delegates to the new modular system via `generate_expression_ir`.
- Documentation:
  - Updated issue template to reflect rvalue terminology.

This refactoring prepares the codebase for more complex expression handling features.

Signed-off-by: LunaStev <youngjae681@gmail.com>
Upgrade `tools/run_tests.py` to robustly detect failures and support interactive tests.

Changes:
- **Error Pattern Matching**: Introduced `looks_like_fail()` to scan stderr for known error keywords (e.g., `WaveError`, `panicked`, `Segfault`). Tests now fail if these patterns appear, even if the exit code is non-zero (which might otherwise be interpreted as a custom error exit).
- **Interactive Input Support**: Automatically provides stdin input (`3\n`) for `test22.wave` to test the `input()` function functionality.
- **Improved Classification**:
  - `PASS (exit=0)` (Green): Standard success.
  - `PASS (non-zero)` (Magenta): Test completed without compiler errors/crashes but returned a non-zero exit code (useful for tests checking error conditions).
  - `FAIL` (Red): Compiler error, panic, crash, or recognized failure pattern.
- **Output Verbosity**: Prints stdout/stderr only when a failure is detected, reducing clutter for successful runs.
- **cwd Fix**: Set `cwd=ROOT` for subprocess execution to ensure relative paths work correctly.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev self-assigned this Jan 2, 2026
@LunaStev LunaStev merged commit 19a9cc7 into wavefnd:master Jan 2, 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