diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-12 02:25:01 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-12 02:25:01 +0200 |
commit | 7acd3bbffbf87f88d0b3510f44ff1c5b35cfd9d6 (patch) | |
tree | 2076fc3378d5d4cae1af3c5b2ac7d03f5510b11f | |
parent | 18ea057b94fbcce585314d661f8c0533a4c0c4f6 (diff) |
refactoring
-rw-r--r-- | src/LambdaCube/Compiler/DeBruijn.hs | 11 |
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 | |||
76 | freeVar i = FreeVars $ 1 `shiftL` i | 76 | freeVar i = FreeVars $ 1 `shiftL` i |
77 | 77 | ||
78 | delVar :: Int -> FreeVars -> FreeVars | 78 | delVar :: Int -> FreeVars -> FreeVars |
79 | delVar i = appFreeVars i (`shiftR` 1) | 79 | delVar l (FreeVars i) = FreeVars $ (i `shiftR` (l+1) `shiftL` l) .|. (i .&. ((1 `shiftL` l)-1)) |
80 | 80 | ||
81 | shiftFreeVars :: Int -> FreeVars -> FreeVars | 81 | shiftFreeVars :: Int -> FreeVars -> FreeVars |
82 | shiftFreeVars i (FreeVars x) = FreeVars $ x `shift` i | 82 | shiftFreeVars i (FreeVars x) = FreeVars $ x `shift` i |
@@ -92,12 +92,13 @@ isClosed (FreeVars x) = x == 0 | |||
92 | 92 | ||
93 | lowerFreeVars = shiftFreeVars (-1) | 93 | lowerFreeVars = shiftFreeVars (-1) |
94 | 94 | ||
95 | rearrangeFreeVars g l = appFreeVars l $ case g of | 95 | rearrangeFreeVars 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 | ||
100 | appFreeVars l f (FreeVars i) = FreeVars $ (f (i `shiftR` l) `shiftL` l) .|. (i .&. (2^l-1)) | ||
101 | 102 | ||
102 | -- TODO: rename | 103 | -- TODO: rename |
103 | dbGE i (getFreeVars -> FreeVars x) = (x `shiftR` i) == 0 | 104 | dbGE i (getFreeVars -> FreeVars x) = (x `shiftR` i) == 0 |