debugging new compilation

This commit is contained in:
aarne
2007-12-09 15:20:50 +00:00
parent 6093c2d3e4
commit 3e788e5bbd
4 changed files with 24 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ comment "{-" "-}" ;
-- identifiers -- identifiers
position token PIdent (letter | '_') (letter | digit | '_' | '\'')* ; position token PIdent ('_')? letter (letter | digit | '_' | '\'')* ;
-- the top-level grammar -- the top-level grammar

View File

@@ -22,11 +22,11 @@ import GF.Devel.Grammar.Compute
--import GF.Infra.Ident --import GF.Infra.Ident
--import GF.Grammar.Lookup import GF.Devel.Grammar.Lookup
--import GF.Grammar.Refresh --import GF.Grammar.Refresh
--import GF.Compile.BackOpt --import GF.Compile.BackOpt
--import GF.Devel.CheckGrammar import GF.Devel.Compile.CheckGrammar
--import GF.Compile.Update --import GF.Compile.Update
@@ -45,8 +45,8 @@ import Debug.Trace
optimizeModule :: Options -> GF -> SourceModule -> Err SourceModule optimizeModule :: Options -> GF -> SourceModule -> Err SourceModule
optimizeModule opts gf0 sm@(m,mo) = case mtype mo of optimizeModule opts gf0 sm@(m,mo) = case mtype mo of
MTConcrete _ -> opt sm MTConcrete _ -> opt sm
MTInstance _ -> opt sm MTInstance _ -> optr sm
MTGrammar -> opt sm MTGrammar -> optr sm
_ -> return sm _ -> return sm
where where
gf = gf0 {gfmodules = Map.insert m mo (gfmodules gf0)} gf = gf0 {gfmodules = Map.insert m mo (gfmodules gf0)}
@@ -54,6 +54,19 @@ optimizeModule opts gf0 sm@(m,mo) = case mtype mo of
mo' <- termOpModule (computeTerm gf) mo mo' <- termOpModule (computeTerm gf) mo
return (m,mo') return (m,mo')
optr (m,mo)= do
let deps = allOperDependencies m $ mjments mo
ids <- topoSortOpers deps
gf' <- foldM evalOp gf ids
mo' <- lookupModule gf' m
return $ (m,mo')
where
evalOp gf i = do
ju <- lookupJudgement gf m i
def' <- computeTerm gf (jdef ju)
updateJudgement m i (ju {jdef = def'}) gf
{- {-

View File

@@ -63,7 +63,7 @@ computeTermOpt rec gr = comp where
---- Computed t' -> return $ unComputed t' ---- Computed t' -> return $ unComputed t'
Vr x -> do Vr x -> do
t' <- maybe (prtBad ("no value given to variable") x) return $ lookup x g t' <- maybe (prtBad ("no value for variable") x) return $ lookup x g
case t' of case t' of
_ | t == t' -> return t _ | t == t' -> return t
_ -> comp g t' _ -> comp g t'

View File

@@ -149,7 +149,11 @@ unifyJudgement old new = do
---- (unwords ["illegal update of",prt oterm,"to",prt nterm]) ---- (unwords ["illegal update of",prt oterm,"to",prt nterm])
return nterm return nterm
updateJudgement :: Ident -> Ident -> Judgement -> GF -> Err GF
updateJudgement m c ju gf = do
mo <- maybe (Bad (show m)) return $ Data.Map.lookup m $ gfmodules gf
let mo' = mo {mjments = insert c ju (mjments mo)}
return $ gf {gfmodules = insert m mo' (gfmodules gf)}
-- abstractions on Term -- abstractions on Term