From 9d7736f1c24e9458b09562977f942f7c9c63d1f2 Mon Sep 17 00:00:00 2001 From: Tristan Morgan Date: Wed, 6 Nov 2024 13:03:35 +1100 Subject: [PATCH] combined printing code for matched instructions. --- parser/print.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/parser/print.go b/parser/print.go index 9cb2137..efd49a5 100644 --- a/parser/print.go +++ b/parser/print.go @@ -51,16 +51,11 @@ func instPrints(program []Instruction) iter.Seq[string] { str = "]" depth-- indent = strings.Repeat("\t", depth) - case opMove: - str = "[-" + repeatDirection("<", ">", inst.operand) + "+" + repeatDirection(">", "<", inst.operand) + "]" case opMovN: str = "[-" + repeatDirection("<", ">", inst.operand) + "-" + repeatDirection(">", "<", inst.operand) + "]" case opSkip: str = "[" + repeatDirection("<", ">", inst.operand) + "]" - case opMulVal: - multiplier := repeatDirection("-", "+", program[pc+1].operand) - str = "[-" + repeatDirection("<", ">", inst.operand) + multiplier + repeatDirection(">", "<", inst.operand) + "]" - case opDupVal: + case opDupVal, opMove: str = "[-" + repeatDirection("<", ">", inst.operand) + "+" for pc+1 < len(program) && program[pc+1].operator == opNoop { str = str + repeatDirection("<", ">", program[pc+1].operand-inst.operand) + "+" @@ -68,7 +63,7 @@ func instPrints(program []Instruction) iter.Seq[string] { inst = program[pc] } str = str + repeatDirection(">", "<", program[pc].operand) + "]" - case opVec: + case opVec, opMulVal: multiplier := repeatDirection("-", "+", program[pc+1].operand) str = "[-" + repeatDirection("<", ">", inst.operand) + multiplier for pc+2 < len(program) && program[pc+2].operator == opNoop {