csixteen / rs-bff

Simple Brainfuck interpreter written in Rust.
MIT License
3 stars 0 forks source link

Hello World fails #1

Closed rdebath closed 4 years ago

rdebath commented 4 years ago

This program should print "Hello, world!"

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

[>]<[[-]<]

The Python version too it appears.

csixteen commented 4 years ago

Thanks, @rdebath ! The while (*ptr) { ... } logic is not properly implemented, I just realised that :) I'll fix it.

csixteen commented 4 years ago

@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!
rdebath commented 4 years ago

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.

csixteen commented 4 years ago

Oh, I see. I'll have to make some more changes then. Also, is it always assumed the cells to be 8 bits?

rdebath commented 4 years ago

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.

csixteen commented 4 years ago

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!