Skip to content

Commit

Permalink
opDupVal middle decrement case.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmorgan committed Jun 2, 2024
1 parent e2ed6aa commit 256ebc1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion parser/tokenise.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Tokenise(input io.ByteReader) (program []Instruction, err error) {
pc++
program = append(program, Instruction{opNoop, factors[0]})
}
case pc-jmpPc == 7: //looking for opDupVal
case pc-jmpPc == 7 || pc-jmpPc == 8: //looking for opDupVal
pointers, factors, ok := evalFactors(program[jmpPc+1 : pc])
if ok && factors[0] == 1 && factors[1] == 1 {
pc = jmpPc
Expand Down
5 changes: 4 additions & 1 deletion parser/tokenise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ func TestTokenise(t *testing.T) {
},
{
"op_dup",
">[->>+>+<<<]",
">[->>+>+<<<]>[>>+<<-<<+>>]",
[]Instruction{
{opNoop, 0},
{opAddDp, 1},
{opDupVal, 2},
{opNoop, 3},
{opAddDp, 1},
{opDupVal, 2},
{opNoop, -2},
},
},
{
Expand Down

0 comments on commit 256ebc1

Please sign in to comment.