1
0
forked from GitHub/gf-core

cleand up Structural

This commit is contained in:
aarne
2005-02-05 20:52:31 +00:00
parent 2429599b50
commit bd432cf147
17 changed files with 84 additions and 48 deletions

View File

@@ -5,11 +5,11 @@
-- Stability : (stability) -- Stability : (stability)
-- Portability : (portability) -- Portability : (portability)
-- --
-- > CVS $Date: 2005/02/04 10:10:28 $ -- > CVS $Date: 2005/02/05 21:52:31 $
-- > CVS $Author: peb $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.19 $ -- > CVS $Revision: 1.20 $
-- --
-- (Description of the module) -- The Main module of GF program.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module Main (main) where module Main (main) where
@@ -89,7 +89,7 @@ welcomeMsg =
"Welcome to " ++ authorMsg ++++ welcomeArch ++ "\n\nType 'h' for help." "Welcome to " ++ authorMsg ++++ welcomeArch ++ "\n\nType 'h' for help."
authorMsg = unlines [ authorMsg = unlines [
"Grammatical Framework, Version 2.1.1b", "Grammatical Framework, Version 2.1.2b",
"Compiled " ++ today, "Compiled " ++ today,
"Copyright (c)", "Copyright (c)",
"Björn Bringert, Markus Forsberg, Thomas Hallgren, Harald Hammarström,", "Björn Bringert, Markus Forsberg, Thomas Hallgren, Harald Hammarström,",

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- Macros for building and analysing terms in GFC concrete syntax.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module CMacros where module CMacros where
@@ -226,6 +226,7 @@ wordsInTerm trm = filter (not . null) $ case trm of
S c _ -> wo c S c _ -> wo c
R rs -> concat [wo t | Ass _ t <- rs] R rs -> concat [wo t | Ass _ t <- rs]
T _ cs -> concat [wo t | Cas _ t <- cs] T _ cs -> concat [wo t | Cas _ t <- cs]
V _ cs -> concat [wo t | t <- cs]
C s t -> wo s ++ wo t C s t -> wo s ++ wo t
FV ts -> concatMap wo ts FV ts -> concatMap wo ts
K (KP ss vs) -> ss ++ concat [s | Var s _ <- vs] K (KP ss vs) -> ss ++ concat [s | Var s _ <- vs]

View File

@@ -143,13 +143,13 @@ redCTerm x = case x of
P term label -> liftM2 G.P (redCTerm term) (return $ redLabel label) P term label -> liftM2 G.P (redCTerm term) (return $ redLabel label)
T ctype cases -> do T ctype cases -> do
ctype' <- redCType ctype ctype' <- redCType ctype
let (ps,ts) = unzip [(p,t) | Cas ps t <- cases, p <- ps] --- destroys sharing let (ps,ts) = unzip [(ps,t) | Cas ps t <- cases]
ps' <- mapM redPatt ps ps' <- mapM (mapM redPatt) ps
ts' <- mapM redCTerm ts --- duplicates work for shared rhss ts' <- mapM redCTerm ts
let tinfo = case ps' of let tinfo = case ps' of
[G.PV _] -> G.TTyped ctype' [[G.PV _]] -> G.TTyped ctype'
_ -> G.TComp ctype' _ -> G.TComp ctype'
return $ G.T tinfo $ zip ps' ts' return $ G.TSh tinfo $ zip ps' ts'
V ctype ts -> do V ctype ts -> do
ctype' <- redCType ctype ctype' <- redCType ctype
ts' <- mapM redCTerm ts ts' <- mapM redCTerm ts

View File

@@ -262,10 +262,10 @@ compileSourceModule opts env@(k,gr,can) mo@(i,mi) = do
(k',mo3r:_) <- ioeErr $ refreshModule (k,mos) mo3 (k',mo3r:_) <- ioeErr $ refreshModule (k,mos) mo3
mo4:_ <- mo4 <-
---- case snd mo1b of ---- case snd mo1b of
---- ModMod n | isModCnc n -> ---- ModMod n | isModCnc n ->
putp " optimizing " $ ioeErr $ evalModule mos mo3r putp " optimizing " $ ioeErr $ optimizeModule opts mos mo3r
---- _ -> return [mo3r] ---- _ -> return [mo3r]
return (k',mo4) return (k',mo4)
where where

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- Code generator from optimized GF source code to GFC.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module GrammarToCanon where module GrammarToCanon where
@@ -187,7 +187,9 @@ redCType t = case t of
redCTerm :: Term -> Err G.Term redCTerm :: Term -> Err G.Term
redCTerm t = case t of redCTerm t = case t of
Vr x -> liftM G.Arg $ redArgvar x Vr x -> checkAgain
(liftM G.Arg $ redArgvar x)
(liftM G.LI $ redIdent x) --- for parametrize optimization
App _ _ -> do -- only constructor applications can remain App _ _ -> do -- only constructor applications can remain
(_,c,xx) <- termForm t (_,c,xx) <- termForm t
xx' <- mapM redCTerm xx xx' <- mapM redCTerm xx
@@ -212,6 +214,13 @@ redCTerm t = case t of
ps' <- mapM redPatt ps ps' <- mapM redPatt ps
ts' <- mapM redCTerm ts ts' <- mapM redCTerm ts
return $ G.T ty' $ map (uncurry G.Cas) $ zip (map singleton ps') ts' return $ G.T ty' $ map (uncurry G.Cas) $ zip (map singleton ps') ts'
TSh i cs -> do
ty <- getTableType i
ty' <- redCType ty
let (pss,ts) = unzip cs
pss' <- mapM (mapM redPatt) pss
ts' <- mapM redCTerm ts
return $ G.T ty' $ map (uncurry G.Cas) $ zip pss' ts'
V ty ts -> do V ty ts -> do
ty' <- redCType ty ty' <- redCType ty
ts' <- mapM redCTerm ts ts' <- mapM redCTerm ts
@@ -247,6 +256,7 @@ redPatt p = case p of
return $ G.PR $ map (uncurry G.PAss) $ zip ls' ts return $ G.PR $ map (uncurry G.PAss) $ zip ls' ts
PT _ q -> redPatt q PT _ q -> redPatt q
PInt i -> return $ G.PI (toInteger i) PInt i -> return $ G.PI (toInteger i)
PV x -> liftM G.PV $ redIdent x --- for parametrize optimization
_ -> prtBad "cannot reduce pattern" p _ -> prtBad "cannot reduce pattern" p
redLabel :: Label -> G.Label redLabel :: Label -> G.Label

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- Compile a gfc module into a "reuse" gfr resource, interface, or instance.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module MkResource where module MkResource where

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- Top-level partial evaluation for GF source modules.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module Optimize where module Optimize where
@@ -22,25 +22,38 @@ import Macros
import Lookup import Lookup
import Refresh import Refresh
import Compute import Compute
import BackOpt
import CheckGrammar import CheckGrammar
import Update import Update
import Operations import Operations
import CheckM import CheckM
import Option
import Monad import Monad
import List import List
-- partial evaluation of concrete syntax. AR 6/2001 -- 16/5/2003 -- partial evaluation of concrete syntax. AR 6/2001 -- 16/5/2003 -- 5/2/2005
{- -- only do this for resource: concrete is optimized in gfc form
evalGrammar :: SourceGrammar -> Err SourceGrammar
evalGrammar gr = do optimizeModule :: Options -> [(Ident,SourceModInfo)] -> (Ident,SourceModInfo) ->
gr2 <- refreshGrammar gr Err (Ident,SourceModInfo)
mos <- foldM evalModule [] $ modules gr2 optimizeModule opts ms mo@(_,mi) = case mi of
return $ MGrammar $ reverse mos ModMod m0@(Module mt st fs me ops js) | st == MSComplete && isModRes m0 -> do
-} mo1 <- evalModule ms mo
let oopts = addOptions opts (iOpts (flagsModule mo1))
optim = maybe "none" id $ getOptVal oopts useOptimizer
return $ case optim of
"parametrize" -> shareModule paramOpt mo1 -- parametrization and sharing
"values" -> shareModule valOpt mo1 -- tables as courses-of-values
"share" -> shareModule shareOpt mo1 -- sharing of branches
"all" -> shareModule allOpt mo1 -- first parametrize then values
"none" -> mo1 -- no optimization
_ -> mo1 -- none; default for src
_ -> evalModule ms mo
evalModule :: [(Ident,SourceModInfo)] -> (Ident,SourceModInfo) -> evalModule :: [(Ident,SourceModInfo)] -> (Ident,SourceModInfo) ->
Err [(Ident,SourceModInfo)] Err (Ident,SourceModInfo)
evalModule ms mo@(name,mod) = case mod of evalModule ms mo@(name,mod) = case mod of
ModMod m0@(Module mt st fs me ops js) | st == MSComplete -> case mt of ModMod m0@(Module mt st fs me ops js) | st == MSComplete -> case mt of
@@ -48,13 +61,13 @@ evalModule ms mo@(name,mod) = case mod of
let deps = allOperDependencies name js let deps = allOperDependencies name js
ids <- topoSortOpers deps ids <- topoSortOpers deps
MGrammar (mod' : _) <- foldM evalOp gr ids MGrammar (mod' : _) <- foldM evalOp gr ids
return $ mod' : ms return $ mod'
MTConcrete a -> do MTConcrete a -> do
js' <- mapMTree (evalCncInfo gr0 name a) js js' <- mapMTree (evalCncInfo gr0 name a) js
return $ (name, ModMod (Module mt st fs me ops js')) : ms return $ (name, ModMod (Module mt st fs me ops js'))
_ -> return $ (name,mod):ms _ -> return $ (name,mod)
_ -> return $ (name,mod):ms _ -> return $ (name,mod)
where where
gr0 = MGrammar $ ms gr0 = MGrammar $ ms
gr = MGrammar $ (name,mod) : ms gr = MGrammar $ (name,mod) : ms

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- Computation of source terms. Used in compilation and in 'cc' command.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module Compute where module Compute where
@@ -218,6 +218,9 @@ computeTerm gr = comp where
cs' <- if (null g) then return cs else mapPairsM (comp g) cs cs' <- if (null g) then return cs else mapPairsM (comp g) cs
return $ T i cs' return $ T i cs'
--- this means some extra work; should implement TSh directly
TSh i cs -> comp g $ T i [(p,v) | (ps,v) <- cs, p <- ps]
T i cs -> do T i cs -> do
pty0 <- getTableType i pty0 <- getTableType i
ptyp <- comp g pty0 ptyp <- comp g pty0

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- GF source abstract syntax used internally in compilation.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module Grammar where module Grammar where
@@ -91,6 +91,7 @@ data Term =
| Table Term Term -- table type: P => A | Table Term Term -- table type: P => A
| T TInfo [Case] -- table: table {p => c ; ...} | T TInfo [Case] -- table: table {p => c ; ...}
| TSh TInfo [Cases] -- table with discjunctive patters (only back end opt)
| V Type [Term] -- table given as course of values: table T [c1 ; ... ; cn] | V Type [Term] -- table given as course of values: table T [c1 ; ... ; cn]
| S Term Term -- selection: t ! p | S Term Term -- selection: t ! p
@@ -149,6 +150,7 @@ type Equation = ([Patt],Term)
type Labelling = (Label, Term) type Labelling = (Label, Term)
type Assign = (Label, (Maybe Type, Term)) type Assign = (Label, (Maybe Type, Term))
type Case = (Patt, Term) type Case = (Patt, Term)
type Cases = ([Patt], Term)
type LocalDef = (Ident, (Maybe Type, Term)) type LocalDef = (Ident, (Maybe Type, Term))
type Param = (Ident, Context) type Param = (Ident, Context)

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- Macros for constructing and analysing source code terms.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module Macros where module Macros where
@@ -603,6 +603,11 @@ composOp co trm =
i' <- changeTableType co i i' <- changeTableType co i
return (T i' cc') return (T i' cc')
TSh i cc ->
do cc' <- mapPairListM (co . snd) cc
i' <- changeTableType co i
return (TSh i' cc')
V ty vs -> V ty vs ->
do ty' <- co ty do ty' <- co ty
vs' <- mapM co vs vs' <- mapM co vs
@@ -661,6 +666,8 @@ collectOp co trm = case trm of
RecType r -> concatMap (co . snd) r RecType r -> concatMap (co . snd) r
P t i -> co t P t i -> co t
T _ cc -> concatMap (co . snd) cc -- not from patterns --- nor from type annot T _ cc -> concatMap (co . snd) cc -- not from patterns --- nor from type annot
TSh _ cc -> concatMap (co . snd) cc -- not from patterns --- nor from type annot
V _ cc -> concatMap co cc --- nor from type annot
Let (x,(mt,a)) b -> maybe [] co mt ++ co a ++ co b Let (x,(mt,a)) b -> maybe [] co mt ++ co a ++ co b
C s1 s2 -> co s1 ++ co s2 C s1 s2 -> co s1 ++ co s2
Glue s1 s2 -> co s1 ++ co s2 Glue s1 s2 -> co s1 ++ co s2

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- GF shell command interpreter.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module Shell where module Shell where

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- From internal source syntax to BNFC-generated (used for printing).
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module GrammarToSource where module GrammarToSource where
@@ -139,6 +139,7 @@ trt trm = case trm of
P t l -> P.EProj (trt t) (trLabel l) P t l -> P.EProj (trt t) (trLabel l)
Q t l -> P.EQCons (tri t) (tri l) Q t l -> P.EQCons (tri t) (tri l)
QC t l -> P.EQConstr (tri t) (tri l) QC t l -> P.EQConstr (tri t) (tri l)
TSh (TComp ty) cc -> P.ETTable (trt ty) (map trCases cc)
T (TTyped ty) cc -> P.ETTable (trt ty) (map trCase cc) T (TTyped ty) cc -> P.ETTable (trt ty) (map trCase cc)
T (TComp ty) cc -> P.ETTable (trt ty) (map trCase cc) T (TComp ty) cc -> P.ETTable (trt ty) (map trCase cc)
T (TWild ty) cc -> P.ETTable (trt ty) (map trCase cc) T (TWild ty) cc -> P.ETTable (trt ty) (map trCase cc)
@@ -192,7 +193,8 @@ trAssign (lab, (mty, t)) = maybe (P.LDDef x t') (\ty -> P.LDFull x (trt ty) t')
trLabelling (lab,ty) = P.LDDecl [trLabelIdent lab] (trt ty) trLabelling (lab,ty) = P.LDDecl [trLabelIdent lab] (trt ty)
trCase (patt,trm) = P.Case [P.AltP (trp patt)] (trt trm) trCase (patt, trm) = P.Case [P.AltP (trp patt)] (trt trm)
trCases (patts,trm) = P.Case (map (P.AltP . trp) patts) (trt trm)
trDecl (x,ty) = P.DDDec [trb x] (trt ty) trDecl (x,ty) = P.DDDec [trb x] (trt ty)

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- A database for customizable GF shell commands.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module Custom where module Custom where

View File

@@ -9,7 +9,7 @@
-- > CVS $Author $ -- > CVS $Author $
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- (Description of the module) -- Morphological analyser constructed from a GF grammar.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module Morphology where module Morphology where

View File

@@ -428,17 +428,15 @@ q, quit: q
The default is unlimited. The default is unlimited.
-optimize, optimization on generated code. -optimize, optimization on generated code.
The default is share. The default is share for concrete, none for resource modules.
-optimize=share share common branches in tables -optimize=share share common branches in tables
-optimize=parametrize first try parametrize then do share with the rest -optimize=parametrize first try parametrize then do share with the rest
-optimize=values represent tables as courses-of-values -optimize=values represent tables as courses-of-values
-optimize=all first try parametrize then do values with the rest -optimize=all first try parametrize then do values with the rest
-optimize=none no optimization -optimize=none no optimization
-parser, Context-free parsing algorithm. Under construction.
-parser, Context-free parsing algorithm. The default is chart. The default is a chart parser via context-free approximation.
-parser=earley Earley algorithm
-parser=chart bottom-up chart parser
-printer, format in which the grammar is printed. The default is gfc. -printer, format in which the grammar is printed. The default is gfc.
-printer=gfc GFC grammar -printer=gfc GFC grammar

View File

@@ -10,6 +10,7 @@
-- > CVS $Revision $ -- > CVS $Revision $
-- --
-- Help on shell commands. Generated from HelpFile by 'make help'. -- Help on shell commands. Generated from HelpFile by 'make help'.
-- PLEASE DON'T EDIT THIS FILE.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
@@ -456,17 +457,15 @@ txtHelpFile =
"\n The default is unlimited." ++ "\n The default is unlimited." ++
"\n" ++ "\n" ++
"\n-optimize, optimization on generated code." ++ "\n-optimize, optimization on generated code." ++
"\n The default is share." ++ "\n The default is share for concrete, none for resource modules." ++
"\n -optimize=share share common branches in tables" ++ "\n -optimize=share share common branches in tables" ++
"\n -optimize=parametrize first try parametrize then do share with the rest" ++ "\n -optimize=parametrize first try parametrize then do share with the rest" ++
"\n -optimize=values represent tables as courses-of-values" ++ "\n -optimize=values represent tables as courses-of-values" ++
"\n -optimize=all first try parametrize then do values with the rest" ++ "\n -optimize=all first try parametrize then do values with the rest" ++
"\n -optimize=none no optimization" ++ "\n -optimize=none no optimization" ++
"\n" ++ "\n" ++
"\n" ++ "\n-parser, Context-free parsing algorithm. Under construction." ++
"\n-parser, Context-free parsing algorithm. The default is chart." ++ "\n The default is a chart parser via context-free approximation." ++
"\n -parser=earley Earley algorithm" ++
"\n -parser=chart bottom-up chart parser" ++
"\n" ++ "\n" ++
"\n-printer, format in which the grammar is printed. The default is gfc." ++ "\n-printer, format in which the grammar is printed. The default is gfc." ++
"\n -printer=gfc GFC grammar" ++ "\n -printer=gfc GFC grammar" ++

View File

@@ -54,6 +54,7 @@ helpHeader = unlines [
"-- > CVS $Revision $", "-- > CVS $Revision $",
"--", "--",
"-- Help on shell commands. Generated from HelpFile by 'make help'.", "-- Help on shell commands. Generated from HelpFile by 'make help'.",
"-- PLEASE DON'T EDIT THIS FILE.",
"-----------------------------------------------------------------------------", "-----------------------------------------------------------------------------",
"", "",
"" ""