Open sunjay opened 7 years ago
The basic scaffolding for optimizations has been implemented. More optimizations will be added as time goes on and more features are added to the language. This issues tracks the progress of that work and other future optimizations as well.
We want to generate the smallest brainfuck files possible while still using as few brainfuck cells as possible. Less instructions is a greater priority than memory efficiency since brainfuck doesn't use that much memory to begin with. That being said, memory is still important and must be taken into account.
Instructions -> Instructions
and write tests><
or<>
and opposing+-
or-+
)><+-
instructions since these have no consequences at the end of the program++++++++++++++,
is completely useless since,
overwrites all the+
[h][e][l][l][o][ ][ ][ ][ ][ ][ ]
where you have the original cells for "hello", enough cells for the copy and a temporary space to use during the copy to keep the original letter. Instead of using a temporary cell at the very end, you can use the adjacent spot to the letter you are copying. So if you were copying "h" into its destination cell, instead of using the temporary cell allocated at the very end, you could use the space for "o". That cell would automatically be cleared at the end of the copy so this is a safe operation. This saves a lot of instructions going back and forth over completely empty cells and will produce even higher savings when the cells to copy aren't right next to each other on the tape. Note: You still need an empty temporary cell at the end for the last character.,>,>,>,<<<.>.>.>.
, we can probably do,.>,.>,.>,.
(needs thought on the consequences of this since it might not be 100% safe)Resources: