match statements

This commit is contained in:
2026-06-28 23:44:01 +02:00
parent 981ccb047a
commit 462632554c
12 changed files with 1057 additions and 6 deletions
+13 -1
View File
@@ -275,6 +275,18 @@ lower_compound_expr :: proc(state: ^State, expr_id: hir.Expr_Id) -> ir.Instructi
target=ir.INVALID_REF, a=location, b=ir.INVALID_INSTRUCTION,
diagnostic=source.INVALID_DIAGNOSTIC,
})
case .Union_Tag:
// Read a tagged union's discriminant: the tag sits at offset 0, so the union's
// address is the tag's address — load the tag enum (`expr.type`) directly.
address := lower_location(state, expr.left)
if address == ir.INVALID_INSTRUCTION {
return append_recovery_value(state, expr.span, expr.type, expr.diagnostic)
}
return append_instruction(state, ir.Instruction{
op=.Union_Tag, span=expr.span, type=expr.type,
target=ir.INVALID_REF, a=address, b=ir.INVALID_INSTRUCTION,
diagnostic=source.INVALID_DIAGNOSTIC,
})
case .Slice:
// Array operands are addressed (locations) or spilled to a temporary
// (rvalues) by lower_location; other containers are slice/pointer values.
@@ -460,7 +472,7 @@ lower_expr :: proc(state: ^State, expr_id: hir.Expr_Id) -> ir.Instruction_Id {
})
_ = pop(&stack)
case .String, .Array, .Struct, .Range, .None, .Optional_Some, .Address, .Deref,
.Index, .Slice, .Field, .Length, .Slice_Ptr, .Unwrap, .Orelse,
.Index, .Slice, .Field, .Union_Tag, .Length, .Slice_Ptr, .Unwrap, .Orelse,
.Not, .Eq, .Ne, .Lt, .Le, .Gt, .Ge, .And, .Or:
last = lower_compound_expr(state, frame.expr)
_ = pop(&stack)