Skip to content

Commit

Permalink
cleanup printing code a little more
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmorgan committed May 13, 2024
1 parent 378f9fe commit e70aab7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions parser/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ func instPrint(inst, lastInst Instruction) string {
if inst.operand < 0 {
multiplier = strings.Repeat("-", abs(inst.operand))
}
if lastInst.operand > 0 {
return "[-" + strings.Repeat(">", lastInst.operand) + multiplier + strings.Repeat("<", lastInst.operand) + "]"
}
return "[-" + strings.Repeat("<", abs(lastInst.operand)) + multiplier + strings.Repeat(">", abs(lastInst.operand)) + "]"
return "[-" + repeatDirection("<", ">", lastInst.operand) + multiplier + repeatDirection(">", "<", lastInst.operand) + "]"
}
return ""
default:
Expand All @@ -70,6 +67,10 @@ func Print(program []Instruction, writer *bufio.Writer) {
endLoop := NewInstruction(']')
lastInst := NewInstruction('!')
for _, inst := range program {
if inst.operator == opMulVal {
lastInst = inst
continue
}
if inst.SameOp(endLoop) {
depth--
}
Expand Down

0 comments on commit e70aab7

Please sign in to comment.