The patches below use a code generator for most of the fix an mirror functions. I dropped tree-sitter for now; maybe it can be used for something later. The code generator is about 800 lines and the generated code 1600. However the generated code is longer than hand written code. WDYT?