on master help sign in
Merge remote-tracking branch 'origin/error-reflection' into error-reflection
commit82fe0c682804ea85c44d14142b064e6ba1b65a8d authorDavid Christiansen <david@davidchristiansen.dk> dateTue 17 Dec 2013, 15:01 (13 years ago) parent00577be9c54fc1
4 files changed+23−3
src/Idris/AbsSyntaxTree.hs+6−2 src/Idris/ElabDecls.hs+11 src/Idris/IBC.hs+3−1 src/Idris/Parser.hs+3
src/Idris/AbsSyntaxTree.hs+6−2
@@ -131,7 +131,8 @@ data IState = IState {
131131 idris_outputmode :: OutputMode,
132132 idris_colourRepl :: Bool,
133133 idris_colourTheme :: ColourTheme,
134− idris_outh :: Handle
134+ idris_outh :: Handle,
135+ idris_errorhandlers :: [Name]
135136 }
136137
137138data SizeChange = Smaller | Same | Bigger | Unknown
@@ -188,13 +189,15 @@ data IBCWrite = IBCFix FixDecl
188189 | IBCLineApp FilePath Int PTerm
189190 deriving Show
190191
192+-- | The initial state for the compiler
193+idrisInit :: IState
191194idrisInit = IState initContext [] [] emptyContext emptyContext emptyContext
192195 emptyContext emptyContext emptyContext emptyContext
193196 emptyContext emptyContext emptyContext emptyContext
194197 emptyContext
195198 [] [] defaultOpts 6 [] [] [] [] [] [] [] [] [] [] [] []
196199 [] Nothing Nothing [] [] [] Hidden False [] Nothing [] [] RawOutput
197− True defaultTheme stdout
200+ True defaultTheme stdout []
198201
199202-- | The monad for the main REPL - reading and processing files and updating
200203-- global state (hence the IO inner monad).
@@ -379,6 +382,7 @@ data FnOpt = Inlinable -- always evaluate when simplifying
379382 -- a function argument, and further evaluation resutls
380383 | Implicit -- implicit coercion
381384 | CExport String -- export, with a C name
385+ | ErrorHandler -- ^^ an error handler for use with the ErrorReflection extension
382386 | Reflection -- a reflecting function, compile-time only
383387 | Specialise [(Name, Maybe Int)] -- specialise it, freeze these names
384388 deriving (Show, Eq)
src/Idris/ElabDecls.hs+11
@@ -112,6 +112,17 @@ elabType' norm info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty
112112 addIBC (IBCFlags n opts')
113113 when (Implicit `elem` opts) $ do addCoercion n
114114 addIBC (IBCCoercion n)
115+ -- If the function is declared as an error handler and the language
116+ -- extension is enabled, then add it to the list of error handlers.
117+ errorReflection <- fmap (elem ErrorReflection . idris_language_extensions) getIState
118+ when (ErrorHandler `elem` opts) $ do
119+ if errorReflection
120+ then do
121+ -- TODO: Check that the declared type is the correct type for an error handler:
122+ -- handler : List (TTName, TT) -> Err -> ErrorReport
123+ i <- getIState
124+ putIState $ i { idris_errorhandlers = n : idris_errorhandlers i }
125+ else ifail "Error handlers can only be defined when the ErrorReflection language extension is enabled."
115126 when corec $ do setAccessibility n Frozen
116127 addIBC (IBCAccess n Frozen)
117128 return usety
src/Idris/IBC.hs+3−1
@@ -634,7 +634,7 @@ instance Binary NameType where
634634 _ -> error "Corrupted binary data for NameType"
635635
636636
637−instance {-(Binary n) =>-} Binary (TT Name) where
637+instance {- (Binary n) => -} Binary (TT Name) where
638638 put x
639639 = {-# SCC "putTT" #-}
640640 case x of
@@ -976,6 +976,7 @@ instance Binary FnOpt where
976976 PartialFn -> putWord8 6
977977 Implicit -> putWord8 7
978978 Reflection -> putWord8 8
979+ ErrorHandler -> putWord8 9
979980 get
980981 = do i <- getWord8
981982 case i of
@@ -989,6 +990,7 @@ instance Binary FnOpt where
989990 6 -> return PartialFn
990991 7 -> return Implicit
991992 8 -> return Reflection
993+ 9 -> return ErrorHandler
992994 _ -> error "Corrupted binary data for FnOpt"
993995
994996instance Binary Fixity where
src/Idris/Parser.hs+3
@@ -309,6 +309,7 @@ FnOpts ::= 'total'
309309 | 'partial'
310310 | 'implicit'
311311 | '%' 'assert_total'
312+ | '%' 'error_handler'
312313 | '%' 'reflection'
313314 | '%' 'specialise' '[' NameTimesList? ']'
314315 ;
@@ -330,6 +331,8 @@ fnOpts opts
330331 fnOpts (CExport c : opts)
331332 <|> do try (lchar '%' *> reserved "assert_total");
332333 fnOpts (AssertTotal : opts)
334+ <|> do try (lchar '%' *> reserved "error_handler");
335+ fnOpts (ErrorHandler : opts)
333336 <|> do try (lchar '%' *> reserved "reflection");
334337 fnOpts (Reflection : opts)
335338 <|> do lchar '%'; reserved "specialise";