Can configure 'force-reload' that makes 'load-once' work just like 'load'.

This commit is contained in:
Erik Svedäng 2020-05-06 10:27:10 +02:00
parent 870d549da9
commit 12ec75ba8b
5 changed files with 33 additions and 19 deletions

View File

@ -45,6 +45,7 @@ defaultProject =
, projectCanExecute = False
, projectFilePathPrintLength = FullPath
, projectGenerateOnly = False
, projectForceReload = False
}
-- | Starting point of the application.

View File

@ -376,7 +376,7 @@ It will create a copy. If you want to avoid that, consider using [`endo-filter`]
=> [[1 2 3 4]]
```")
(sig partition (Fn [(Ref (Array a) b) Int] (Array (Array a))))
(defn partition [arr n]
(defn partition [arr n]
(let-do [x 0
y 0
a []]
@ -398,3 +398,4 @@ It will create a copy. If you want to avoid that, consider using [`endo-filter`]
(aset-uninitialized! &darr i @(StaticArray.unsafe-nth sarr i)))
darr)))
(macro-log "hello from Array")

View File

@ -120,6 +120,8 @@ commandProjectConfig ctx [xobj@(XObj (Str key) _ _), value] = do
"paren-balance-hints" ->
do balanceHints <- unwrapBoolXObj value
return (proj { projectBalanceHints = balanceHints })
"force-reload" -> do forceReload <- unwrapBoolXObj value
return (proj { projectForceReload = forceReload })
_ -> Left ("Project.config can't understand the key '" ++ key ++ "' at " ++ prettyInfoFromXObj xobj ++ ".")
case newProj of
Left errorMessage -> presentError ("[CONFIG ERROR] " ++ errorMessage) (ctx, dynamicNil)
@ -369,23 +371,25 @@ commandHelp ctx [XObj(Str "interop") _ _] =
commandHelp ctx [XObj(Str "project") _ _] =
liftIO $ do putStrLn "(Project.config <setting> <value>) handles the following settings:"
putStrLn ""
putStrLn "'cflag' - Add a flag to the compiler."
putStrLn "'libflag' - Add a library flag to the compiler."
putStrLn "'compiler' - Set what compiler should be run with the 'build' command."
putStrLn "'title' - Set the title of the current project, will affect the name of the binary produced."
putStrLn "'output-directory' - Where to put compiler artifacts, etc."
putStrLn "'docs-directory' - Where to put generated documentation."
putStrLn "'docs-logo' - Location of the documentation logo."
putStrLn "'docs-prelude' - The documentation foreword."
putStrLn "'docs-url' - A URL for the project (useful for generated documentation)."
putStrLn "'docs-generate-index'- Whether to generate the documentation index."
putStrLn "'docs-styling' - A URL to CSS for the project documentation."
putStrLn "'prompt' - Set the prompt in the repl."
putStrLn "'search-path' - Add a path where the Carp compiler will look for '*.carp' files."
putStrLn "'cflag' - Add a flag to the compiler."
putStrLn "'libflag' - Add a library flag to the compiler."
putStrLn "'compiler' - Set what compiler should be run with the 'build' command."
putStrLn "'title' - Set the title of the current project, will affect the name of the binary produced."
putStrLn "'output-directory' - Where to put compiler artifacts, etc."
putStrLn "'docs-directory' - Where to put generated documentation."
putStrLn "'docs-logo' - Location of the documentation logo."
putStrLn "'docs-prelude' - The documentation foreword."
putStrLn "'docs-url' - A URL for the project (useful for generated documentation)."
putStrLn "'docs-generate-index' - Whether to generate the documentation index."
putStrLn "'docs-styling' - A URL to CSS for the project documentation."
putStrLn "'prompt' - Set the prompt in the repl."
putStrLn "'search-path' - Add a path where the Carp compiler will look for '*.carp' files."
putStrLn ""
putStrLn "'echo-c' - When a form is defined using 'def' or 'defn' its C code will be printed."
putStrLn "'echo-compiler-cmd' - When building the project the command for running the C compiler will be printed."
putStrLn "'print-ast' - The 'info' command will print the AST for a binding."
putStrLn "'echo-c' - When a form is defined using 'def' or 'defn' its C code will be printed."
putStrLn "'echo-compiler-cmd' - When building the project the command for running the C compiler will be printed."
putStrLn "'print-ast' - The 'info' command will print the AST for a binding."
putStrLn "'paren-balance-hints' - Whether to print the ongoing stack of parens to close in the REPL, or not."
putStrLn "'force-reload' - If true, the 'load-once' command will work just like 'load' (useful for library developers)."
putStrLn ""
return (ctx, dynamicNil)

View File

@ -543,7 +543,10 @@ commandLoad ctx [x] =
commandLoadOnce :: CommandCallback
commandLoadOnce ctx [xobj@(XObj (Str path) i _)] =
loadInternal ctx xobj path i Frozen
let reloadMode = if projectForceReload (contextProj ctx)
then DoesReload -- Forced by project setting!
else Frozen -- Normal behaviour.
in loadInternal ctx xobj path i reloadMode
commandLoadOnce ctx [x] =
return $ evalError ctx ("Invalid args to `load-once`: " ++ pretty x) (info x)
@ -597,7 +600,9 @@ loadInternal ctx xobj path i reloadMode = do
return (newCtx, dynamicNil)
where
frozenPaths proj =
map fst $ filter (isFrozen . snd) (projectFiles proj)
if projectForceReload proj
then [] -- No paths are Frozen when the "force reload" project setting is true.
else map fst $ filter (isFrozen . snd) (projectFiles proj)
isFrozen Frozen = True
isFrozen _ = False

View File

@ -654,6 +654,7 @@ data Project = Project { projectTitle :: String
, projectFilePathPrintLength :: FilePathPrintLength
, projectGenerateOnly :: Bool
, projectBalanceHints :: Bool
, projectForceReload :: Bool -- Setting this to true will make the `load-once` command work just like `load`.
}
projectFlags :: Project -> String
@ -687,6 +688,7 @@ instance Show Project where
filePathPrintLength
generateOnly
balanceHints
forceReload
) =
unlines [ "Title: " ++ title
, "Compiler: " ++ compiler
@ -714,6 +716,7 @@ instance Show Project where
, "File path print length (when using --check): " ++ show filePathPrintLength
, "Generate Only: " ++ showB generateOnly
, "Balance Hints: " ++ showB balanceHints
, "Force Reload: " ++ showB forceReload
]
where showB b = if b then "true" else "false"