Skip to content

Commit

Permalink
catch a couple more uses of set val.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmorgan committed May 10, 2024
1 parent 0d32acc commit be1a32f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion parser/tokenise.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
11 changes: 7 additions & 4 deletions parser/tokenise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -51,10 +51,12 @@ func TestTokenise(t *testing.T) {
},
{
"op_val",
"----++----++",
"----++->---++",
[]Instruction{
{opNoop, 0},
{opAddVal, -4},
{opSetVal, -3},
{opAddDp, 1},
{opAddVal, -1},
},
},
{
Expand All @@ -68,13 +70,14 @@ func TestTokenise(t *testing.T) {
},
{
"op_move",
">[->>+<<]>[<<<+>>>-]",
">[->>+<<]>[<<<+>>>-]++",
[]Instruction{
{opNoop, 0},
{opAddDp, 1},
{opMove, 2},
{opAddDp, 1},
{opMove, -3},
{opSetVal, 2},
},
},
{
Expand Down

0 comments on commit be1a32f

Please sign in to comment.