Remove IO related code from SemSyn.hs
authorJoachim Breitner <mail@joachim-breitner.de>
Sun, 18 Jul 2010 17:29:52 +0000 (17:29 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Sun, 18 Jul 2010 17:29:52 +0000 (17:29 +0000)
Main.hs
SemSyn.hs

diff --git a/Main.hs b/Main.hs
index 37a88d5..b0717f6 100644 (file)
--- a/Main.hs
+++ b/Main.hs
@@ -216,12 +216,12 @@ main = do { args <- getArgs
                          Left err -> hPutStrLn stderr (show err)
                          Right cprog -> 
                              case execMode conf of 
-                               Normal -> 
+                               Normal -> print $
                                    outputCode conf False (cprog) (typeInference cprog)
-                               Shapify ->
+                               Shapify -> print $
                                    outputCode conf False (cprog) (shapify $ typeInference cprog)
                                    -- putStrLn "Not Supported Now."
-                               ShapifyPlus ->
+                               ShapifyPlus -> print $
                                    outputCode conf True  (cprog) (introNat $ shapify $ typeInference cprog)
                                Debug ->
                                    do { print $ ppr   $ cprog
index 3d412df..40543df 100644 (file)
--- a/SemSyn.hs
+++ b/SemSyn.hs
@@ -49,25 +49,29 @@ defaultConfig = Config {
                   isShowType  = True  }
 
 
-outputCode :: Config -> Bool -> AST -> AST -> IO ()
+outputCode :: Config -> Bool -> AST -> AST -> Doc
 outputCode conf isShapify orig ast =
     let (p1,p2,p3) = constructBwdFunction ast
     in case outputMode conf of 
-         ForwardCode -> 
-             do print $ ppr (typeFilter ast)
-         PseudoCode  ->
-             do print $ ppr (constructTypeDecl p2)
-                print $ ppr orig $$  ppr (typeFilter p1) $$ ppr (typeFilter p2) $$ ppr (typeFilterT p3)
-         HaskellCode ->
-             do putStrLn $ "import Control.Monad"
-                putStrLn $ "import BUtil"
-                when isShapify $
-                     print $ vcat $ map genBwdDef 
-                               (let AST decls = typeInference orig
-                                in map (\(Decl f t _ _:_) -> (f,t)) $ 
-                                     groupBy isSameFunc decls)
-                print $ ppr (constructTypeDecl p2)
-                print $ ppr $ generateCodeBwd (orig,p1,p2,p3)
+         ForwardCode ->
+                  ppr (typeFilter ast)
+         PseudoCode  -> vcat
+                [ ppr (constructTypeDecl p2)
+                , ppr orig $$  ppr (typeFilter p1) $$ ppr (typeFilter p2) $$ ppr (typeFilterT p3)
+                ]
+         HaskellCode -> vcat $
+                [ text "import Control.Monad"
+                , text "import BUtil"
+                ] ++ (
+                if isShapify
+                then map genBwdDef $
+                        let AST decls = typeInference orig
+                        in map (\(Decl f t _ _:_) -> (f,t)) $ groupBy isSameFunc decls
+                else []                                     
+                ) ++
+                [ ppr (constructTypeDecl p2)
+                , ppr $ generateCodeBwd (orig,p1,p2,p3)
+                ]
     where
       typeFilter  = if isShowType conf then id else eraseType
       typeFilterT = if isShowType conf then id else eraseTypeT