Direct unit tests for compiler optimisations

We currently do not have a way to directly test compiler optimisations, and the tests we have are not always reliable (more background).

We need to be able to feed a sequence of bytecode instructions into the optimiser from python, and get its output back into python. Then we can write tests.