lukad / bf

bf is a Brainfuck interpreter written in Elixir.
MIT License
2 stars 0 forks source link

Mis-optimising loops. #6

Closed rdebath closed 6 years ago

rdebath commented 6 years ago

Hi, There's a problem with the way you're optimising your brainfuck loops. Specifically, empty loops should NOT be skipped by the interpreter.

This isn't usually a problem, because the programmer will normally make sure that empty loops aren't run as they are in fact infinite loops. I would say that the result of an infinite loop is undefined (obviously) so the best the interpreter can do is to drop out if an infinite loop is executed (With or without a message). However, you're not just eliminating empty loops, but some loops close to them too.

Specific tests: ++[[[[][]]][]]++ is an infinite loop eg: add 2, stop +++[-][.+]- is a set and a comment loop: set -1 >>[] is move 2, loop{ stop }

This is an unusual bug and as BF optimisers will generally eliminate the problematic loops, will rarely cause a problem.

The programs I've found that break so far are: Lost Kingdom and my bf interpreter testing program It also stops running Daniel B. Cristofani e calculation program e.b after a few digits, but I'm not sure that's the same problem.

lukad commented 6 years ago

Thanks for reporting the issue. I'll get that fixed. By the way, your Brainfuck repo has been a great learning resource for me!