@@ -6,7 +6,7 @@ import qualified Data.Map as Map
66import qualified Data.List as List
77import Data.Binary (encodeFile, decodeFile)
88import Data.Version (showVersion)
9−import System.Console.CmdArgs
9+import System.Console.CmdArgs hiding (program)
1010import System.Directory
1111import System.Exit
1212import System.FilePath
@@ -17,11 +17,12 @@ import qualified Text.Jasmine as JS
1717import qualified Data.ByteString.Lazy.Char8 as BS
1818
1919import SourceSyntax.Module
20−import Initialize (buildFromSource, getSortedModuleNames, TypeLibrary)
20+import Initialize (buildFromSource, getSortedModuleNames, Interfaces)
2121import Generate.JavaScript (jsModule)
2222import Generate.Html (createHtml, JSStyle(..), JSSource(..))
2323import Paths_Elm
2424
25+import SourceSyntax.PrettyPrint (pretty)
2526import Text.PrettyPrint as P
2627import qualified Type.Type as Type
2728import qualified Parse.Type as Parse
@@ -33,6 +34,7 @@ data Flags =
3334 , runtime :: Maybe FilePath
3435 , only_js :: Bool
3536 , print_types :: Bool
37+ , print_program :: Bool
3638 , scripts :: [FilePath]
3739 , no_prelude :: Bool
3840 , minify :: Bool
@@ -50,6 +52,8 @@ flags = Flags
5052 &= help "Compile only to JavaScript."
5153 , print_types = False
5254 &= help "Print out infered types of top-level definitions."
55+ , print_program = False
56+ &= help "Print out an internal representation of a program."
5357 , scripts = [] &= typFile
5458 &= help "Load JavaScript files in generated HTML. Files will be included in the given order."
5559 , no_prelude = False
@@ -79,7 +83,7 @@ elmo flags filePath = file flags filePath "elmo"
7983elmi flags filePath = file flags filePath "elmi"
8084
8185
82−buildFile :: Flags -> Int -> Int -> TypeLibrary -> FilePath -> IO ModuleInterface
86+buildFile :: Flags -> Int -> Int -> Interfaces -> FilePath -> IO ModuleInterface
8387buildFile flags moduleNum numModules interfaces filePath =
8488 do compiled <- alreadyCompiled
8589 if compiled then decodeFile (elmi flags filePath) else compile
@@ -107,13 +111,15 @@ buildFile flags moduleNum numModules interfaces filePath =
107111 metaModule <-
108112 case buildFromSource interfaces source of
109113 Left err -> mapM print err >> exitFailure
110− Right modul -> return (modul :: MetadataModule () ())
114+ Right modul -> do
115+ if print_program flags then print . pretty $ program modul else return ()
116+ return (modul :: MetadataModule () ())
117+
111118 if print_types flags then printTypes metaModule else return ()
112119 tipes <- toSrcTypes (types metaModule)
113− let fmt (name, tvars, ctors) = (name, (length tvars, map fst ctors))
114− interface = ModuleInterface {
120+ let interface = ModuleInterface {
115121 iTypes = tipes,
116− iAdts = Map.fromList . map fmt $ datatypes metaModule
122+ iAdts = datatypes metaModule
117123 }
118124 encodeFile (elmi flags filePath) interface
119125 let js = jsModule metaModule
@@ -167,7 +173,7 @@ build flags rootFile = do
167173 [ Source (if minify flags then Minified else Readable) js ]
168174
169175
170−buildFiles :: Flags -> Int -> TypeLibrary -> [FilePath] -> IO TypeLibrary
176+buildFiles :: Flags -> Int -> Interfaces -> [FilePath] -> IO Interfaces
171177buildFiles _ _ interfaces [] = return interfaces
172178buildFiles flags numModules interfaces (filePath:rest) = do
173179 interface <- buildFile flags (numModules - length rest) numModules interfaces filePath