summaryrefslogtreecommitdiff
path: root/src/LambdaCube/Compiler/Parser.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/LambdaCube/Compiler/Parser.hs')
-rw-r--r--src/LambdaCube/Compiler/Parser.hs53
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
179newtype MaxDB = MaxDB {getMaxDB :: Bool} -- True: closed 179newtype MaxDB = MaxDB {getMaxDB :: Int} -- True: closed
180 180
181instance Monoid MaxDB where 181instance 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
185instance Show MaxDB where show _ = "MaxDB" 188instance Show MaxDB where show _ = "MaxDB"
186 189
187varDB i = MaxDB False 190varDB i = MaxDB 1 --
191
192lowerDB = id --
193
194cmpDB _ (maxDB_ -> MaxDB x) = x == 0
195
196upDB _ (MaxDB 0) = MaxDB 0
197upDB x (MaxDB i) = MaxDB $ x + i
198{-
199data Na = Ze | Su Na
200
201newtype MaxDB = MaxDB {getMaxDB :: Na} -- True: closed
188 202
189lowerDB = id 203instance 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
212instance Show MaxDB where show _ = "MaxDB"
190 213
191-- 0 means that no free variable is used 214varDB 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
194cmpDB _ (maxDB_ -> MaxDB x) = x --isNothing x 217 fr i = Su $ fr $ i-1
195 218
196upDB n = id --(MaxDB i) = MaxDB $ (\x -> if x == 0 then x else x+n) $ i 219lowerDB (MaxDB Ze) = MaxDB Ze
220lowerDB (MaxDB (Su i)) = MaxDB i
197 221
198notClosed = MaxDB False 222cmpDB _ (maxDB_ -> MaxDB x) = case x of Ze -> True; _ -> False -- == 0
199 223
224upDB _ (MaxDB Ze) = MaxDB Ze
225upDB 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
202class Up a where 231class Up a where