Bytecode - PreyMa/advanced-brainfq GitHub Wiki
The source Brainfuck source code is compiled by the parser to optimized bytecode. As the name suggests all valus are stored only as single bytes. Since Brainfuck is a quite weird example of this system, because commands consist of single characters whith a length of only one byte, the main difference between the source code and bytecode are the optimizations and the storage of Adanced Brainfq constants in binary format.
There are three types of commands that can be declared in the bytecode. The most basic version is only one byte long and contains it's name, like '.' to print out data. There is no additional information needed from the sourcecode.
But the increment command '+' needs some extra data. That is due to the optimizations done buy the parser. Since in regular Brainfuck values of memory cells have to be set by incrementing a lot of times, many increment commands would have to be processed in a row. Instead the parser counts the amount of the same command and saves this number as a byte directly after it. This leads to a command with a total of two bytes in bytecode format.
Loop commands in contrast do not save the maount of their occurrence rigth next to each other, instead the adresses in the code, where they have to jump during execution, based on the logic value of the current cell.
The set commands are part of the last type of commands. These save their id and a value description operator in the bytecode. This special value saves what type of information source is used for this commnd. The available options are: the value of the current memory cell, the position of the current memory cell pointer or a constant. If a constant is selected another 4 bytes are added which contains this constant.