Multiple issues in single threaded mode

#2 · closed · 13 comments

View on GitHub ↗

rdebath

A loop at the start of the file is incorrectly parsed (the third one). The first one hangs, The other two segfault. They should all print variations on `Hello World!` Running on Debian Linux "jessie" x64 and i686. ``` bf >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.#>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>++++++++[ <++++>-]<+.[-]++++++++++. ``` ``` bf >++++++++[-<+++++++++>]<.>[][<-]>+>-[+]++>++>+++[>[->+++<<+++>]<<]>-----. >->+++..+++.>-.<<+[>[+>+]>>]<--------------.>>.+++.------.--------.>+.>+. ``` ``` bf [.....]>>>[-]<[-]++++++++[->+++++++++<]>.----[--<+++>]<-.+++++++.><.+++. [-][[-]>[-]+++++++++[<+++++>-]<+...--------------.>++++++++++[<+++++>-]< .+++.-------.>+++++++++[<----->-]<.-.>++++++++[<+++++++>-]<++.---------- -.--.-----------.+++++++.----.++++++++++++++.>++++++++++[<----->-]<..[-] ++++++++++.[-]+++++++[.,]-]<<++++++++[>++++++++<-]>[<++++>-]+<[>-<[>++++ <-]>[<++++++++>-]<[>++++++++<-]+>[>>+[<]>-<++>[-]++++++[<+++++++>-]<.--- ---------.[-]<[>+<[-]]>++++++++>[-]++++++++++[<+++++++++++>-]<.--------. +++.------.--------.[-]<[-]<[-]>]<[>>++>[-]+++++[<++++++>-]<.[-]+>>++++[ -<<[->++++<]>[-<+>]>]<+<[>>>[-]++++++++++[<+++++++++++>-]<+++++++++.---- ----.+++.------.--------.[-]<[-]<[-]]>[>>[-]>[-]+++++++++[<++++++++++>-] <.>++++[<+++++>-]<+.--.-----------.+++++++.----.[-]<<[-]]<<<[-]]>[-]<]>[ >+++++[>++++<-]>[<+++++++++++++>-]<----[[-]>[-]+++++[<++++++>-]<++.>++++ +[<+++++++>-]<.>++++++[<+++++++>-]<+++++.>++++[<---->-]<-.++.++++++++.-- ----.-.[-]]++>[-]+++++[<++++++>-]<.[-]>++[>++<-]>[<<+>>[-<<[>++++<-]>[<+ +++>-]>]]<<[>++++[>---<++++]>++.[<++>+]<.[>+<------]>.+++.[<--->++]<--.[ -]<[-]][-]>[-]>[-]<++[>++++++++<-]>[<++++++++>-]<[>++++++++<-]>[<+++++++ +>-]<[<++++++++>-]<[[-]>[-]+++++++++[<++++++++++>-]<.>++++[<+++++>-]<+.- -.-----------.+++++++.----.>>[-]<+++++[>++++++<-]>++.<<[-]][-]<[>+<[-]]> +++++>[-]+++++++++[<+++++++++>-]<.>++++[<++++++>-]<.+++.------.--------. [-]<[-]]<+[[>]<-]>>[<[[<[[<[[<[,]]]<]<]<]<][-]]+>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>-[+<-]--[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>++<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<+]+>----[++++>----]-[+<-]+[>]<-[-<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<++++>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>][..][>++++++[<+ ++>-]<+[>+++++++++<-]>+[[->+>+<<]>>[-<<+>>]<[<[->>+<<]+>[->>+<<]+[>]<-]< -]<[-<]]>+[>[[-]+++>[-]++++++-[<++++++>-]<.<[-]>[-]]+<]<++++++++[[>]+[<] >-]>[>]<[[-]<]+[[>]<-[,]+[>]<-[]][-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<+ +++[->>++++>>++++>>++++<<<<<<]++++++++++++++>>>>+>>++<<<<<<[->>[->+>[->+ >[->+>+[>>>+<<]>>[-<<+>]<-[<<<[-]<<[-]<<[-]<<[-]>>>[-]>>[-]>>[-]>->+]<<< ]>[-<+>]<<<]>[-<+>]<<<]>[-<+>]<<<]>+>[[-]<->]<[->>>>>>>[-<<<<<<<<+>>>>>> >>]<<<<<<<]<>+<[>[-]>[-]+++++[<++++++>-]<++.[-]<[[->>+<<]>>[-<++>[-<+>[- <+>[-<+>[-<+>[-<+>[-<+>[-<+>[-<+>[<[-]+>->+<[<-]]]]]]]]]]>]<<[>++++++[<+ +++++++>-]<-.[-]<]]]>[>[-]>[-]++++[<++++++++>-]<[<++++++++>-]>+++[<+++++ +++>-]<+++++++[<-------->-]<------->+<[[-]>-<]>[>[-]<[-]++++[->++++++++< ]>.++++++[-<++>]<.[-->+++<]>++.<++++[>----<-]>.[-]<]<[-]>[-]++++++++[<++ ++++++>-]<[>++++<-]+>[<->[-]]<[>[-]<[-]++++[->++++++++<]>.---[-<+++>]<.- --.--------------.[-->+<]>--.[-]<]]<++++++++[[>]+[<]>-]>[>]<[[-]<][-]+++ +++++++.[-][,,.]<< ```

