Skip to content

Add Go-style switch-case statement#479

Open
ganehag wants to merge 1 commit into
d5:masterfrom
ganehag:feature/switch
Open

Add Go-style switch-case statement#479
ganehag wants to merge 1 commit into
d5:masterfrom
ganehag:feature/switch

Conversation

@ganehag

@ganehag ganehag commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Implements switch/case/default/fallthrough/break with multi-value cases, tagless switch (acts as if/else chain), and optional init statement.

  • token: add Switch, Case, Default, Fallthrough keywords
  • parser: add SwitchStmt and CaseClause AST nodes, parseSwitchStmt/parseCaseClause
  • parser: fix expectSemi to accept case/default as implicit terminators
  • parser: add OpDup opcode (duplicates stack top for tag comparisons)
  • compiler: implement compileSwitchStmt with two-entry-point body pattern for correct stack discipline on fallthrough
  • compiler: update loop struct and branch handling so break/continue/fallthrough correctly target switch vs loop contexts
  • vm: add OpDup handler

Implements switch/case/default/fallthrough/break with multi-value cases,
tagless switch (acts as if/else chain), and optional init statement.

- token: add Switch, Case, Default, Fallthrough keywords
- parser: add SwitchStmt and CaseClause AST nodes, parseSwitchStmt/parseCaseClause
- parser: fix expectSemi to accept case/default as implicit terminators
- parser: add OpDup opcode (duplicates stack top for tag comparisons)
- compiler: implement compileSwitchStmt with two-entry-point body pattern
  for correct stack discipline on fallthrough
- compiler: update loop struct and branch handling so break/continue/fallthrough
  correctly target switch vs loop contexts
- vm: add OpDup handler
@ganehag ganehag changed the title Add Go-style switch-case statement (not from my master branch this time) Add Go-style switch-case statement Apr 30, 2026
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