65
66
-- | The main function
68
do progName <- liftIO getProgName
69
argv <- liftIO getArgs
70
let opts = parseStandardOptions progName argv
72
Left err -> liftIO $ optionError err
74
| optShowHelp opts -> liftIO printUsage
75
| optShowVersion opts -> liftIO printVersion
76
| optRunTests opts -> liftIO $ do
79
| isNothing (optInputFile opts)
80
&& not (optInteractive opts)
82
| otherwise -> do setCommandLineOptions opts
87
do i <- optInteractive <$> liftTCM commandLineOptions
88
compile <- optCompile <$> liftTCM commandLineOptions
89
alonzo <- optCompileAlonzo <$> liftTCM commandLineOptions
90
malonzo <- optCompileMAlonzo <$> liftTCM commandLineOptions
91
when i $ liftIO $ UTF8.putStr splashScreen
92
let failIfError (_, Right _) = return ()
93
failIfError (_, Left err) = typeError err
95
failIfNoInt (_, Right (Just i)) = return i
96
-- The allowed combinations of command-line
97
-- options should rule out Right Nothing here.
98
failIfNoInt (_, Right Nothing) = __IMPOSSIBLE__
99
failIfNoInt (_, Left err) = typeError err
102
:: TCM (ScopeInfo, Either TypeError (Maybe Interface))
104
interaction | i = runIM . interactionLoop
105
| compile = Agate.compilerMain . (failIfError =<<)
106
| alonzo = Alonzo.compilerMain . (failIfError =<<)
107
| malonzo = MAlonzo.compilerMain . (failIfNoInt =<<)
108
| otherwise = (failIfError =<<)
110
do hasFile <- hasInputFile
113
do file <- getInputFile
114
options <- commandLineOptions
116
(topLevel, ok) <- Imp.createInterface options
118
Map.empty emptySignature
119
Map.empty Nothing file False
121
-- The value of options from above
122
-- cannot be reused here, because then
123
-- options set in pragmas would have
125
unsolvedOK <- optAllowUnsolved <$> commandLineOptions
127
let result = case ok of
128
Imp.Warnings [] [] -> __IMPOSSIBLE__
129
Imp.Warnings _ unsolved@(_:_)
130
| unsolvedOK -> Right Nothing
131
| otherwise -> Left $ UnsolvedMetas unsolved
132
Imp.Warnings termErrs@(_:_) _ ->
133
Left (TerminationCheckFailed termErrs)
134
Imp.Success { Imp.cirInterface = i } ->
138
stats <- Map.toList <$> getStatistics
142
UTF8.putStrLn "Statistics"
143
UTF8.putStrLn "----------"
144
mapM_ (\ (s,n) -> UTF8.putStrLn $ s ++ " : " ++ show n) $
145
sortBy (\x y -> compare (snd x) (snd y)) stats
147
whenM (optGenerateHTML <$> commandLineOptions) $ do
149
Imp.Success {} -> generateHTML $ topLevelModuleName topLevel
151
-- The error will be handled by interaction.
153
return (insideScope topLevel, result)
154
else return (emptyScopeInfo, Right Nothing)
69
progName <- liftIO getProgName
70
argv <- liftIO getArgs
71
let opts = parseStandardOptions progName argv
73
Left err -> liftIO $ optionError err
75
| optShowHelp opts -> liftIO printUsage
76
| optShowVersion opts -> liftIO printVersion
77
| optRunTests opts -> liftIO $ do
80
| isNothing (optInputFile opts)
81
&& not (optInteractive opts)
84
setCommandLineOptions PersistentOptions opts
89
i <- optInteractive <$> liftTCM commandLineOptions
90
compile <- optCompile <$> liftTCM commandLineOptions
91
alonzo <- optCompileAlonzo <$> liftTCM commandLineOptions
92
malonzo <- optCompileMAlonzo <$> liftTCM commandLineOptions
93
when i $ liftIO $ LocIO.putStr splashScreen
94
let failIfNoInt (Just i) = return i
95
-- The allowed combinations of command-line
96
-- options should rule out Nothing here.
97
failIfNoInt Nothing = __IMPOSSIBLE__
99
interaction :: TCM (Maybe Interface) -> TCM ()
100
interaction | i = runIM . interactionLoop
101
| compile = Agate.compilerMain . (() <$)
102
| alonzo = Alonzo.compilerMain . (() <$)
103
| malonzo = (MAlonzo.compilerMain =<<) . (failIfNoInt =<<)
104
| otherwise = (() <$)
106
hasFile <- hasInputFile
108
if not hasFile then return Nothing else do
110
(i, mw) <- Imp.typeCheck file Imp.CurrentDir Nothing
112
unsolvedOK <- optAllowUnsolved <$> commandLineOptions
115
Just (Imp.Warnings [] [] []) -> __IMPOSSIBLE__
116
Just (Imp.Warnings _ unsolved@(_:_) _)
117
| not unsolvedOK -> typeError $ UnsolvedMetas unsolved
118
Just (Imp.Warnings _ _ unsolved@(_:_))
119
| not unsolvedOK -> typeError $ UnsolvedConstraints unsolved
120
Just (Imp.Warnings termErrs@(_:_) _ _) ->
121
typeError $ TerminationCheckFailed termErrs
122
Just _ -> return Nothing
123
Nothing -> return $ Just i
126
stats <- Map.toList <$> getStatistics
130
LocIO.putStrLn "Statistics"
131
LocIO.putStrLn "----------"
132
mapM_ (\ (s,n) -> LocIO.putStrLn $ s ++ " : " ++ show n) $
133
sortBy (\x y -> compare (snd x) (snd y)) stats
135
whenM (optGenerateHTML <$> commandLineOptions) $ do
137
Nothing -> generateHTML $ iModuleName i
138
Just _ -> reportSLn "" 1
139
"HTML is not generated (unsolved meta-variables)."
156
143
-- | Print usage information.
157
144
printUsage :: IO ()
159
do progName <- getProgName
160
UTF8.putStr $ usage standardOptions_ [] progName
146
progName <- getProgName
147
LocIO.putStr $ usage standardOptions_ [] progName
162
149
-- | Print version information.
163
150
printVersion :: IO ()
165
UTF8.putStrLn $ "Agda version " ++ version
152
LocIO.putStrLn $ "Agda version " ++ version
167
154
-- | What to do for bad options.
168
155
optionError :: String -> IO ()
170
do UTF8.putStrLn $ "Error: " ++ err
157
LocIO.putStrLn $ "Error: " ++ err
177
164
r <- runTCM $ runAgda `catchError` \err -> do
179
liftIO $ UTF8.putStrLn s
166
liftIO $ LocIO.putStrLn s
182
Right _ -> exitSuccess
183
Left _ -> exitFailure
169
Right _ -> exitSuccess
170
Left _ -> exitFailure
184
171
`catchImpossible` \e -> do
172
LocIO.putStr $ show e