summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Compile/GrammarToPGF.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2011-08-30 18:54:50 +0000
committerhallgren <hallgren@chalmers.se>2011-08-30 18:54:50 +0000
commitba10b5b0ca0c906b1b5c94f64b37b5a34f200f71 (patch)
tree360302c1d8eb917dd650a9df405b3cca504459ab /src/compiler/GF/Compile/GrammarToPGF.hs
parent2001788b0242a0c945655c503262ccf104bcc3bd (diff)
GF.Infra.Modules: keep the modules of a grammar in a finite map instead of a list
This speeds up the compilation of PhrasebookFin.pgf by 12%, mosly by speeding up calls to lookupModule in calls from lookupParamValues, in calls from allParamValues. The invariant "modules are stored in dependency order" is no longer respected! But the type MGrammar is now abstract, making it easier to maintain this or other invariants in the future.
Diffstat (limited to 'src/compiler/GF/Compile/GrammarToPGF.hs')
-rw-r--r--src/compiler/GF/Compile/GrammarToPGF.hs17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/compiler/GF/Compile/GrammarToPGF.hs b/src/compiler/GF/Compile/GrammarToPGF.hs
index a6c7035d5..ed10697fd 100644
--- a/src/compiler/GF/Compile/GrammarToPGF.hs
+++ b/src/compiler/GF/Compile/GrammarToPGF.hs
@@ -44,10 +44,13 @@ mkCanon2pgf opts cnc gr = (canon2pgf opts gr . reorder abs) gr
-- Generate PGF from grammar.
-canon2pgf :: Options -> SourceGrammar -> SourceGrammar -> IO D.PGF
-canon2pgf opts gr cgr@(M.MGrammar (am:cms)) = do
+type AbsConcsGrammar = (IdModInfo,[IdModInfo]) -- (abstract,concretes)
+type IdModInfo = (Ident,SourceModInfo)
+
+canon2pgf :: Options -> SourceGrammar -> AbsConcsGrammar -> IO D.PGF
+canon2pgf opts gr (am,cms) = do
if dump opts DumpCanon
- then putStrLn (render (vcat (map (ppModule Qualified) (M.modules cgr))))
+ then putStrLn (render (vcat (map (ppModule Qualified) (am:cms))))
else return ()
(an,abs) <- mkAbstr am
cncs <- mapM (mkConcr am) cms
@@ -148,12 +151,12 @@ compilePatt eqs = whilePP eqs Map.empty
-- return just one module per language
-reorder :: Ident -> SourceGrammar -> SourceGrammar
+reorder :: Ident -> SourceGrammar -> AbsConcsGrammar
reorder abs cg =
- M.MGrammar $
- (abs, M.ModInfo M.MTAbstract M.MSComplete aflags [] Nothing [] [] adefs):
+-- M.MGrammar $
+ ((abs, M.ModInfo M.MTAbstract M.MSComplete aflags [] Nothing [] [] adefs),
[(cnc, M.ModInfo (M.MTConcrete abs) M.MSComplete cflags [] Nothing [] [] cdefs)
- | cnc <- M.allConcretes cg abs, let (cflags,cdefs) = concr cnc]
+ | cnc <- M.allConcretes cg abs, let (cflags,cdefs) = concr cnc])
where
aflags =
concatOptions (reverse [M.flags mo | (_,mo) <- M.modules cg, M.isModAbs mo])