Added support for -XNoImplicitPrelude properly

This commit is contained in:
Andrew Gibiansky 2014-05-17 22:24:24 -07:00
parent 0fc3a1a9bf
commit 9b95c5e3ff
2 changed files with 19 additions and 5 deletions

View File

@ -36,8 +36,8 @@
"cell_type": "code",
"collapsed": false,
"input": [
":load a/Test.hs\n",
"test"
":ext Impli\n",
"4 + 4"
],
"language": "python",
"metadata": {
@ -48,11 +48,11 @@
"metadata": {},
"output_type": "display_data",
"text": [
"3"
"8"
]
}
],
"prompt_number": 14
"prompt_number": 2
},
{
"cell_type": "code",

View File

@ -105,6 +105,7 @@ instance MonadIO.MonadIO Interpreter where
globalImports :: [String]
globalImports =
[ "import IHaskell.Display()"
, "import qualified Prelude as IHaskellPrelude"
, "import qualified IHaskell.Display"
, "import qualified IHaskell.IPython.Stdin"
, "import qualified System.Posix.IO as IHaskellIO"
@ -409,6 +410,19 @@ evalCommand output (Directive SetDynFlag flags) state =
let display = case errs of
[] -> mempty
_ -> displayError $ intercalate "\n" errs
-- For -XNoImplicitPrelude, remove the Prelude import.
-- For -XImplicitPrelude, add it back in.
case flag of
"-XNoImplicitPrelude" ->
evalImport "import qualified Prelude as Prelude"
"-XImplicitPrelude" -> do
importDecl <- parseImportDecl "import Prelude"
let implicitPrelude = importDecl { ideclImplicit = True }
imports <- getContext
setContext $ IIDecl implicitPrelude : imports
_ -> return ()
return EvalOut {
evalStatus = Success,
evalResult = display,
@ -1005,7 +1019,7 @@ capturedStatement output stmt = do
-- Variable used to store true `it` value.
itVariable = var "it_var_"
voidpf str = printf $ str ++ " >> return ()"
voidpf str = printf $ str ++ " IHaskellPrelude.>> IHaskellPrelude.return ()"
-- Statements run before the thing we're evaluating.
initStmts =