diff --git a/parser/execute.go b/parser/execute.go index b3c414d..ec48542 100644 --- a/parser/execute.go +++ b/parser/execute.go @@ -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++ diff --git a/parser/execute_test.go b/parser/execute_test.go index 500568a..1abb40b 100644 --- a/parser/execute_test.go +++ b/parser/execute_test.go @@ -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{}) diff --git a/parser/print.go b/parser/print.go index 1d28b6c..1e50604 100644 --- a/parser/print.go +++ b/parser/print.go @@ -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: diff --git a/parser/print_test.go b/parser/print_test.go index 019c471..0a875c6 100644 --- a/parser/print_test.go +++ b/parser/print_test.go @@ -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}, diff --git a/parser/tokenise.go b/parser/tokenise.go index 05847ce..36118f3 100644 --- a/parser/tokenise.go +++ b/parser/tokenise.go @@ -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]}) } } } diff --git a/parser/tokenise_test.go b/parser/tokenise_test.go index 86b659e..c686ab8 100644 --- a/parser/tokenise_test.go +++ b/parser/tokenise_test.go @@ -84,13 +84,13 @@ func TestTokenise(t *testing.T) { }, { "op_vec", - ">[->>+++>+++<<<]", + ">[->>+++>>+++<<<<]", []Instruction{ {opNoop, 0}, {opAddDp, 1}, {opVec, 2}, {opNoop, 3}, - {opNoop, 3}, + {opNoop, 4}, }, }, {