unoptimize for Java ; Finnish

This commit is contained in:
aarne
2005-06-29 15:27:56 +00:00
parent 3f8fecbf30
commit ffe5c1b999
7 changed files with 70 additions and 21 deletions

View File

@@ -12,6 +12,17 @@ Changes in functionality since May 17, 2005, release of GF Version 2.2
</center> </center>
29/6 (AR) The printer used by Embedded Java GF Interpreter
(<tt>pm -header</tt>) now produces
working code from all optimized grammars - hence you need not select a
weaker optimization just to use the interpreter. However, the
optimization <tt>-optimize=share</tt> usually produces smaller object
grammars because the "unoptimizer" just undoes all optimizations.
(This is to be considered a temporary solution until the interpreter
knows how to handle stronger optimizations.)
<p>
27/6 (AR) The flag <tt>flags optimize=noexpand</tt> placed in a 27/6 (AR) The flag <tt>flags optimize=noexpand</tt> placed in a
resource module prevents the optimization phase of the compiler when resource module prevents the optimization phase of the compiler when
the <tt>.gfr</tt> file is created. This can prevent serious code the <tt>.gfr</tt> file is created. This can prevent serious code

View File

@@ -113,7 +113,7 @@ lin
leather_N = regN "nahka" ; --- nahan leather_N = regN "nahka" ; --- nahan
leave_V2 = dirV2 (regV "jättää") ; leave_V2 = dirV2 (regV "jättää") ;
like_V2 = caseV2 (regV "pitää") elative ; like_V2 = caseV2 (regV "pitää") elative ;
listen_V2 = caseV2 (reg3V "kuunnella" "kuuntelen" "kuuntelin") partitive ; listen_V2 = caseV2 (reg3V "kuunnella" "kuuntelen" "kuunteli") partitive ;
live_V = regV "elää" ; live_V = regV "elää" ;
long_ADeg = mkADeg (regN "pitkä") "pitempi" "pisin" ; long_ADeg = mkADeg (regN "pitkä") "pitempi" "pisin" ;
lose_V2 = dirV2 (regV "hävitä") ; --- hukata lose_V2 = dirV2 (regV "hävitä") ; --- hukata
@@ -200,7 +200,7 @@ lin
tree_N = regN "puu" ; tree_N = regN "puu" ;
---- trousers_N = regN "trousers" ; ---- trousers_N = regN "trousers" ;
ugly_ADeg = mkADeg (regN "ruma") "rumempi" "rumin" ; ugly_ADeg = mkADeg (regN "ruma") "rumempi" "rumin" ;
understand_V2 = dirV2 (reg3V "ymmärtää" "ymmärrän" "ymmärsin") ; understand_V2 = dirV2 (reg3V "ymmärtää" "ymmärrän" "ymmärsi") ;
university_N = regN "yliopisto" ; university_N = regN "yliopisto" ;
village_N = regN "kylä" ; village_N = regN "kylä" ;
wait_V2 = caseV2 (regV "odottaa") partitive ; wait_V2 = caseV2 (regV "odottaa") partitive ;

View File

@@ -921,7 +921,7 @@ caseTable : Number -> CommonNoun -> Case => Str = \n,cn ->
vOttaa : (_,_ : Str) -> Verb = \ottaa,otan -> vOttaa : (_,_ : Str) -> Verb = \ottaa,otan ->
let let
i = if_then_Str (pbool2bool (Predef.occurs "ou" ottaa)) "i" "oi" i = "i" ; --- wrong rule if_then_Str (pbool2bool (Predef.occurs "ou" ottaa)) "i" "oi"
in in
vHuoltaa ottaa otan (Predef.tk 2 ottaa + i) (Predef.tk 2 otan + i + "n") ; vHuoltaa ottaa otan (Predef.tk 2 ottaa + i) (Predef.tk 2 otan + i + "n") ;

View File

