Skip to content

feat(compiler): support switch-case-default control flow (#43) - #52

Merged
sql-hkr merged 1 commit into
mainfrom
feat/switch-case
Oct 28, 2026
Merged

sql-hkr merged 1 commit into
mainfrom
feat/switch-case

Conversation

@sql-hkr

@sql-hkr sql-hkr commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #43.

This PR implements switch-case-default control flow support in the C compiler:

  • Lexer: Added switch, case, default keywords and : punctuation.
  • AST: Defined SwitchStmt, CaseClause, and DefaultClause.
  • Parser: Implemented parsing of switch statements, multiple case clauses, and default clauses.
  • CodeGenerator:
    • Evaluates switch condition once into R16.
    • Sequential dispatch using CPI / BREQ (and CP for non-literal expressions).
    • Emits clause bodies sequentially to support natural C fall-through.
    • Integrates with loop_end_stack so that break exits the switch statement, while preserving outer loop continue behavior.
  • Tests: Comprehensive unit tests covering basic dispatch, fall-through, arbitrary default placement, non-literal cases, break/continue inside loops, nested switches, and parser error cases (maintaining 100% test coverage on compiler.py).

Verification

  • uv run pytest tests/test_compiler.py --cov=tiny8.compiler --cov-report=term-missing (100% coverage, 65 tests passed)
  • uv run pytest (329 tests passed)
  • uv run ruff check & uv run ruff format --check (clean)

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sql-hkr
sql-hkr merged commit 4f9413c into main Oct 28, 2026
5 checks passed
@sql-hkr
sql-hkr deleted the feat/switch-case branch October 28, 2026 14:14
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(compiler): support switch-case-default control flow

1 participant