module Main where

import DD (dd) 
import Buddha (runComp)
import qualified Main_Buddha (main)
import IOPrims_Buddha (runIO)
import Prelude
import Posix
import Control.Concurrent
import Control.Exception

main :: Prelude.IO ()
main = do catchCtrlC 
          let comp = do ioComp <- Main_Buddha.main
                        IOPrims_Buddha.runIO ioComp
          case runComp 0 comp of
             (Left e, _line, trees)   -> dd (Just e) trees
             (Right (), _line, trees) -> dd Nothing  trees 

catchCtrlC :: Prelude.IO Handler 
catchCtrlC 
   = do main_thread <- myThreadId
        installHandler sigINT (Catch (hupHandler main_thread)) Nothing
        where
        hupHandler :: ThreadId -> IO ()
        hupHandler main_thread
           = throwTo main_thread (ErrorCall "Interrupt Signal")
