/compiler/GHC/Runtime/Interpreter/Types.hs

https://github.com/bgamari/ghc · Haskell · 74 lines · 45 code · 13 blank · 16 comment · 0 complexity · 2fea3fc346a00d1a99cae46de386e3ca MD5 · raw file

  1. {-# LANGUAGE CPP #-}
  2. -- | Types used by the runtime interpreter
  3. module GHC.Runtime.Interpreter.Types
  4. ( Interp(..)
  5. , InterpInstance(..)
  6. , IServ(..)
  7. , IServInstance(..)
  8. , IServConfig(..)
  9. , IServState(..)
  10. )
  11. where
  12. import GHC.Prelude
  13. import GHC.Linker.Types
  14. import GHCi.RemoteTypes
  15. import GHCi.Message ( Pipe )
  16. import GHC.Types.Unique.FM
  17. import GHC.Data.FastString ( FastString )
  18. import Foreign
  19. import Control.Concurrent
  20. import System.Process ( ProcessHandle, CreateProcess )
  21. -- | Interpreter
  22. data Interp = Interp
  23. { interpInstance :: !InterpInstance
  24. -- ^ Interpreter instance (internal, external)
  25. , interpLoader :: !Loader
  26. -- ^ Interpreter loader
  27. }
  28. data InterpInstance
  29. = ExternalInterp !IServConfig !IServ -- ^ External interpreter
  30. #if defined(HAVE_INTERNAL_INTERPRETER)
  31. | InternalInterp -- ^ Internal interpreter
  32. #endif
  33. -- | External interpreter
  34. --
  35. -- The external interpreter is spawned lazily (on first use) to avoid slowing
  36. -- down sessions that don't require it. The contents of the MVar reflects the
  37. -- state of the interpreter (running or not).
  38. newtype IServ = IServ (MVar IServState)
  39. -- | State of an external interpreter
  40. data IServState
  41. = IServPending -- ^ Not spawned yet
  42. | IServRunning !IServInstance -- ^ Running
  43. -- | Configuration needed to spawn an external interpreter
  44. data IServConfig = IServConfig
  45. { iservConfProgram :: !String -- ^ External program to run
  46. , iservConfOpts :: ![String] -- ^ Command-line options
  47. , iservConfProfiled :: !Bool -- ^ Use Profiling way
  48. , iservConfDynamic :: !Bool -- ^ Use Dynamic way
  49. , iservConfHook :: !(Maybe (CreateProcess -> IO ProcessHandle)) -- ^ Hook
  50. , iservConfTrace :: IO () -- ^ Trace action executed after spawn
  51. }
  52. -- | External interpreter instance
  53. data IServInstance = IServInstance
  54. { iservPipe :: !Pipe
  55. , iservProcess :: !ProcessHandle
  56. , iservLookupSymbolCache :: !(UniqFM FastString (Ptr ()))
  57. , iservPendingFrees :: ![HValueRef]
  58. -- ^ Values that need to be freed before the next command is sent.
  59. -- Threads can append values to this list asynchronously (by modifying the
  60. -- IServ state MVar).
  61. }