Comments

hellerve

Thanks! The first two seem to run fine for me now, after I applied a fix related to handling single newlines. The paren matcher seems not to work on the third one, however. I will investigate!

hellerve

The third one seems to work now as well. Would you please verify whether they work for you, so we can close this?

rdebath

Looks like _my_ tests work fine, but yours is broken ... ``` Hello World! Actor tried to write to non-existant up channel, ignoring.ð #ÿ #$Ô!Ô6Ÿ¦¦©E©¬¦ž ```

hellerve

Oops, good catch! My first parser fix actually missed a crucial detail! This should work as well now.

rdebath

And "of course" I stuck my three examples together into one file ... ``` $ bin/cspfuck x.b Hello World! Segmentation fault ``` This too... ``` bf >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.#>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>++++++++[ <++++>-]<+.[-]++++++++++. >++++++++[-<+++++++++>]<.>[][<-]>+>-[+]++>++>+++[>[->+++<<+++>]<<]>-----. >->+++..+++.>-.<<+[>[+>+]>>]<--------------.>>.+++.------.--------.>+.>+. ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<++++ +++++++++++.>.+++.------.--------.>+.>. ``` Gives: ``` $ bin/cspfuck xx2.b Hello World! HHello World! Segmentation fault $ ```

hellerve

This seems to be a different bug alltogether. The segmentation fault occurs because we overrun the tape boundaries (which I am fixing now). This should not happen in any of the programs, though, which suggests there is something wrong with the VM. Just out of curiosity: why is there a hash symbol in the first actor of the listing of your last comment? Is this intentional, incidental, or a bug?

rdebath

The hash is from the original `Hello World!` in Urban Müller 1993 archive. https://github.com/rdebath/Brainfuck/blob/umueller-1993/src/hello.b In there it was a debugging instruction to dump out a few cells.

hellerve

Ah, that’s interesting, thank you! I’ll look into this some more when I find time! I’ll tell you when I make any headway.

hellerve

I had a chance to look at this. It seems that this was caused by how I calculated loop offsets in the opcodes (off-by-one errors). This should be fixed now, and both examples work on my end. Could you confirm that they work for you as well? Did you discover anything else? Thank you for trying this little gadget out.

rdebath

It looks like it's working pretty well. I did notice that the below takes a very long time to run, but that's because you're not using optimisation with 32 bit cells. Now that's not a problem, except, for some reason it seems to `Abort` if something else is running (or rather has finished) too. ``` bf +[>[<->+[>+++>[+++++++++++>][]-[<]>-]]++++++++++<]>>>>>>----.<<+++.<-..+++.<-.> >>.<<.+++.------.>-.<<+.<.[>]<[[-]<] ```

hellerve

The problem is the "cleanup" at the end (`[>]<[[-]<]`). We’re underflowing at one of the instructions (offset 31). Then we have to wrap around all the way again. This program runs much faster when I set cell size to 8 bits instead (and doesn’t seem to abort either). I’m not actually sure what to set cell size to, or whether that should be made configurable.

hellerve

I’m closing this for now and reopening a new issue with more specificity, as the original and subsequent issues have been resolved. Feel free to contribute on the new issue if you so desire, though!

rdebath

Oh, I see you're using `-ftrapv`. That means that if an integer overflows you get an abort.