ihaskell 0.4.0.0 → 0.4.1.0
raw patch · 7 files changed
+115/−52 lines, 7 filesdep ~basedep ~ghcdep ~ghc-parser
Dependency ranges changed: base, ghc, ghc-parser
Files
- ihaskell.cabal +8/−8
- installation/run.sh +6/−1
- src/Hspec.hs +5/−1
- src/IHaskell/Eval/Evaluate.hs +25/−34
- src/IHaskell/Eval/Parser.hs +1/−1
- src/IHaskell/Eval/Util.hs +67/−5
- src/IHaskell/IPython.hs +3/−2
ihaskell.cabal view
@@ -7,7 +7,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.4.0.0+version: 0.4.1.0 -- A short (one-line) description of the package. synopsis: A Haskell backend kernel for the IPython project.@@ -54,7 +54,7 @@ ghc-options: -threaded build-depends: aeson >=0.6 && < 0.8,- base ==4.6.*,+ base >=4.6 && < 4.8, base64-bytestring >=1.0, bytestring >=0.10, cereal >=0.3,@@ -64,8 +64,8 @@ containers >=0.5, directory -any, filepath -any,- ghc ==7.6.*,- ghc-parser >=0.1.1,+ ghc ==7.6.* || == 7.8.*,+ ghc-parser >=0.1.2, ghc-paths ==0.1.*, haskeline -any, here ==1.2.*,@@ -133,7 +133,7 @@ -- Other library packages from which modules are imported. default-language: Haskell2010 build-depends: - base ==4.6.*,+ base >=4.6 && < 4.8, aeson >=0.6 && < 0.8, bytestring >=0.10, cereal >=0.3,@@ -141,7 +141,7 @@ mono-traversable ==0.6.0, containers >=0.5, directory -any,- ghc ==7.6.*,+ ghc ==7.6.* || == 7.8.*, ihaskell -any, MissingH >=1.2, text -any,@@ -155,7 +155,7 @@ default-language: Haskell2010 build-depends: aeson >=0.6 && < 0.8,- base ==4.6.*,+ base >=4.6 && < 4.8, base64-bytestring >=1.0, bytestring >=0.10, cereal >=0.3,@@ -165,7 +165,7 @@ containers >=0.5, directory -any, filepath -any,- ghc ==7.6.*,+ ghc ==7.6.* || == 7.8.*, ghc-parser >=0.1.1, ghc-paths ==0.1.*, haskeline -any,
installation/run.sh view
@@ -12,4 +12,9 @@ # Run IPython. # Quotes around $@ are necessary to deal properly with spaces.-ipython "$@" $IHASKELL_IPYTHON_ARGS+# Only add IHASKELL_IPYTHON_ARGS to notebook.+if [[ $1 == "notebook" ]]; then+ ipython "$@" $IHASKELL_IPYTHON_ARGS+else+ ipython "$@"+fi
src/Hspec.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE QuasiQuotes, OverloadedStrings, ExtendedDefaultRules #-}+{-# LANGUAGE QuasiQuotes, OverloadedStrings, ExtendedDefaultRules, CPP #-} -- Keep all the language pragmas here so it can be compiled separately. module Main where import Prelude@@ -500,7 +500,11 @@ it "breaks without data kinds" $ parses "data X = 3" `like` [+#if MIN_VERSION_ghc(7, 8, 0)+ ParseError (Loc 1 10) "Illegal literal in type (use DataKinds to enable): 3"+#else ParseError (Loc 1 10) "Illegal literal in type (use -XDataKinds to enable): 3"+#endif ] it "parses statements after imports" $ do
src/IHaskell/Eval/Evaluate.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE DoAndIfThenElse, NoOverloadedStrings, TypeSynonymInstances #-}+{-# LANGUAGE DoAndIfThenElse, NoOverloadedStrings, TypeSynonymInstances, CPP #-} {- | Description : Wrapper around GHC API, exposing a single `evaluate` interface that runs a statement, declaration, import, or directive.@@ -77,9 +77,14 @@ data ErrorOccurred = Success | Failure deriving (Show, Eq) +-- | Enable debugging output debug :: Bool debug = False +-- | Set GHC's verbosity for debugging+ghcVerbosity :: Maybe Int+ghcVerbosity = Nothing -- Just 5+ ignoreTypePrefixes :: [String] ignoreTypePrefixes = ["GHC.Types", "GHC.Base", "GHC.Show", "System.IO", "GHC.Float", ":Interactive", "GHC.Num", "GHC.IO",@@ -96,8 +101,12 @@ type Interpreter = Ghc +#if MIN_VERSION_ghc(7, 8, 0)+ -- GHC 7.8 exports a MonadIO instance for Ghc+#else instance MonadIO.MonadIO Interpreter where liftIO = MonadUtils.liftIO+#endif globalImports :: [String] globalImports =@@ -115,18 +124,13 @@ -- is handled specially, which cannot be done in a testing environment. interpret :: Bool -> Interpreter a -> IO a interpret allowedStdin action = runGhc (Just libdir) $ do- initGhci- -- If we're in a sandbox, add the relevant package database- dflags <- getSessionDynFlags sandboxPackages <- liftIO getSandboxPackageConf- let pkgConfs = case sandboxPackages of- Nothing -> extraPkgConfs dflags- Just path ->- let pkg = PkgConfFile path in- (pkg:) . extraPkgConfs dflags-- void $ setSessionDynFlags $ dflags { extraPkgConfs = pkgConfs }+ initGhci sandboxPackages+ case ghcVerbosity of+ Just verb -> do dflags <- getSessionDynFlags+ void $ setSessionDynFlags $ dflags { verbosity = verb }+ Nothing -> return () initializeImports @@ -618,30 +622,8 @@ evalCommand _ (Directive GetInfo str) state = safely state $ do write $ "Info: " ++ str -- Get all the info for all the names we're given.- names <- parseName str- maybeInfos <- mapM getInfo names-- -- Filter out types that have parents in the same set.- -- GHCi also does this.- let getType (theType, _, _) = theType- infos = catMaybes maybeInfos- allNames = mkNameSet $ map (getName . getType) infos- hasParent info = case tyThingParent_maybe (getType info) of- Just parent -> getName parent `elemNameSet` allNames- Nothing -> False- filteredOutput = filter (not . hasParent) infos-- -- Convert to textual data.- let printInfo (thing, fixity, classInstances) =- pprTyThingInContextLoc False thing $$ showFixity fixity $$ vcat (map GHC.pprInstance classInstances)- where- showFixity fixity =- if fixity == GHC.defaultFixity- then empty- else ppr fixity <+> pprInfixName (getName thing)+ strings <- getDescription str - -- Print nicely.- strings <- mapM (doc . printInfo) filteredOutput let output = case getFrontend state of IPythonConsole -> unlines strings IPythonNotebook -> unlines (map htmlify strings)@@ -723,6 +705,9 @@ let widgetExpr = printf "(IHaskell.Display.Widget (%s))" expr :: String isWidget <- attempt $ exprType widgetExpr + write $ "Can Display: " ++ show canRunDisplay+ write $ " Is Widget: " ++ show canRunDisplay+ if canRunDisplay then do -- Use the display. As a result, `it` is set to the output.@@ -944,7 +929,12 @@ flip gcatch (unload importedModules) $ do -- Compile loaded modules. flags <- getSessionDynFlags+#if MIN_VERSION_ghc(7,8,0)+ let objTarget = defaultObjectTarget platform+ platform = targetPlatform flags+#else let objTarget = defaultObjectTarget+#endif setSessionDynFlags flags{ hscTarget = objTarget } -- Clear old targets to be sure.@@ -1157,6 +1147,7 @@ printf "<span class='%s'>%s</span>" cls . replace "\n" "<br/>" . replace useDashV "" .+ replace "Ghci" "IHaskell" . fixDollarSigns . rstrip . typeCleaner
src/IHaskell/Eval/Parser.hs view
@@ -175,8 +175,8 @@ parsers flags = [ (Import, unparser parserImport) , (TypeSignature, unparser parserTypeSignature)- , (Declaration, unparser parserDeclaration) , (Statement, unparser parserStatement)+ , (Declaration, unparser parserDeclaration) ] where unparser :: Parser a -> String -> ParseOutput String
src/IHaskell/Eval/Util.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP, NoImplicitPrelude #-} module IHaskell.Eval.Util ( -- * Initialization initGhci,@@ -12,11 +13,14 @@ evalImport, evalDeclarations, getType,+ getDescription, -- * Pretty printing doc, ) where +import ClassyPrelude+ -- GHC imports. import DynFlags import FastString@@ -29,11 +33,13 @@ import Outputable import Packages import RdrName+import NameSet+import Name+import PprTyThing import qualified Pretty import Control.Monad (void) import Data.Function (on)-import Data.List (find) import Data.String.Utils (replace) -- | A extension flag that can be set or unset.@@ -125,18 +131,28 @@ -- @NoMonomorphismRestriction@), sets the target to interpreted, link in -- memory, sets a reasonable output width, and potentially a few other -- things. It should be invoked before other functions from this module.-initGhci :: GhcMonad m => m ()-initGhci = do+--+-- We also require that the sandbox PackageConf (if any) is passed here+-- as setSessionDynFlags will read the package database the first time+-- (and only the first time) it is called.+initGhci :: GhcMonad m => Maybe String -> m ()+initGhci sandboxPackages = do -- Initialize dyn flags. -- Start with -XExtendedDefaultRules and -XNoMonomorphismRestriction. originalFlags <- getSessionDynFlags let flag = flip xopt_set unflag = flip xopt_unset dflags = flag Opt_ExtendedDefaultRules . unflag Opt_MonomorphismRestriction $ originalFlags+ pkgConfs = case sandboxPackages of+ Nothing -> extraPkgConfs originalFlags+ Just path ->+ let pkg = PkgConfFile path in+ (pkg:) . extraPkgConfs originalFlags void $ setSessionDynFlags $ dflags { hscTarget = HscInterpreted, ghcLink = LinkInMemory,- pprCols = 300 }+ pprCols = 300,+ extraPkgConfs = pkgConfs } -- | Evaluate a single import statement. -- If this import statement is importing a module which was previously@@ -162,7 +178,8 @@ -- Check whether an import is the same as another import (same module). importOf :: ImportDecl RdrName -> InteractiveImport -> Bool importOf _ (IIModule _) = False- importOf imp (IIDecl decl) = ((==) `on` (unLoc . ideclName)) decl imp+ importOf imp (IIDecl decl) = + ((==) `on` (unLoc . ideclName)) decl imp && not (ideclQualified decl) -- Check whether an import is an *implicit* import of something. implicitImportOf :: ImportDecl RdrName -> InteractiveImport -> Bool@@ -190,3 +207,48 @@ flags <- getSessionDynFlags let typeStr = showSDocUnqual flags $ ppr result return typeStr++-- | A wrapper around @getInfo@. Return info about each name in the string.+getDescription :: GhcMonad m => String -> m [String]+getDescription str = do+ names <- parseName str+ maybeInfos <- mapM getInfo' names++ -- Filter out types that have parents in the same set.+ -- GHCi also does this.+ let infos = catMaybes maybeInfos+ allNames = mkNameSet $ map (getName . getType) infos+ hasParent info = case tyThingParent_maybe (getType info) of+ Just parent -> getName parent `elemNameSet` allNames+ Nothing -> False+ filteredOutput = filter (not . hasParent) infos++ -- Print nicely+ mapM (doc . printInfo) filteredOutput+ where+#if MIN_VERSION_ghc(7,8,0)+ getInfo' = getInfo False+#else+ getInfo' = getInfo+#endif++#if MIN_VERSION_ghc(7,8,0)+ getType (theType, _, _, _) = theType+#else+ getType (theType, _, _) = theType+#endif++#if MIN_VERSION_ghc(7,8,0)+ printInfo (thing, fixity, classInstances, famInstances) =+ pprTyThingInContextLoc thing $$+ showFixity thing fixity $$+ vcat (map GHC.pprInstance classInstances) $$+ vcat (map GHC.pprFamInst famInstances)+#else+ printInfo (thing, fixity, classInstances) =+ pprTyThingInContextLoc False thing $$ showFixity thing fixity $$ vcat (map GHC.pprInstance classInstances)+#endif+ showFixity thing fixity =+ if fixity == GHC.defaultFixity+ then empty+ else ppr fixity <+> pprInfixName (getName thing)
src/IHaskell/IPython.hs view
@@ -183,12 +183,13 @@ case parseVersion output of Just (2:_) -> putStrLn "Using system-wide IPython." Just (1:_) -> badIPython "Detected old version of IPython. IHaskell requires 2.0.0 or up."- Nothing -> badIPython "Detected IPython, but could not parse version number."+ Just (0:_) -> badIPython "Detected old version of IPython. IHaskell requires 2.0.0 or up."+ _ -> badIPython "Detected IPython, but could not parse version number." badIPython :: Text -> IO () badIPython reason = void $ do putStrLn reason- putStrLn "IHaskell will not proceed to install IPython (locally for itself)."+ putStrLn "IHaskell will now proceed to install IPython (locally for itself)." putStrLn "Installing IPython in IHaskell's virtualenv in 10 seconds. Ctrl-C to cancel." threadDelay $ 1000 * 1000 * 10 installIPython