ultrabear / bfi

A commandline brainfuck interpreter written to balance execution speed and convenience
GNU General Public License v3.0
0 stars 0 forks source link

Programs cell count is NOT limited to program length. #1

Closed rdebath closed 3 years ago

rdebath commented 3 years ago

This BF program uses 100000 cells then prints "OK" and stops.

++++++++++>>>>>+++++[<+++++>-]<++++[>+>+>+<<<-]>-------->[->[>+<-]>[<+<<+
>>>-]<<<[->>[>+<-]>[<+<<<+>>>>-]<<<<[-[>>>>+<<<<-]>[>>>>+<<<<-]>[>>>>+<<<
<-]>[>>>>+<<<<-]+<+<+<+>>>>]>]>]>[-]<<<<[-<]<<<[>++++++++>+<<-]>-.----.>.

This tiny BF program uses 27306 cells prints "OK" and stops.

root@70dd00f7b46a:/go/bfi# ./bfi '>+>+>+>+>+>+>+[->[>]+[->[>]+>+>+[<]+<]+<]+++++++[>+++++++++++>+<<-]>+.----.>++.'
ERROR: BF Runtime: Overflowed pointer location
root@70dd00f7b46a:/go/bfi#

This BF program >+>+>+[->[>]+[->[>]+[->[>]+[<]+<]+<]+<] uses 118842243771396506390315925502 cells then stops. In theory anyway, it would take a little while to run.

See: https://sites.google.com/site/res0001/f And: https://sites.google.com/site/res0001/surpassing-graham-s-number

ultrabear commented 3 years ago

I will note that this is what was stated, some brainfuck programs will use more than their length in program buffers, I refer to it as code that "flies" on its own, maybe that wording is a bit unclear, my bad

Turing machine this and that it is impossible to tell when it will stop or if it will stop at all, but most programs that people make will only use the length of the program worth of buffer space, and since bfi was built for convenience over being a customizable interpreter I think its fine to allow some programs to not run on it.

I have changed the way it works so it allocates at least 30k, which is the standard as noted by wikipedia

ultrabear commented 3 years ago

I have also updated the readme to not state that every stable program wont go over its allocated buffer, and that it is a quirk of bfi, I think that solves the issue so im going to close it

rdebath commented 3 years ago

This sounds reasonable as your program is probably far too slow for any non-trivial BF program that needs that many cells such as http://brainfuck.org/impeccable.b