From a8300520a714fa5e46e342e10175d237d89221c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 22 Aug 2019 12:09:24 +0300 Subject: Make non-streaming LLVM and C backends streaming This adds a Stream.consume function, uses it in LLVM and C code generators, and removes the use of Stream.collect function which was used to collect streaming Cmm generation results into a list. LLVM and C backends now properly use streamed Cmm generation, instead of collecting Cmm groups into a list before generating LLVM/C code. --- compiler/utils/Stream.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'compiler/utils') diff --git a/compiler/utils/Stream.hs b/compiler/utils/Stream.hs index ad01fad40c..2ad2b8cc7a 100644 --- a/compiler/utils/Stream.hs +++ b/compiler/utils/Stream.hs @@ -7,7 +7,7 @@ -- ----------------------------------------------------------------------------- module Stream ( Stream(..), yield, liftIO, - collect, fromList, + collect, consume, fromList, Stream.map, Stream.mapM, Stream.mapAccumL ) where @@ -71,6 +71,15 @@ collect str = go str [] Left () -> return (reverse acc) Right (a, str') -> go str' (a:acc) +consume :: Monad m => Stream m a b -> (a -> m ()) -> m b +consume str f = do + r <- runStream str + case r of + Left ret -> return ret + Right (a, str') -> do + f a + consume str' f + -- | Turn a list into a 'Stream', by yielding each element in turn. fromList :: Monad m => [a] -> Stream m a () fromList = mapM_ yield -- cgit v1.2.1