~jacksonchen666/brainfuck_interpreter

74aee1c29c0541a0032ab465c9d37920b085bbef — Jackson Chen 1 year, 1 month ago a71f759
errors stuff
1 files changed, 8 insertions(+), 1 deletions(-)

M brainfuck.go
M brainfuck.go => brainfuck.go +8 -1
@@ 2,6 2,7 @@ package brainfuck_interpreter

import (
	"bufio"
	"errors"
	"fmt"
	"log"
	"math"


@@ 11,6 12,8 @@ import (
	"golang.org/x/term"
)

var EOF = errors.New("End of brainfuck code")

// Brainfuck program state
type ProgramState struct {
	// Memory tape, or the program's memory


@@ 50,7 53,10 @@ func getChar() (byte, error) {
}

// Does a single brainfuck instruction.
func (ps *ProgramState) Step() {
func (ps *ProgramState) Step() (error) {
	if ps.codePointer > len(*ps.code) { // len: wasteful? store in program state?
		return EOF
	}
	if ps.memoryPointer >= len(*ps.tape) {
		*ps.tape = append(*ps.tape, 0)
	}


@@ 87,6 93,7 @@ func (ps *ProgramState) Step() {
	}
	(*ps.tape)[ps.memoryPointer] = currentMemory
	ps.codePointer++
	return nil
}

func InitProgramState(code *string) *ProgramState {