Skip to content

Commit

Permalink
gofmt -s cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmorgan committed Apr 17, 2024
1 parent 8832e7c commit 66b4443
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 63 deletions.
4 changes: 2 additions & 2 deletions parser/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type Number interface {

// Execute a compiled program
func Execute[T Number](data []T, program []Instruction, reader io.ByteReader, writer *bufio.Writer) []T {
var dataPtr, operand, writeCount int = 0, 0, 0
var dataPtr, writeCount int = 0, 0
for pc := 0; pc < len(program); pc++ {
operand = program[pc].operand
operand := program[pc].operand
switch program[pc].operator {
case opAddDp:
dataPtr = (operand + dataPtr) & DataMask
Expand Down
12 changes: 6 additions & 6 deletions parser/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (

func TestExecuteSmall(t *testing.T) {
program := []Instruction{
Instruction{opNoop, 0},
Instruction{opAddDp, 5},
Instruction{opSetVal, 0},
Instruction{opAddVal, 5},
Instruction{opMove, 2},
Instruction{opAddDp, 2},
{opNoop, 0},
{opAddDp, 5},
{opSetVal, 0},
{opAddVal, 5},
{opMove, 2},
{opAddDp, 2},
}
startdata := make([]int, 65536)
outputBuf := bufio.NewWriter(os.Stdout)
Expand Down
18 changes: 9 additions & 9 deletions parser/instruction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
func TestNewInstruction(t *testing.T) {
sourceCode := "g><+-.,[]"
program := []Instruction{
Instruction{opNoop, 0},
Instruction{opAddDp, 1},
Instruction{opAddDp, -1},
Instruction{opAddVal, 1},
Instruction{opAddVal, -1},
Instruction{opOut, 1},
Instruction{opIn, 1},
Instruction{opJmpZ, 0},
Instruction{opJmpNz, 0},
{opNoop, 0},
{opAddDp, 1},
{opAddDp, -1},
{opAddVal, 1},
{opAddVal, -1},
{opOut, 1},
{opIn, 1},
{opJmpZ, 0},
{opJmpNz, 0},
}

for idx, val := range []byte(sourceCode) {
Expand Down
4 changes: 2 additions & 2 deletions parser/tokenise.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// Tokenise sourcecode into an array of operators
func Tokenise(input io.ByteReader) (program []Instruction, err error) {
var pc, jmpPc int = 0, 0
var pc int = 0
jmpStack := make([]int, 0)
program = append(program, Instruction{opNoop, 0})
pc++
Expand Down Expand Up @@ -47,7 +47,7 @@ func Tokenise(input io.ByteReader) (program []Instruction, err error) {
if len(jmpStack) == 0 {
return nil, errors.New("tokenisation error: unbalanced braces")
}
jmpPc = jmpStack[len(jmpStack)-1]
jmpPc := jmpStack[len(jmpStack)-1]
jmpStack = jmpStack[:len(jmpStack)-1]
program[pc].operand = jmpPc
program[jmpPc].operand = pc
Expand Down
88 changes: 44 additions & 44 deletions parser/tokenise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,86 +18,86 @@ func TestTokenise(t *testing.T) {
"small_prog",
">>>>>[-]zero+++++>+++++[->>+<<]move>>",
[]Instruction{
Instruction{opNoop, 0},
Instruction{opAddDp, 5},
Instruction{opSetVal, 5},
Instruction{opAddDp, 1},
Instruction{opAddVal, 5},
Instruction{opMove, 2},
Instruction{opAddDp, 2},
{opNoop, 0},
{opAddDp, 5},
{opSetVal, 5},
{opAddDp, 1},
{opAddVal, 5},
{opMove, 2},
{opAddDp, 2},
},
},
{
"op_dp",
">>>>>>><<<<<<>",
[]Instruction{
Instruction{opNoop, 0},
Instruction{opAddDp, 2},
{opNoop, 0},
{opAddDp, 2},
},
},
{
"op_val",
"----++----++",
[]Instruction{
Instruction{opNoop, 0},
Instruction{opAddVal, -4},
{opNoop, 0},
{opAddVal, -4},
},
},
{
"op_skip",
"[>>>>>]",
[]Instruction{
Instruction{opNoop, 0},
Instruction{opSkip, 5},
{opNoop, 0},
{opSkip, 5},
},
},
{
"op_move",
"[->>+<<][<<<+>>>-]",
[]Instruction{
Instruction{opNoop, 0},
Instruction{opMove, 2},
Instruction{opMove, -3},
{opNoop, 0},
{opMove, 2},
{opMove, -3},
},
},
{
"op_jmp_z_nz",
"[->>+>+<<<]",
[]Instruction{
Instruction{opNoop, 0},
Instruction{opJmpZ, 8},
Instruction{opAddVal, -1},
Instruction{opAddDp, 2},
Instruction{opAddVal, 1},
Instruction{opAddDp, 1},
Instruction{opAddVal, 1},
Instruction{opAddDp, -3},
Instruction{opJmpNz, 1},
{opNoop, 0},
{opJmpZ, 8},
{opAddVal, -1},
{opAddDp, 2},
{opAddVal, 1},
{opAddDp, 1},
{opAddVal, 1},
{opAddDp, -3},
{opJmpNz, 1},
},
},
{
"op_nested",
"[[[[[[[,]]]]]]][comment.]",
[]Instruction{
Instruction{opNoop, 0},
Instruction{opJmpZ, 15},
Instruction{opJmpZ, 14},
Instruction{opJmpZ, 13},
Instruction{opJmpZ, 12},
Instruction{opJmpZ, 11},
Instruction{opJmpZ, 10},
Instruction{opJmpZ, 9},
Instruction{opIn, 1},
Instruction{opJmpNz, 7},
Instruction{opJmpNz, 6},
Instruction{opJmpNz, 5},
Instruction{opJmpNz, 4},
Instruction{opJmpNz, 3},
Instruction{opJmpNz, 2},
Instruction{opJmpNz, 1},
Instruction{opJmpZ, 18},
Instruction{opOut, 1},
Instruction{opJmpNz, 16},
{opNoop, 0},
{opJmpZ, 15},
{opJmpZ, 14},
{opJmpZ, 13},
{opJmpZ, 12},
{opJmpZ, 11},
{opJmpZ, 10},
{opJmpZ, 9},
{opIn, 1},
{opJmpNz, 7},
{opJmpNz, 6},
{opJmpNz, 5},
{opJmpNz, 4},
{opJmpNz, 3},
{opJmpNz, 2},
{opJmpNz, 1},
{opJmpZ, 18},
{opOut, 1},
{opJmpNz, 16},
},
},
}
Expand Down

0 comments on commit 66b4443

Please sign in to comment.