@@ -402,8 +402,7 @@ regV soutaa =
u = ifTok Str a "a" "u" "y" ; u = ifTok Str a "a" "u" "y" ;
joi = Predef.tk 2 juo + (o + "i") joi = Predef.tk 2 juo + (o + "i")
in case ta of { in case ta of {
"st" => vJuosta soutaa soudan (juo + "s"+u+"t") (juo + "t"+u) ; "st" | "nn" | "rr" | "ll" => vJuosta soutaa soudan (juo + o+u+"t") (juo + "t"+u) ;
"nn" | "rr" | "ll" => vJuosta soutaa soudan (juo + o+u+"t") (juo + "t"+u) ;
_ => case aa of { _ => case aa of {
"aa" | "ää" => vOttaa soutaa (souda + "n") ; "aa" | "ää" => vOttaa soutaa (souda + "n") ;
"da" | "dä" => vJuoda soutaa joi ; "da" | "dä" => vJuoda soutaa joi ;
@@ -429,7 +428,7 @@ reg2V : (soutaa,souti : Str) -> V = \soutaa,souti ->
_ => soudat _ => soudat
} ** {lock_V = <>} ; } ** {lock_V = <>} ;
reg3V soutaa soudan soudin = reg3V soutaa soudan souti =
let let
taa = Predef.dp 3 soutaa ; taa = Predef.dp 3 soutaa ;
ta = init taa ; ta = init taa ;
@@ -439,15 +438,14 @@ reg3V soutaa soudan soudin =
o = last juo ; o = last juo ;
a = last aa ; a = last aa ;
u = ifTok Str a "a" "u" "y" ; u = ifTok Str a "a" "u" "y" ;
joi = init soudin soudin = weakGrade souti + "n" ;
soudat = reg2V soutaa souti ;
in case ta of { in case ta of {
"st" => vJuosta soutaa soudan (juo + "s"+u+"t") (juo + "t"+u) ; "ll" => vJuosta soutaa soudan (juo + o+u+"t") (juo + "t"+u) ;
"nn" | "rr" | "ll" => vJuosta soutaa soudan (juo + o+u+"t") (juo + "t"+u) ;
_ => case aa of { _ => case aa of {
"aa" | "ää" => vHuoltaa soutaa soudan (init soudin) soudin ; "aa" | "ää" => vHuoltaa soutaa soudan souti soudin ;
"da" | "dä" => vJuoda soutaa joi ; "da" | "dä" => vJuoda soutaa souti ;
"ta" | "tä" => vOsata soutaa ; _ => soudat
_ => vHukkua soudan souda
}} ** {lock_V = <>} ; }} ** {lock_V = <>} ;
vValua v = vSanoa v ** {lock_V = <>} ; vValua v = vSanoa v ** {lock_V = <>} ;

View File

@@ -211,7 +211,7 @@ concrete SwadeshLexFin of SwadeshLex = CategoriesFin
hunt_V = regV "metsästää" ; hunt_V = regV "metsästää" ;
kill_V = regV "tappaa" ; kill_V = regV "tappaa" ;
know_V =reg2V "tietää" "tiesin" ; know_V =reg2V "tietää" "tiesin" ;
laugh_V = reg3V "nauraa" "nauran" "nauroin" ; laugh_V = reg3V "nauraa" "nauran" "nauroi" ;
lie_V = regV "maata" ; lie_V = regV "maata" ;
live_V = live_V ; live_V = live_V ;
play_V = UseV2 play_V2 ; play_V = UseV2 play_V2 ;
@@ -235,8 +235,8 @@ concrete SwadeshLexFin of SwadeshLex = CategoriesFin
suck_V = regV "imeä" ; suck_V = regV "imeä" ;
swell_V = mkV "turvota" "turpoaa" "turpoan" "turpoavat" "turvotkaa" "turvotaan" swell_V = mkV "turvota" "turpoaa" "turpoan" "turpoavat" "turvotkaa" "turvotaan"
"turposi" "turposin" "turpoaisi" "turvonnut" "turvottu" "turvotun" ; "turposi" "turposin" "turpoaisi" "turvonnut" "turvottu" "turvotun" ;
swim_V = reg3V "uida" "uin" "uin" ; swim_V = reg3V "uida" "uin" "ui" ;
think_V = reg3V "ajatella" "ajattelen" "ajattelin" ; think_V = reg3V "ajatella" "ajattelen" "ajatteli" ;
throw_V = regV "heittää" ; throw_V = regV "heittää" ;
tie_V = regV "sitoa" ; tie_V = regV "sitoa" ;
turn_V = regV "kääntyä" ; turn_V = regV "kääntyä" ;

View File

@@ -5,9 +5,9 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/06/23 14:32:44 $ -- > CVS $Date: 2005/06/29 16:27:56 $
-- > CVS $Author: aarne $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.65 $ -- > CVS $Revision: 1.66 $
-- --
-- A database for customizable GF shell commands. -- A database for customizable GF shell commands.
-- --
@@ -39,6 +39,7 @@ import qualified GF.Grammar.MMacros as MM
import GF.Grammar.AbsCompute import GF.Grammar.AbsCompute
import GF.Grammar.TypeCheck import GF.Grammar.TypeCheck
import GF.UseGrammar.Generate import GF.UseGrammar.Generate
import GF.UseGrammar.Linear (unoptimizeCanon)
------import Compile ------import Compile
import GF.Compile.ShellState import GF.Compile.ShellState
import GF.UseGrammar.Editing import GF.UseGrammar.Editing
@@ -282,7 +283,7 @@ customMultiGrammarPrinter =
customData "Printers for multiple grammars, selected by option -printer=x" $ customData "Printers for multiple grammars, selected by option -printer=x" $
[ [
(strCI "gfcm", const MC.prCanon) (strCI "gfcm", const MC.prCanon)
,(strCI "header", const MC.prCanonMGr) ,(strCI "header", const (MC.prCanonMGr . unoptimizeCanon))
,(strCI "cfgm", prCanonAsCFGM) ,(strCI "cfgm", prCanonAsCFGM)
,(strCI "graph", visualizeCanonGrammar) ,(strCI "graph", visualizeCanonGrammar)
] ]

View File

@@ -5,9 +5,9 @@
-- Stability : (stable) -- Stability : (stable)
-- Portability : (portable) -- Portability : (portable)
-- --
-- > CVS $Date: 2005/06/23 14:32:44 $ -- > CVS $Date: 2005/06/29 16:27:56 $
-- > CVS $Author: aarne $ -- > CVS $Author: aarne $
-- > CVS $Revision: 1.17 $ -- > CVS $Revision: 1.18 $
-- --
-- Linearization for canonical GF. AR 7\/6\/2003 -- Linearization for canonical GF. AR 7\/6\/2003
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
@@ -31,6 +31,7 @@ import GF.Text.Text
import GF.Data.Operations import GF.Data.Operations
import GF.Data.Zipper import GF.Data.Zipper
import qualified GF.Infra.Modules as M
import Control.Monad import Control.Monad
import Data.List (intersperse) import Data.List (intersperse)
@@ -104,6 +105,11 @@ expandLinTables gr t = case t of
ps <- mapM term2patt vs ps <- mapM term2patt vs
ts' <- mapM (comp . S t') $ vs ts' <- mapM (comp . S t') $ vs
return $ T ty [Cas [p] t | (p,t) <- zip ps ts'] return $ T ty [Cas [p] t | (p,t) <- zip ps ts']
V ty ts0 -> do
ts <- mapM exp ts0 -- expand from inside-out
vs <- alls ty
ps <- mapM term2patt vs
return $ T ty [Cas [p] t | (p,t) <- zip ps ts]
FV ts -> liftM FV $ mapM exp ts FV ts -> liftM FV $ mapM exp ts
_ -> composOp exp t _ -> composOp exp t
where where
@@ -111,6 +117,39 @@ expandLinTables gr t = case t of
exp = expandLinTables gr exp = expandLinTables gr
comp = ccompute gr [] comp = ccompute gr []
-- Do this for an entire grammar:
unoptimizeCanon :: CanonGrammar -> CanonGrammar
unoptimizeCanon g@(M.MGrammar ms) = M.MGrammar $ map convMod ms where
convMod (m, M.ModMod (M.Module (M.MTConcrete a) x flags me os defs)) =
(m, M.ModMod (M.Module (M.MTConcrete a) x flags me os (mapTree convDef defs)))
convMod mm = mm
convDef (c,CncCat ty df pr) = (c,CncCat ty (convT df) (convT pr))
convDef (f,CncFun c xs li pr) = (f,CncFun c xs (convT li) (convT pr))
convDef cd = cd
convT = err error id . exp
-- a version of expandLinTables that does not destroy share optimization
exp t = case t of
R rs -> liftM (R . map (uncurry Ass)) $ mapPairsM exp [(l,r) | Ass l r <- rs]
T ty rs@[Cas [_] _] -> do
rs' <- mapPairsM exp [(l,r) | Cas l r <- rs] -- expand from inside-out
let t' = T ty $ map (uncurry Cas) rs'
vs <- alls ty
ps <- mapM term2patt vs
ts' <- mapM (comp . S t') $ vs
return $ T ty [Cas [p] t | (p,t) <- zip ps ts']
V ty ts0 -> do
ts <- mapM exp ts0 -- expand from inside-out
vs <- alls ty
ps <- mapM term2patt vs
return $ T ty [Cas [p] t | (p,t) <- zip ps ts]
FV ts -> liftM FV $ mapM exp ts
_ -> composOp exp t
where
alls = allParamValues g
comp = ccompute g []
-- | from records, one can get to records of tables of strings -- | from records, one can get to records of tables of strings
rec2strTables :: Term -> Err [[(Label,[([Patt],[Str])])]] rec2strTables :: Term -> Err [[(Label,[([Patt],[Str])])]]
rec2strTables r = do rec2strTables r = do