MikeInnes / BrainForth

An Impractical Stack Language
Other
13 stars 2 forks source link

Overflow using bools #2

Open Laeri opened 1 year ago

Laeri commented 1 year ago

Hey there, we had an issue using BrainForth in production regarding how bools are handled.

The snippet should return 25 in my opinion as we or connect only true values. If I have seen correctly 1 resolves to true and 0 to false. If one or statement is left out then it returns 50.

@run [1,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or,1,or, [25],[50],iff]

EDIT: As we were working feverishly to fix this issue I was quite tired one snippet didn't work, so I removed it. Thanks by the way for the blog post, I enjoyed reading it because I am developing a small forth compiler for fun and looked out for a reverence implementation and found yours :)

MikeInnes commented 1 year ago

Thanks, really glad you found the blog post useful! I am... very curious what you mean by "in production" here, and how you're using this generally. Email in profile if you want to chat privately.

I was able to reproduce the issue and I agree with your assessment. There are 255 ors in your example so I suspect some counter is overflowing the 8-bit brainfuck registers. That's certainly possible if you have >255 closures. But your example isn't closure-heavy so I'm not sure at a glance.

Unfortunately I won't be able to spend tons of time on this; it might be really easy to fix, but there's a good chance it could need a bigger overhaul to fix. I'll take a look though.

Laeri commented 1 year ago

I am writing my own forth to brainf*ck compiler and I use this as a reference therefore I found the bug and I thought I would mention it here. The production part was a bit of a joke as brainf*ck seems to be too minimal for any serious use. However, after reading up on it I saw some cases where brainfuck has some upsides apart from the minimal instruction. So please don't be in a hurry to fix this.

I will try to provide a fix if I understand your implementation a bit better. Just wanted to say thanks again for the blog post and putting your code on github, very helpful :)

MikeInnes commented 1 year ago

Heh, I wondered, but Poe's law and all that :)

If you ever put your compiler online do throw a link my way!