Added new optimization stage: 'collapse'

This collapses loops which just have a single body item which is a
loop itself, recursively. E.g. [[[.]]] -> [.]