Split VirtualMachine module

This commit is contained in:
2021-11-09 18:25:15 +01:00
parent 3faa4f4abf
commit bfb231d483
10 changed files with 212 additions and 193 deletions

View File

@@ -1,22 +1,21 @@
module Main where
import System.Environment
import qualified Data.ByteString as B
import qualified VirtualMachine as VM
import Control.Monad.Trans.Except (runExceptT, except)
import VirtualMachine.VM (VM)
import VirtualMachine.Interpreter (run)
import Assembler.Compiler (compile)
import qualified Data.ByteString as B
import Control.Monad.Trans.Except
run :: String -> IO (Either String VM.VM)
run input = runExceptT $ (except $ return $ input) >>= (except . compile) >>= (except . return . B.pack) >>= VM.run
interpret :: String -> IO (Either String VM)
interpret input = runExceptT $ (except $ return $ input) >>= (except . compile) >>= (except . return . B.pack) >>= run
main :: IO ()
main = do
(filename:_) <- getArgs
input <- readFile filename
result <- run input
result <- interpret input
case result of
(Right vm) -> do
putStrLn $ "\n\nDone:\n" ++ (show vm)