Skip to content

feat: support break and continue statements - #10

Merged
AdamHameed merged 1 commit into
mainfrom
feature/break-continue
Jul 15, 2026
Merged

feat: support break and continue statements#10
AdamHameed merged 1 commit into
mainfrom
feature/break-continue

Conversation

@AdamHameed

Copy link
Copy Markdown
Owner

PR Description

Adds break and continue.

  • Lexer/AST/Parser: new keywords and Statement::Break / Statement::Continue variants.
  • Codegen: a LoopContext { continue_bb, break_bb } is threaded through emit_statement. while maps continue to its condition block; for maps it to the step block (so the post clause still runs, matching C); both map break to their merge block. Nested statements inherit the innermost loop's context, and the existing terminator checks already skip unreachable statements after a jump.
  • Diagnostics: break/continue outside 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

- 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>
@AdamHameed
AdamHameed merged commit ab77dad into main Jul 15, 2026
1 check 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