feat: switch/case statement
- Add syntax - Desugars to if-else chain in HIR lowering (both compilers) - No new HIR/C backend nodes needed — reuses hIf/hBinary/hBlock - Supports integer, char, and enum tag dispatch - Case body can be single statement (no braces required)
This commit is contained in:
@@ -239,6 +239,7 @@ type
|
||||
skComptime
|
||||
skEmit
|
||||
skDefer
|
||||
skSwitch
|
||||
skDecl
|
||||
|
||||
ElseIf* = object
|
||||
@@ -246,6 +247,11 @@ type
|
||||
cond*: Expr
|
||||
blk*: Block
|
||||
|
||||
SwitchCase* = object
|
||||
loc*: SourceLocation
|
||||
caseValue*: Expr
|
||||
caseBody*: Block
|
||||
|
||||
Block* = ref object
|
||||
loc*: SourceLocation
|
||||
stmts*: seq[Stmt]
|
||||
@@ -301,6 +307,10 @@ type
|
||||
stmtEmitEvaluated*: string ## filled by sema CTFE
|
||||
of skDefer:
|
||||
stmtDeferBody*: Expr
|
||||
of skSwitch:
|
||||
stmtSwitchExpr*: Expr
|
||||
stmtSwitchCases*: seq[SwitchCase]
|
||||
stmtSwitchDefault*: Block
|
||||
of skDecl:
|
||||
stmtDecl*: Decl
|
||||
|
||||
|
||||
Reference in New Issue
Block a user