Create compiler facade for Tokenizer, Parser and Emitter
This commit is contained in:
@@ -31,6 +31,7 @@ executable MVM
|
|||||||
Assembler.Tokenizer
|
Assembler.Tokenizer
|
||||||
Assembler.Parser
|
Assembler.Parser
|
||||||
Assembler.Emitter
|
Assembler.Emitter
|
||||||
|
Assembler.Compiler
|
||||||
Util
|
Util
|
||||||
|
|
||||||
-- LANGUAGE extensions used by modules in this package.
|
-- LANGUAGE extensions used by modules in this package.
|
||||||
|
|||||||
10
app/Assembler/Compiler.hs
Normal file
10
app/Assembler/Compiler.hs
Normal 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
|
||||||
17
app/Main.hs
17
app/Main.hs
@@ -1,4 +1,19 @@
|
|||||||
module Main where
|
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 :: IO ()
|
||||||
main = putStrLn "Hello, Haskell!"
|
main = do
|
||||||
|
(filename:_) <- getArgs
|
||||||
|
input <- readFile filename
|
||||||
|
run input
|
||||||
|
|||||||
Reference in New Issue
Block a user