Skip to content

feat(ast): implement switch, case, and default - #67

Merged
rieske merged 4 commits into
masterfrom
feature/switch-case
Jul 24, 2026
Merged

feat(ast): implement switch, case, and default#67
rieske merged 4 commits into
masterfrom
feature/switch-case

Conversation

@rieske

@rieske rieske commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • switch / case / default (grammar already present).
  • Semantic: register cases, fold case constants, switch exit for break.
  • Codegen: compare chain then body with fall-through labels.
  • Functional tests: multi-case, default, fall-through, no-match, break, error.

Stack

PR 4/6 — stacks on #66 (goto) → #65#64.

Test plan

  • Full local ctest
  • SwitchTest
  • CI green

@mergify

mergify Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@coveralls

coveralls commented Jul 24, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 92.455% (+0.1%) from 92.337% — feature/switch-case into master

@rieske
rieske force-pushed the feature/goto-labels branch from 715b004 to 8c49590 Compare July 24, 2026 07:12
@rieske
rieske force-pushed the feature/switch-case branch 2 times, most recently from 664d527 to 608b6e1 Compare July 24, 2026 07:18
@rieske
rieske force-pushed the feature/goto-labels branch from 8c49590 to 4c41e77 Compare July 24, 2026 07:18
Base automatically changed from feature/goto-labels to master July 24, 2026 07:23
rieske added 4 commits July 24, 2026 10:23
Add SwitchStatement/CaseLabel/DefaultLabel with if-chain codegen via
ValueCompare. Break exits the switch by reusing loopStack (continue stays
loop-only). Functional tests cover cases, default, fall-through, and
case-outside-switch diagnostics.
Multiple default labels error without overwriting the first default
target. DefaultLabel stores the default keyword for source locations
instead of EXTERNAL_CONTEXT.
Case labels outside switch still get a codegen label. Non-constant case
expressions error without being registered as jump targets. Test continue
inside bare switch.
Diagnose equal case constant expressions in one switch (C constraint).
Also cover continue from a switch nested in a loop (loop continue target).
@rieske
rieske force-pushed the feature/switch-case branch from 608b6e1 to 015d412 Compare July 24, 2026 07:27
@rieske
rieske merged commit fb7b2df into master Jul 24, 2026
4 checks passed
@rieske
rieske deleted the feature/switch-case branch July 24, 2026 07:33
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.

2 participants