Create Runner

This commit is contained in:
2021-11-10 11:48:09 +01:00
parent 8880fcae8a
commit 00219b6316
3 changed files with 18 additions and 9 deletions

View File

@@ -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

View File

@@ -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)

14
app/Runner.hs Normal file
View File

@@ -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 }