-- -----------------------------------------------------------------------------
--
-- (c) The University of Glasgow, 2005-2007
--
-- Running statements interactively
--
-- -----------------------------------------------------------------------------

module GHC.Runtime.Eval.Types (
        Resume(..), History(..), ExecResult(..),
        SingleStep(..), isStep, ExecOptions(..),
        BreakInfo(..)
        ) where

import GHC.Prelude

import GHCi.RemoteTypes
import GHCi.Message (EvalExpr, ResumeContext)
import GHC.Types.Id
import GHC.Types.Name
import GHC.Unit.Module
import GHC.Types.Name.Reader
import GHC.Core.Type
import GHC.Types.SrcLoc
import GHC.Utils.Exception

import Data.Word
import GHC.Stack.CCS

data ExecOptions
 = ExecOptions
     { ExecOptions -> SingleStep
execSingleStep :: SingleStep         -- ^ stepping mode
     , ExecOptions -> String
execSourceFile :: String             -- ^ filename (for errors)
     , ExecOptions -> Int
execLineNumber :: Int                -- ^ line number (for errors)
     , ExecOptions -> ForeignHValue -> EvalExpr ForeignHValue
execWrap :: ForeignHValue -> EvalExpr ForeignHValue
     }

data SingleStep
   = RunToCompletion
   | SingleStep
   | RunAndLogSteps

isStep :: SingleStep -> Bool
isStep :: SingleStep -> Bool
isStep SingleStep
RunToCompletion = Bool
False
isStep SingleStep
_ = Bool
True

data ExecResult
  = ExecComplete
       { ExecResult -> Either SomeException [Name]
execResult :: Either SomeException [Name]
       , ExecResult -> Word64
execAllocation :: Word64
       }
  | ExecBreak
       { ExecResult -> [Name]
breakNames :: [Name]
       , ExecResult -> Maybe BreakInfo
breakInfo :: Maybe BreakInfo
       }

data BreakInfo = BreakInfo
  { BreakInfo -> Module
breakInfo_module :: Module
  , BreakInfo -> Int
breakInfo_number :: Int
  }

data Resume = Resume
       { Resume -> String
resumeStmt      :: String       -- the original statement
       , Resume -> ForeignRef (ResumeContext [HValueRef])
resumeContext   :: ForeignRef (ResumeContext [HValueRef])
       , Resume -> ([TyThing], GlobalRdrEnv)
resumeBindings  :: ([TyThing], GlobalRdrEnv)
       , Resume -> [Id]
resumeFinalIds  :: [Id]         -- [Id] to bind on completion
       , Resume -> ForeignHValue
resumeApStack   :: ForeignHValue -- The object from which we can get
                                        -- value of the free variables.
       , Resume -> Maybe BreakInfo
resumeBreakInfo :: Maybe BreakInfo
                                        -- the breakpoint we stopped at
                                        -- (module, index)
                                        -- (Nothing <=> exception)
       , Resume -> SrcSpan
resumeSpan      :: SrcSpan      -- just a copy of the SrcSpan
                                        -- from the ModBreaks,
                                        -- otherwise it's a pain to
                                        -- fetch the ModDetails &
                                        -- ModBreaks to get this.
       , Resume -> String
resumeDecl      :: String       -- ditto
       , Resume -> RemotePtr CostCentreStack
resumeCCS       :: RemotePtr CostCentreStack
       , Resume -> [History]
resumeHistory   :: [History]
       , Resume -> Int
resumeHistoryIx :: Int           -- 0 <==> at the top of the history
       }

data History
   = History {
        History -> ForeignHValue
historyApStack   :: ForeignHValue,
        History -> BreakInfo
historyBreakInfo :: BreakInfo,
        History -> [String]
historyEnclosingDecls :: [String]  -- declarations enclosing the breakpoint
   }