Commit d59590b6 authored by Michael Hanus's avatar Michael Hanus
Browse files

Modify option to specify that "load" command compiles the main program

parent dac6d40d
......@@ -5,7 +5,7 @@
--- > cypm curry :l C2GoREPL.curry :save :q
---
--- @author Michael Hanus
--- @version February 2021
--- @version June 2021
------------------------------------------------------------------------------
module C2GoREPL where
......@@ -27,20 +27,20 @@ c2goHome = "/usr/local/curry2go"
c2go :: CCDescription
c2go = CCDescription
"curry2go" -- the compiler name
(1,0,0) -- the version number
c2goBanner -- the banner
c2goHome -- home directory of the compiler
"info@curry-lang.org" -- contact email
"curry2goc" -- compiler executable
(c2goHome ++ "/lib") -- base library path
False -- parser should read untyped FlatCurry
True -- use CURRYPATH variable
(\s -> "-v" ++ s) -- option to pass verbosity
(\_ -> "") -- option to pass parser options
(\s -> "--compile " ++ s) -- option to compile only
(\s -> s) -- option to create an executable
cleanCmd -- command to clean module
"curry2go" -- the compiler name
(1,0,0) -- the version number
c2goBanner -- the banner
c2goHome -- home directory of the compiler
"info@curry-lang.org" -- contact email
(c2goHome ++ "/bin/curry2goc") -- compiler executable
(c2goHome ++ "/lib") -- base library path
Nothing -- compile program with load command
True -- use CURRYPATH variable
(\s -> "-v" ++ s) -- option to pass verbosity
(\_ -> "") -- option to pass parser options
(\s -> "--compile " ++ s) -- option to compile only
(\s -> "--noimports " ++ s) -- option to create an executable
cleanCmd -- command to clean module
[stratOpt, intOpt, firstOpt]
where
cleanCmd m =
......
......@@ -7,7 +7,7 @@
--- > cypm curry :l JucsREPL.curry :save :q
---
--- @author Michael Hanus
--- @version February 2021
--- @version June 2021
------------------------------------------------------------------------------
module JucsREPL where
......@@ -33,7 +33,7 @@ jucs = CCDescription
"info@curry-lang.org" -- contact email
"jucs" -- compiler executable
(installDir ++ "/lib") -- base library path
False -- parser should read untyped FlatCurry
(Just False) -- load command reads untyped FlatCurry
True -- use CURRYPATH variable
(\s -> "-v" ++ s) -- option to pass verbosity
(\_ -> "") -- option to pass parser options
......
......@@ -5,7 +5,7 @@
--- > cypm curry :l PakcsREPL.curry :save :q
---
--- @author Michael Hanus
--- @version February 2021
--- @version June 2021
------------------------------------------------------------------------------
module PakcsREPL where
......@@ -35,7 +35,7 @@ pakcs = CCDescription
"pakcs@curry-lang.org" -- contact email
(pakcsHome ++ "/bin/pakcs") -- compiler executable
(pakcsHome ++ "/lib") -- base library path
False -- parser reads untyped FlatCurry
(Just False) -- load command reads untyped FlatCurry
True -- use CURRYPATH variable
(\s -> ":set v" ++ s) -- option to pass verbosity
(\s -> ":set parser " ++ s) -- option to pass parser options
......
......@@ -6,7 +6,7 @@
--- a JSON file) or statically defined in some module.
---
--- @author Michael Hanus
--- @version April 2021
--- @version June 2021
------------------------------------------------------------------------------
module REPL.Compiler where
......@@ -29,8 +29,11 @@ module REPL.Compiler where
--- the base libraries of the Curry compiler. This path will be appended
--- to an existing load path (specified by the envrionment variable
--- `CURRYPATH`).
--- * `ccTypedFC` should be set to `True` if the front end should read
--- Typed FlatCurry files instead of FlatCurry files.
--- * `ccTypedFC` should be set to `Nothing` if the (re)load command should
--- compile the main program. Otherwise, the main program is only parsed
--- with the front end where `Just True` indicates that the front end
--- should produce Typed FlatCurry files instead of FlatCurry files
--- (in case of `Just False`).
--- * If `ccCurryPath` is `True`, then the actual load path is passed
--- by the environment variable `CURRYPATH` to the compiler,
--- otherwise it is passed by a sequence of options of the form `-iDIR`.
......@@ -55,7 +58,7 @@ data CCDescription = CCDescription
, ccEmail :: String -- contact email (shown at startup)
, ccExec :: String -- the executable of the compiler
, ccLibPath :: String -- the path of the standard libraries
, ccTypedFC :: Bool -- should the parser read typed FlatCurry?
, ccTypedFC :: Maybe Bool -- should the parser read typed FlatCurry?
, ccCurryPath :: Bool -- use CURRYPATH instead of '-i' for imports
, ccVerbOpt :: String -> String -- option to pass verbosity
, ccParseOpt :: String -> String -- option to pass parser options
......
......@@ -73,6 +73,7 @@ processArgsAndStart rst []
writeVerboseInfo rst 1 (ccBanner (compiler rst))
writeVerboseInfo rst 1 $
"Type \":h\" for help (contact: " ++ ccEmail (compiler rst) ++ ")"
processCompile (reduceVerbose rst) "Prelude"
repLoop rst
processArgsAndStart rst (arg:args)
-- ignore empty arguments which can be provided by single or double quotes
......@@ -435,10 +436,11 @@ processCd rst args = do
--- Process :compile command
processCompile :: ReplState -> String -> IO (Maybe ReplState)
processCompile rst args =
processLoad rst args >>=
maybe (return Nothing)
(\rst' -> compileCurryProgram rst' (currMod rst'))
processCompile rst args = do
let modname = stripCurrySuffix args
if null modname
then skipCommand "missing module name"
else compileCurryProgram rst modname
--- Process :edit command
processEdit :: ReplState -> String -> IO (Maybe ReplState)
......@@ -509,10 +511,9 @@ processLoad rst args = do
(\rst2 ->
lookupModuleSource (loadPaths rst2) modname >>=
maybe (skipCommand $
"source file of module " ++ dirmodname ++ " not found")
(\_ -> do parseCurryProgram rst2 modname
return $
Just rst2 { currMod = modname, addMods = [] })
"source file of module '" ++ dirmodname ++ "' not found")
(\_ -> loadCurryProgram rst2 { currMod = modname, addMods = [] }
modname)
)
mbrst
......@@ -522,7 +523,7 @@ processReload rst args
| currMod rst == preludeName rst
= skipCommand "no program loaded!"
| null (stripCurrySuffix args)
= parseCurryProgram rst (currMod rst) >> return (Just rst)
= loadCurryProgram rst (currMod rst)
| otherwise
= skipCommand "superfluous argument"
......@@ -611,7 +612,7 @@ printHelpOnCommands = putStrLn $ unlines
, ""
, ":!<command> - execute <command> in shell"
, ":browse - browse program and its imported modules"
, ":compile <prog> - like ':load <prog>' but also compile program"
, ":compile <m> - compile module <m> (but do not load it)"
, ":cd <dir> - change current directory to <dir>"
, ":edit - load source of currently loaded module into editor"
, ":edit <m> - load source of module <m> into editor"
......@@ -832,7 +833,7 @@ compileMainExpression rst exp runrmexec = do
putStrLn "GENERATED MAIN MODULE:"
readFile (mainExpFile rst) >>= putStrLn
let mainexpmod = mainExpMod rst
compilecmd = curryCompilerCommand rst ++ " " ++
compilecmd = curryCompilerCommand (reduceVerbose rst) ++ " " ++
(ccExecOpt (compiler rst)) mainexpmod
timecompilecmd <- getTimeCmd rst "Compilation" compilecmd
if ccCurryPath (compiler rst)
......@@ -1076,13 +1077,20 @@ substTypeVar tv def (CTApply te1 te2) =
---------------------------------------------------------------------------
-- Parse a Curry program to detect errors (for load/reload command):
parseCurryProgram :: ReplState -> String -> IO Int
parseCurryProgram rst curryprog = do
parseCurryProgram :: ReplState -> String -> Bool -> IO (Maybe ReplState)
parseCurryProgram rst curryprog tfcy = do
let frontendparams = currentFrontendParams rst (verbose rst == 0)
target = if ccTypedFC (compiler rst) then TFCY else FCY
target = if tfcy then TFCY else FCY
catch (verbCallFrontendWithParams rst target frontendparams curryprog
>> return 0)
(\_ -> return 1)
>> return (Just rst))
(\_ -> return Nothing)
-- Load a Curry program (parse onyl or compile it):
loadCurryProgram :: ReplState -> String -> IO (Maybe ReplState)
loadCurryProgram rst curryprog =
maybe (compileCurryProgram rst curryprog)
(parseCurryProgram rst curryprog)
(ccTypedFC (compiler rst))
-- Compile a Curry program with the Curry compiler:
compileCurryProgram :: ReplState -> String -> IO (Maybe ReplState)
......@@ -1093,8 +1101,8 @@ compileCurryProgram rst curryprog = do
if ccCurryPath (compiler rst)
then execCommandWithPath rst timecompilecmd []
else do writeVerboseInfo rst 2 $ "Executing: " ++ timecompilecmd
system timecompilecmd
return $ Just rst
es <- system timecompilecmd
return $ if es == 0 then Just rst else Nothing
-- Generate the base command to call the Curry compiler:
curryCompilerCommand :: ReplState -> String
......@@ -1103,7 +1111,7 @@ curryCompilerCommand rst = unwords [ccExec (compiler rst), cmpopts]
cmpopts = unwords $
[ -- pass current value of "bindingoptimization" property to compiler:
-- "-Dbindingoptimization=" ++ rcValue (rcVars rst) "bindingoptimization"
(ccVerbOpt (compiler rst)) (show (transVerbose (verbose rst)))
(ccVerbOpt (compiler rst)) (show (verbose rst))
] ++
(if ccCurryPath (compiler rst)
then []
......@@ -1113,9 +1121,6 @@ curryCompilerCommand rst = unwords [ccExec (compiler rst), cmpopts]
then []
else [(ccParseOpt (compiler rst)) (parseOpts rst)])
transVerbose n | n == 0 = 0
| otherwise = n - 1
--- Extract a module name, possibly prefixed by a path, from an argument,
--- or return the current module name if the argument is the empty string.
getModuleName :: ReplState -> String -> IO String
......@@ -1127,6 +1132,13 @@ getModuleName rst args =
then return mname
else getAbsolutePath (stripCurrySuffix args)
-- Reduce verbosity in the REPL state.
reduceVerbose :: ReplState -> ReplState
reduceVerbose rst = rst { verbose = redVerb (verbose rst) }
where
redVerb n | n == 0 = 0
| otherwise = n - 1
---------------------------------------------------------------------------
-- Operations to call auxiliary tools.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment