From 9249c4c641dde3e14d7fff103f0c32bfe5f9fc9f Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Wed, 4 Feb 2026 20:56:58 -0800 Subject: [PATCH] Invalidate on :load --- src/Main.newt | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Main.newt b/src/Main.newt index d724f8b..08f3a8b 100644 --- a/src/Main.newt +++ b/src/Main.newt @@ -208,6 +208,9 @@ showErrors fn src = do exitFailure "Compile failed" pure MkUnit +invalidateModule : QName -> M Unit +invalidateModule (QN ns nm) = modifyTop [modules $= deleteMap (snoc ns nm)] + -- processFile called on the top level file -- it sets up everything and then recurses into processModule processFile : String -> M Unit @@ -239,6 +242,8 @@ processFile fn = do let modules = updateMap primNS (MkModCtx "" top.defs (MC emptyMap Nil 0 CheckAll) top.ops Nil) top.modules modifyTop (\ top => MkTop modules (primNS :: Nil) emptyMap Nil emptyMap top.metaCtx top.verbose top.errors top.ops) + invalidateModule qn + src <- processModule emptyFC base Nil qn top <- getTop @@ -305,16 +310,21 @@ runCommand (Verbose Nothing) = modifyTop [ verbose $= _+_ 1 ] runCommand (Verbose (Just v)) = modifyTop [ verbose := v ] runCommand (OutputJS fn) = writeSource fn +-- Broken out to a separate function so I can hook it. +runString : String → M Unit +runString line = do + let (Right toks) = tokenise "" line + | Left err => putStrLn (showError line err) + let (Right cmd) = parse "" parseCommand toks + | Left err => putStrLn (showError line err) + catchError (runCommand cmd) (\ err => putStrLn $ showError line err) + runRepl : M Unit runRepl = do liftIO $ putStr "> " Right line <- liftIO {M} $ readLine | Left err => pure MkUnit - let (Right toks) = tokenise "" line - | Left err => putStrLn (showError line err) >> runRepl - let (Right cmd) = parse "" parseCommand toks - | Left err => putStrLn (showError line err) >> runRepl - catchError (runCommand cmd) (\ err => putStrLn $ showError line err) + runString line runRepl -- TODO translate args into REPL commands?