diff options
Diffstat (limited to 'src/LambdaCube/Compiler/Parser.hs')
-rw-r--r-- | src/LambdaCube/Compiler/Parser.hs | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/src/LambdaCube/Compiler/Parser.hs b/src/LambdaCube/Compiler/Parser.hs index 8430caa7..277f67b1 100644 --- a/src/LambdaCube/Compiler/Parser.hs +++ b/src/LambdaCube/Compiler/Parser.hs | |||
@@ -15,7 +15,7 @@ module LambdaCube.Compiler.Parser | |||
15 | , pattern SVar, pattern SType, pattern Wildcard, pattern SAppV, pattern SLamV, pattern SAnn | 15 | , pattern SVar, pattern SType, pattern Wildcard, pattern SAppV, pattern SLamV, pattern SAnn |
16 | , pattern SBuiltin, pattern SPi, pattern Primitive, pattern SLabelEnd, pattern SLam, pattern Parens | 16 | , pattern SBuiltin, pattern SPi, pattern Primitive, pattern SLabelEnd, pattern SLam, pattern Parens |
17 | , pattern TyType, pattern Wildcard_ | 17 | , pattern TyType, pattern Wildcard_ |
18 | , debug, isPi, varDB, lowerDB, upDB, notClosed, cmpDB, MaxDB(..), iterateN, traceD | 18 | , debug, isPi, varDB, lowerDB, upDB, cmpDB, MaxDB(..), iterateN, traceD |
19 | , parseLC, runDefParser | 19 | , parseLC, runDefParser |
20 | , getParamsS, addParamsS, getApps, apps', downToS, addForalls | 20 | , getParamsS, addParamsS, getApps, apps', downToS, addForalls |
21 | , Up (..), up1, up | 21 | , Up (..), up1, up |
@@ -176,27 +176,56 @@ instance SetSourceInfo (SExp' a) where | |||
176 | 176 | ||
177 | -------------------------------------------------------------------------------- De-Bruijn limit | 177 | -------------------------------------------------------------------------------- De-Bruijn limit |
178 | 178 | ||
179 | newtype MaxDB = MaxDB {getMaxDB :: Bool} -- True: closed | 179 | newtype MaxDB = MaxDB {getMaxDB :: Int} -- True: closed |
180 | 180 | ||
181 | instance Monoid MaxDB where | 181 | instance Monoid MaxDB where |
182 | mempty = MaxDB True | 182 | mempty = MaxDB 0 |
183 | MaxDB a `mappend` MaxDB a' = MaxDB $ a && a' -- $ Just $ max (fromMaybe 0 a) (fromMaybe 0 a') | 183 | MaxDB a `mappend` MaxDB a' = MaxDB $ max a a' |
184 | where | ||
185 | max 0 x = x | ||
186 | max _ _ = 1 -- | ||
184 | 187 | ||
185 | instance Show MaxDB where show _ = "MaxDB" | 188 | instance Show MaxDB where show _ = "MaxDB" |
186 | 189 | ||
187 | varDB i = MaxDB False | 190 | varDB i = MaxDB 1 -- |
191 | |||
192 | lowerDB = id -- | ||
193 | |||
194 | cmpDB _ (maxDB_ -> MaxDB x) = x == 0 | ||
195 | |||
196 | upDB _ (MaxDB 0) = MaxDB 0 | ||
197 | upDB x (MaxDB i) = MaxDB $ x + i | ||
198 | {- | ||
199 | data Na = Ze | Su Na | ||
200 | |||
201 | newtype MaxDB = MaxDB {getMaxDB :: Na} -- True: closed | ||
188 | 202 | ||
189 | lowerDB = id | 203 | instance Monoid MaxDB where |
204 | mempty = MaxDB Ze | ||
205 | MaxDB a `mappend` MaxDB a' = MaxDB $ max a a' | ||
206 | where | ||
207 | max Ze x = x | ||
208 | max (Su i) x = Su $ case x of | ||
209 | Ze -> i | ||
210 | Su j -> max i j | ||
211 | |||
212 | instance Show MaxDB where show _ = "MaxDB" | ||
190 | 213 | ||
191 | -- 0 means that no free variable is used | 214 | varDB i = MaxDB $ Su $ fr i |
192 | -- 1 means that only var 0 is used | 215 | where |
193 | --cmpDB i e = i >= maxDB e | 216 | fr 0 = Ze |
194 | cmpDB _ (maxDB_ -> MaxDB x) = x --isNothing x | 217 | fr i = Su $ fr $ i-1 |
195 | 218 | ||
196 | upDB n = id --(MaxDB i) = MaxDB $ (\x -> if x == 0 then x else x+n) $ i | 219 | lowerDB (MaxDB Ze) = MaxDB Ze |
220 | lowerDB (MaxDB (Su i)) = MaxDB i | ||
197 | 221 | ||
198 | notClosed = MaxDB False | 222 | cmpDB _ (maxDB_ -> MaxDB x) = case x of Ze -> True; _ -> False -- == 0 |
199 | 223 | ||
224 | upDB _ (MaxDB Ze) = MaxDB Ze | ||
225 | upDB x (MaxDB i) = MaxDB $ ad x i where | ||
226 | ad 0 i = i | ||
227 | ad n i = Su $ ad (n-1) i | ||
228 | -} | ||
200 | -------------------------------------------------------------------------------- low-level toolbox | 229 | -------------------------------------------------------------------------------- low-level toolbox |
201 | 230 | ||
202 | class Up a where | 231 | class Up a where |