unary minus

This commit is contained in:
2026-06-12 17:55:07 +02:00
parent 66e41e1d9a
commit 94e56f6888
14 changed files with 378 additions and 18 deletions
+11
View File
@@ -138,6 +138,9 @@ lower_expr :: proc(state: ^State, expr_id: hir.Expr_Id) -> ir.Instruction_Id {
case .Widen:
stack[frame_index].stage = 1
append(&stack, Lower_Expr_Frame{expr=expr.left})
case .Negate:
stack[frame_index].stage = 5
append(&stack, Lower_Expr_Frame{expr=expr.left})
case .Add:
stack[frame_index].stage = 2
append(&stack, Lower_Expr_Frame{expr=expr.left})
@@ -156,6 +159,14 @@ lower_expr :: proc(state: ^State, expr_id: hir.Expr_Id) -> ir.Instruction_Id {
}
continue
}
if frame.stage == 5 {
last = append_instruction(state, ir.Instruction{
op=.Neg_Checked, span=expr.span, type=expr.type, target=ir.INVALID_REF,
a=last, b=ir.INVALID_INSTRUCTION, diagnostic=source.INVALID_DIAGNOSTIC,
})
_ = pop(&stack)
continue
}
if frame.stage == 1 {
last = append_instruction(state, ir.Instruction{
op=.Widen, span=expr.span, type=expr.type, target=ir.INVALID_REF,