Skip to content

Commit

Permalink
fix runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ArunMurugan78 committed Dec 16, 2021
1 parent 256b581 commit 211fa72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions bfuk.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (bf *Bfuk) handleCommand(inputReader io.ByteReader, outputWriter io.ByteWri
func NewBfuk(commandReader io.RuneReader) *Bfuk {
return &Bfuk{
commandTape: NewCommandTape(commandReader),
tape: NewTape(),
}
}

Expand All @@ -72,11 +73,13 @@ func (bf *Bfuk) Run(inputReader io.ByteReader, outputWriter io.ByteWriter) error
err := bf.commandTape.MoveRight()

if err != nil {
break
if err == io.EOF {
return nil
}

return err
}

bf.handleCommand(inputReader, outputWriter)
}

return nil
}
6 changes: 3 additions & 3 deletions commandTape.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ func (ct *CommandTape) GetCurrentCommand() rune {
}

func (ct *CommandTape) MoveRight() error {
ct.commandPointer++

if ct.commandPointer == len(ct.parsedCommands) {
if ct.commandPointer == len(ct.parsedCommands)-1 {
r, _, err := ct.commandReader.ReadRune()

if err != nil {
Expand All @@ -36,6 +34,8 @@ func (ct *CommandTape) MoveRight() error {
ct.parsedCommands = append(ct.parsedCommands, r)
}

ct.commandPointer++

return nil
}

Expand Down

0 comments on commit 211fa72

Please sign in to comment.