Skip to content

Commit

Permalink
combined printing code for matched instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmorgan committed Nov 6, 2024
1 parent afe9b5d commit 9d7736f
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions parser/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,19 @@ 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) + "+"
pc++
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 {
Expand Down

0 comments on commit 9d7736f

Please sign in to comment.