summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2015-02-27 13:49:13 +0000
committerhallgren <hallgren@chalmers.se>2015-02-27 13:49:13 +0000
commite0bc6308e07edf4302242e434932c9da42c162bd (patch)
tree338cabbc8ab4ae2cf78775074e30496ee275e8de
parentd3f6b9851f696b0b5f476f8e70f8c9797825df11 (diff)
GF shell: create a PGF also when the -retain flag is used
The commands available in the shell after import -retain are now a superset of the commands available after import without -retain. The PGF is created lazily, so there should be no performance penalty if the PGF isn't needed. If there are errors, they won't be reported until a command that uses the PGF is entered.
-rw-r--r--src/compiler/GF/Infra/SIO.hs6
-rw-r--r--src/compiler/GF/Interactive.hs20
2 files changed, 17 insertions, 9 deletions
diff --git a/src/compiler/GF/Infra/SIO.hs b/src/compiler/GF/Infra/SIO.hs
index 39c3da489..ed75f0898 100644
--- a/src/compiler/GF/Infra/SIO.hs
+++ b/src/compiler/GF/Infra/SIO.hs
@@ -11,7 +11,7 @@ module GF.Infra.SIO(
newStdGen,print,putStrLn,
-- ** Specific to GF
importGrammar,importSource,
- putStrLnFlush,runInterruptibly,
+ putStrLnFlush,runInterruptibly,lazySIO,
-- * Restricted accesss to arbitrary (potentially unsafe) IO operations
-- | If the environment variable GF_RESTRICTED is defined, these
-- operations will fail. Otherwise, they will be executed normally.
@@ -26,6 +26,7 @@ import GF.System.Catch(try)
import System.Process(system)
import System.Environment(getEnv)
import Control.Concurrent.Chan(newChan,writeChan,getChanContents)
+import GF.Infra.Concurrency(lazyIO)
import qualified System.CPUTime as IO(getCPUTime)
import qualified System.Directory as IO(getCurrentDirectory)
import qualified System.Random as IO(newStdGen)
@@ -91,6 +92,7 @@ getCurrentDirectory = lift0 IO.getCurrentDirectory
getLibraryDirectory = lift0 . IO.getLibraryDirectory
newStdGen = lift0 IO.newStdGen
runInterruptibly = lift1 IO.runInterruptibly
+lazySIO = lift1 lazyIO
importGrammar pgf opts files = lift0 $ GF.importGrammar pgf opts files
-importSource src opts files = lift0 $ GF.importSource src opts files \ No newline at end of file
+importSource src opts files = lift0 $ GF.importSource src opts files
diff --git a/src/compiler/GF/Interactive.hs b/src/compiler/GF/Interactive.hs
index 82806bebb..15c14bbbe 100644
--- a/src/compiler/GF/Interactive.hs
+++ b/src/compiler/GF/Interactive.hs
@@ -355,15 +355,21 @@ importInEnv :: GFEnv -> Options -> [FilePath] -> SIO GFEnv
importInEnv gfenv opts files
| flag optRetainResource opts =
do src <- importSource (grammar gfenv) opts files
- return $ gfenv {grammar = src}
+ pgf <- lazySIO importPGF -- duplicates some work, better to link src
+ return $ gfenv {grammar = src, commandenv = mkCommandEnv pgf}
| otherwise =
- do let opts' = addOptions (setOptimization OptCSE False) opts
- pgf0 = multigrammar (commandenv gfenv)
- pgf1 <- importGrammar pgf0 opts' files
- if (verbAtLeast opts Normal)
- then putStrLnFlush $ unwords $ "\nLanguages:" : map showCId (languages pgf1)
- else done
+ do pgf1 <- importPGF
return $ gfenv { commandenv = mkCommandEnv pgf1 }
+ where
+ importPGF =
+ do let opts' = addOptions (setOptimization OptCSE False) opts
+ pgf0 = multigrammar (commandenv gfenv)
+ pgf1 <- importGrammar pgf0 opts' files
+ if (verbAtLeast opts Normal)
+ then putStrLnFlush $
+ unwords $ "\nLanguages:" : map showCId (languages pgf1)
+ else done
+ return pgf1
tryGetLine = do
res <- try getLine