Implement basic mima-run functionality

Bugs fixed:
- Print correct file name when load/save error occurs
- Correctly identify invalid file formats
This commit is contained in:
Joscha 2020-03-27 22:07:24 +00:00
parent 362025c8df
commit 6b81fd67b4
5 changed files with 52 additions and 16 deletions

View file

@ -1,10 +1,31 @@
module Main where
import Options.Applicative
import Control.Monad.IO.Class
import qualified Data.Text.IO as T
import Options.Applicative
import Mima.MimaRun.Options
import Mima.Format
import Mima.MimaRun.Options
import Mima.Run
import Mima.Vm.State
import Mima.Vm.Storage
main :: IO ()
main = do
opts <- execParser parserInfo
putStrLn $ "The options are: " ++ show opts
main = runOrExit 2 $ do
opts <- liftIO $ execParser parserInfo
initialState <- loadMimaState $ inputFile opts
finalState <- liftIO $ case steps opts of
Nothing -> do
let (finalState, abortReason, stepsMade) = execute initialState
putStrLn $ "Stopped after " ++ show stepsMade ++ " steps, reason:"
T.putStrLn $ toText abortReason
pure finalState
Just n -> do
let (finalState, mAbortReason, stepsMade) = executeN n initialState
putStrLn $ "Stopped after " ++ show stepsMade ++ " steps, reason:"
case mAbortReason of
Nothing -> putStrLn "Ran out of steps"
Just abortReason -> T.putStrLn $ toText abortReason
pure finalState
liftIO $ putStrLn ""
liftIO $ print finalState

View file

@ -3,16 +3,16 @@ module Mima.MimaRun.Options
, parserInfo
) where
import Options.Applicative
import Options.Applicative
data Options = Options
{ inputFile :: FilePath
, steps :: Maybe Integer
, steps :: Maybe Integer
} deriving (Show)
parser :: Parser Options
parser = Options
<$> strOption
<$> strArgument
( help "The .mima file to use"
<> metavar "INPUTFILE"
)