5 | module Language.Reflection.Compat
7 | import public Data.Alternative
8 | import public Data.List.Quantifiers
9 | import public Data.List1
10 | import public Data.String
11 | import public Data.Vect
13 | import public Deriving.Show
15 | import public Language.Reflection
16 | import Language.Reflection.Expr
17 | import Language.Reflection.Logging
18 | import public Language.Reflection.Syntax
19 | import public Language.Reflection.Syntax.Ops
23 | %language ElabReflection
38 | countShow : Show Count
39 | countShow = %runElab derive
42 | piInfoShow : Show a => Show (PiInfo a)
43 | piInfoShow = %runElab derive
47 | argShow = %runElab derive
51 | conShow = %runElab derive
55 | getCon : Elaboration m => Name -> m Con
56 | getCon n = do (n', tt) <- lookupName n
57 | let (args, tpe) = unPi $
cleanupNamedHoles tt
58 | pure $
MkCon n' args tpe
61 | LogPosition Con where
62 | logPosition con = do
63 | let fullName = show con.name
64 | let fullName' = unpack fullName
65 | maybe fullName (pack . flip drop fullName' . S . finToNat) $
findLastIndex (== '.') fullName'
75 | record TypeInfo where
76 | constructor MkTypeInfo
82 | LogPosition TypeInfo where
83 | logPosition = show . name
86 | tiShow : Show TypeInfo
87 | tiShow = %runElab derive
93 | getInfo' : Elaboration m => Name -> m TypeInfo
95 | (n',tt) <- lookupName n
96 | let (args,IType _) = unPi $
cleanupNamedHoles tt
97 | | (_,_) => fail "Type declaration does not end in IType"
98 | conNames <- getCons n'
99 | cons <- traverse getCon conNames
100 | pure (MkTypeInfo n' args cons)
104 | getInfo : Name -> Elab TypeInfo
110 | data ConArgsNamed : Con -> Type where
111 | TheyAreNamed : All IsNamedArg ars -> ConArgsNamed $
MkCon nm ars ty
114 | areConArgsNamed : (con : Con) -> Dec $
ConArgsNamed con
115 | areConArgsNamed $
MkCon _ ars _ with (all isNamedArg ars)
116 | _ | Yes ars' = Yes $
TheyAreNamed ars'
117 | _ | No nars = No $
\(TheyAreNamed ars') => nars ars'
120 | 0 conArgsNamed : (0 _ : ConArgsNamed c) => All IsNamedArg c.args
121 | conArgsNamed @{TheyAreNamed p} = p
124 | data AllTyArgsNamed : TypeInfo -> Type where
125 | TheyAllAreNamed : All IsNamedArg ars -> All ConArgsNamed cns -> AllTyArgsNamed $
MkTypeInfo nm ars cns
128 | areAllTyArgsNamed : (ty : TypeInfo) -> Dec $
AllTyArgsNamed ty
129 | areAllTyArgsNamed $
MkTypeInfo _ ars cns with (all isNamedArg ars, all areConArgsNamed cns)
130 | _ | (Yes ars', Yes cns') = Yes $
TheyAllAreNamed ars' cns'
131 | _ | (No nars, _) = No $
\(TheyAllAreNamed ars' _) => nars ars'
132 | _ | (_, No ncns) = No $
\(TheyAllAreNamed _ cns') => ncns cns'
135 | 0 (.tyArgsNamed) : (0 _ : AllTyArgsNamed t) -> All IsNamedArg t.args
136 | (.tyArgsNamed) (TheyAllAreNamed at ct) = at
139 | 0 (.tyConArgsNamed) : (0 _ : AllTyArgsNamed t) -> All ConArgsNamed t.cons
140 | (.tyConArgsNamed) (TheyAllAreNamed at ct) = ct
146 | public export %inline
147 | (.tyName) : TypeInfo -> Name
150 | public export %inline
151 | (.tyArgs) : TypeInfo -> List Arg
154 | public export %inline
155 | (.tyCons) : TypeInfo -> List Con
158 | public export %inline
159 | (.conArgs) : Con -> List Arg
163 | [ConEqByName] Eq Con where
164 | (==) = (==) `on` name
167 | [ConOrdByName] Ord Con using ConEqByName where
168 | compare = comparing name