{-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-} module HERMIT.Shell.Externals where import Control.Arrow import Control.Monad (liftM) import Data.Dynamic (fromDynamic) import Data.List (intercalate) import qualified Data.Map as M import Data.Maybe (fromMaybe) import Data.Monoid (mempty) import HERMIT.External import HERMIT.Kernel import HERMIT.Kure import HERMIT.Lemma import HERMIT.Parser import HERMIT.Plugin.Renderer import HERMIT.PrettyPrinter.Common import HERMIT.Dictionary.Reasoning import HERMIT.Shell.Dictionary import HERMIT.Shell.KernelEffect import HERMIT.Shell.Proof as Proof import HERMIT.Shell.ScriptToRewrite import HERMIT.Shell.ShellEffect import HERMIT.Shell.Types ---------------------------------------------------------------------------------- shell_externals :: [External] shell_externals = map (.+ Shell) [ external "resume" Resume -- HERMIT Kernel Exit [ "stops HERMIT; resumes compile" ] , external "abort" Abort -- UNIX Exit [ "hard UNIX-style exit; does not return to GHC; does not save" ] , external "continue" Continue -- Shell Exit, but not HERMIT [ "exits shell; resumes HERMIT" ] , external "gc" Delete [ "garbage-collect a given AST" ] , external "gc" (CLSModify $ liftM Right . gc) [ "garbage-collect all ASTs except for the initial and current AST" ] , external "display" (CLSModify $ \ st -> do (er,st') <- runCLT st (showWindow Nothing) return $ fmap (const st') er) [ "redisplays current state" ] , external "up" (Direction U) [ "move to the parent node"] , external "navigate" (CLSModify $ \ st -> return $ Right $ st { cl_nav = True }) [ "switch to navigate mode" ] , external "command-line" (CLSModify $ \ st -> return $ Right $ st { cl_nav = False }) [ "switch to command line mode" ] , external "set-window" (CLSModifyAndShow setWindow) [ "fix the window to the current focus" ] , external "top" (Direction T) [ "move to root of current scope" ] , external "log" (Inquiry showDerivationTree) [ "go back in the derivation" ] .+ VersionControl , external "back" (CLSModifyAndShow $ versionCmd Back) [ "go back in the derivation" ] .+ VersionControl , external "step" (CLSModifyAndShow $ versionCmd Step) [ "step forward in the derivation" ] .+ VersionControl , external "goto" (CLSModifyAndShow . versionCmd . Goto) [ "goto a specific step in the derivation" ] .+ VersionControl , external "goto" (CLSModifyAndShow . versionCmd . GotoTag) [ "goto a specific step in the derivation by tag name" ] .+ VersionControl , external "tag" (CLSModify . versionCmd . Tag) [ "name the current step in the derivation" ] .+ VersionControl , external "diff" Diff [ "show diff of two ASTs" ] .+ VersionControl , external "set-pp-diffonly" (\ bStr -> CLSModifyAndShow $ \ st -> case reads bStr of [(b,"")] -> return $ Right $ setDiffOnly st b _ -> return $ Left $ CLError "valid arguments are True and False" ) [ "set-pp-diffonly ; False by default" , "print diffs rather than full code after a rewrite" ] , external "set-fail-hard" (\ bStr -> CLSModify $ \ st -> case reads bStr of [(b,"")] -> return $ Right $ setFailHard st b _ -> return $ Left $ CLError "valid arguments are True and False" ) [ "set-fail-hard ; False by default" , "any rewrite failure causes compilation to abort" ] , external "set-auto-corelint" (\ bStr -> CLSModify $ \ st -> case reads bStr of [(b,"")] -> return $ Right $ setCoreLint st b _ -> return $ Left $ CLError "valid arguments are True and False" ) [ "set-auto-corelint ; False by default" , "run core lint type-checker after every rewrite, reverting on failure" ] , external "set-pp" (\ name -> CLSModifyAndShow $ \ st -> case M.lookup name pp_dictionary of Nothing -> return $ Left $ CLError $ "List of Pretty Printers: " ++ intercalate ", " (M.keys pp_dictionary) Just pp -> return $ Right $ flip setPrettyOpts (cl_pretty_opts st) $ setPretty st pp) -- careful to preserve the current options [ "set the pretty printer" , "use 'set-pp ls' to list available pretty printers" ] , external "set-pp-renderer" (PluginComp . changeRenderer) [ "set the output renderer mode"] , external "set-pp-renderer" showRenderers [ "set the output renderer mode"] , -- DEPRECATED - this dump behavior uses the current pretty printer selected in the shell external "dump" (\pp fp r w -> CLSModify (dump fp pp r w)) [ "dump - DEPRECATED"] , external "dump" (\fp pp r w -> CLSModify (dump fp pp r w)) [ "dump "] , external "dump-lemma" ((\nm fp pp r w -> getLemmaByNameT nm >>> liftPrettyH (pOptions pp) (ppLemmaT pp nm) >>> dumpT fp pp r w) :: LemmaName -> FilePath -> PrettyPrinter -> String -> Int -> TransformH LCoreTC ()) [ "Dump named lemma to a file." , "dump-lemma " ] , external "dump-lemma" ((\pp nm fp r w -> getLemmaByNameT nm >>> liftPrettyH (pOptions pp) (ppLemmaT pp nm) >>> dumpT fp pp r w) :: PrettyPrinter -> LemmaName -> FilePath -> String -> Int -> TransformH LCoreTC ()) [ "Dump named lemma to a file." , "dump-lemma " ] , external "set-pp-width" (\ w -> CLSModifyAndShow $ \ st -> return $ Right $ setPrettyOpts st (updateWidthOption w (cl_pretty_opts st))) ["set the width of the screen"] , external "set-pp-type" (\ str -> CLSModifyAndShow $ \ st -> case reads str :: [(ShowOption,String)] of [(opt,"")] -> return $ Right $ setPrettyOpts st (updateTypeShowOption opt (cl_pretty_opts st)) _ -> return $ Left $ CLError "valid arguments are Show, Abstract, and Omit") ["set how to show expression-level types (Show|Abstact|Omit)"] , external "set-pp-coercion" (\ str -> CLSModifyAndShow $ \ st -> case reads str :: [(ShowOption,String)] of [(opt,"")] -> return $ Right $ setPrettyOpts st (updateCoShowOption opt (cl_pretty_opts st)) _ -> return $ Left $ CLError "valid arguments are Show, Abstract, and Omit") ["set how to show coercions (Show|Abstact|Omit)"] , external "set-pp-uniques" (\ str -> CLSModifyAndShow $ \ st -> case reads str of [(b,"")] -> return $ Right $ setPrettyOpts st ((cl_pretty_opts st) { po_showUniques = b } ) _ -> return $ Left $ CLError "valid arguments are True and False") ["set whether uniques are printed with variable names"] , external "{" BeginScope ["push current lens onto a stack"] -- tag as internal , external "}" EndScope ["pop a lens off a stack"] -- tag as internal , external "load" LoadFile ["load : load a HERMIT script from a file and save it under the specified name."] , external "load-and-run" loadAndRun ["load-and-run : load a HERMIT script from a file and run it immediately."] , external "save" (SaveFile False) ["save : save the current complete derivation into a file."] , external "save-verbose" (SaveFile True) ["save-verbose : save the current complete derivation into a file," ,"including output of each command as a comment."] , external "save-script" SaveScript ["save-script