Closed rdebath closed 4 years ago
Thanks, @rdebath ! The while (*ptr) { ... }
logic is not properly implemented, I just realised that :) I'll fix it.
@rdebath I've identified the issue and I've fixed it (I guess).
$ cat tests/hello5.bf
+[>[<->+[>+++>++++>[++++++++++++>][]+[<]>-]]++++++++++<]>>
>>>>>>-.<<++++.<-..+++.<<.<-.>>--.>.+++.------.>-.<<<<+.<.
[>]<[[-]<]
$ cargo run tests/hello5.bf
Compiling rs-bff v0.1.0 (/Users/pmpro/Code/Repositories/rs-bff)
Finished dev [unoptimized + debuginfo] target(s) in 0.52s
Running `target/debug/rs-bff tests/hello5.bf`
Hello, world!
Looks good; the only thing I can see that stops you running most BF code now is that BF programs usually assume wrapping_add
(and sub) not one of the other couple of reasonable ways of handling computer arithmetic. Very few need more than 30k cells.
Oh, I see. I'll have to make some more changes then. Also, is it always assumed the cells to be 8 bits?
https://esolangs.org/wiki/Brainfuck#Implementation_issues
Yes, usually the cells will be 8 bit wrapping. Other sizes (usually 32bit or unbounded) are sometimes used, but often need the interpreter to do optimisations.
Pushed some last changes and I'm now using wrapping_add
and wrapping_sub
where it makes sense. It solved some other hidden issues. I've tested with some BF code I've found in your GitHub repo https://github.com/rdebath/Brainfuck (namely beer.b
) and it worked like a charm!
This program should print "Hello, world!"
The Python version too it appears.