#ifndef R8FORGE_TAPE_OPT_HPP #define R8FORGE_TAPE_OPT_HPP #include #include /* The tape level peephole pass. Three run-local rules: * * > < a maximal run of pointer moves becomes its net displacement * + a run becomes (length % cell_size): a whole turn is a no-op * - a run becomes (length % 2): two flips cancel * * It needs no bracket bookkeeping: '[' and ']' are not in any of the three * character classes, so they always end a run, and keeping each run's net keeps * the data pointer identical at every surviving character -- brackets included -- * so the pairing the machine finds by scanning cannot change. Bracket * characters are never added or removed either, so a run can never be merged * across one. * * Non-instruction characters are dropped (they do nothing at run time). */ std::string rot8_optimize(const std::string &tape, size_t cell_size); #endif