-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
51 lines (44 loc) · 2 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{-# LANGUAGE LambdaCase #-}
module Main (main, runTest) where
import Frontend.HsParser (hsParse)
import Frontend.HsRenamer (hsRename)
import Frontend.HsTypeChecker (hsElaborate)
import Backend.FcTypeChecker (fcTypeCheck)
import Utils.Unique (newUniqueSupply)
import Utils.PrettyPrint
import System.Environment (getArgs)
main :: IO ()
main = getArgs >>= \case
[filename] -> runTest filename
_other -> putStrLn "Usage: ghc <filename>"
-- | Run a single testfile
runTest :: FilePath -> IO ()
runTest file = do
-- Parsing
hsParse file >>= \case
Left err -> throwMainError "parser" err
Right ps_pgm -> do
-- Renaming
us0 <- newUniqueSupply 'u'
case hsRename us0 ps_pgm of
(Left err,_) -> throwMainError "renamer" err
(Right (((rn_pgm, _rn_ctx), us1), rn_env), _) ->
case hsElaborate rn_env us1 rn_pgm of
(Left err,_) -> throwMainError "typechecker" err
(Right ((((fc_pgm, tc_ty, theory), envs), us2), _tc_env), _) ->
case fcTypeCheck envs us2 fc_pgm of
(Left err,_) -> throwMainError "System F typechecker" err
(Right ((fc_ty, _us3), _fc_env), _trace) -> do
putStrLn "---------------------------- Elaborated Program ---------------------------"
putStrLn $ renderWithColor $ ppr fc_pgm
putStrLn "------------------------------- Program Type ------------------------------"
putStrLn $ renderWithColor $ ppr tc_ty
putStrLn "------------------------------ Program Theory -----------------------------"
putStrLn $ renderWithColor $ ppr theory
putStrLn "-------------------------- System F Program Type --------------------------"
putStrLn $ renderWithColor $ ppr fc_ty
where
throwMainError phase e
| label <- colorDoc red (text phase <+> text "failure")
, msg <- brackets label <+> colorDoc red (text e)
= putStrLn (renderWithColor msg)