From be1a32fa602462ac2849e1e86c7195138927f6df Mon Sep 17 00:00:00 2001 From: Tristan Morgan Date: Fri, 10 May 2024 11:41:26 +1000 Subject: [PATCH] catch a couple more uses of set val. --- parser/tokenise.go | 4 +++- parser/tokenise_test.go | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/parser/tokenise.go b/parser/tokenise.go index 81adb73..c434445 100644 --- a/parser/tokenise.go +++ b/parser/tokenise.go @@ -36,7 +36,9 @@ func Tokenise(input io.ByteReader) (program []Instruction, err error) { program[pc-1].operand += instruction.operand program = program[:pc] pc-- - } else if program[pc-1].SameOp(NewInstruction(']')) { + } else if program[pc-1].SameOp(NewInstruction(']')) || + program[pc-1].operator == opMove || + program[pc-1].operator == opNoop { operand := instruction.operand program = program[:pc] program = append(program, Instruction{opSetVal, operand}) diff --git a/parser/tokenise_test.go b/parser/tokenise_test.go index 9649dea..3cd459d 100644 --- a/parser/tokenise_test.go +++ b/parser/tokenise_test.go @@ -33,7 +33,7 @@ func TestTokenise(t *testing.T) { "+[<++++++>-]>[->>---<<]", []Instruction{ {opNoop, 0}, - {opAddVal, 1}, + {opSetVal, 1}, {opMulVal, -1}, // dest value pointer {opNoop, 6}, // multiplication factor {opAddDp, 1}, @@ -51,10 +51,12 @@ func TestTokenise(t *testing.T) { }, { "op_val", - "----++----++", + "----++->---++", []Instruction{ {opNoop, 0}, - {opAddVal, -4}, + {opSetVal, -3}, + {opAddDp, 1}, + {opAddVal, -1}, }, }, { @@ -68,13 +70,14 @@ func TestTokenise(t *testing.T) { }, { "op_move", - ">[->>+<<]>[<<<+>>>-]", + ">[->>+<<]>[<<<+>>>-]++", []Instruction{ {opNoop, 0}, {opAddDp, 1}, {opMove, 2}, {opAddDp, 1}, {opMove, -3}, + {opSetVal, 2}, }, }, {