<commit_before>{-# LANGUAGE CPP, NondecreasingIndentation #-}
-- GHC frontend ( ghc/Main.hs ) adapted for GHCJS
#undef GHCI

{-# OPTIONS -fno-warn-incomplete-patterns -optc-DNON_POSIX_SOURCE #-}

-----------------------------------------------------------------------------
--
-- GHC Driver program
--
-- (c) The University of Glasgow 2005
--
-----------------------------------------------------------------------------

module Compiler.Program where

import qualified Compiler.GhcjsProgram  as Ghcjs
import qualified Compiler.GhcjsPlatform as Ghcjs
import qualified Compiler.GhcjsHooks    as Ghcjs
import qualified Compiler.Info          as Ghcjs
import qualified Compiler.Settings      as Ghcjs
import qualified Compiler.Utils         as Ghcjs
import           Data.IORef

-- The official GHC API
import qualified GHC
import GHC              ( -- DynFlags(..), HscTarget(..),
                          -- GhcMode(..), GhcLink(..),
                          Ghc, GhcMonad(..),
                          LoadHowMuch(..) )
import CmdLineParser

-- Implementations of the various modes (--show-iface, mkdependHS. etc.)
import LoadIface        ( showIface )
import HscMain          ( newHscEnv )
import DriverPipeline   ( compileFile )
import DriverMkDepend   ( doMkDependHS )
#ifdef GHCI
import InteractiveUI    ( interactiveUI, ghciWelcomeMsg, defaultGhciSettings )
#endif


-- Various other random stuff that we need
import Config
import Constants
import HscTypes
import Packages         ( dumpPackages )
import DriverPhases
import BasicTypes       ( failed )
import StaticFlags
import DynFlags
import ErrUtils
import FastString
import Outputable
import SrcLoc
import Util
import Panic
import MonadUtils       ( liftIO )

-- Imports for --abi-hash
import LoadIface           ( loadUserInterface )
import Module              ( mkModuleName )
import Finder              ( findImportedModule, cannotFindInterface )
import TcRnMonad           ( initIfaceCheck )
import Binary              ( openBinMem, put_, fingerprintBinMem )

-- Standard Haskell libraries
import System.IO
import System.Environment
import System.Exit
import System.FilePath
import Control.Monad
import Data.Char
import Data.List
import Data.Maybe

-----------------------------------------------------------------------------
-- ToDo:

-- time commands when run with -v
-- user ways
-- Win32 support: proper signal handling
-- reading the package configuration file is too slow
-- -K<size>

-----------------------------------------------------------------------------
-- GHC's command-line interface

main :: IO ()
main = do
   hSetBuffering stdout LineBuffering
   hSetBuffering stderr LineBuffering
   Ghcjs.ghcjsErrorHandler defaultFatalMessager defaultFlushOut $ do
    -- 1. extract the -B flag from the args
    argv0 <- getArgs

    -- fall back to native GHC if we're booting (we can't build Setup.hs with GHCJS yet)
    booting <- Ghcjs.getEnvOpt "GHCJS_BOOTING"
    when (booting && any ("Cabal-" `isPrefixOf`) argv0) Ghcjs.bootstrapFallback
    when (not booting) Ghcjs.checkIsBooted

    let (minusB_args, argv1) = partition ("-B" `isPrefixOf`) argv0
        mbMinusB | null minusB_args = Nothing
                 | otherwise = Just (drop 2 (last minusB_args))

    let argv1' = map (mkGeneralLocated "on the commandline") argv1
    (argv1'', ghcjsSettings)    <- Ghcjs.getGhcjsSettings argv1'
    (argv2, staticFlagWarnings) <- parseStaticFlags argv1''

    -- 2. Parse the "mode" flags (--make, --interactive etc.)
    (mode, argv3, modeFlagWarnings) <- parseModeFlags argv2

    let flagWarnings = staticFlagWarnings ++ modeFlagWarnings

    -- If all we want to do is something like showing the version number
    -- then do it now, before we start a GHC session etc. This makes
    -- getting basic information much more resilient.

    -- In particular, if we wait until later before giving the version
    -- number then bootstrapping gets confused, as it tries to find out
    -- what version of GHC it's using before package.conf exists, so
    -- starting the session fails.
    case mode of
         Left preStartupMode ->
            do case preStartupMode of
                   ShowSupportedExtensions -> showSupportedExtensions
                   ShowVersion             -> Ghcjs.printVersion
                   ShowNumVersion          -> Ghcjs.printNumericVersion
                   ShowNumGhcVersion       -> putStrLn cProjectVersion
                   ShowOptions             -> showOptions
         Right postStartupMode -> do
            -- start our GHC session

          let runPostStartup native = Ghcjs.runGhcSession mbMinusB $ do

               dflags0 <- GHC.getSessionDynFlags

               dflags1 <- if isJust mbMinusB
                            then return dflags0
                            else liftIO (Ghcjs.addPkgConf dflags0)

               dataDir <- liftIO Ghcjs.ghcjsDataDir
               let settings0 = (settings dflags1)
                     { sGhcUsagePath  = dataDir ++ "/doc/ghcjs-usage.txt"
                     , sGhciUsagePath = dataDir ++ "/doc/ghci-usage.txt"<commit_msg>only check that GHCJS is booted in a post startup mode, fixes #141<commit_after>{-# LANGUAGE CPP, NondecreasingIndentation #-}
-- GHC frontend ( ghc/Main.hs ) adapted for GHCJS
#undef GHCI

{-# OPTIONS -fno-warn-incomplete-patterns -optc-DNON_POSIX_SOURCE #-}

-----------------------------------------------------------------------------
--
-- GHC Driver program
--
-- (c) The University of Glasgow 2005
--
-----------------------------------------------------------------------------

module Compiler.Program where

import qualified Compiler.GhcjsProgram  as Ghcjs
import qualified Compiler.GhcjsPlatform as Ghcjs
import qualified Compiler.GhcjsHooks    as Ghcjs
import qualified Compiler.Info          as Ghcjs
import qualified Compiler.Settings      as Ghcjs
import qualified Compiler.Utils         as Ghcjs
import           Data.IORef

-- The official GHC API
import qualified GHC
import GHC              ( -- DynFlags(..), HscTarget(..),
                          -- GhcMode(..), GhcLink(..),
                          Ghc, GhcMonad(..),
                          LoadHowMuch(..) )
import CmdLineParser

-- Implementations of the various modes (--show-iface, mkdependHS. etc.)
import LoadIface        ( showIface )
import HscMain          ( newHscEnv )
import DriverPipeline   ( compileFile )
import DriverMkDepend   ( doMkDependHS )
#ifdef GHCI
import InteractiveUI    ( interactiveUI, ghciWelcomeMsg, defaultGhciSettings )
#endif


-- Various other random stuff that we need
import Config
import Constants
import HscTypes
import Packages         ( dumpPackages )
import DriverPhases
import BasicTypes       ( failed )
import StaticFlags
import DynFlags
import ErrUtils
import FastString
import Outputable
import SrcLoc
import Util
import Panic
import MonadUtils       ( liftIO )

-- Imports for --abi-hash
import LoadIface           ( loadUserInterface )
import Module              ( mkModuleName )
import Finder              ( findImportedModule, cannotFindInterface )
import TcRnMonad           ( initIfaceCheck )
import Binary              ( openBinMem, put_, fingerprintBinMem )

-- Standard Haskell libraries
import System.IO
import System.Environment
import System.Exit
import System.FilePath
import Control.Monad
import Data.Char
import Data.List
import Data.Maybe

-----------------------------------------------------------------------------
-- ToDo:

-- time commands when run with -v
-- user ways
-- Win32 support: proper signal handling
-- reading the package configuration file is too slow
-- -K<size>

-----------------------------------------------------------------------------
-- GHC's command-line interface

main :: IO ()
main = do
   hSetBuffering stdout LineBuffering
   hSetBuffering stderr LineBuffering
   Ghcjs.ghcjsErrorHandler defaultFatalMessager defaultFlushOut $ do
    -- 1. extract the -B flag from the args
    argv0 <- getArgs

    -- fall back to native GHC if we're booting (we can't build Setup.hs with GHCJS yet)
    booting <- Ghcjs.getEnvOpt "GHCJS_BOOTING"
    when (booting && any ("Cabal-" `isPrefixOf`) argv0) Ghcjs.bootstrapFallback

    let (minusB_args, argv1) = partition ("-B" `isPrefixOf`) argv0
        mbMinusB | null minusB_args = Nothing
                 | otherwise = Just (drop 2 (last minusB_args))

    let argv1' = map (mkGeneralLocated "on the commandline") argv1
    (argv1'', ghcjsSettings)    <- Ghcjs.getGhcjsSettings argv1'
    (argv2, staticFlagWarnings) <- parseStaticFlags argv1''

    -- 2. Parse the "mode" flags (--make, --interactive etc.)
    (mode, argv3, modeFlagWarnings) <- parseModeFlags argv2

    let flagWarnings = staticFlagWarnings ++ modeFlagWarnings

    -- If all we want to do is something like showing the version number
    -- then do it now, before we start a GHC session etc. This makes
    -- getting basic information much more resilient.

    -- In particular, if we wait until later before giving the version
    -- number then bootstrapping gets confused, as it tries to find out
    -- what version of GHC it's using before package.conf exists, so
    -- starting the session fails.
    case mode of
         Left preStartupMode ->
            do case preStartupMode of
                   ShowSupportedExtensions -> showSupportedExtensions
                   ShowVersion             -> Ghcjs.printVersion
                   ShowNumVersion          -> Ghcjs.printNumericVersion
                   ShowNumGhcVersion       -> putStrLn cProjectVersion
                   ShowOptions             -> showOptions
         Right postStartupMode -> do
          when (not booting) Ghcjs.checkIsBooted
            -- start our GHC session

          let runPostStartup native = Ghcjs.runGhcSession mbMinusB $ do

               dflags0 <- GHC.getSessionDynFlags

               dflags1 <- if isJust mbMinusB
                            then return dflags0
                            else liftIO (Ghcjs.addPkgConf dflags0)

               dataDir <- liftIO Ghcjs.ghcjsDataDir
               let settings0 = (settings dflags1)
                     { sGhcUsagePath  = dataDir ++ "/doc/ghcjs-usage.txt"
                     , sGhciUsagePath = dataDir ++ "/doc/ghci-usage.txt"
{'fraction_non_alphanumeric': 0.12827250608272506, 'fraction_numerical': 0.005547445255474452, 'mean_word_length': 1.945256520492978, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4976036', 'n_tokens_mistral': 2813, 'n_tokens_neox': 2697, 'n_words': 893}