getCodeWithResult :: CodeGen a -> CodeGen (a, Code)
getCodeWithResult gen = do
  state1 <- get
  modify $ \s -> s { cgCode = mempty }
  a <- gen
  state2 <- get
  put $ state2 { cgCode = cgCode state1 }
  return (a, cgCode state2)
getCodeWithResult :: CodeGen a -> CodeGen (a, Code)
getCodeWithResult gen = do
  state1 <- get
  modify $ \s -> s { cgCode = mempty }
  a <- gen
  state2 <- get
  put $ state2 { cgCode = cgCode state1 }
  return (a, cgCode state2)
getCodeWithResult gen = do
  state1 <- get
  modify $ \s -> s { cgCode = mempty }
  a <- gen
  state2 <- get
  put $ state2 { cgCode = cgCode state1 }
  return (a, cgCode state2)