InteractiveEval

ghc-8.6.3: The GHC API

Safe Haskell | None
Language | Haskell2010

InteractiveEval

Synopsis

- data Resume = Resume {
  - resumeStmt :: String
  - resumeContext :: ForeignRef (ResumeContext [HValueRef])
  - resumeBindings :: ([TyThing], GlobalRdrEnv)
  - resumeFinalIds :: [Id]
  - resumeApStack :: ForeignHValue
  - resumeBreakInfo :: Maybe BreakInfo
  - resumeSpan :: SrcSpan
  - resumeDecl :: String
  - resumeCCS :: RemotePtr CostCentreStack
  - resumeHistory :: [History]
  - resumeHistoryIx :: Int
  }
- data History = History {
  - historyApStack :: ForeignHValue
  - historyBreakInfo :: BreakInfo
  - historyEnclosingDecls :: [String]
  }
- execStmt :: GhcMonad m => String -> ExecOptions -> m ExecResult
- data ExecOptions = ExecOptions {
  - execSingleStep :: SingleStep
  - execSourceFile :: String
  - execLineNumber :: Int
  - execWrap :: ForeignHValue -> EvalExpr ForeignHValue
  }
- execOptions :: ExecOptions
- data ExecResult
  - = ExecComplete {
    - execResult :: Either SomeException [Name]
    - execAllocation :: Word64
    }
  - | ExecBreak {
    - breakNames :: [Name]
    - breakInfo :: Maybe BreakInfo
    }
- resumeExec :: GhcMonad m => (SrcSpan -> Bool) -> SingleStep -> m ExecResult
- runDecls :: GhcMonad m => String -> m [Name]
- runDeclsWithLocation :: GhcMonad m => String -> Int -> String -> m [Name]
- isStmt :: DynFlags -> String -> Bool
- hasImport :: DynFlags -> String -> Bool
- isImport :: DynFlags -> String -> Bool
- isDecl :: DynFlags -> String -> Bool
- parseImportDecl :: GhcMonad m => String -> m (ImportDecl GhcPs)
- data SingleStep
  - = RunToCompletion
  - | SingleStep
  - | RunAndLogSteps
- abandon :: GhcMonad m => m Bool
- abandonAll :: GhcMonad m => m Bool
- getResumeContext :: GhcMonad m => m [Resume]
- getHistorySpan :: HscEnv -> History -> SrcSpan
- getModBreaks :: HomeModInfo -> ModBreaks
- getHistoryModule :: History -> Module
- back :: GhcMonad m => Int -> m ([Name], Int, SrcSpan, String)
- forward :: GhcMonad m => Int -> m ([Name], Int, SrcSpan, String)
- setContext :: GhcMonad m => [InteractiveImport] -> m ()
- getContext :: GhcMonad m => m [InteractiveImport]
- availsToGlobalRdrEnv :: ModuleName -> [AvailInfo] -> GlobalRdrEnv
- getNamesInScope :: GhcMonad m => m [Name]
- getRdrNamesInScope :: GhcMonad m => m [RdrName]
- moduleIsInterpreted :: GhcMonad m => Module -> m Bool
- getInfo :: GhcMonad m => Bool -> Name -> m (Maybe (TyThing, Fixity, [ClsInst], [FamInst], SDoc))
- exprType :: GhcMonad m => TcRnExprMode -> String -> m Type
- typeKind :: GhcMonad m => Bool -> String -> m (Type, Kind)
- parseName :: GhcMonad m => String -> m [Name]
- getDocs :: GhcMonad m => Name -> m (Either GetDocsFailure (Maybe HsDocString, Map Int HsDocString))
- data GetDocsFailure
  - = NameHasNoModule Name
  - | NoDocsInIface Module Bool
  - | InteractiveName
- showModule :: GhcMonad m => ModSummary -> m String
- moduleIsBootOrNotObjectLinkable :: GhcMonad m => ModSummary -> m Bool
- parseExpr :: GhcMonad m => String -> m (LHsExpr GhcPs)
- compileParsedExpr :: GhcMonad m => LHsExpr GhcPs -> m HValue
- compileExpr :: GhcMonad m => String -> m HValue
- dynCompileExpr :: GhcMonad m => String -> m Dynamic
- compileExprRemote :: GhcMonad m => String -> m ForeignHValue
- compileParsedExprRemote :: GhcMonad m => LHsExpr GhcPs -> m ForeignHValue
- data Term
  - = Term {
    - ty :: RttiType
    - dc :: Either String DataCon
    - val :: HValue
    - subTerms :: [Term]
    }
  - | Prim {
    - ty :: RttiType
    - valRaw :: [Word]
    }
  - | Suspension {
    - ctype :: ClosureType
    - ty :: RttiType
    - val :: HValue
    - bound_to :: Maybe Name
    }
  - | NewtypeWrap {
    - ty :: RttiType
    - dc :: Either String DataCon
    - wrapped_term :: Term
    }
  - | RefWrap {
    - ty :: RttiType
    - wrapped_term :: Term
    }
- obtainTermFromId :: HscEnv -> Int -> Bool -> Id -> IO Term
- obtainTermFromVal :: HscEnv -> Int -> Bool -> Type -> a -> IO Term
- reconstructType :: HscEnv -> Int -> Id -> IO (Maybe Type)

# Documentation

data Resume #

Constructors

Resume |
Fields resumeStmt :: String resumeContext :: ForeignRef (ResumeContext [HValueRef]) resumeBindings :: ([TyThing], GlobalRdrEnv) resumeFinalIds :: [Id] resumeApStack :: ForeignHValue resumeBreakInfo :: Maybe BreakInfo resumeSpan :: SrcSpan resumeDecl :: String resumeCCS :: RemotePtr CostCentreStack resumeHistory :: [History] resumeHistoryIx :: Int

data History #

Constructors

History |
Fields historyApStack :: ForeignHValue historyBreakInfo :: BreakInfo historyEnclosingDecls :: [String]

execStmt #

Arguments

:: GhcMonad m |
=> String | a statement (bind or expression)
-> ExecOptions |
-> m ExecResult |

Run a statement in the current interactive context.

data ExecOptions #

Constructors

ExecOptions |
Fields execSingleStep :: SingleStep stepping mode execSourceFile :: String filename (for errors) execLineNumber :: Int line number (for errors) execWrap :: ForeignHValue -> EvalExpr ForeignHValue

execOptions :: ExecOptions #

default ExecOptions

data ExecResult #

Constructors

ExecComplete |
Fields execResult :: Either SomeException [Name] execAllocation :: Word64
ExecBreak |
Fields breakNames :: [Name] breakInfo :: Maybe BreakInfo

resumeExec :: GhcMonad m => (SrcSpan -> Bool) -> SingleStep -> m ExecResult #

runDecls :: GhcMonad m => String -> m [Name] #

runDeclsWithLocation :: GhcMonad m => String -> Int -> String -> m [Name] #

Run some declarations and return any user-visible names that were brought into scope.

isStmt :: DynFlags -> String -> Bool #

Returns `True` if passed string is a statement.

hasImport :: DynFlags -> String -> Bool #

Returns `True` if passed string has an import declaration.

isImport :: DynFlags -> String -> Bool #

Returns `True` if passed string is an import declaration.

isDecl :: DynFlags -> String -> Bool #

Returns `True` if passed string is a declaration but not a splice.

parseImportDecl :: GhcMonad m => String -> m (ImportDecl GhcPs) #

data SingleStep #

Constructors

RunToCompletion |
SingleStep |
RunAndLogSteps |

abandon :: GhcMonad m => m Bool #

abandonAll :: GhcMonad m => m Bool #

getResumeContext :: GhcMonad m => m [Resume] #

getHistorySpan :: HscEnv -> History -> SrcSpan #

getModBreaks :: HomeModInfo -> ModBreaks #

getHistoryModule :: History -> Module #

back :: GhcMonad m => Int -> m ([Name], Int, SrcSpan, String) #

forward :: GhcMonad m => Int -> m ([Name], Int, SrcSpan, String) #

setContext :: GhcMonad m => [InteractiveImport] -> m () #

Set the interactive evaluation context.

(setContext imports) sets the ic_imports field (which in turn determines what is in scope at the prompt) to `imports`, and constructs the ic_rn_glb_env environment to reflect it.

