Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mod obu
: Cleanup transpilation-specific control flow (#598)
Some `continue`s in loops were not translated, and instead turned into a long `if` block with the opposite condition. This turns them back into `continue`. And `switch`es with early `break`s and fall-throughs were turned into `current_block_[0-9]+`-style state machines that are very confusing to read. This keeps them as state machines, but uses this pattern: ```rust let mut state = scrutinee; loop { match state { A => { ... state = B; continue; // fall-through } B => { if early_break_condition { break; } } } break; } ``` `break`s at the end of `switch` cases turn into nothing like a normal `match` arm. Early `break`s turn into `break`s out of the surrounding `loop`. And fall-throughs turn into switching to the following state and `continue`ing. This is a lot more readable than the `current_block_[0-9]+`-style state machines and closely matches how C writes it. There is one early `break` that I left as a long `else` block as I think it's easier to read that way without adding the surrounding `loop`.
- Loading branch information