ref: 1b58ced57a161d6a8746abc62aa07ad6c483cd3e
parent: db2e57c571aa84063ef01b8a5589db02cb9d5b4a
author: Lennart Augustsson <lennart@augustsson.net>
date: Thu Nov 2 09:07:29 EDT 2023
Better reload.
--- a/src/MicroHs/Interactive.hs
+++ b/src/MicroHs/Interactive.hs
@@ -24,7 +24,7 @@
putStrLn "Welcome to interactive MicroHs!"
putStrLn "Type ':quit' to quit, ':help' for help"
let flags' = Flags a b c d True
- _ <- S.runStateIO repl (preamble, flags', emptyCache)
+ _ <- S.runStateIO start (preamble, flags', emptyCache)
return ()
preamble :: String
@@ -31,6 +31,11 @@
preamble = "module " ++ interactiveName ++ "(module " ++ interactiveName ++
") where\nimport Prelude\nimport Unsafe.Coerce\n"
+start :: I ()
+start = S.do
+ reload
+ repl
+
repl :: I ()
repl = S.do
ms <- S.liftIO $ getInputLineHist ".mhsi" "> "
@@ -71,6 +76,7 @@
)
, ("reload", const $ S.doS.modify $ \ (ls, flgs, _) -> (ls, flgs, emptyCache)
+ reload
S.return True
)
, ("delete", \ del -> S.do@@ -83,8 +89,15 @@
)
]
+reload :: I ()
+reload = S.do
+ (ls, _, _) <- S.get
+ _ <- tryCompile ls -- reload modules right away
+ S.return ()
+
+
helpText :: String
-helpText = "Commands:\n :quit quit MicroHs\n :clear clear all definitions\n :delete d delete definition(s) d\n :help this text\n expr evaluate expression\n defn add top level definition\n"
+helpText = "Commands:\n :quit quit MicroHs\n :reload reload modules\n:clear clear all definitions\n :delete d delete definition(s) d\n :help this text\n expr evaluate expression\n defn add top level definition\n"
updateLines :: (String -> String) -> I ()
updateLines f = S.modify $ \ (ls, flgs, cache) -> (f ls, flgs, cache)
--
⑨