We retain in scope all the things defined at the prompt, and kept in ic_tythings. (Indeed, they shadow stuff from ic_imports.)

getContext :: GhcMonad m => m [InteractiveImport] #

Get the interactive evaluation context, consisting of a pair of the set of modules from which we take the full top-level scope, and the set of modules from which we take just the exports respectively.

availsToGlobalRdrEnv :: ModuleName -> [AvailInfo] -> GlobalRdrEnv #

getNamesInScope :: GhcMonad m => m [Name] #

Returns all names in scope in the current interactive context

getRdrNamesInScope :: GhcMonad m => m [RdrName] #

Returns all `RdrName`s in scope in the current interactive context, excluding any that are internally-generated.

moduleIsInterpreted :: GhcMonad m => Module -> m Bool #

Returns `True` if the specified module is interpreted, and hence has its full top-level scope available.

getInfo :: GhcMonad m => Bool -> Name -> m (Maybe (TyThing, Fixity, [ClsInst], [FamInst], SDoc)) #

Looks up an identifier in the current interactive context (for :info) Filter the instances by the ones whose tycons (or clases resp) are in scope (qualified or otherwise). Otherwise we list a whole lot too many! The exact choice of which ones to show, and which to hide, is a judgement call. (see Trac #1581)

exprType :: GhcMonad m => TcRnExprMode -> String -> m Type #

Get the type of an expression Returns the type as described by `TcRnExprMode`

typeKind :: GhcMonad m => Bool -> String -> m (Type, Kind) #

Get the kind of a type

parseName :: GhcMonad m => String -> m [Name] #

Parses a string as an identifier, and returns the list of `Name`s that the identifier can refer to in the current interactive context.

getDocs :: GhcMonad m => Name -> m (Either GetDocsFailure (Maybe HsDocString, Map Int HsDocString)) #

data GetDocsFailure #

Failure modes for `getDocs`.

Constructors

NameHasNoModule Name | `nameModule_maybe` returned `Nothing`.
NoDocsInIface Module Bool | `True`: The module was compiled. `False`: The module was :loaded.
InteractiveName | The `Name` was defined interactively.

Instances

Outputable GetDocsFailure # |
Instance details Defined in InteractiveEval Methods ppr :: GetDocsFailure -> SDoc # pprPrec :: Rational -> GetDocsFailure -> SDoc #

showModule :: GhcMonad m => ModSummary -> m String #

moduleIsBootOrNotObjectLinkable :: GhcMonad m => ModSummary -> m Bool #

parseExpr :: GhcMonad m => String -> m (LHsExpr GhcPs) #

Parse an expression, the parsed expression can be further processed and passed to compileParsedExpr.

compileParsedExpr :: GhcMonad m => LHsExpr GhcPs -> m HValue #

compileExpr :: GhcMonad m => String -> m HValue #

Compile an expression, run it, and deliver the resulting HValue.

dynCompileExpr :: GhcMonad m => String -> m Dynamic #

Compile an expression, run it and return the result as a Dynamic.

compileExprRemote :: GhcMonad m => String -> m ForeignHValue #

Compile an expression, run it, and deliver the resulting HValue.

compileParsedExprRemote :: GhcMonad m => LHsExpr GhcPs -> m ForeignHValue #

Compile a parsed expression (before renaming), run it, and deliver the resulting HValue.

data Term #

Constructors

Term |
Fields ty :: RttiType dc :: Either String DataCon val :: HValue subTerms :: [Term]
Prim |
Fields ty :: RttiType valRaw :: [Word]
Suspension |
Fields ctype :: ClosureType ty :: RttiType val :: HValue bound_to :: Maybe Name
NewtypeWrap |
Fields ty :: RttiType dc :: Either String DataCon wrapped_term :: Term
RefWrap |
Fields ty :: RttiType wrapped_term :: Term

Instances

Outputable Term # |
Instance details Defined in RtClosureInspect Methods ppr :: Term -> SDoc # pprPrec :: Rational -> Term -> SDoc #

obtainTermFromId :: HscEnv -> Int -> Bool -> Id -> IO Term #

obtainTermFromVal :: HscEnv -> Int -> Bool -> Type -> a -> IO Term #

reconstructType :: HscEnv -> Int -> Id -> IO (Maybe Type) #