diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-09 15:03:32 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-09 15:03:32 +0200 |
commit | 735a3afaf84c47bed66e9da23cd04fd275a3e2a9 (patch) | |
tree | e4d7ff59bd0cf61a2c85e9e9338ce54bea8d46ec | |
parent | 9e24de1e2da956665e82418d8880d3d7ab96bce3 (diff) |
simplification
-rw-r--r-- | lambdacube-compiler.cabal | 3 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Utils.hs | 18 |
2 files changed, 9 insertions, 12 deletions
diff --git a/lambdacube-compiler.cabal b/lambdacube-compiler.cabal index c97c2196..9912743d 100644 --- a/lambdacube-compiler.cabal +++ b/lambdacube-compiler.cabal | |||
@@ -86,7 +86,6 @@ library | |||
86 | mtl >=2.2 && <2.3, | 86 | mtl >=2.2 && <2.3, |
87 | megaparsec >= 4.4.0 && <4.5, | 87 | megaparsec >= 4.4.0 && <4.5, |
88 | ansi-wl-pprint >=0.6 && <0.7, | 88 | ansi-wl-pprint >=0.6 && <0.7, |
89 | bv >= 0.4 && <0.5, | ||
90 | pretty-show >= 1.6.9, | 89 | pretty-show >= 1.6.9, |
91 | text >= 1.2 && <1.3, | 90 | text >= 1.2 && <1.3, |
92 | lambdacube-ir == 0.4.*, | 91 | lambdacube-ir == 0.4.*, |
@@ -140,7 +139,6 @@ executable lambdacube-compiler-test-suite | |||
140 | optparse-applicative == 0.12.*, | 139 | optparse-applicative == 0.12.*, |
141 | megaparsec >= 4.3.0 && <4.5, | 140 | megaparsec >= 4.3.0 && <4.5, |
142 | ansi-wl-pprint >=0.6 && <0.7, | 141 | ansi-wl-pprint >=0.6 && <0.7, |
143 | bv >= 0.4 && <0.5, | ||
144 | patience >= 0.1 && < 0.2, | 142 | patience >= 0.1 && < 0.2, |
145 | text >= 1.2 && <1.3, | 143 | text >= 1.2 && <1.3, |
146 | time >= 1.5 && <1.6, | 144 | time >= 1.5 && <1.6, |
@@ -249,7 +247,6 @@ executable lambdacube-compiler-coverage-test-suite | |||
249 | optparse-applicative == 0.12.*, | 247 | optparse-applicative == 0.12.*, |
250 | megaparsec >= 4.3.0 && <4.5, | 248 | megaparsec >= 4.3.0 && <4.5, |
251 | ansi-wl-pprint >=0.6 && <0.7, | 249 | ansi-wl-pprint >=0.6 && <0.7, |
252 | bv >= 0.4 && <0.5, | ||
253 | pretty-show >= 1.6.9, | 250 | pretty-show >= 1.6.9, |
254 | patience >= 0.1 && < 0.2, | 251 | patience >= 0.1 && < 0.2, |
255 | text >= 1.2 && <1.3, | 252 | text >= 1.2 && <1.3, |
diff --git a/src/LambdaCube/Compiler/Utils.hs b/src/LambdaCube/Compiler/Utils.hs index c5f02fd7..1909f271 100644 --- a/src/LambdaCube/Compiler/Utils.hs +++ b/src/LambdaCube/Compiler/Utils.hs | |||
@@ -17,7 +17,7 @@ import System.Directory | |||
17 | import qualified Data.Text.IO as TIO | 17 | import qualified Data.Text.IO as TIO |
18 | import qualified Text.Megaparsec as P | 18 | import qualified Text.Megaparsec as P |
19 | import qualified Text.Megaparsec.Prim as P | 19 | import qualified Text.Megaparsec.Prim as P |
20 | import qualified Data.BitVector as BV | 20 | import Data.Bits |
21 | 21 | ||
22 | ------------------------------------------------------- general functions | 22 | ------------------------------------------------------- general functions |
23 | 23 | ||
@@ -89,26 +89,26 @@ scc key children revChildren | |||
89 | 89 | ||
90 | ------------------------------------------------------- set of free variables (implemented with bit vectors) | 90 | ------------------------------------------------------- set of free variables (implemented with bit vectors) |
91 | 91 | ||
92 | newtype FreeVars = FreeVars BV.BV | 92 | newtype FreeVars = FreeVars Integer |
93 | 93 | ||
94 | instance Monoid FreeVars where | 94 | instance Monoid FreeVars where |
95 | mempty = FreeVars mempty | 95 | mempty = FreeVars 0 |
96 | FreeVars a `mappend` FreeVars b = FreeVars $ BV.or [a, b] | 96 | FreeVars a `mappend` FreeVars b = FreeVars $ a .|. b |
97 | 97 | ||
98 | freeVar :: Int -> FreeVars | 98 | freeVar :: Int -> FreeVars |
99 | freeVar i = FreeVars $ BV.ones 1 <> BV.zeros i | 99 | freeVar i = FreeVars $ 1 `shiftL` i |
100 | 100 | ||
101 | shiftFreeVars :: Int -> FreeVars -> FreeVars | 101 | shiftFreeVars :: Int -> FreeVars -> FreeVars |
102 | shiftFreeVars i (FreeVars x) = FreeVars $ x <> BV.zeros i | 102 | shiftFreeVars i (FreeVars x) = FreeVars $ x `shift` i |
103 | 103 | ||
104 | isFreeVar :: FreeVars -> Int -> Bool | 104 | isFreeVar :: FreeVars -> Int -> Bool |
105 | isFreeVar (FreeVars x) i = if i < BV.size x then BV.index i x else False | 105 | isFreeVar (FreeVars x) i = testBit x i |
106 | 106 | ||
107 | freeVars :: FreeVars -> [Int] | 107 | freeVars :: FreeVars -> [Int] |
108 | freeVars (FreeVars x) = [i | i <- [0..BV.size x-1], BV.index i x] | 108 | freeVars (FreeVars x) = take (popCount x) [i | i <- [0..], testBit x i] |
109 | 109 | ||
110 | isClosed :: FreeVars -> Bool | 110 | isClosed :: FreeVars -> Bool |
111 | isClosed (FreeVars x) = BV.nat x == 0 | 111 | isClosed (FreeVars x) = x == 0 |
112 | 112 | ||
113 | 113 | ||
114 | ------------------------------------------------------- wrapped pretty show | 114 | ------------------------------------------------------- wrapped pretty show |