Skip to content

Conversation

@LunaStev
Copy link
Member

This PR addresses critical issues in the code generation logic for if statements and significantly upgrades the integration testing infrastructure. The changes ensure that control flow is generated correctly for complex conditional chains and that the automated test suite can handle networking and interactive scenarios without manual intervention.

Key Changes

1. Robust If Statement Codegen

  • Automatic Type Coercion: Implemented a conversion layer that transforms Integers, Floats, and Pointers into i1 (boolean) types. This allows the Wave compiler to support C-style truthiness (e.g., if (pointer)) while satisfying LLVM's strict branching requirements.
  • Control Flow structural Fix:
    • Reorganized else if and else BasicBlock generation to ensure correct linear ordering in the IR.
    • Fixed termination logic where certain code paths would previously fail to branch to the merge block, leading to "terminator found in the middle of a block" errors.
  • Reliable Branching: Ensured every conditional path properly ends with a jump to the final merge point, preventing IR validation failures.

2. Test Runner (run_tests.py) Enhancements

  • UDP Support for Networking Tests: Added a background threading mechanism to send a UDP packet specifically during test61.wave. This allows the network listener test to receive data and exit successfully instead of hanging until a timeout.
  • Interactive Test Skipping: Introduced a SKIP status for tests that require manual user input (e.g., test22.wave for input() verification). This prevents the CI/CD pipeline from reporting false-positive failures for tests that cannot be fully automated.
  • Improved Reporting: Updated the terminal output and final summary to clearly distinguish between Passed, Failed, and Skipped tests.

3. Maintenance

  • GitHub Config: Cleaned up the repository configuration by removing the custom link from .github/FUNDING.yml.

Examples of Improved Codegen Behavior

// Now correctly coerced to i1 in LLVM IR
var p: ptr<i32> = ...;
if (p) { 
    // executes if p is not null
}

var count: i32 = 10;
if (count) {
    // executes if count != 0
}

Benefits

  • Correctness: Fixes invalid IR generation for nested or chained conditional blocks.
  • Developer Experience: The test runner is now "greener" by correctly handling edge-case tests (networking/interactive).
  • Standard Compliance: Brings if condition behavior closer to industry standards (C/C++, Rust).

Refactor the LLVM IR generation for `If` statements to fix control flow
ordering and improve robustness, alongside significant improvements to
the integration test runner.

Changes:
- Codegen (`statement.rs`):
  - Implement explicit type coercion for conditions: automatically
    converts Integers, Floats, and Pointers to `i1` (boolean) for LLVM
    branch instructions.
  - Fix BasicBlock ordering and termination logic for `else if` and
    `else` chains to ensure correct control flow.
  - Ensure all code paths properly terminate by branching to the merge block.
- Tools (`run_tests.py`):
  - Add a background thread to send a UDP packet for `test61.wave`,
    allowing the network listener test to pass without timing out.
  - Introduce a `SKIP` status for known interactive tests (e.g.,
    `test22.wave`) to prevent false-positive failures in CI.
  - Update output formatting and summary to distinguish skipped tests.
- Config:
  - Remove custom funding link from `.github/FUNDING.yml`.

Signed-off-by: LunaStev <luna@lunastev.org>
@LunaStev LunaStev self-assigned this Dec 26, 2025
@LunaStev LunaStev merged commit a60b557 into wavefnd:master Dec 26, 2025
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