@@ -30,7 +30,13 @@ factorial :: Int -> Process Int
30factorial 0 = return 1
30factorial 0 = return 1
31factorial n = (n *) <$> factorial (n - 1)
31factorial n = (n *) <$> factorial (n - 1)
33+factorialOf :: () -> Int -> Process Int
34+factorialOf () = factorial
36+returnInt :: Int -> Process Int
33−$(remotable ['addInt, 'putInt, 'sendInt, 'sendPid, 'factorial])
39+$(remotable ['addInt, 'putInt, 'sendInt, 'sendPid, 'factorial, 'factorialOf, 'returnInt])
35testSendPureClosure :: Transport -> RemoteTable -> IO ()
41testSendPureClosure :: Transport -> RemoteTable -> IO ()
36testSendPureClosure transport rtable = do
42testSendPureClosure transport rtable = do
@@ -140,18 +146,38 @@ testCall transport rtable = do
141 takeMVar clientDone
147 takeMVar clientDone
149+sendFac :: Int -> ProcessId -> Closure (Process ())
150+sendFac n pid = $(mkClosure 'factorial) n `bindCP` $(mkClosure 'sendInt) pid
152+factorial' :: Int -> Closure (Process Int)
153+factorial' n = $(mkClosure 'returnInt) n `bindCP` $(mkClosure 'factorialOf) ()
143testBind :: Transport -> RemoteTable -> IO ()
155testBind :: Transport -> RemoteTable -> IO ()
144testBind transport rtable = do
156testBind transport rtable = do
145 node <- newLocalNode transport rtable
157 node <- newLocalNode transport rtable
146 runProcess node $ do
158 runProcess node $ do
147 us <- getSelfPid
159 us <- getSelfPid
148− let fac5 :: Closure (Process Int)
160+ join . unClosure $ sendFac 6 us
161+ (720 :: Int) <- expect
164+testCallBind :: Transport -> RemoteTable -> IO ()
165+testCallBind transport rtable = do
166+ serverNodeAddr <- newEmptyMVar
167+ clientDone <- newEmptyMVar
170+ node <- newLocalNode transport rtable
171+ putMVar serverNodeAddr (localNodeId node)
174+ node <- newLocalNode transport rtable
175+ nid <- readMVar serverNodeAddr
176+ runProcess node $ do
149− fac5 = $(mkClosure 'factorial) 5
177+ (120 :: Int) <- call nid (factorial' 5)
150− sendVal :: Closure (Int -> Process ())
178+ liftIO $ putMVar clientDone ()
151− sendVal = $(mkClosure 'sendInt) us
179+
152− go :: Closure (Process ())
180+ takeMVar clientDone
153− go = fac5 `bindCP` sendVal
156main :: IO ()
182main :: IO ()
@@ -164,4 +190,5 @@ main = do
164 , ("Spawn", testSpawn transport rtable)
190 , ("Spawn", testSpawn transport rtable)
165 , ("Call", testCall transport rtable)
191 , ("Call", testCall transport rtable)
166 , ("Bind", testBind transport rtable)
192 , ("Bind", testBind transport rtable)
193+ , ("CallBind", testCallBind transport rtable)