packages feed

hint-server (empty) → 1.0.0

raw patch · 5 files changed

+153/−0 lines, 5 filesdep +basedep +eprocessdep +hintsetup-changed

Dependencies added: base, eprocess, hint, monad-loops, mtl

Files

+ LICENSE view
@@ -0,0 +1,31 @@+Copyright Fernando Brujo Benavides 2009++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Fernando Brujo Benavides nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+
+ README view
@@ -0,0 +1,2 @@+This library provides a server process (implemented using eprocess) that can receive and run actions in the Interpreter monad.+See http://hackage.haskell.org/package/hint-server
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hint-server.cabal view
@@ -0,0 +1,34 @@+name: hint-server+version: 1.0.0+cabal-version: >=1.6+build-type: Simple+license: BSD3+license-file: LICENSE+copyright: 2009 Fernando "Brujo" Benavides+maintainer: greenmellon@gmail.com+stability: stable+package-url: http://code.haskell.org/hint-server+bug-reports: http://github.com/elbrujohalcon/hint-server/issues+synopsis: A server process that runs hint.+description: This library provides a server process (implemented using eprocess) that can receive and run actions in the Interpreter monad.+category: Concurrency, Language, Compilers/Interpreters+author: Fernando "Brujo" Benavides+tested-with: GHC ==6.10.3, GHC ==6.10.4+data-files: LICENSE README+data-dir: ""+extra-source-files: Setup.hs+extra-tmp-files:++source-repository head+    type:     git+    location: git://github.com/elbrujohalcon/hint-server.git++Library+    build-depends: base >= 4,                   base < 5,+                   mtl >=1.1.0,                 mtl < 1.2,+                   monad-loops >=0.3.0,         monad-loops < 0.4,+                   hint >=0.3.1,                hint < 0.4,+                   eprocess >=1.0.0,            eprocess < 2+    exposed-modules: Language.Haskell.Interpreter.Server+    hs-source-dirs: src+    
+ src/Language/Haskell/Interpreter/Server.hs view
@@ -0,0 +1,84 @@+-- | This module provides a server process (implemented using eprocess) that can receive and run actions in the Interpreter monad.+module Language.Haskell.Interpreter.Server (+-- * Types+        ServerHandle,+-- * Functions+        start, stop, runIn, asyncRunIn, flush+    ) where++import Control.Concurrent.MVar+import Control.Monad.Error+import Control.Monad.Loops+import Control.Concurrent.Process+import Language.Haskell.Interpreter++-- | The server handle.  It's returned on process creation and should be used+-- afterwards to send messages to it+newtype ServerHandle = SH {handle :: Handle (Either Stop (InterpreterT IO ()))}++data Stop = Stop++instance MonadInterpreter m => MonadInterpreter (ReceiverT r m) where+    fromSession = lift . fromSession+    modifySessionRef a = lift . (modifySessionRef a)+    runGhc = lift . runGhc ++-- | Starts the server. Usage:+-- @+--      handle <- start+-- @+start :: IO ServerHandle+start = (spawn $ makeProcess runInterpreter interpreter) >>= return . SH+    where interpreter =+            do+                setImports ["Prelude"]+                iterateWhile id $ do+                                    v <- recv+                                    case v of+                                        Left Stop ->+                                            return False+                                        Right acc ->+                                            lift acc >> return True++-- | Asynchronically runs an action and returns the /MVar/ that will be filled+-- with the result when it's there. Usage:+-- @+--      mvar <- asyncRunIn serverhandle action+-- @+asyncRunIn :: ServerHandle              -- ^ The handle of the server that will run the action+            -> InterpreterT IO a        -- ^ The action to be run+            -> IO (MVar (Either InterpreterError a))+asyncRunIn server action = do+                                resVar <- liftIO newEmptyMVar+                                sendTo (handle server) $ Right $ try action >>= liftIO . putMVar resVar+                                return resVar++-- | Runs the action. Usage:+-- @+--      result <- runIn serverhandle action+-- @+runIn :: ServerHandle       -- ^ The handle of the server that will run the action+       -> InterpreterT IO a -- ^ The action to be run+       -> IO (Either InterpreterError a)+runIn server action = runHere $ do+                                    me <- self+                                    sendTo (handle server) $ Right $ try action >>= sendTo me+                                    recv++-- | Runs all the pending actions (those that where run using 'asyncRunIn'. Usage:+-- @+--      flush serverhandle+-- @+flush :: ServerHandle                    -- ^ The handle of the server that will run the action+      -> IO (Either InterpreterError ()) -- ^ The meaningful results are stored in the corresponding mvars+flush server = runIn server $ return ()++try :: InterpreterT IO b -> InterpreterT IO (Either InterpreterError b)+try a = (a >>= return . Right) `catchError` (return . Left)++-- | Stops the server. Usage:+-- @+--      stop serverhandle+-- @+stop :: ServerHandle -> IO ()+stop server = sendTo (handle server) $ Left Stop