summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-05-12 02:25:01 +0200
committerPéter Diviánszky <divipp@gmail.com>2016-05-12 02:25:01 +0200
commit7acd3bbffbf87f88d0b3510f44ff1c5b35cfd9d6 (patch)
tree2076fc3378d5d4cae1af3c5b2ac7d03f5510b11f
parent18ea057b94fbcce585314d661f8c0533a4c0c4f6 (diff)
refactoring
-rw-r--r--src/LambdaCube/Compiler/DeBruijn.hs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/LambdaCube/Compiler/DeBruijn.hs b/src/LambdaCube/Compiler/DeBruijn.hs
index 8244a5d0..7d3e2679 100644
--- a/src/LambdaCube/Compiler/DeBruijn.hs
+++ b/src/LambdaCube/Compiler/DeBruijn.hs
@@ -76,7 +76,7 @@ freeVar :: Int -> FreeVars
76freeVar i = FreeVars $ 1 `shiftL` i 76freeVar i = FreeVars $ 1 `shiftL` i
77 77
78delVar :: Int -> FreeVars -> FreeVars 78delVar :: Int -> FreeVars -> FreeVars
79delVar i = appFreeVars i (`shiftR` 1) 79delVar l (FreeVars i) = FreeVars $ (i `shiftR` (l+1) `shiftL` l) .|. (i .&. ((1 `shiftL` l)-1))
80 80
81shiftFreeVars :: Int -> FreeVars -> FreeVars 81shiftFreeVars :: Int -> FreeVars -> FreeVars
82shiftFreeVars i (FreeVars x) = FreeVars $ x `shift` i 82shiftFreeVars i (FreeVars x) = FreeVars $ x `shift` i
@@ -92,12 +92,13 @@ isClosed (FreeVars x) = x == 0
92 92
93lowerFreeVars = shiftFreeVars (-1) 93lowerFreeVars = shiftFreeVars (-1)
94 94
95rearrangeFreeVars g l = appFreeVars l $ case g of 95rearrangeFreeVars g l (FreeVars i) = FreeVars $ case g of
96 RFUp n -> (`shiftL` n) 96 RFUp n -> (i `shiftR` l `shiftL` (n+l)) .|. (i .&. ((1 `shiftL` l)-1))
97 RFMove n -> \x -> if testBit x n then (clearBit x n `shiftL` 1) `setBit` 0 else x `shiftL` 1 97 RFMove n -> (f $ i `shiftR` l `shiftL` (l+1)) .|. (i .&. ((1 `shiftL` l)-1))
98 where
99 f x = if testBit x (n+l+1) then x `clearBit` (n+l+1) `setBit` l else x
98 _ -> error $ "rearrangeFreeVars: " ++ show g 100 _ -> error $ "rearrangeFreeVars: " ++ show g
99 101
100appFreeVars l f (FreeVars i) = FreeVars $ (f (i `shiftR` l) `shiftL` l) .|. (i .&. (2^l-1))
101 102
102-- TODO: rename 103-- TODO: rename
103dbGE i (getFreeVars -> FreeVars x) = (x `shiftR` i) == 0 104dbGE i (getFreeVars -> FreeVars x) = (x `shiftR` i) == 0