feat: support break and continue statements - #10
Merged
Conversation
- New break/continue keywords, tokens, and Statement variants - Codegen threads a LoopContext (continue/break branch targets) through emit_statement; while loops continue to the condition block, for loops continue to the step block, both break to their merge block - Using break/continue outside a loop is a clear compile error - e2e tests: break in while, continue in for, innermost-loop targeting, and the outside-a-loop error; verified against clang with a prime-counting program Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
PR Description
Adds
breakandcontinue.Statement::Break/Statement::Continuevariants.LoopContext { continue_bb, break_bb }is threaded throughemit_statement.whilemapscontinueto its condition block;formaps it to the step block (so the post clause still runs, matching C); both mapbreakto their merge block. Nested statements inherit the innermost loop's context, and the existing terminator checks already skip unreachable statements after a jump.break/continueoutside a loop fails compilation with a clear message instead of emitting invalid IR.Tests: e2e for break-in-while, continue-in-for (with the
%operator from #7), innermost-loop targeting with nested loops, and the outside-a-loop error. 33 unit + 36 e2e green; differentially verified against clang with a prime-counting program that exercises both statements.cc @hand-burger
🤖 Generated with Claude Code