Skip to content

feat: implement LEAVE and UNLOOP words#26

Merged
tetsuo-cpp merged 1 commit intocanonfrom
feat/leave-unloop
Feb 19, 2026
Merged

feat: implement LEAVE and UNLOOP words#26
tetsuo-cpp merged 1 commit intocanonfrom
feat/leave-unloop

Conversation

@tetsuo-cpp
Copy link
Owner

@tetsuo-cpp tetsuo-cpp commented Feb 19, 2026

Summary

  • Implement LEAVE and UNLOOP in the Forth-to-MLIR translator.
  • Fix conditional LEAVE semantics in DO/LOOP so the backedge is preserved for non-LEAVE paths.
  • Add translation, conversion, and pipeline tests for LEAVE plus UNLOOP error handling.
  • Add a translation regression test for conditional LEAVE.

Tests

  • cmake --build build --target check-warpforth

Implementation Notes

  • LEAVE lowers to a cf.cond_br with a constant true to the loop exit and a dead block that carries the stack argument, avoiding type-conversion mismatches.
  • LOOP always emits the counter increment and backedge; only the block executing LEAVE branches to the loop exit.
  • UNLOOP pops the innermost loop context and falls through; it errors if used without a matching DO.

Closes #23.

@tetsuo-cpp
Copy link
Owner Author

The current leaveDepth gate in LOOP disables the counter increment/backedge for the entire loop whenever any LEAVE appears, which changes semantics for conditional LEAVE (loop exits after first iteration even when condition is false). The backedge should still be emitted for non-LEAVE paths; only the block that executes LEAVE should branch to loop-exit.

@tetsuo-cpp tetsuo-cpp merged commit 8591ba6 into canon Feb 19, 2026
1 check passed
@tetsuo-cpp tetsuo-cpp deleted the feat/leave-unloop branch February 19, 2026 07:40
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.

feat: implement LEAVE and UNLOOP words

1 participant

Comments