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 /src | |
parent | 9e24de1e2da956665e82418d8880d3d7ab96bce3 (diff) |
simplification
Diffstat (limited to 'src')
-rw-r--r-- | src/LambdaCube/Compiler/Utils.hs | 18 |
1 files changed, 9 insertions, 9 deletions
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 |