runCodeGen :: CgEnv -> CgState -> CodeGen a -> IO [ClassFile]
runCodeGen env state codeGenAction = do
  let codeGenActionPlus = do
        codeGenAction
        modClass <- getModClass
        initCode <- getInitCode
        defineMethod $ mkMethodDef modClass
          [Public, Static] "<clinit>" [] void (initCode <> vreturn)

  (state'@CgState {..}, _) <- unCG codeGenActionPlus env state

  -- NOTE: addInnerClasses is to ensure that any unused data types/closures
  --       are added to the constant pool
  let compiledModuleClass =
        addInnerClasses cgCompiledClosures $
          classFromCgState state'

  return (compiledModuleClass : cgCompiledClosures)
runCodeGen :: CgEnv -> CgState -> CodeGen a -> IO [ClassFile]
runCodeGen env state codeGenAction = do
  let codeGenActionPlus = do
        codeGenAction
        modClass <- getModClass
        initCode <- getInitCode
        defineMethod $ mkMethodDef modClass
          [Public, Static] "<clinit>" [] void (initCode <> vreturn)

  (state'@CgState {..}, _) <- unCG codeGenActionPlus env state

  -- NOTE: addInnerClasses is to ensure that any unused data types/closures
  --       are added to the constant pool
  let compiledModuleClass =
        addInnerClasses cgCompiledClosures $
          classFromCgState state'

  return (compiledModuleClass : cgCompiledClosures)
runCodeGen env state codeGenAction = do
  let codeGenActionPlus = do
        codeGenAction
        modClass <- getModClass
        initCode <- getInitCode
        defineMethod $ mkMethodDef modClass
          [Public, Static] "<clinit>" [] void (initCode <> vreturn)

  (state'@CgState {..}, _) <- unCG codeGenActionPlus env state

  -- NOTE: addInnerClasses is to ensure that any unused data types/closures
  --       are added to the constant pool
  let compiledModuleClass =
        addInnerClasses cgCompiledClosures $
          classFromCgState state'

  return (compiledModuleClass : cgCompiledClosures)