module Main where import System.Exit import qualified CC.Parser as Parser import qualified CC.Typecheck as Typecheck import qualified CC.Backend.Dumb as Backend import CC.Context import CC.Pretty -- Put the passes in a type-level list to be able to run subsequences of -- passes. type Pass a b = Context -> a -> Either String b pass :: (Read a, Show b, Pretty e) => (Context -> a -> Either e b) -> Pass a b pass f ctx a = either (Left . pretty) Right (f ctx a) passJoin :: (Read a, Show c) => Pass a b -> Pass b c -> Pass a c passJoin f1 f2 ctx a = f1 ctx a >>= f2 ctx main :: IO () main = do let parse = pass Parser.runPass typecheck = pass Typecheck.runPass let combined = parse `passJoin` typecheck source <- getContents let context = Context "" Backend.builtins case combined context (read source) of Right prog -> pprint prog Left err -> die err