@@ -36,29 +36,36 @@ fputState field x = fmodifyState field (const x)
36fmodifyState :: MonadState s m => Field s a -> (a -> a) -> m ()
36fmodifyState :: MonadState s m => Field s a -> (a -> a) -> m ()
37fmodifyState field f = modify $ fmodify field f
37fmodifyState field f = modify $ fmodify field f
39+-- Until now, we'd have just ad-hoc empty lists and Falses thrown around
40+-- whenever a new instance of a record was to be created.
42+-- This class formalises the notion of an initial value for a record.
39class InitialValue a where
43class InitialValue a where
40 initialValue :: a
44 initialValue :: a
46+-- Exact-name context lookup; uses the initial value if needed.
42ctxt_lookupExact :: InitialValue a => Name -> Field (Ctxt a) a
47ctxt_lookupExact :: InitialValue a => Name -> Field (Ctxt a) a
43ctxt_lookupExact n = Field
48ctxt_lookupExact n = Field
44 { fget = fromMaybe initialValue . lookupCtxtExact n
49 { fget = fromMaybe initialValue . lookupCtxtExact n
45 , fset = addDef n
50 , fset = addDef n
48-----------------------------------
54-----------------------------------
49-- Individual records and fields --
55-- Individual records and fields --
50-----------------------------------
56-----------------------------------
52instance InitialValue OptInfo where
62instance InitialValue OptInfo where
53 initialValue = Optimise [] False
63 initialValue = Optimise [] False
55−-- raw context, probably won't be used much
56−ist_optimisation_ctxt :: Field IState (Ctxt OptInfo)
57−ist_optimisation_ctxt = Field idris_optimisation (\v ist -> ist{ idris_optimisation = v })
59−-- the optimisation record for the given name
65+-- the optimisation record for the given (exact) name
60ist_optimisation :: Name -> Field IState OptInfo
66ist_optimisation :: Name -> Field IState OptInfo
61−ist_optimisation n = ctxt_lookupExact n . ist_optimisation_ctxt
67+ist_optimisation n = ctxt_lookupExact n
68+ . Field idris_optimisation (\v ist -> ist{ idris_optimisation = v })
63-- two fields of the optimisation record
70-- two fields of the optimisation record
64opt_inaccessible :: Field OptInfo [(Int, Name)]
71opt_inaccessible :: Field OptInfo [(Int, Name)]
@@ -66,3 +73,19 @@ opt_inaccessible = Field inaccessible (\v opt -> opt{ inaccessible = v })
67opt_detaggable :: Field OptInfo Bool
74opt_detaggable :: Field OptInfo Bool
68opt_detaggable = Field detaggable (\v opt -> opt{ detaggable = v })
75opt_detaggable = Field detaggable (\v opt -> opt{ detaggable = v })
81+instance InitialValue CGInfo where
82+ initialValue = CGInfo [] [] [] [] []
84+-- callgraph record for the given (exact) name
85+ist_callgraph :: Name -> Field IState CGInfo
86+ist_callgraph n = ctxt_lookupExact n
87+ . Field idris_callgraph (\v ist -> ist{ idris_callgraph = v })
89+-- some fields of the CGInfo record
90+cg_usedpos :: Field CGInfo [(Int, [UsageReason])]
91+cg_usedpos = Field usedpos (\v cg -> cg{ usedpos = v })