module GHC.Debugger.Runtime.Compile
( compileVar
, compileRaw
)
where
import Control.Monad.Reader
import Data.IORef
import GHC
import GHC.Debugger.Monad
import GHC.Debugger.Runtime.Compile.Cache
compileVar :: ModuleName -> String -> [String] -> Debugger ForeignHValue
compileVar :: ModuleName -> String -> [String] -> Debugger ForeignHValue
compileVar ModuleName
mod_name String
var_name [String]
ty_args =
let raw_expr :: String
raw_expr =
(String
"(" String -> String -> String
forall a. [a] -> [a] -> [a]
++ ModuleName -> String
moduleNameString ModuleName
mod_name
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"." String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
var_name String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
") "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ [String] -> String
unwords ((String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (Char
'@'Char -> String -> String
forall a. a -> [a] -> [a]
:) [String]
ty_args))
in String -> Debugger ForeignHValue
compileRaw String
raw_expr
compileRaw :: String -> Debugger ForeignHValue
compileRaw :: String -> Debugger ForeignHValue
compileRaw String
raw_expr = do
compCacheRef <- (DebuggerState -> IORef CompCache) -> Debugger (IORef CompCache)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks DebuggerState -> IORef CompCache
compCache
compCacheVal <- liftIO $ readIORef compCacheRef
case lookupCompRaw raw_expr compCacheVal of
Just ForeignHValue
fhv -> do
ForeignHValue -> Debugger ForeignHValue
forall a. a -> Debugger a
forall (m :: * -> *) a. Monad m => a -> m a
return ForeignHValue
fhv
Maybe ForeignHValue
Nothing -> do
fhv <- String -> Debugger ForeignHValue
forall (m :: * -> *). GhcMonad m => String -> m ForeignHValue
compileExprRemote String
raw_expr
liftIO $ modifyIORef' compCacheRef (insertCompRaw raw_expr fhv)
return fhv