Ticket #3867: 0002-Export-State-monad-transformer-from-ByteCodeItbls.patch

File 0002-Export-State-monad-transformer-from-ByteCodeItbls.patch, 2.7 KB (added by pcapriotti, 3 years ago)
  • compiler/ghci/ByteCodeItbls.lhs

    From af3027e8625c9734fbc87447bfaf6a021c106968 Mon Sep 17 00:00:00 2001
    From: Paolo Capriotti <[email protected]>
    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 ByteCodeItbls: Generate infotables for interpreter-made bytecodes 
    1515
    1616module ByteCodeItbls ( ItblEnv, ItblPtr(..), itblCode, mkITbls
    1717                     , StgInfoTable(..)
     18                     , State(..), runState, evalState, execState, MonadT
    1819                     ) where
    1920
    2021#include "HsVersions.h"
    import Util 
    3132import Foreign
    3233import Foreign.C
    3334
     35import Control.Monad    ( liftM )
     36
    3437import GHC.Exts         ( Int(I#), addr2Int# )
    3538import GHC.Ptr          ( Ptr(..) )
    3639\end{code}
    instance Storable StgConInfoTable where 
    286289            , sizeOf (infoTable conInfoTable) ]
    287290   alignment _ = SIZEOF_VOID_P
    288291   peek ptr
    289       = runState (castPtr ptr) $ do
     292      = evalState (castPtr ptr) $ do
    290293#ifdef GHCI_TABLES_NEXT_TO_CODE
    291294           desc <- load
    292295#endif
    instance Storable StgConInfoTable where 
    310313pokeConItbl :: Ptr StgConInfoTable -> Ptr StgConInfoTable -> StgConInfoTable
    311314            -> IO ()
    312315pokeConItbl wr_ptr ex_ptr itbl
    313       = runState (castPtr wr_ptr) $ do
     316      = evalState (castPtr wr_ptr) $ do
    314317#ifdef GHCI_TABLES_NEXT_TO_CODE
    315318           store (conDesc itbl `minusPtr` (ex_ptr `plusPtr` conInfoTableSizeB))
    316319#endif
    instance Storable StgInfoTable where 
    353356      = SIZEOF_VOID_P
    354357
    355358   poke a0 itbl
    356       = runState (castPtr a0)
     359      = evalState (castPtr a0)
    357360      $ do
    358361#ifndef GHCI_TABLES_NEXT_TO_CODE
    359362           store (entry  itbl)
    instance Storable StgInfoTable where 
    367370#endif
    368371
    369372   peek a0
    370       = runState (castPtr a0)
     373      = evalState (castPtr a0)
    371374      $ do
    372375#ifndef GHCI_TABLES_NEXT_TO_CODE
    373376           entry'  <- load
    class (Monad m, Monad (t m)) => MonadT t m where 
    409412instance Monad m => MonadT (State s) m where
    410413  lift m        = State (\s -> m >>= \a -> return (s, a))
    411414
    412 runState :: (Monad m) => s -> State s m a -> m a
    413 runState s (State m) = m s >>= return . snd
     415runState :: Monad m => s -> State s m a -> m (s, a)
     416runState s (State m) = m s
     417
     418evalState :: Monad m => s -> State s m a -> m a
     419evalState s m = liftM snd (runState s m)
     420
     421execState :: Monad m => s -> State s m a -> m s
     422execState s m = liftM fst (runState s m)
    414423
    415424type PtrIO = State (Ptr Word8) IO
    416425