{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ScopedTypeVariables #-} module HERMIT.Shell.Externals where import Control.Arrow import Control.Monad (liftM) import Control.Monad.Reader (asks) import Control.Monad.State (gets, modify) import Data.Dynamic (fromDynamic) import Data.List (intercalate) import qualified Data.Map as M import Data.Maybe (fromMaybe) import HERMIT.External import HERMIT.Kernel import HERMIT.Kure import HERMIT.Lemma import HERMIT.Parser import HERMIT.Plugin.Renderer import HERMIT.Plugin.Types 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 import Prelude.Compat ---------------------------------------------------------------------------------- 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 gc) [ "garbage-collect all ASTs except for the initial and current AST" ] , external "display" (CLSModify $ showWindowAlways Nothing) [ "redisplays current state" ] , external "up" (Direction U) [ "move to the parent node"] , external "navigate" (CLSModify $ modify $ \ st -> st { cl_nav = True }) [ "switch to navigate mode" ] , external "command-line" (CLSModify $ modify $ \ st -> st { cl_nav = False }) [ "switch to command line mode" ] , external "set-window" (CLSModify $ setWindow >> showWindow Nothing) [ "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" (CLSModify $ versionCmd Back) [ "go back in the derivation" ] .+ VersionControl , external "step" (CLSModify $ versionCmd Step) [ "step forward in the derivation" ] .+ VersionControl , external "goto" (CLSModify . versionCmd . Goto) [ "goto a specific step in the derivation" ] .+ VersionControl , external "goto" (CLSModify . 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 -> CLSModify $ case reads bStr of [(b,"")] -> modify (\st -> st { cl_diffonly = b }) >> showWindow Nothing _ -> fail "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 $ case reads bStr of [(b,"")] -> modify $ \ st -> st { cl_failhard = b } _ -> fail "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 $ case reads bStr of [(b,"")] -> modify $ flip setCoreLint b _ -> fail "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 -> CLSModify $ case M.lookup name pp_dictionary of Nothing -> fail $ "List of Pretty Printers: " ++ intercalate ", " (M.keys pp_dictionary) Just pp -> do modify $ \ st -> setPrettyOpts (setPretty st pp) (cl_pretty_opts st) -- careful to preserve the current options showWindow Nothing) [ "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 -> CLSModify $ do modify $ \ st -> setPrettyOpts st (updateWidthOption w (cl_pretty_opts st)) showWindow Nothing) ["set the width of the screen"] , external "set-pp-type" (\ str -> CLSModify $ case reads str :: [(ShowOption,String)] of [(opt,"")] -> do modify $ \ st -> setPrettyOpts st (updateTypeShowOption opt (cl_pretty_opts st)) showWindow Nothing _ -> fail "valid arguments are Show, Abstract, and Omit") ["set how to show expression-level types (Show|Abstact|Omit)"] , external "set-pp-coercion" (\ str -> CLSModify $ case reads str :: [(ShowOption,String)] of [(opt,"")] -> do modify $ \ st -> setPrettyOpts st (updateCoShowOption opt (cl_pretty_opts st)) showWindow Nothing _ -> fail "valid arguments are Show, Abstract, and Omit") ["set how to show coercions (Show|Abstact|Omit)"] , external "set-pp-uniques" (\ str -> CLSModify $ case reads str of [(b,"")] -> do modify $ \ st -> setPrettyOpts st ((cl_pretty_opts st) { po_showUniques = b }) showWindow Nothing _ -> fail "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