Create compiler facade for Tokenizer, Parser and Emitter

This commit is contained in:
2021-11-08 16:42:28 +01:00
parent e353caca8d
commit f9496adf8c
3 changed files with 27 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ executable MVM
Assembler.Tokenizer
Assembler.Parser
Assembler.Emitter
Assembler.Compiler
Util
-- LANGUAGE extensions used by modules in this package.

10
app/Assembler/Compiler.hs Normal file
View File

@@ -0,0 +1,10 @@
module Assembler.Compiler where
import Data.Word (Word8)
import Assembler.Tokenizer (tokenize)
import Assembler.Parser (parse)
import Assembler.Emitter (emit)
compile :: String -> Either String [Word8]
compile input = return input >>= tokenize >>= parse >>= emit

View File

@@ -1,4 +1,19 @@
module Main where
import System.Environment
import qualified Data.ByteString as B
import qualified VirtualMachine as VM
import Assembler.Compiler (compile)
run :: String -> IO ()
run input = case compile input of
(Right bytes) -> print $ VM.run VM.empty (B.pack bytes)
(Left err) -> putStrLn err
main :: IO ()
main = putStrLn "Hello, Haskell!"
main = do
(filename:_) <- getArgs
input <- readFile filename
run input