nixpulvis / brainfuck

A simple brainfuck interpreter in Rust.
http://nixpulvis.com/brainfuck
23 stars 3 forks source link

Remove Unreachable Code #20

Open nixpulvis opened 8 years ago

nixpulvis commented 8 years ago

In an effort to start some simple optimizations, we could save a bunch of space in some brainfuck programs by determining up front that some while loops (aka [...] constructs) will never be entered, and can be removed.

A baseline argument could be if there has been no reachable user input, then we can calculate the values of each cell. This might be expensive, so maybe for a start we simply track readable values until the first reached loop.

This covers the most common case of using a loop for comments at the beginning of a file.