From 0696f46bfb64bcd41926e5da4c2f4a4e10f4298d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 13 Jul 2026 16:02:38 +0100 Subject: [PATCH] Add indentation for `block`, `loop`, `if`, else` constructs --- core/rexcode/ir/wasm/print_wat.odin | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/rexcode/ir/wasm/print_wat.odin b/core/rexcode/ir/wasm/print_wat.odin index f7e4d1719..4244d5cec 100644 --- a/core/rexcode/ir/wasm/print_wat.odin +++ b/core/rexcode/ir/wasm/print_wat.odin @@ -276,14 +276,26 @@ wat_write_function :: proc(sb: ^strings.Builder, m: Module, func_relocs: []Reloc opts := DEFAULT_PRINT_OPTIONS opts.indent = " " assert(len(f.blocks) <= 1) + level := 0 for blk in f.blocks { for &op, i in blk.ops { - if i+1 == len(blk.ops) && Opcode(op.opcode) == .END { - // TODO(bill): Should this be rendered or NOT? - // break + opcode := Opcode(op.opcode) + #partial switch opcode { + case .END, .ELSE: + level -= 1 + } + level = max(level, 0) + + for _ in 0..