0 | module Core.Case.Util
2 | import Core.Case.CaseTree
6 | import Libraries.Data.List.SizeOf
10 | constructor MkDataCon
18 | getCons : Defs -> NF vars -> Core (List DataCon)
19 | getCons defs (NTCon _ tn _ _)
20 | = case !(lookupDefExact tn (gamma defs)) of
21 | Just (TCon _ _ _ _ _ cons _) =>
22 | do cs' <- traverse addTy (fromMaybe [] cons)
23 | pure (catMaybes cs')
24 | _ => throw (InternalError "Called `getCons` on something that is not a Type constructor")
26 | addTy : Name -> Core (Maybe DataCon)
28 | = do Just gdef <- lookupCtxtExact cn (gamma defs)
30 | case (gdef.definition, gdef.type) of
31 | (DCon t arity _, ty) =>
32 | pure . Just $
MkDataCon cn t arity
34 | getCons defs _ = pure []
36 | emptyRHS : FC -> CaseTree vars -> CaseTree vars
37 | emptyRHS fc (Case idx el sc alts) = Case idx el sc (map emptyRHSalt alts)
39 | emptyRHSalt : CaseAlt vars -> CaseAlt vars
40 | emptyRHSalt (ConCase n t args sc) = ConCase n t args (emptyRHS fc sc)
41 | emptyRHSalt (DelayCase c arg sc) = DelayCase c arg (emptyRHS fc sc)
42 | emptyRHSalt (ConstCase c sc) = ConstCase c (emptyRHS fc sc)
43 | emptyRHSalt (DefaultCase sc) = DefaultCase (emptyRHS fc sc)
44 | emptyRHS fc (STerm i s) = STerm i (Erased fc Placeholder)
48 | mkAlt : FC -> CaseTree vars -> DataCon -> CaseAlt vars
49 | mkAlt fc sc (MkDataCon cn t ar)
50 | = ConCase cn t (map (MN "m") (take ar [0..]))
51 | (weakenNs (map take) (emptyRHS fc sc))
54 | tagIs : Int -> CaseAlt vars -> Bool
55 | tagIs t (ConCase _ t' _ _) = t == t'
56 | tagIs t (ConstCase {}) = False
57 | tagIs t (DelayCase {}) = False
58 | tagIs t (DefaultCase _) = True