Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (40 sloc) 1.09 KB
module Main where
import Text.Show.Pretty (ppShow)
import Parser
import Codegen
import Emit
import Control.Monad.Trans
import System.IO
import System.Environment
import System.Console.Haskeline
import qualified LLVM.General.AST as AST
initModule :: AST.Module
initModule = emptyModule "my cool jit"
process :: AST.Module -> String -> IO (Maybe AST.Module)
process modo source = do
let res = parseToplevel source
case res of
Left err -> print err >> return Nothing
Right ex -> do
ast <- codegen modo ex
return $ Just ast
processFile :: String -> IO (Maybe AST.Module)
processFile fname = readFile fname >>= process initModule
repl :: IO ()
repl = runInputT defaultSettings (loop initModule)
where
loop mod = do
minput <- getInputLine "ready> "
case minput of
Nothing -> outputStrLn "Goodbye."
Just input -> do
modn <- liftIO $ process mod input
case modn of
Just modn -> loop modn
Nothing -> loop mod
main :: IO ()
main = do
args <- getArgs
case args of
[] -> repl
[fname] -> processFile fname >> return ()