on master help sign in
WIP set the proper context for the AtomFunction
commit242039104f6a7637c8cdd2c873229fb322cb54d2 authorAgentM <agentm@themactionfaction.com> dateThu 18 Aug 2016, 17:20 (10 years ago) parent9a9f3bb
2 files changed+32−7
ProjectM36/AtomFunctionBody.hs+28−7 ProjectM36/ScriptBase.hs+4
ProjectM36/AtomFunctionBody.hs+28−7
@@ -22,23 +22,44 @@ type ScriptSession = HscEnv
2222-- | Configure a GHC environment/session which we will use for all script compilation.
2323initScriptSession :: IO ScriptSession
2424initScriptSession = runGhc (Just libdir) $ do
25− liftIO $ putStrLn "Setting up HscEnv"
2625 dflags <- getSessionDynFlags
2726 let dflags' = dflags { hscTarget = HscInterpreted ,
2827 ghcLink = LinkInMemory,
2928 safeHaskell = Sf_Safe,
3029 safeInfer = True,
31− safeInferred = True
30+ safeInferred = True,
31+ --trustFlags = [TrustPackage "base"] -- new in 8
32+ packageFlags = (packageFlags dflags) ++ [TrustPackage "base"]
3233 }
3334 `xopt_set` Opt_ExtendedDefaultRules
34− --`xopt_unset` Opt_ImplicitPrelude
35+ `xopt_set` Opt_ImplicitPrelude
3536 `gopt_set` Opt_DistrustAllPackages
37+ `xopt_set` Opt_ScopedTypeVariables
3638 `gopt_set` Opt_PackageTrust
37− `gopt_set` Opt_ImplicitImportQualified
39+ --`gopt_set` Opt_ImplicitImportQualified
3840 _ <- setSessionDynFlags dflags'
39− setContext [ IIDecl $ simpleImportDecl (mkModuleName "Prelude") ]
40− env <- getSession
41− return env
41+ let safeImportDecl mn = ImportDecl {
42+ ideclSourceSrc = Nothing,
43+ ideclName = noLoc mn,
44+ ideclPkgQual = Nothing,
45+ ideclSource = False,
46+ ideclSafe = True,
47+ ideclImplicit = False,
48+ ideclQualified = False,
49+ ideclAs = Nothing,
50+ ideclHiding = Nothing
51+ }
52+
53+ baseTarget <- guessTarget "ProjectM36.ScriptBase" Nothing
54+ addTarget baseTarget
55+ flag <- load LoadAllTargets
56+ case flag of
57+ Failed -> error "failed to load"
58+ Succeeded -> do
59+ setContext [ IIDecl $ safeImportDecl (mkModuleName "Prelude"),
60+ IIDecl $ safeImportDecl (mkModuleName "ProjectM36.ScriptBase")]
61+ env <- getSession
62+ pure env
4263
4364addImport :: String -> Ghc ()
4465addImport moduleNam = do
ProjectM36/ScriptBase.hsnew file+4
@@ -0,0 +1,4 @@
1+module ProjectM36.ScriptBase where
2+import Prelude
3+
4+data Atom = IntAtom Int