feat(translate): implement EXIT word and fix UNLOOP for early loop exit#27
Merged
tetsuo-cpp merged 1 commit intocanonfrom Feb 19, 2026
Merged
feat(translate): implement EXIT word and fix UNLOOP for early loop exit#27tetsuo-cpp merged 1 commit intocanonfrom
tetsuo-cpp merged 1 commit intocanonfrom
Conversation
tetsuo-cpp
commented
Feb 19, 2026
Owner
Author
tetsuo-cpp
left a comment
There was a problem hiding this comment.
Looks good! Clean implementation that follows the established LEAVE pattern well.
A few observations:
- UNLOOP fix is correct —
pop_back_val()was desyncing theloopStack, this no-op approach is right since loop control is CFG blocks + memref counter. - EXIT implementation mirrors LEAVE's
cond_br %true→ return/dead block pattern nicely. Good use ofInsertionGuard. - Test coverage is solid — translation, negative, pipeline, and the realistic
FIND-FIVEidiom.
One thing to consider as a follow-up: EXIT inside a loop without UNLOOP (e.g. DO ... EXIT ... LOOP) silently leaks the loop counter alloca. Matches standard Forth semantics where UNLOOP is the programmer's responsibility, but a diagnostic warning could be helpful down the line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
func.returnvia a dummycond_brpattern to keep dead blocks structurally reachable for dialect conversionUNLOOP EXITpattern for early loop exitTest plan
test/Translation/Forth/exit.forth)test/Translation/Forth/exit-outside-word-error.forth)test/Translation/Forth/unloop-exit.forth)test/Pipeline/exit.forth)test/Pipeline/unloop-exit.forth)Closes #24