0 | module Language.Reflection.TT
2 | import public Data.List
3 | import public Data.String
5 | import Decidable.Equality
10 | data Namespace = MkNS (List String)
15 | data ModuleIdent = MkMI (List String)
17 | %name ModuleIdent
mi
20 | showSep : String -> List String -> String
23 | showSep sep (x :: xs) = x ++ sep ++ showSep sep xs
26 | Show Namespace where
27 | show (MkNS ns) = showSep "." (reverse ns)
34 | FilePos = (Int, Int)
37 | data VirtualIdent : Type where
38 | Interactive : VirtualIdent
41 | data OriginDesc : Type where
45 | PhysicalIdrSrc : (ident : ModuleIdent) -> OriginDesc
48 | PhysicalPkgSrc : (fname : String) -> OriginDesc
49 | Virtual : (ident : VirtualIdent) -> OriginDesc
51 | %name OriginDesc
origin
58 | data FC = MkFC OriginDesc FilePos FilePos
61 | MkVirtualFC OriginDesc FilePos FilePos
73 | record WithFC (ty : Type) where
80 | NoFC : a -> WithFC a
81 | NoFC = MkFCVal EmptyFC
84 | Functor WithFC where
85 | map f = { value $= f}
88 | Foldable WithFC where
89 | foldr f i v = f v.value i
92 | Traversable WithFC where
93 | traverse f (MkFCVal fc val) = map (MkFCVal fc) (f val)
97 | Eq a => Eq (WithFC a) where
98 | x == y = x.value == y.value
102 | Ord a => Ord (WithFC a) where
103 | compare x y = compare x.value y.value
106 | data NameType : Type where
109 | DataCon : (tag : Int) -> (arity : Nat) -> NameType
110 | TyCon : (tag : Int) -> (arity : Nat) -> NameType
155 | Show PrimType where
156 | show IntType = "Int"
157 | show IntegerType = "Integer"
158 | show Int8Type = "Int8"
159 | show Int16Type = "Int16"
160 | show Int32Type = "Int32"
161 | show Int64Type = "Int64"
162 | show Bits8Type = "Bits8"
163 | show Bits16Type = "Bits16"
164 | show Bits32Type = "Bits32"
165 | show Bits64Type = "Bits64"
166 | show StringType = "String"
167 | show CharType = "Char"
168 | show DoubleType = "Double"
169 | show WorldType = "%World"
172 | Show Constant where
173 | show (I x) = show x
174 | show (BI x) = show x
175 | show (I8 x) = show x
176 | show (I16 x) = show x
177 | show (I32 x) = show x
178 | show (I64 x) = show x
179 | show (B8 x) = show x
180 | show (B16 x) = show x
181 | show (B32 x) = show x
182 | show (B64 x) = show x
183 | show (Str x) = show x
184 | show (Ch x) = show x
185 | show (Db x) = show x
186 | show (PrT x) = show x
187 | show WorldVal = "%World"
198 | data Name = NS Namespace Name
202 | | Nested (Int, Int) Name
203 | | CaseBlock String Int
204 | | WithBlock String Int
211 | fromName : Name -> Name
215 | dropNS : Name -> Name
216 | dropNS (NS _ n) = dropNS n
220 | isOp : Name -> Bool
221 | isOp nm = case dropNS nm of
222 | UN (Basic n) => case strM n of
223 | StrCons c _ => not (isAlpha c)
228 | Show UserName where
230 | show (Field n) = "." ++ n
231 | show Underscore = "_"
234 | showPrefix : Bool -> Name -> String
235 | showPrefix b nm@(UN un) = showParens (b && isOp nm) (show un)
236 | showPrefix b (NS ns n) = show ns ++ "." ++ showPrefix True n
237 | showPrefix b (MN x y) = "{" ++ x ++ ":" ++ show y ++ "}"
238 | showPrefix b (DN str y) = str
239 | showPrefix b (Nested (outer, idx) inner)
240 | = show outer ++ ":" ++ show idx ++ ":" ++ showPrefix False inner
241 | showPrefix b (CaseBlock outer i) = "case block in " ++ show outer
242 | showPrefix b (WithBlock outer i) = "with block in " ++ show outer
246 | show = showPrefix False
249 | record NameInfo where
250 | constructor MkNameInfo
251 | nametype : NameType
254 | data Count = M0 | M1 | MW
258 | enunciate : Count -> String
259 | enunciate M0 = "runtime irrelevant"
260 | enunciate M1 = "linear"
261 | enunciate MW = "unconstrained"
264 | showCount : Count -> String -> String
265 | showCount M0 s = "0 \{s}"
266 | showCount M1 s = "1 \{s}"
270 | data PiInfo t = ImplicitArg | ExplicitArg | AutoImplicit | DefImplicit t
274 | Functor PiInfo where
275 | map f ImplicitArg = ImplicitArg
276 | map f ExplicitArg = ExplicitArg
277 | map f AutoImplicit = AutoImplicit
278 | map f $
DefImplicit x = DefImplicit $
f x
281 | showPiInfo : Show a => {default True wrapExplicit : Bool} -> PiInfo a -> String -> String
282 | showPiInfo ImplicitArg s = "{\{s}}"
283 | showPiInfo ExplicitArg s = if wrapExplicit then "(\{s})" else s
284 | showPiInfo AutoImplicit s = "{auto \{s}}"
285 | showPiInfo (DefImplicit t) s = "{default \{assert_total $ showPrec App t} \{s}}"
288 | data IsVar : Name -> Nat -> List Name -> Type where
289 | First : IsVar n Z (n :: ns)
290 | Later : IsVar n i ns -> IsVar n (S i) (m :: ns)
294 | data LazyReason = LInf | LLazy | LUnknown
295 | %name LazyReason
lr
298 | Show LazyReason where
300 | show LLazy = "Lazy"
301 | show LUnknown = "Unknown"
304 | data TotalReq = Total | CoveringOnly | PartialOK
305 | %name TotalReq
treq
308 | Show TotalReq where
309 | show Total = "total"
310 | show CoveringOnly = "covering"
311 | show PartialOK = "partial"
314 | showTotalReq : Maybe TotalReq -> String -> String
315 | showTotalReq Nothing s = s
316 | showTotalReq (Just treq) s = unwords [show treq, s]
319 | data Visibility = Private | Export | Public
320 | %name Visibility
vis
323 | Show Visibility where
324 | show Private = "private"
325 | show Export = "export"
326 | show Public = "public export"
329 | data BuiltinType = BuiltinNatural | NaturalToInteger | IntegerToNatural
330 | %name BuiltinType
bty
333 | Show BuiltinType where
334 | show BuiltinNatural = "Natural"
335 | show NaturalToInteger = "NaturalToInteger"
336 | show IntegerToNatural = "IntegerToNatural"
340 | Total == Total = True
341 | CoveringOnly == CoveringOnly = True
342 | PartialOK == PartialOK = True
346 | Eq Visibility where
347 | Private == Private = True
348 | Export == Export = True
349 | Public == Public = True
353 | Eq BuiltinType where
354 | BuiltinNatural == BuiltinNatural = True
355 | NaturalToInteger == NaturalToInteger = True
356 | IntegerToNatural == IntegerToNatural = True
361 | Eq LazyReason where
362 | LInf == LInf = True
363 | LLazy == LLazy = True
364 | LUnknown == LUnknown = True
369 | MkNS ns == MkNS ns' = ns == ns'
380 | Basic n == Basic n' = n == n'
381 | Field n == Field n' = n == n'
382 | Underscore == Underscore = True
387 | NS ns n == NS ns' n' = ns == ns' && n == n'
388 | UN n == UN n' = n == n'
389 | MN n i == MN n' i' = n == n' && i == i'
390 | DN _ n == DN _ n' = n == n'
391 | Nested i n == Nested i' n' = i == i' && n == n'
392 | CaseBlock n i == CaseBlock n' i' = n == n' && i == i'
393 | WithBlock n i == WithBlock n' i' = n == n' && i == i'
398 | IntType == IntType = True
399 | IntegerType == IntegerType = True
400 | Int8Type == Int8Type = True
401 | Int16Type == Int16Type = True
402 | Int32Type == Int32Type = True
403 | Int64Type == Int64Type = True
404 | Bits8Type == Bits8Type = True
405 | Bits16Type == Bits16Type = True
406 | Bits32Type == Bits32Type = True
407 | Bits64Type == Bits64Type = True
408 | StringType == StringType = True
409 | CharType == CharType = True
410 | DoubleType == DoubleType = True
411 | WorldType == WorldType = True
416 | I c == I c' = c == c'
417 | BI c == BI c' = c == c'
418 | I8 c == I8 c' = c == c'
419 | I16 c == I16 c' = c == c'
420 | I32 c == I32 c' = c == c'
421 | I64 c == I64 c' = c == c'
422 | B8 c == B8 c' = c == c'
423 | B16 c == B16 c' = c == c'
424 | B32 c == B32 c' = c == c'
425 | B64 c == B64 c' = c == c'
426 | Str c == Str c' = c == c'
427 | Ch c == Ch c' = c == c'
428 | Db c == Db c' = c == c'
429 | PrT t == PrT t' = t == t'
430 | WorldVal == WorldVal = True
434 | Ord Namespace where
435 | compare (MkNS ms) (MkNS ns) = compare ms ns
447 | usernameTag : UserName -> Int
448 | usernameTag (Basic _) = 0
449 | usernameTag (Field _) = 1
450 | usernameTag Underscore = 2
454 | compare (Basic x) (Basic y) = compare x y
455 | compare (Field x) (Field y) = compare x y
456 | compare Underscore Underscore = EQ
457 | compare x y = compare (usernameTag x) (usernameTag y)
459 | nameTag : Name -> Int
460 | nameTag (NS _ _) = 0
462 | nameTag (MN _ _) = 2
463 | nameTag (DN _ _) = 3
464 | nameTag (Nested _ _) = 4
465 | nameTag (CaseBlock _ _) = 5
466 | nameTag (WithBlock _ _) = 6
470 | compare (NS x y) (NS x' y')
471 | = case compare y y' of
477 | compare (UN x) (UN y) = compare x y
478 | compare (MN x y) (MN x' y')
479 | = case compare y y' of
483 | compare (DN _ n) (DN _ n') = compare n n'
484 | compare (Nested x y) (Nested x' y')
485 | = case compare y y' of
489 | compare (CaseBlock x y) (CaseBlock x' y')
490 | = case compare y y' of
494 | compare (WithBlock x y) (WithBlock x' y')
495 | = case compare y y' of
500 | compare x y = compare (nameTag x) (nameTag y)
502 | export Injective MkNS where injective Refl = Refl
505 | DecEq Namespace where
506 | decEq (MkNS ns) (MkNS ns') = decEqCong (decEq ns ns')
508 | export Injective Basic where injective Refl = Refl
509 | export Injective Field where injective Refl = Refl
512 | DecEq UserName where
513 | decEq (Basic str) (Basic str1) = decEqCong (decEq str str1)
514 | decEq (Basic str) (Field str1) = No (\case Refl
impossible)
515 | decEq (Basic str) Underscore = No (\case Refl
impossible)
516 | decEq (Field str) (Basic str1) = No (\case Refl
impossible)
517 | decEq (Field str) (Field str1) = decEqCong (decEq str str1)
518 | decEq (Field str) Underscore = No (\case Refl
impossible)
519 | decEq Underscore (Basic str) = No (\case Refl
impossible)
520 | decEq Underscore (Field str) = No (\case Refl
impossible)
521 | decEq Underscore Underscore = Yes Refl
523 | export Biinjective NS where biinjective Refl = (Refl, Refl)
524 | export Injective UN where injective Refl = Refl
525 | export Biinjective MN where biinjective Refl = (Refl, Refl)
526 | export Biinjective DN where biinjective Refl = (Refl, Refl)
527 | export Biinjective Nested where biinjective Refl = (Refl, Refl)
528 | export Biinjective CaseBlock where biinjective Refl = (Refl, Refl)
529 | export Biinjective WithBlock where biinjective Refl = (Refl, Refl)
533 | decEq (NS ns nm) (NS ns1 nm1) = decEqCong2 (decEq ns ns1) (decEq nm nm1)
534 | decEq (NS ns nm) (UN un) = No (\case Refl
impossible)
535 | decEq (NS ns nm) (MN str i) = No (\case Refl
impossible)
536 | decEq (NS ns nm) (DN str nm1) = No (\case Refl
impossible)
537 | decEq (NS ns nm) (Nested x nm1) = No (\case Refl
impossible)
538 | decEq (NS ns nm) (CaseBlock str i) = No (\case Refl
impossible)
539 | decEq (NS ns nm) (WithBlock str i) = No (\case Refl
impossible)
540 | decEq (UN un) (NS ns nm) = No (\case Refl
impossible)
541 | decEq (UN un) (UN un1) = decEqCong (decEq un un1)
542 | decEq (UN un) (MN str i) = No (\case Refl
impossible)
543 | decEq (UN un) (DN str nm) = No (\case Refl
impossible)
544 | decEq (UN un) (Nested x nm) = No (\case Refl
impossible)
545 | decEq (UN un) (CaseBlock str i) = No (\case Refl
impossible)
546 | decEq (UN un) (WithBlock str i) = No (\case Refl
impossible)
547 | decEq (MN str i) (NS ns nm) = No (\case Refl
impossible)
548 | decEq (MN str i) (UN un) = No (\case Refl
impossible)
549 | decEq (MN str i) (MN str1 j) = decEqCong2 (decEq str str1) (decEq i j)
550 | decEq (MN str i) (DN str1 nm) = No (\case Refl
impossible)
551 | decEq (MN str i) (Nested x nm) = No (\case Refl
impossible)
552 | decEq (MN str i) (CaseBlock str1 j) = No (\case Refl
impossible)
553 | decEq (MN str i) (WithBlock str1 j) = No (\case Refl
impossible)
554 | decEq (DN str nm) (NS ns nm1) = No (\case Refl
impossible)
555 | decEq (DN str nm) (UN un) = No (\case Refl
impossible)
556 | decEq (DN str nm) (MN str1 i) = No (\case Refl
impossible)
557 | decEq (DN str nm) (DN str1 nm1) = decEqCong2 (decEq str str1) (decEq nm nm1)
558 | decEq (DN str nm) (Nested x nm1) = No (\case Refl
impossible)
559 | decEq (DN str nm) (CaseBlock str1 i) = No (\case Refl
impossible)
560 | decEq (DN str nm) (WithBlock str1 i) = No (\case Refl
impossible)
561 | decEq (Nested x nm) (NS ns nm1) = No (\case Refl
impossible)
562 | decEq (Nested x nm) (UN un) = No (\case Refl
impossible)
563 | decEq (Nested x nm) (MN str i) = No (\case Refl
impossible)
564 | decEq (Nested x nm) (DN str nm1) = No (\case Refl
impossible)
565 | decEq (Nested x nm) (Nested y nm1) = decEqCong2 (decEq x y) (decEq nm nm1)
566 | decEq (Nested x nm) (CaseBlock str i) = No (\case Refl
impossible)
567 | decEq (Nested x nm) (WithBlock str i) = No (\case Refl
impossible)
568 | decEq (CaseBlock str i) (NS ns nm) = No (\case Refl
impossible)
569 | decEq (CaseBlock str i) (UN un) = No (\case Refl
impossible)
570 | decEq (CaseBlock str i) (MN str1 j) = No (\case Refl
impossible)
571 | decEq (CaseBlock str i) (DN str1 nm) = No (\case Refl
impossible)
572 | decEq (CaseBlock str i) (Nested x nm) = No (\case Refl
impossible)
573 | decEq (CaseBlock str i) (CaseBlock str1 j) = decEqCong2 (decEq str str1) (decEq i j)
574 | decEq (CaseBlock str i) (WithBlock str1 j) = No (\case Refl
impossible)
575 | decEq (WithBlock str i) (NS ns nm) = No (\case Refl
impossible)
576 | decEq (WithBlock str i) (UN un) = No (\case Refl
impossible)
577 | decEq (WithBlock str i) (MN str1 j) = No (\case Refl
impossible)
578 | decEq (WithBlock str i) (DN str1 nm) = No (\case Refl
impossible)
579 | decEq (WithBlock str i) (Nested x nm) = No (\case Refl
impossible)
580 | decEq (WithBlock str i) (CaseBlock str1 j) = No (\case Refl
impossible)
581 | decEq (WithBlock str i) (WithBlock str1 j) = decEqCong2 (decEq str str1) (decEq i j)