@@ -366,6 +366,7 @@ instance MonadPlus TransIO where
366
366
mx <- runTrans x
367
367
368
368
was <- gets execMode -- getData `onNothing` return Serial
369
+
369
370
if was == Remote
370
371
371
372
then return Nothing
@@ -1309,14 +1310,7 @@ inputf remove ident message mv cond = do
1309
1310
when remove $ do removeChild; liftIO $ delConsoleAction ident
1310
1311
c <- liftIO $ readIORef rconsumed
1311
1312
if c then returnm mv else do
1312
- -- if null str
1313
- -- then
1314
-
1315
- -- if retry then do
1316
- -- liftIO $ writeIORef rconsumed True;
1317
- -- loop
1318
- -- else do liftIO $ writeIORef rconsumed True; returnm mv
1319
- -- else do
1313
+
1320
1314
let rr = read1 str
1321
1315
1322
1316
case (rr,str) of
@@ -1395,7 +1389,7 @@ inputLoop= do
1395
1389
1396
1390
1397
1391
inputLoop
1398
- `catch` \ (SomeException _) -> myThreadId >>= killThread
1392
+ `catch` \ (SomeException _) -> inputLoop -- myThreadId >>= killThread
1399
1393
1400
1394
1401
1395
{-# NOINLINE rconsumed #-}
@@ -1420,7 +1414,7 @@ processLine r = do
1420
1414
mbs <- readIORef rcb
1421
1415
mapM_ (\ cb -> cb x) $ map (\ (_,_,p)-> p) mbs
1422
1416
1423
- mapM' f [] = return ()
1417
+ mapM' _ [] = return ()
1424
1418
mapM' f (xss@ (x: xs)) = do
1425
1419
f x
1426
1420
r <- readIORef rconsumed
@@ -1434,7 +1428,7 @@ processLine r = do
1434
1428
else do
1435
1429
threadDelay 1000
1436
1430
n <- atomicModifyIORef riterloop $ \ n -> (n+ 1 ,n)
1437
- if n== 100
1431
+ if n== 1
1438
1432
then do
1439
1433
when (not $ null x) $ hPutStr stderr x >> hPutStrLn stderr " : can't read, skip"
1440
1434
writeIORef riterloop 0
@@ -1530,8 +1524,8 @@ keep mx = do
1530
1524
1531
1525
st <- get
1532
1526
setData $ Exit rexit
1533
- (abduce >> labelState (fromString " input " ) >> liftIO inputLoop >> empty)
1534
- <|> do
1527
+
1528
+ do
1535
1529
option " options" " show all options"
1536
1530
mbs <- liftIO $ readIORef rcb
1537
1531
@@ -1569,21 +1563,26 @@ keep mx = do
1569
1563
empty
1570
1564
1571
1565
<|> mx
1566
+ <|> do
1567
+ abduce
1568
+ liftIO $ execCommandLine
1569
+ labelState (fromString " input" )
1570
+ liftIO inputLoop
1571
+ empty
1572
1572
return ()
1573
- threadDelay 10000
1574
- execCommandLine
1573
+
1575
1574
stay rexit
1576
1575
1577
1576
where
1578
1577
type1 :: TransIO a -> Either String (Maybe a )
1579
1578
type1= undefined
1580
1579
1581
1580
-- | Same as `keep` but does not read from the standard input, and therefore
1582
- -- the async input APIs ('option' and 'input') cannot be used in the monad .
1583
- -- However, keyboard input can still be passed via command line arguments as
1581
+ -- the async input APIs ('option' and 'input') cannot respond interactively .
1582
+ -- However, input can still be passed via command line arguments as
1584
1583
-- described in 'keep'. Useful for debugging or for creating background tasks,
1585
1584
-- as well as to embed the Transient monad inside another computation. It
1586
- -- returns either the value returned by `exit`. or Nothing, when there are no
1585
+ -- returns either the value returned by `exit` or Nothing, when there are no
1587
1586
-- more threads running
1588
1587
--
1589
1588
@@ -1687,10 +1686,7 @@ onBack ac bac = registerBack (typeof bac) $ Transient $ do
1687
1686
Backtrack mreason stack <- getData `onNothing` (return $ backStateOf (typeof bac))
1688
1687
runTrans $ case mreason of
1689
1688
Nothing -> ac -- !> "ONBACK NOTHING"
1690
- Just reason -> do
1691
-
1692
- -- setState $ Backtrack mreason $ tail stack -- to avoid recursive call to the same handler
1693
- bac reason -- !> ("ONBACK JUST",reason)
1689
+ Just reason -> bac reason -- !> ("ONBACK JUST",reason)
1694
1690
where
1695
1691
typeof :: (b -> TransIO a ) -> b
1696
1692
typeof = undefined
@@ -1708,6 +1704,7 @@ onUndo x y= onBack x (\() -> y)
1708
1704
{-# NOINLINE registerUndo #-}
1709
1705
registerBack :: (Typeable b , Show b ) => b -> TransientIO a -> TransientIO a
1710
1706
registerBack witness f = Transient $ do
1707
+ tr " registerBack"
1711
1708
cont@ (EventF _ x _ _ _ _ _ _ _ _ _ _ _) <- get
1712
1709
-- if isJust (event cont) then return Nothing else do
1713
1710
md <- getData `asTypeOf` (Just <$> return (backStateOf witness))
@@ -1720,7 +1717,7 @@ registerBack witness f = Transient $ do
1720
1717
1721
1718
Nothing -> setData $ Backtrack mwit [cont]
1722
1719
1723
- runTrans f
1720
+ runTrans $ return () >> f
1724
1721
where
1725
1722
mwit= Nothing `asTypeOf` (Just witness)
1726
1723
-- addr x = liftIO $ return . hashStableName =<< (makeStableName $! x)
@@ -1731,6 +1728,7 @@ registerUndo f= registerBack () f
1731
1728
1732
1729
-- XXX Should we enforce retry of the same track which is being undone? If the
1733
1730
-- user specifies a different track would it make sense?
1731
+ -- see https://gitter.im/Transient-Transient-Universe-HPlay/Lobby?at=5ef46626e0e5673398d33afb
1734
1732
--
1735
1733
-- | For a given undo track type, stop executing more backtracking actions and
1736
1734
-- resume normal execution in the forward direction. Used inside an undo
@@ -1761,6 +1759,7 @@ noFinish= continue
1761
1759
--
1762
1760
back :: (Typeable b , Show b ) => b -> TransIO a
1763
1761
back reason = do
1762
+ tr " back"
1764
1763
bs <- getData `onNothing` return (backStateOf reason)
1765
1764
goBackt bs -- !>"GOBACK"
1766
1765
@@ -1773,15 +1772,17 @@ back reason = do
1773
1772
1774
1773
goBackt (Backtrack _ [] )= empty
1775
1774
goBackt (Backtrack b (stack@ (first : bs)) )= do
1776
- setData $ Backtrack (Just reason) stack
1777
- x <- runClosure first -- !> ("RUNCLOSURE",length stack)
1775
+ setData $ Backtrack (Just reason) bs -- stack
1776
+ x <- runClosure first !> (" RUNCLOSURE" ,length stack)
1778
1777
Backtrack back bs' <- getData `onNothing` return (backStateOf reason)
1779
1778
1780
1779
case back of
1781
- Nothing -> runContinuation first x -- !> "FORWARD EXEC"
1780
+ Nothing -> do
1781
+ setData $ Backtrack (Just reason) stack
1782
+ runContinuation first x !> " FORWARD EXEC"
1782
1783
justreason -> do
1783
- setData $ Backtrack justreason bs
1784
- goBackt $ Backtrack justreason bs -- !> ("BACK AGAIN",back)
1784
+ -- setData $ Backtrack justreason bs
1785
+ goBackt $ Backtrack justreason bs !> (" BACK AGAIN" ,back)
1785
1786
empty
1786
1787
1787
1788
backStateOf :: (Show a , Typeable a ) => a -> Backtrack a
@@ -1936,8 +1937,14 @@ onException' mx f= onAnyException mx $ \e -> do
1936
1937
1937
1938
exceptBack st = \ (e :: SomeException ) -> do -- recursive catch itself
1938
1939
runStateT ( runTrans $ back e ) st -- !> "EXCEPTBACK"
1939
- `catch` exceptBack st
1940
+ -- `catch` exceptBack st -- removed
1941
+
1942
+ -- re execute the first argument as long as the exception is produced within the argument.
1943
+ -- The second argument is executed before every re-execution
1944
+ -- if the second argument executes `empty` the execution is aborted.
1940
1945
1946
+ whileException :: Exception e => TransIO b -> (e -> TransIO () ) -> TransIO b
1947
+ whileException mx fixexc = mx `catcht` \ e -> do fixexc e; whileException mx fixexc
1941
1948
1942
1949
-- | Delete all the exception handlers registered till now.
1943
1950
cutExceptions :: TransIO ()
0 commit comments