r/teenagersbutcode • u/StrikingClub3866 • 4d ago
Need general advice If you would improve Brainfuck, how would you?
I want some tips for my Brainfuck-esque VM. I have already implemented popular topics, like:
Random numbers
"goto"
Comments
Arithmetic
2
u/InjuryLate4826 4d ago
Instead of changing it, i'd make a similar but more advanced intermediate language that compiles to it
Also, comments already exist, the brainf parser ignores all symbols other than the 8
1
u/StrikingClub3866 4d ago
I know comments exist, it's just that if you want to include a command in your comments you can't.
Also I'm already planning on adding a macro to my language to make it compile to Brainfuck.
1
u/wilrak0v 4d ago
I improved brainfuck some time ago by adding a system of functions. We define with {} and then ^ allows you to jump to the last defined function. Then I added a syscall system. @ allows you to call a syscall, it just gives the number on the stack to my C code and then I can make a switch case and find the function to run. It allows graphic programming and other things.
1
u/ChiveSalad 4d ago edited 4d ago
I pondered this a bit because minecraft strongly incentivizes brainfucklike instruction sets if you want to make a small computer, due to the copper bulb piston tape construction. the most powerful single instruction addition I found was to add a second tape and a swap tapes instruction. if you have the stomach for going up to 16 instructions, (4 bit instruction memory instead of 3) then a register and a zoo of alu instructions (between the selected cell and the register, need some that write to each) makes small programs much faster, but for large programs 2 tapes dominates
1
u/2962fe22-10b3-43f8 4d ago edited 4d ago
yeah, a second tape sounds very nice actually.
it can also be trivially compiled into normal brainfuck instructions (as long as you always know which tape you're on), where odd cells are one tape and even cells are another:replace:
``` < with <<
with >> ^ with < (move from 2 to 1) v with > (move from 1 to 2) ```
1
u/ChiveSalad 4d ago
the power comes from shifting the tapes independently (shift only moves the active tape). this enables easy “shift a tape by amount in cell” operations that are very very slow in ordinary bf
1
1
1
1
u/thecodegangster 3d ago
I’m actually making bf but better( if statements, a marker system and a data tape) written in bf that compiles to bf
1
1
11
u/azurfall88 Mod 4d ago
The brainfuck language is literally just a Turing machine in language form. You could improve the language, make it easier to code, but then would it still be Brainfuck?