-
-
Save DanielG/f1b92066b910a19ba707 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module A where | |
| foo = 123 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- $ ghc -package ghc -package ghc-paths GhcTestcase.hs | |
| -- $ ghc Main.hs | |
| -- $ ./GhcTestcase | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| module Main where | |
| import GHC | |
| import GHC.Paths (libdir) | |
| import DynFlags | |
| import System.Environment | |
| main :: IO () | |
| main = do | |
| args <- getArgs | |
| defaultErrorHandler defaultFatalMessager defaultFlushOut $ | |
| runGhc (Just libdir) $ | |
| doStuff "Main.hs" "Main" args | |
| doStuff :: String -> String -> [String] -> Ghc () | |
| doStuff targetFile targetModule args = do | |
| dflags0 <- getSessionDynFlags | |
| let dflags1 = dflags0 { | |
| ghcMode = CompManager | |
| , ghcLink = LinkInMemory | |
| , hscTarget = HscInterpreted | |
| , optLevel = 0 | |
| } | |
| (dflags2, _, _) <- parseDynamicFlags dflags1 (map noLoc args) | |
| _ <- setSessionDynFlags dflags2 | |
| target <- guessTarget targetFile Nothing | |
| target' <- guessTarget "A.hs" Nothing | |
| setTargets [target { targetAllowObjCode = False }] -- target' { targetAllowObjCode = False } | |
| _ <- load LoadAllTargets | |
| setContext [IIModule $ mkModuleName "A"] | |
| return () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main where | |
| import A | |
| main = print foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment