sourcecode:
|
import Data.List ( intersperse )
import System.Environment ( getArgs )
import FlatCurry.Types
import FlatCurry.Files
import FlatCurry.Compact
import System.CurryPath ( runModuleAction )
import System.Process ( system )
-- Check arguments and call main function:
main :: IO ()
main = do
args <- getArgs
case args of
["-h"] -> putStrLn usage
["--help"] -> putStrLn usage
["--export",mname] -> compactProgAndReplace [Exports] mname
["--main",func,mname] -> compactProgAndReplace [Main func] mname
[mname] -> compactProgAndReplace [] mname
_ -> putStrLn $ useError args
where
useError args = "ERROR: Illegal arguments: " ++ unwords args ++ "\n" ++ usage
usage = "Usage: curry-compactflat [--export | --main func] <module_name>"
-- replace a FlatCurry program by a compactified version:
compactProgAndReplace :: [Option] -> String -> IO ()
compactProgAndReplace options = runModuleAction compact
where
compact mname = do
generateCompactFlatCurryFile (Required defaultRequired : options)
mname (mname ++ "_comp.fcy")
let fcyname = flatCurryFileName mname
system $ "mv " ++ mname ++ "_comp.fcy " ++ fcyname
putStrLn $
"curry-compactflat: compacted program '" ++ fcyname ++ "' written."
|