Create Runner
This commit is contained in:
@@ -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
|
||||
|
||||
11
app/Main.hs
11
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)
|
||||
|
||||
14
app/Runner.hs
Normal file
14
app/Runner.hs
Normal 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 }
|
||||
Reference in New Issue
Block a user