summaryrefslogtreecommitdiff
path: root/src-3.0/GF/Compile/BackOpt.hs
diff options
context:
space:
mode:
authorbjorn <bjorn@bringert.net>2008-05-28 15:10:36 +0000
committerbjorn <bjorn@bringert.net>2008-05-28 15:10:36 +0000
commit3fd1f5652a3af22e90a040a821d244a91a3553a0 (patch)
tree15225df670e1fb1c55f4a9eb1ca45eae7952061f /src-3.0/GF/Compile/BackOpt.hs
parent1bc74749aa7a9ec6ecfced68c0cdf38f43c7f9ef (diff)
Switch to new options handling.
This changes lots of stuff, let me know if it broke anything. Comments: - We use a local hacked version of GetOpt that allows long forms of commands to start with a single dash. This breaks other parts of GetOpt. For example, arguments to short options now require a =, and does not allo pace after the option character. - The new command parsing is currently only used for the program command line, pragmas and the arguments for the 'i' shell command. - I made a quick hack for the options for showTerm, which currently makes it impossible to use the print style flags for cc. This will be replaced by a facility for parsing command-specific options. - The verbosity handling is broken in some places. I will fix that in a later patch.
Diffstat (limited to 'src-3.0/GF/Compile/BackOpt.hs')
-rw-r--r--src-3.0/GF/Compile/BackOpt.hs50
1 files changed, 5 insertions, 45 deletions
diff --git a/src-3.0/GF/Compile/BackOpt.hs b/src-3.0/GF/Compile/BackOpt.hs
index 0f74bbf92..0043d02d8 100644
--- a/src-3.0/GF/Compile/BackOpt.hs
+++ b/src-3.0/GF/Compile/BackOpt.hs
@@ -15,10 +15,11 @@
-- following advice of Josef Svenningsson
-----------------------------------------------------------------------------
-module GF.Compile.BackOpt (shareModule, OptSpec, shareOpt, paramOpt, valOpt, allOpt) where
+module GF.Compile.BackOpt (shareModule, OptSpec) where
import GF.Grammar.Grammar
import GF.Infra.Ident
+import GF.Infra.Option
import qualified GF.Grammar.Macros as C
import GF.Grammar.PrGrammar (prt)
import GF.Data.Operations
@@ -26,25 +27,7 @@ import Data.List
import qualified GF.Infra.Modules as M
import qualified Data.ByteString.Char8 as BS
-type OptSpec = [Integer] ---
-
-doOptFactor :: OptSpec -> Bool
-doOptFactor opt = elem 2 opt
-
-doOptValues :: OptSpec -> Bool
-doOptValues opt = elem 3 opt
-
-shareOpt :: OptSpec
-shareOpt = []
-
-paramOpt :: OptSpec
-paramOpt = [2]
-
-valOpt :: OptSpec
-valOpt = [3]
-
-allOpt :: OptSpec
-allOpt = [2,3]
+type OptSpec = [Optimization]
shareModule :: OptSpec -> (Ident, SourceModInfo) -> (Ident, SourceModInfo)
shareModule opt (i,m) = case m of
@@ -59,31 +42,8 @@ shareInfo _ i = i
-- the function putting together optimizations
shareOptim :: OptSpec -> Ident -> Term -> Term
-shareOptim opt c
- | doOptFactor opt && doOptValues opt = values . factor c 0
- | doOptFactor opt = share . factor c 0
- | doOptValues opt = values
- | otherwise = share
-
--- we need no counter to create new variable names, since variables are
--- local to tables (only true in GFC) ---
-
-share :: Term -> Term
-share t = case t of
- T ty@(TComp _) cs -> shareT ty [(p, share v) | (p, v) <- cs]
- _ -> C.composSafeOp share t
-
- where
- shareT ty = finalize ty . groupC . sortC
-
- sortC :: [(Patt,Term)] -> [(Patt,Term)]
- sortC = sortBy $ \a b -> compare (snd a) (snd b)
-
- groupC :: [(Patt,Term)] -> [[(Patt,Term)]]
- groupC = groupBy $ \a b -> snd a == snd b
-
- finalize :: TInfo -> [[(Patt,Term)]] -> Term
- finalize ty css = TSh ty [(map fst ps, t) | ps@((_,t):_) <- css]
+shareOptim opt c = (if OptValues `elem` opt then values else id)
+ . (if OptParametrize `elem` opt then factor c 0 else id)
-- do even more: factor parametric branches