Reorganisation of the source tree
[ghc-hetmet.git] / utils / ext-core / Driver.hs
1 {- A simple driver that loads, typechecks, prepares, re-typechecks, and interprets the 
2     GHC standard Prelude modules and an application module called Main. 
3
4    Note that, if compiled under GHC, this requires a very large heap to run!
5 -}
6
7 import Monad
8 import Core
9 import Printer
10 import Parser
11 import Lex
12 import ParseGlue
13 import Env
14 import Prims
15 import Check
16 import Prep
17 import Interp
18
19 process (senv,modules) f = 
20        do putStrLn ("Processing " ++ f)
21           s <- readFile f
22           case parse s 1 of
23             OkP m -> do putStrLn "Parse succeeded"
24                         {- writeFile (f ++ ".parsed") (show m) -}
25                         case checkModule senv m of
26                           OkC senv' -> 
27                             do putStrLn "Check succeeded"
28                                let m' = prepModule senv' m
29                                {- writeFile (f ++ ".prepped") (show m') -}
30                                case checkModule senv m' of
31                                  OkC senv'' ->
32                                    do putStrLn "Recheck succeeded"
33                                       return (senv'',modules ++ [m'])
34                                  FailC s -> 
35                                    do putStrLn ("Recheck failed: " ++ s)
36                                       error "quit"
37                           FailC s -> 
38                             do putStrLn ("Check failed: " ++ s)
39                                error "quit"
40             FailP s -> do putStrLn ("Parse failed: " ++ s)
41                           error "quit"
42
43 main = do (_,modules) <- foldM process (initialEnv,[]) flist
44           let result = evalProgram modules
45           putStrLn ("Result = " ++ show result)
46           putStrLn "All done"
47        where flist =     ["PrelBase.hcr",
48                           "PrelMaybe.hcr",
49                           "PrelTup.hcr",
50                           "PrelList.hcr", 
51                           "PrelShow.hcr",
52                           "PrelEnum.hcr",
53                           "PrelNum.hcr",
54                           "PrelST.hcr",
55                           "PrelArr.hcr",
56                           "PrelDynamic.hcr",
57                           "PrelReal.hcr",
58                           "PrelFloat.hcr",
59                           "PrelRead.hcr",
60                           "PrelIOBase.hcr",
61                           "PrelException.hcr",
62                           "PrelErr.hcr",
63                           "PrelConc.hcr",
64                           "PrelPtr.hcr",
65                           "PrelByteArr.hcr",
66                           "PrelPack.hcr",
67                           "PrelBits.hcr",
68                           "PrelWord.hcr",
69                           "PrelInt.hcr",
70                           "PrelCTypes.hcr",
71                           "PrelStable.hcr",
72                           "PrelCTypesISO.hcr",
73                           "Monad.hcr",
74                           "PrelStorable.hcr",
75                           "PrelMarshalAlloc.hcr",
76                           "PrelMarshalUtils.hcr",
77                           "PrelMarshalArray.hcr",
78                           "PrelCString.hcr",
79                           "PrelMarshalError.hcr",
80                           "PrelCError.hcr",
81                           "PrelPosix.hcr",
82                           "PrelHandle.hcr",
83                           "PrelIO.hcr",
84                           "Prelude.hcr",
85                           "Main.hcr" ] 
86