Skip to content

Commit

Permalink
Swap opVec operands to match opMulVal
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmorgan committed Aug 26, 2024
1 parent 393a065 commit e2ab3ce
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions parser/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func Execute[T Number](data []T, program []Instruction, reader io.ByteReader, wr
data[dataPtr] = 0
pc++
case opVec:
factor := program[pc+2].operand
factor := program[pc+1].operand
dataVal := data[dataPtr] * T(factor)
firstPtr := (operand + dataPtr) & DataMask
data[firstPtr] += dataVal
secondPtr := (program[pc+1].operand + dataPtr) & DataMask
secondPtr := (program[pc+2].operand + dataPtr) & DataMask
data[secondPtr] += dataVal
data[dataPtr] = 0
pc++
Expand Down
2 changes: 1 addition & 1 deletion parser/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func TestExecuteSmall(t *testing.T) {
{opMovN, 2},
{opAddDp, 1},
{opVec, 2},
{opNoop, 3},
{opNoop, 2},
{opNoop, 3},
}
startdata := make([]int, 65536)
outputBuf := bufio.NewWriter(&bufferWriter{})
Expand Down
4 changes: 2 additions & 2 deletions parser/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func instPrint(inst, lastInst, lastlastInst Instruction) string {
} else if lastInst.operator == opDupVal {
return "[-" + repeatDirection("<", ">", lastInst.operand) + "+" + repeatDirection("<", ">", inst.operand-lastInst.operand) + "+" + repeatDirection(">", "<", inst.operand) + "]"
} else if lastlastInst.operator == opVec {
multiplier := repeatDirection("-", "+", inst.operand)
return "[-" + repeatDirection("<", ">", lastlastInst.operand) + multiplier + repeatDirection("<", ">", lastInst.operand-lastlastInst.operand) + multiplier + repeatDirection(">", "<", lastInst.operand) + "]"
multiplier := repeatDirection("-", "+", lastInst.operand)
return "[-" + repeatDirection("<", ">", lastlastInst.operand) + multiplier + repeatDirection("<", ">", inst.operand-lastlastInst.operand) + multiplier + repeatDirection(">", "<", inst.operand) + "]"
}
return ""
default:
Expand Down
2 changes: 1 addition & 1 deletion parser/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func TestPrint(t *testing.T) {
{opNoop, 2},
{opAddDp, 1},
{opVec, 1},
{opNoop, 2},
{opNoop, 3},
{opNoop, 2},
{opJmpNz, 5},
{opAddDp, 2},
{opOut, 1},
Expand Down
4 changes: 2 additions & 2 deletions parser/tokenise.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ func Tokenise(input io.ByteReader) (program []Instruction, err error) {
program = program[:pc]
program = append(program, Instruction{opVec, pointers[0]})
pc++
program = append(program, Instruction{opNoop, pointers[1]})
pc++
program = append(program, Instruction{opNoop, factors[1]})
pc++
program = append(program, Instruction{opNoop, pointers[1]})
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions parser/tokenise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func TestTokenise(t *testing.T) {
},
{
"op_vec",
">[->>+++>+++<<<]",
">[->>+++>>+++<<<<]",
[]Instruction{
{opNoop, 0},
{opAddDp, 1},
{opVec, 2},
{opNoop, 3},
{opNoop, 3},
{opNoop, 4},
},
},
{
Expand Down

0 comments on commit e2ab3ce

Please sign in to comment.