{-# LANGUAGE FlexibleContexts #-}

module Jikka.CPlusPlus.Convert
  ( run,
  )
where

import qualified Jikka.CPlusPlus.Convert.AddMain as AddMain
import qualified Jikka.CPlusPlus.Convert.FromCore as FromCore
import qualified Jikka.CPlusPlus.Convert.MoveSemantics as MoveSemantics
import qualified Jikka.CPlusPlus.Convert.OptimizeRange as OptimizeRange
import qualified Jikka.CPlusPlus.Convert.UnpackTuples as UnpackTuples
import qualified Jikka.CPlusPlus.Convert.UseInitialization as UseInitialization
import qualified Jikka.CPlusPlus.Language.Expr as Y
import Jikka.Common.Alpha
import Jikka.Common.Error
import Jikka.Common.IOFormat
import qualified Jikka.Core.Language.Expr as X

run :: (MonadAlpha m, MonadError Error m) => X.Program -> IOFormat -> m Y.Program
run :: Program -> IOFormat -> m Program
run Program
prog IOFormat
format = do
  Program
prog <- Program -> m Program
forall (m :: * -> *).
(MonadAlpha m, MonadError Error m) =>
Program -> m Program
FromCore.run Program
prog
  let go :: Program -> m Program
go Program
prog = do
        Program
prog <- Program -> m Program
forall (m :: * -> *).
(MonadAlpha m, MonadError Error m) =>
Program -> m Program
UnpackTuples.run Program
prog
        Program
prog <- Program -> m Program
forall (m :: * -> *). MonadError Error m => Program -> m Program
MoveSemantics.run Program
prog
        Program -> m Program
forall (m :: * -> *). MonadError Error m => Program -> m Program
OptimizeRange.run Program
prog
  Program
prog <- Program -> m Program
forall (m :: * -> *).
(MonadAlpha m, MonadError Error m) =>
Program -> m Program
go Program
prog
  Program
prog <- Program -> m Program
forall (m :: * -> *).
(MonadAlpha m, MonadError Error m) =>
Program -> m Program
go Program
prog
  Program
prog <- Program -> m Program
forall (m :: * -> *).
(MonadAlpha m, MonadError Error m) =>
Program -> m Program
go Program
prog
  Program
prog <- Program -> IOFormat -> m Program
forall (m :: * -> *).
(MonadAlpha m, MonadError Error m) =>
Program -> IOFormat -> m Program
AddMain.run Program
prog IOFormat
format
  Program -> m Program
forall (m :: * -> *).
(MonadAlpha m, MonadError Error m) =>
Program -> m Program
UseInitialization.run Program
prog