2Module : Idris.Directives
3Description : Act upon Idris directives.
6Maintainer : The Idris Community.
8module Idris.Directives(directiveAction) where
12import Idris.Core.Evaluate
15import Idris.Output (sendHighlighting)
17import Util.DynamicLinker
19-- | Run the action corresponding to a directive
20directiveAction :: Directive -> Idris ()
21directiveAction (DLib cgn lib) = do
23 addIBC (IBCLib cgn lib)
25directiveAction (DLink cgn obj) = do
27 o <- runIO $ findInPath dirs obj
28 addIBC (IBCObj cgn obj) -- just name, search on loading ibc
31directiveAction (DFlag cgn flag) = do
32 let flags = words flag
33 mapM_ (\f -> addIBC (IBCCGFlag cgn f)) flags
34 mapM_ (addFlag cgn) flags
36directiveAction (DInclude cgn hdr) = do
38 addIBC (IBCHeader cgn hdr)
40directiveAction (DHide n') = do
41 ns <- allNamespaces n'
43 setAccessibility n Hidden
44 addIBC (IBCAccess n Hidden)) ns
45directiveAction (DFreeze n') = do
46 ns <- allNamespaces n'
48 setAccessibility n Frozen
49 addIBC (IBCAccess n Frozen)) ns
50directiveAction (DThaw n') = do
51 ns <- allNamespaces n'
54 case lookupDefAccExact n False ctxt of
55 Just (_, Frozen) -> do setAccessibility n Public
56 addIBC (IBCAccess n Public)
57 _ -> throwError (Msg (show n ++ " is not frozen"))) ns
58directiveAction (DInjective n') = do
59 ns <- allNamespaces n'
62 addIBC (IBCInjective n True)) ns
63directiveAction (DSetTotal n') = do
64 ns <- allNamespaces n'
66 setTotality n (Total [])
67 addIBC (IBCTotal n (Total []))) ns
69directiveAction (DAccess acc) = do updateIState (\i -> i { default_access = acc })
71directiveAction (DDefault tot) = do updateIState (\i -> i { default_total = tot })
73directiveAction (DLogging lvl) = setLogLevel (fromInteger lvl)
75directiveAction (DDynamicLibs libs) = do
76 added <- addDyLib libs
78 Left lib -> addIBC (IBCDyLib (lib_name lib))
81directiveAction (DNameHint ty tyFC ns) = do
82 ty' <- disambiguate ty
83 mapM_ (addNameHint ty' . fst) ns
84 mapM_ (\n -> addIBC (IBCNameHint (ty', fst n))) ns
85 sendHighlighting $ [(tyFC, AnnName ty' Nothing Nothing Nothing)] ++ map (\(n, fc) -> (fc, AnnBoundName n False)) ns
87directiveAction (DErrorHandlers fn nfc arg afc ns) = do
88 fn' <- disambiguate fn
89 ns' <- mapM (\(n, fc) -> do
92 addFunctionErrorHandlers fn' arg (map fst ns')
93 mapM_ (addIBC . IBCFunctionErrorHandler fn' arg . fst) ns'
95 [ (nfc, AnnName fn' Nothing Nothing Nothing)
96 , (afc, AnnBoundName arg False)
97 ] ++ map (\(n, fc) -> (fc, AnnName n Nothing Nothing Nothing)) ns'
99directiveAction (DLanguage ext) = addLangExt ext
101directiveAction (DDeprecate n reason) = do
103 addDeprecated n' reason
104 addIBC (IBCDeprecate n' reason)
106directiveAction (DFragile n reason) = do
109 addIBC (IBCFragile n' reason)
111directiveAction (DAutoImplicits b) = setAutoImpls b
112directiveAction (DUsed fc fn arg) = addUsedName fc fn arg
114disambiguate :: Name -> Idris Name
117 case lookupCtxtName n (idris_implicits i) of
118 [(n', _)] -> return n'
119 [] -> throwError (NoSuchVariable n)
120 more -> throwError (CantResolveAlts (map fst more))
123allNamespaces :: Name -> Idris [Name]
126 case lookupCtxtName n (idris_implicits i) of
127 [(n', _)] -> return [n']
128 [] -> throwError (NoSuchVariable n)
129 more -> return (map fst more)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list