[project @ 2001-09-06 10:03:32 by sewardj]
[ghc-hetmet.git] / ghc / 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.core",
48                           "PrelMaybe.core",
49                           "PrelTup.core",
50                           "PrelList.core", 
51                           "PrelShow.core",
52                           "PrelEnum.core",
53                           "PrelNum.core",
54                           "PrelST.core",
55                           "PrelArr.core",
56                           "PrelDynamic.core",
57                           "PrelReal.core",
58                           "PrelFloat.core",
59                           "PrelRead.core",
60                           "PrelIOBase.core",
61                           "PrelException.core",
62                           "PrelErr.core",
63                           "PrelConc.core",
64                           "PrelPtr.core",
65                           "PrelByteArr.core",
66                           "PrelPack.core",
67                           "PrelBits.core",
68                           "PrelWord.core",
69                           "PrelInt.core",
70                           "PrelCTypes.core",
71                           "PrelStable.core",
72                           "PrelCTypesISO.core",
73                           "Monad.core",
74                           "PrelStorable.core",
75                           "PrelMarshalAlloc.core",
76                           "PrelMarshalUtils.core",
77                           "PrelMarshalArray.core",
78                           "PrelCString.core",
79                           "PrelMarshalError.core",
80                           "PrelCError.core",
81                           "PrelPosix.core",
82                           "PrelHandle.core",
83                           "PrelIO.core",
84                           "Prelude.core",
85                           "Main.core" ] 
86