summaryrefslogtreecommitdiff
path: root/src/LambdaCube
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-05-09 15:03:32 +0200
committerPéter Diviánszky <divipp@gmail.com>2016-05-09 15:03:32 +0200
commit735a3afaf84c47bed66e9da23cd04fd275a3e2a9 (patch)
treee4d7ff59bd0cf61a2c85e9e9338ce54bea8d46ec /src/LambdaCube
parent9e24de1e2da956665e82418d8880d3d7ab96bce3 (diff)
simplification
Diffstat (limited to 'src/LambdaCube')
-rw-r--r--src/LambdaCube/Compiler/Utils.hs18
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
17import qualified Data.Text.IO as TIO 17import qualified Data.Text.IO as TIO
18import qualified Text.Megaparsec as P 18import qualified Text.Megaparsec as P
19import qualified Text.Megaparsec.Prim as P 19import qualified Text.Megaparsec.Prim as P
20import qualified Data.BitVector as BV 20import 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
92newtype FreeVars = FreeVars BV.BV 92newtype FreeVars = FreeVars Integer
93 93
94instance Monoid FreeVars where 94instance 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
98freeVar :: Int -> FreeVars 98freeVar :: Int -> FreeVars
99freeVar i = FreeVars $ BV.ones 1 <> BV.zeros i 99freeVar i = FreeVars $ 1 `shiftL` i
100 100
101shiftFreeVars :: Int -> FreeVars -> FreeVars 101shiftFreeVars :: Int -> FreeVars -> FreeVars
102shiftFreeVars i (FreeVars x) = FreeVars $ x <> BV.zeros i 102shiftFreeVars i (FreeVars x) = FreeVars $ x `shift` i
103 103
104isFreeVar :: FreeVars -> Int -> Bool 104isFreeVar :: FreeVars -> Int -> Bool
105isFreeVar (FreeVars x) i = if i < BV.size x then BV.index i x else False 105isFreeVar (FreeVars x) i = testBit x i
106 106
107freeVars :: FreeVars -> [Int] 107freeVars :: FreeVars -> [Int]
108freeVars (FreeVars x) = [i | i <- [0..BV.size x-1], BV.index i x] 108freeVars (FreeVars x) = take (popCount x) [i | i <- [0..], testBit x i]
109 109
110isClosed :: FreeVars -> Bool 110isClosed :: FreeVars -> Bool
111isClosed (FreeVars x) = BV.nat x == 0 111isClosed (FreeVars x) = x == 0
112 112
113 113
114------------------------------------------------------- wrapped pretty show 114------------------------------------------------------- wrapped pretty show