From af3027e8625c9734fbc87447bfaf6a021c106968 Mon Sep 17 00:00:00 2001
From: Paolo Capriotti <p.capriotti@gmail.com>
Date: Thu, 5 Apr 2012 16:45:21 +0100
Subject: [PATCH 2/4] Export State monad transformer from ByteCodeItbls.
---
compiler/ghci/ByteCodeItbls.lhs | 21 +++++++++++++++------
1 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/compiler/ghci/ByteCodeItbls.lhs b/compiler/ghci/ByteCodeItbls.lhs
index c1d5ed3..bbf68bf 100644
|
a
|
b
|
|
| 15 | 15 | |
| 16 | 16 | module ByteCodeItbls ( ItblEnv, ItblPtr(..), itblCode, mkITbls |
| 17 | 17 | , StgInfoTable(..) |
| | 18 | , State(..), runState, evalState, execState, MonadT |
| 18 | 19 | ) where |
| 19 | 20 | |
| 20 | 21 | #include "HsVersions.h" |
| … |
… |
|
| 31 | 32 | import Foreign |
| 32 | 33 | import Foreign.C |
| 33 | 34 | |
| | 35 | import Control.Monad ( liftM ) |
| | 36 | |
| 34 | 37 | import GHC.Exts ( Int(I#), addr2Int# ) |
| 35 | 38 | import GHC.Ptr ( Ptr(..) ) |
| 36 | 39 | \end{code} |
| … |
… |
|
| 286 | 289 | , sizeOf (infoTable conInfoTable) ] |
| 287 | 290 | alignment _ = SIZEOF_VOID_P |
| 288 | 291 | peek ptr |
| 289 | | = runState (castPtr ptr) $ do |
| | 292 | = evalState (castPtr ptr) $ do |
| 290 | 293 | #ifdef GHCI_TABLES_NEXT_TO_CODE |
| 291 | 294 | desc <- load |
| 292 | 295 | #endif |
| … |
… |
|
| 310 | 313 | pokeConItbl :: Ptr StgConInfoTable -> Ptr StgConInfoTable -> StgConInfoTable |
| 311 | 314 | -> IO () |
| 312 | 315 | pokeConItbl wr_ptr ex_ptr itbl |
| 313 | | = runState (castPtr wr_ptr) $ do |
| | 316 | = evalState (castPtr wr_ptr) $ do |
| 314 | 317 | #ifdef GHCI_TABLES_NEXT_TO_CODE |
| 315 | 318 | store (conDesc itbl `minusPtr` (ex_ptr `plusPtr` conInfoTableSizeB)) |
| 316 | 319 | #endif |
| … |
… |
|
| 353 | 356 | = SIZEOF_VOID_P |
| 354 | 357 | |
| 355 | 358 | poke a0 itbl |
| 356 | | = runState (castPtr a0) |
| | 359 | = evalState (castPtr a0) |
| 357 | 360 | $ do |
| 358 | 361 | #ifndef GHCI_TABLES_NEXT_TO_CODE |
| 359 | 362 | store (entry itbl) |
| … |
… |
|
| 367 | 370 | #endif |
| 368 | 371 | |
| 369 | 372 | peek a0 |
| 370 | | = runState (castPtr a0) |
| | 373 | = evalState (castPtr a0) |
| 371 | 374 | $ do |
| 372 | 375 | #ifndef GHCI_TABLES_NEXT_TO_CODE |
| 373 | 376 | entry' <- load |
| … |
… |
|
| 409 | 412 | instance Monad m => MonadT (State s) m where |
| 410 | 413 | lift m = State (\s -> m >>= \a -> return (s, a)) |
| 411 | 414 | |
| 412 | | runState :: (Monad m) => s -> State s m a -> m a |
| 413 | | runState s (State m) = m s >>= return . snd |
| | 415 | runState :: Monad m => s -> State s m a -> m (s, a) |
| | 416 | runState s (State m) = m s |
| | 417 | |
| | 418 | evalState :: Monad m => s -> State s m a -> m a |
| | 419 | evalState s m = liftM snd (runState s m) |
| | 420 | |
| | 421 | execState :: Monad m => s -> State s m a -> m s |
| | 422 | execState s m = liftM fst (runState s m) |
| 414 | 423 | |
| 415 | 424 | type PtrIO = State (Ptr Word8) IO |
| 416 | 425 | |