diff --git a/MVM.cabal b/MVM.cabal index 51d0a42..3e603cf 100644 --- a/MVM.cabal +++ b/MVM.cabal @@ -34,6 +34,7 @@ executable MVM Assembler.Parser Assembler.Emitter Assembler.Compiler + Runner Util -- LANGUAGE extensions used by modules in this package. @@ -74,6 +75,7 @@ test-suite spec Assembler.Tokenizer Assembler.Parser Assembler.Emitter + Runner Util default-language: Haskell2010 diff --git a/app/Main.hs b/app/Main.hs index 94f719b..f2cd37d 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,21 +1,14 @@ module Main where import System.Environment -import Control.Monad.Trans.Except (runExceptT, except) -import VirtualMachine.VM (VM(..), empty) -import VirtualMachine.Interpreter (run) -import Assembler.Compiler (compile) -import qualified Data.ByteString as B +import Runner (run, runDebug) -interpret :: String -> IO (Either String VM) -interpret input = runExceptT $ (except $ return $ input) >>= (except . compile) >>= (except . return . B.pack) >>= run empty { _debug = False } - main :: IO () main = do (filename:_) <- getArgs input <- readFile filename - result <- interpret input + result <- run input case result of (Right vm) -> do putStrLn $ "\n\nDone:\n" ++ (show vm) diff --git a/app/Runner.hs b/app/Runner.hs new file mode 100644 index 0000000..ccf3deb --- /dev/null +++ b/app/Runner.hs @@ -0,0 +1,14 @@ +module Runner where + +import Control.Monad.Trans.Except (runExceptT, except) +import qualified Data.ByteString as B + +import Assembler.Compiler (compile) +import VirtualMachine.VM (VM(..), empty) +import qualified VirtualMachine.Interpreter as VM (run) + +run :: String -> IO (Either String VM) +run input = runExceptT $ (except $ return $ input) >>= (except . compile) >>= (except . return . B.pack) >>= VM.run empty + +runDebug :: String -> IO (Either String VM) +runDebug input = runExceptT $ (except $ return $ input) >>= (except . compile) >>= (except . return . B.pack) >>= VM.run empty { _debug = True } \ No newline at end of file