summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2018-01-17 09:10:52 +0100
committerGitHub <noreply@github.com>2018-01-17 09:10:52 +0100
commitff6e3b136eede172f20ea8a0f7017ad1ecd029b8 (patch)
tree7cd322a359dbd2bb8eec18e697e04c300e216b9f
parentcbac76692978c316223eda2407deda4978a09241 (diff)
parent77508af752f01c9f4283e6149684084c6982da9e (diff)
Merge pull request #13 from deepfire/master
Build with GHC 8.4.1
-rw-r--r--lambdacube-compiler.cabal22
-rw-r--r--prototypes/FreeVars.hs24
-rw-r--r--prototypes/LamMachineV2.hs6
-rw-r--r--prototypes/SplayList.hs8
-rw-r--r--prototypes/Stream.hs5
-rw-r--r--src/LambdaCube/Compiler/DeBruijn.hs6
-rw-r--r--src/LambdaCube/Compiler/DesugaredSource.hs9
-rw-r--r--src/LambdaCube/Compiler/Lexer.hs12
-rw-r--r--src/LambdaCube/Compiler/Parser.hs8
-rw-r--r--src/LambdaCube/Compiler/Patterns.hs10
-rw-r--r--src/LambdaCube/Compiler/Pretty.hs6
-rw-r--r--src/LambdaCube/Compiler/Utils.hs1
12 files changed, 100 insertions, 17 deletions
diff --git a/lambdacube-compiler.cabal b/lambdacube-compiler.cabal
index a874e08e..09a96589 100644
--- a/lambdacube-compiler.cabal
+++ b/lambdacube-compiler.cabal
@@ -96,20 +96,20 @@ library
96 binary, 96 binary,
97 bytestring, 97 bytestring,
98 time, 98 time,
99 aeson >=1.1 && <1.2, 99 aeson >=1.1,
100 base >=4.9 && <5, 100 base >=4.9,
101 semigroups, 101 semigroups,
102 containers >=0.5 && <0.6, 102 containers >=0.5,
103 directory >=1.3 && <1.4, 103 directory >=1.3,
104 exceptions >= 0.8 && <0.9, 104 exceptions >= 0.8,
105 filepath >=1.4 && <1.5, 105 filepath >=1.4,
106 mtl >=2.2 && <2.3, 106 mtl >=2.2,
107 megaparsec >=5.3 && <5.4, 107 megaparsec >=5.3,
108 ansi-wl-pprint >=0.6 && <0.7, 108 ansi-wl-pprint >=0.6,
109 pretty-show >= 1.6.9, 109 pretty-show >= 1.6.9,
110 text >= 1.2 && <1.3, 110 text >= 1.2,
111 lambdacube-ir == 0.3.*, 111 lambdacube-ir == 0.3.*,
112 vector >= 0.12 && <0.13 112 vector >= 0.12
113 113
114 hs-source-dirs: src 114 hs-source-dirs: src
115 default-language: Haskell2010 115 default-language: Haskell2010
diff --git a/prototypes/FreeVars.hs b/prototypes/FreeVars.hs
index f0fb9a4b..32ad98a7 100644
--- a/prototypes/FreeVars.hs
+++ b/prototypes/FreeVars.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE OverloadedStrings #-} 2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE PatternSynonyms #-} 3{-# LANGUAGE PatternSynonyms #-}
3{-# LANGUAGE PatternGuards #-} 4{-# LANGUAGE PatternGuards #-}
@@ -74,7 +75,12 @@ instance Num Nat where
74 75
75instance Monoid Nat where 76instance Monoid Nat where
76 mempty = 0 77 mempty = 0
78#if !MIN_VERSION_base(4,11,0)
77 Nat a `mappend` Nat b = Nat (a + b) 79 Nat a `mappend` Nat b = Nat (a + b)
80#else
81instance Semigroup Nat where
82 Nat a <> Nat b = Nat (a + b)
83#endif
78 84
79instance PShow Nat where pShow (Nat i) = pShow i 85instance PShow Nat where pShow (Nat i) = pShow i
80instance Show Nat where show = ppShow 86instance Show Nat where show = ppShow
@@ -157,6 +163,7 @@ fromStr = fromBools . map (=='1')
157instance Monoid FV where 163instance Monoid FV where
158 mempty = FE 164 mempty = FE
159 165
166#if !MIN_VERSION_base(4,11,0)
160 mappend x FE = x 167 mappend x FE = x
161 mappend FE x = x 168 mappend FE x = x
162 mappend (FV a b us) (FV a' b' us') 169 mappend (FV a b us) (FV a' b' us')
@@ -166,6 +173,18 @@ instance Monoid FV where
166 | otherwise = fv c (a' + b' - c) $ mappend (FV 0 ((a + b) - (a' + b')) us) us' 173 | otherwise = fv c (a' + b' - c) $ mappend (FV 0 ((a + b) - (a' + b')) us) us'
167 where 174 where
168 c = min a a' 175 c = min a a'
176#else
177instance Semigroup FV where
178 (<>) x FE = x
179 (<>) FE x = x
180 (<>) (FV a b us) (FV a' b' us')
181 | a + b <= a' = fv a b $ us <> (FV (a' - (a + b)) b' us')
182 | a + b - a' <= b' = fv c (a + b - c) $ us <> (FV 0 (b' - (a + b - a')) us')
183 | a' + b' <= a = fv a' b' $ (FV (a - (a' + b')) b us) <> us'
184 | otherwise = fv c (a' + b' - c) $ (FV 0 ((a + b) - (a' + b')) us) <> us'
185 where
186 c = min a a'
187#endif
169 188
170prop_monoid_FV = prop_Monoid (T :: T FV) 189prop_monoid_FV = prop_Monoid (T :: T FV)
171prop_mappend_normal_FV (a :: FV) b = testNormalFV (a <> b) 190prop_mappend_normal_FV (a :: FV) b = testNormalFV (a <> b)
@@ -335,7 +354,12 @@ instance Arbitrary SFV where
335instance Monoid SFV where 354instance Monoid SFV where
336 mempty = SFV 0 mempty 355 mempty = SFV 0 mempty
337 356
357#if !MIN_VERSION_base(4,11,0)
338 SFV m b `mappend` SFV n a = SFV (n + m) $ sDrop n b <> a 358 SFV m b `mappend` SFV n a = SFV (n + m) $ sDrop n b <> a
359#else
360instance Semigroup SFV where
361 SFV m b <> SFV n a = SFV (n + m) $ sDrop n b <> a
362#endif
339 363
340prop_monoid_SFV = prop_Monoid (T :: T SFV) 364prop_monoid_SFV = prop_Monoid (T :: T SFV)
341{- 365{-
diff --git a/prototypes/LamMachineV2.hs b/prototypes/LamMachineV2.hs
index 0d51d8a8..acacdf4b 100644
--- a/prototypes/LamMachineV2.hs
+++ b/prototypes/LamMachineV2.hs
@@ -3,6 +3,7 @@
3-- LamMachine is a variant of the machine described in 3-- LamMachine is a variant of the machine described in
4-- "Deriving a Lazy Abstract Machine" (1997) by Peter Sestoft 4-- "Deriving a Lazy Abstract Machine" (1997) by Peter Sestoft
5 5
6{-# LANGUAGE CPP #-}
6{-# LANGUAGE OverloadedStrings #-} 7{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE PatternSynonyms #-} 8{-# LANGUAGE PatternSynonyms #-}
8{-# LANGUAGE PatternGuards #-} 9{-# LANGUAGE PatternGuards #-}
@@ -192,7 +193,12 @@ newtype MDB = MDB {getMDB :: Int}
192 193
193instance Monoid MDB where 194instance Monoid MDB where
194 mempty = MDB 0 195 mempty = MDB 0
196#if !MIN_VERSION_base(4,11,0)
195 MDB n `mappend` MDB m = MDB $ n `max` m 197 MDB n `mappend` MDB m = MDB $ n `max` m
198#else
199instance Semigroup MDB where
200 MDB n <> MDB m = MDB $ n `max` m
201#endif
196 202
197------------------------------------- rearrange De Bruijn indices 203------------------------------------- rearrange De Bruijn indices
198 204
diff --git a/prototypes/SplayList.hs b/prototypes/SplayList.hs
index 2cee0699..b2a8c743 100644
--- a/prototypes/SplayList.hs
+++ b/prototypes/SplayList.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE FlexibleContexts #-} 2{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleInstances #-} 3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE UndecidableInstances #-} 4{-# LANGUAGE UndecidableInstances #-}
@@ -58,9 +59,16 @@ class (HasFV a, Measure a ~ Nat) => Measured a where
58 59
59instance Measured a => Monoid (SplayList a) where 60instance Measured a => Monoid (SplayList a) where
60 mempty = Nil 61 mempty = Nil
62#if !MIN_VERSION_base(4,11,0)
61 Nil `mappend` ys = ys 63 Nil `mappend` ys = ys
62 xs `mappend` Nil = xs 64 xs `mappend` Nil = xs
63 xs `mappend` ys = Append xs ys 65 xs `mappend` ys = Append xs ys
66#else
67instance Semigroup (SplayList a) where
68 Nil <> ys = ys
69 xs <> Nil = xs
70 xs <> ys = Append xs ys
71#endif
64 72
65instance (Measured a, HasFV a) => HasFV (SplayList a) where 73instance (Measured a, HasFV a) => HasFV (SplayList a) where
66 fvLens = \case 74 fvLens = \case
diff --git a/prototypes/Stream.hs b/prototypes/Stream.hs
index e848fe36..b887f1ad 100644
--- a/prototypes/Stream.hs
+++ b/prototypes/Stream.hs
@@ -139,7 +139,12 @@ dbAnd a b = not <$> sOr (not <$> a) (not <$> b)
139 139
140instance Monoid (Stream Bool) where 140instance Monoid (Stream Bool) where
141 mempty = Repeat False 141 mempty = Repeat False
142#if !MIN_VERSION_base(4,11,0)
142 mappend = sOr 143 mappend = sOr
144#else
145instance Semigroup (Stream Bool) where
146 (<>) = sOr
147#endif
143 148
144prop_StreamBool_monoid_left (a :: Stream Bool) = mempty <> a == a 149prop_StreamBool_monoid_left (a :: Stream Bool) = mempty <> a == a
145prop_StreamBool_monoid_right (a :: Stream Bool) = a <> mempty == a 150prop_StreamBool_monoid_right (a :: Stream Bool) = a <> mempty == a
diff --git a/src/LambdaCube/Compiler/DeBruijn.hs b/src/LambdaCube/Compiler/DeBruijn.hs
index a0fd8326..a3d1d0fd 100644
--- a/src/LambdaCube/Compiler/DeBruijn.hs
+++ b/src/LambdaCube/Compiler/DeBruijn.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE DeriveGeneric #-} 2{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE LambdaCase #-} 3{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE ViewPatterns #-} 4{-# LANGUAGE ViewPatterns #-}
@@ -76,7 +77,12 @@ instance PShow FreeVars where
76 77
77instance Monoid FreeVars where 78instance Monoid FreeVars where
78 mempty = FreeVars 0 79 mempty = FreeVars 0
80#if !MIN_VERSION_base(4,11,0)
79 FreeVars a `mappend` FreeVars b = FreeVars $ a .|. b 81 FreeVars a `mappend` FreeVars b = FreeVars $ a .|. b
82#else
83instance Semigroup FreeVars where
84 FreeVars a <> FreeVars b = FreeVars $ a .|. b
85#endif
80 86
81freeVar :: Int -> FreeVars 87freeVar :: Int -> FreeVars
82freeVar i = FreeVars $ 1 `shiftL` i 88freeVar i = FreeVars $ 1 `shiftL` i
diff --git a/src/LambdaCube/Compiler/DesugaredSource.hs b/src/LambdaCube/Compiler/DesugaredSource.hs
index 4a556c32..2e967eff 100644
--- a/src/LambdaCube/Compiler/DesugaredSource.hs
+++ b/src/LambdaCube/Compiler/DesugaredSource.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE DeriveGeneric #-} 2{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE LambdaCase #-} 3{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE ViewPatterns #-} 4{-# LANGUAGE ViewPatterns #-}
@@ -148,10 +149,18 @@ instance Ord SI where _ `compare` _ = EQ
148 149
149instance Monoid SI where 150instance Monoid SI where
150 mempty = NoSI Set.empty 151 mempty = NoSI Set.empty
152#if !MIN_VERSION_base(4,11,0)
151 mappend (RangeSI r1) (RangeSI r2) = RangeSI (joinRange r1 r2) 153 mappend (RangeSI r1) (RangeSI r2) = RangeSI (joinRange r1 r2)
152 mappend (NoSI ds1) (NoSI ds2) = NoSI (ds1 `Set.union` ds2) 154 mappend (NoSI ds1) (NoSI ds2) = NoSI (ds1 `Set.union` ds2)
153 mappend r@RangeSI{} _ = r 155 mappend r@RangeSI{} _ = r
154 mappend _ r@RangeSI{} = r 156 mappend _ r@RangeSI{} = r
157#else
158instance Semigroup SI where
159 (<>) (RangeSI r1) (RangeSI r2) = RangeSI (joinRange r1 r2)
160 (<>) (NoSI ds1) (NoSI ds2) = NoSI (ds1 `Set.union` ds2)
161 (<>) r@RangeSI{} _ = r
162 (<>) _ r@RangeSI{} = r
163#endif
155 164
156instance PShow SI where 165instance PShow SI where
157 pShow (NoSI ds) = hsep $ map text $ Set.toList ds 166 pShow (NoSI ds) = hsep $ map text $ Set.toList ds
diff --git a/src/LambdaCube/Compiler/Lexer.hs b/src/LambdaCube/Compiler/Lexer.hs
index ac7f7f71..c3f4e285 100644
--- a/src/LambdaCube/Compiler/Lexer.hs
+++ b/src/LambdaCube/Compiler/Lexer.hs
@@ -17,15 +17,17 @@ import Data.List
17import Data.List.NonEmpty (fromList) 17import Data.List.NonEmpty (fromList)
18import Data.Char 18import Data.Char
19import qualified Data.Set as Set 19import qualified Data.Set as Set
20import Data.Void
20import Control.Monad.Except 21import Control.Monad.Except
21import Control.Monad.RWS 22import Control.Monad.RWS
22import Control.Applicative 23import Control.Applicative
23import Control.Arrow 24import Control.Arrow
24 25
25import Text.Megaparsec hiding (State, ParseError) 26import Text.Megaparsec hiding (State, ParseError)
27import Text.Megaparsec.Char
28import Text.Megaparsec.Char.Lexer hiding (lexeme, symbol)
26import qualified Text.Megaparsec as P 29import qualified Text.Megaparsec as P
27import Text.Megaparsec as ParseUtils hiding (try, Message, State, ParseError) 30import Text.Megaparsec as ParseUtils hiding (try, Message, State, ParseError, lexeme, symbol)
28import Text.Megaparsec.Lexer hiding (lexeme, symbol, negate)
29 31
30import LambdaCube.Compiler.Pretty hiding (parens) 32import LambdaCube.Compiler.Pretty hiding (parens)
31import LambdaCube.Compiler.DesugaredSource 33import LambdaCube.Compiler.DesugaredSource
@@ -114,12 +116,12 @@ data ParseEnv r = ParseEnv
114type ParseState r = (ParseEnv r, P.State String) 116type ParseState r = (ParseEnv r, P.State String)
115 117
116parseState :: FileInfo -> r -> ParseState r 118parseState :: FileInfo -> r -> ParseState r
117parseState fi di = (ParseEnv fi di ExpNS (SPos 0 0), either (error "impossible") id $ runParser (getParserState :: Parsec Dec String (P.State String)) (filePath fi) (fileContent fi)) 119parseState fi di = (ParseEnv fi di ExpNS (SPos 0 0), either (error "impossible") id $ runParser (getParserState :: Parsec (ErrorFancy Void) String (P.State String)) (filePath fi) (fileContent fi))
118 120
119--type Parse r w = ReaderT (ParseEnv r) (WriterT [w] (StateT SPos (Parsec String))) 121--type Parse r w = ReaderT (ParseEnv r) (WriterT [w] (StateT SPos (Parsec String)))
120type Parse r w = RWST (ParseEnv r) [w] SPos (Parsec Dec String) 122type Parse r w = RWST (ParseEnv r) [w] SPos (Parsec (ErrorFancy Void) String)
121 123
122newtype ParseError = ParseErr (P.ParseError (Token String) Dec) 124newtype ParseError = ParseErr (P.ParseError (Token String) (ErrorFancy Void))
123 125
124instance Show ParseError where 126instance Show ParseError where
125 show (ParseErr e) = parseErrorPretty e 127 show (ParseErr e) = parseErrorPretty e
diff --git a/src/LambdaCube/Compiler/Parser.hs b/src/LambdaCube/Compiler/Parser.hs
index 1ed8ac8c..752d7957 100644
--- a/src/LambdaCube/Compiler/Parser.hs
+++ b/src/LambdaCube/Compiler/Parser.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE LambdaCase #-} 2{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE ViewPatterns #-} 3{-# LANGUAGE ViewPatterns #-}
3{-# LANGUAGE PatternSynonyms #-} 4{-# LANGUAGE PatternSynonyms #-}
@@ -37,6 +38,8 @@ import LambdaCube.Compiler.DesugaredSource
37import LambdaCube.Compiler.Patterns 38import LambdaCube.Compiler.Patterns
38import LambdaCube.Compiler.Statements 39import LambdaCube.Compiler.Statements
39 40
41import Text.Megaparsec.Char
42
40-------------------------------------------------------------------------------- parser type 43-------------------------------------------------------------------------------- parser type
41 44
42type BodyParser = Parse DesugarInfo PostponedCheck 45type BodyParser = Parse DesugarInfo PostponedCheck
@@ -124,7 +127,12 @@ data DesugarInfo = DesugarInfo
124 127
125instance Monoid DesugarInfo where 128instance Monoid DesugarInfo where
126 mempty = DesugarInfo mempty mempty mempty 129 mempty = DesugarInfo mempty mempty mempty
130#if !MIN_VERSION_base(4,11,0)
127 DesugarInfo a b c `mappend` DesugarInfo a' b' c' = DesugarInfo (a <> a') (b <> b') (c <> c') 131 DesugarInfo a b c `mappend` DesugarInfo a' b' c' = DesugarInfo (a <> a') (b <> b') (c <> c')
132#else
133instance Semigroup DesugarInfo where
134 DesugarInfo a b c <> DesugarInfo a' b' c' = DesugarInfo (a <> a') (b <> b') (c <> c')
135#endif
128 136
129mkDesugarInfo :: [Stmt] -> DesugarInfo 137mkDesugarInfo :: [Stmt] -> DesugarInfo
130mkDesugarInfo ss = DesugarInfo 138mkDesugarInfo ss = DesugarInfo
diff --git a/src/LambdaCube/Compiler/Patterns.hs b/src/LambdaCube/Compiler/Patterns.hs
index a354ccf3..e2b18223 100644
--- a/src/LambdaCube/Compiler/Patterns.hs
+++ b/src/LambdaCube/Compiler/Patterns.hs
@@ -3,6 +3,7 @@
3-- overview: 3-- overview:
4-- https://rawgit.com/BP-HUG/presentations/master/2016_april/pattern-match-compilation/patternMatchComp.html 4-- https://rawgit.com/BP-HUG/presentations/master/2016_april/pattern-match-compilation/patternMatchComp.html
5 5
6{-# LANGUAGE CPP #-}
6{-# LANGUAGE LambdaCase #-} 7{-# LANGUAGE LambdaCase #-}
7{-# LANGUAGE ViewPatterns #-} 8{-# LANGUAGE ViewPatterns #-}
8{-# LANGUAGE PatternSynonyms #-} 9{-# LANGUAGE PatternSynonyms #-}
@@ -292,11 +293,20 @@ type GuardTrees = Lets GuardTree
292 293
293instance Monoid GuardTrees where 294instance Monoid GuardTrees where
294 mempty = In GTFailure 295 mempty = In GTFailure
296#if !MIN_VERSION_base(4,11,0)
295 LLet sn e x `mappend` y = LLet sn e $ x `mappend` rUp 1 0 y 297 LLet sn e x `mappend` y = LLet sn e $ x `mappend` rUp 1 0 y
296 LTypeAnn t x `mappend` y = LTypeAnn t $ x `mappend` y 298 LTypeAnn t x `mappend` y = LTypeAnn t $ x `mappend` y
297 In (GuardNode e n ps t ts) `mappend` y = In $ GuardNode e n ps t (ts `mappend` y) 299 In (GuardNode e n ps t ts) `mappend` y = In $ GuardNode e n ps t (ts `mappend` y)
298 In GTFailure `mappend` y = y 300 In GTFailure `mappend` y = y
299 x@(In GTSuccess{}) `mappend` _ = x 301 x@(In GTSuccess{}) `mappend` _ = x
302#else
303instance Semigroup GuardTrees where
304 LLet sn e x <> y = LLet sn e $ x <> rUp 1 0 y
305 LTypeAnn t x <> y = LTypeAnn t $ x <> y
306 In (GuardNode e n ps t ts) <> y = In $ GuardNode e n ps t (ts <> y)
307 In GTFailure <> y = y
308 x@(In GTSuccess{}) <> _ = x
309#endif
300 310
301noGuards :: SExp -> GuardTrees 311noGuards :: SExp -> GuardTrees
302noGuards = In . GTSuccess 312noGuards = In . GTSuccess
diff --git a/src/LambdaCube/Compiler/Pretty.hs b/src/LambdaCube/Compiler/Pretty.hs
index 24e540dd..2f333e85 100644
--- a/src/LambdaCube/Compiler/Pretty.hs
+++ b/src/LambdaCube/Compiler/Pretty.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE DeriveGeneric #-} 2{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE OverloadedStrings #-} 3{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE NoMonomorphismRestriction #-} 4{-# LANGUAGE NoMonomorphismRestriction #-}
@@ -101,7 +102,12 @@ pattern DText s = DAtom (SimpleAtom s)
101 102
102instance Monoid Doc where 103instance Monoid Doc where
103 mempty = text "" 104 mempty = text ""
105#if !MIN_VERSION_base(4,11,0)
104 mappend = dTwo mappend 106 mappend = dTwo mappend
107#else
108instance Semigroup Doc where
109 (<>) = dTwo (<>)
110#endif
105 111
106instance Show Doc where 112instance Show Doc where
107 show = ($ "") . P.displayS . P.renderPretty 0.4 200 . renderDoc 113 show = ($ "") . P.displayS . P.renderPretty 0.4 200 . renderDoc
diff --git a/src/LambdaCube/Compiler/Utils.hs b/src/LambdaCube/Compiler/Utils.hs
index 4e9eab27..42a63843 100644
--- a/src/LambdaCube/Compiler/Utils.hs
+++ b/src/LambdaCube/Compiler/Utils.hs
@@ -24,7 +24,6 @@ import Control.Monad.RWS
24import System.Directory 24import System.Directory
25import qualified Data.Text.IO as TIO 25import qualified Data.Text.IO as TIO
26import qualified Text.Megaparsec as P 26import qualified Text.Megaparsec as P
27import qualified Text.Megaparsec.Prim as P
28 27
29------------------------------------------------------- general functions 28------------------------------------------------------- general functions
30 29