fixed a Compute bug due to failure to match typed record values with untyped record patterns

This commit is contained in:
aarne
2008-12-04 17:02:24 +00:00
parent 95840d7cdc
commit 7de283f322
3 changed files with 17 additions and 8 deletions

View File

@@ -5,10 +5,10 @@ all: magnet
magnet: magnet:
# gfc --make -src --parser=off --name=fre BronzeageFre.gf +RTS -K100M # gfc --make -src --parser=off --name=fre BronzeageFre.gf +RTS -K100M
# gfc --make -src --erasing=on --name=bul BronzeageBul.gf # gfc --make -src --erasing=on --name=bul BronzeageBul.gf
gfc --make -src --parser=off --name=fin BronzeageFin.gf +RTS -K100M gfc --make -src --erasing=on --name=fin BronzeageFin.gf +RTS -K100M
gfc --make -src --erasing=on --name=eng BronzeageEng.gf gfc --make -src --erasing=on --name=eng BronzeageEng.gf
gfc --make -src --erasing=on --name=ger BronzeageGer.gf gfc --make -src --erasing=on --name=ger BronzeageGer.gf
gfc --make -src --erasing=on --name=scand BronzeageNor.gf BronzeageSwe.gf gfc --make -src --erasing=on --name=scand BronzeageNor.gf BronzeageSwe.gf
gfc --make -src --name=rom BronzeageIta.gf BronzeageSpa.gf gfc --make -src --name=rom BronzeageIta.gf BronzeageSpa.gf BronzeageFre.gf
gfc --make --name=bronze eng.pgf fin.pgf ger.pgf rom.pgf scand.pgf gfc --make --name=bronze eng.pgf fin.pgf ger.pgf rom.pgf scand.pgf

View File

@@ -33,6 +33,8 @@ import GF.Grammar.AppPredefined
import Data.List (nub,intersperse) import Data.List (nub,intersperse)
import Control.Monad (liftM2, liftM) import Control.Monad (liftM2, liftM)
----import Debug.Trace ----
-- | computation of concrete syntax terms into normal form -- | computation of concrete syntax terms into normal form
-- used mainly for partial evaluation -- used mainly for partial evaluation
computeConcrete :: SourceGrammar -> Term -> Err Term computeConcrete :: SourceGrammar -> Term -> Err Term
@@ -309,7 +311,7 @@ computeTermOpt rec gr = comput True where
-- course-of-values table: look up by index, no pattern matching needed -- course-of-values table: look up by index, no pattern matching needed
V ptyp ts -> do V ptyp ts -> do
vs <- allParamValues gr ptyp vs <- allParamValues gr ptyp
case lookup v' (zip vs [0 .. length vs - 1]) of case lookupR v' (zip vs [0 .. length vs - 1]) of
Just i -> comp g $ ts !! i Just i -> comp g $ ts !! i
_ -> return $ S t' v' -- if v' is not canonical _ -> return $ S t' v' -- if v' is not canonical
T _ cc -> case matchPattern cc v' of T _ cc -> case matchPattern cc v' of
@@ -321,6 +323,13 @@ computeTermOpt rec gr = comput True where
S (V i cs) e -> prawitzV g i (flip S v') cs e S (V i cs) e -> prawitzV g i (flip S v') cs e
_ -> returnC $ S t' v' _ -> returnC $ S t' v'
--- needed to match records with and without type information
---- todo: eliminate linear search in a list of records!
lookupR v vs = case v of
R rs -> lookup ([(x,y) | (x,(_,y)) <- rs])
[([(x,y) | (x,(_,y)) <- rs],v) | (R rs,v) <- vs]
_ -> lookup v vs
-- case-expand tables -- case-expand tables
-- if already expanded, don't expand again -- if already expanded, don't expand again
compTable g t = case t of compTable g t = case t of

View File

@@ -38,7 +38,7 @@ traceD s t = t
-- the main function: generate PGF from GF. -- the main function: generate PGF from GF.
mkCanon2gfcc :: Options -> String -> SourceGrammar -> (String,D.PGF) mkCanon2gfcc :: Options -> String -> SourceGrammar -> (String,D.PGF)
mkCanon2gfcc opts cnc gr = mkCanon2gfcc opts cnc gr =
(prIdent abs, (canon2gfcc opts pars . reorder abs . canon2canon abs) gr) (prIdent abs, (canon2gfcc opts pars . reorder abs . canon2canon opts abs) gr)
where where
abs = err (const c) id $ M.abstractOfConcrete gr c where c = identC (BS.pack cnc) abs = err (const c) id $ M.abstractOfConcrete gr c where c = identC (BS.pack cnc)
pars = mkParamLincat gr pars = mkParamLincat gr
@@ -267,8 +267,8 @@ repartition abs cg =
-- translate tables and records to arrays, parameters and labels to indices -- translate tables and records to arrays, parameters and labels to indices
canon2canon :: Ident -> SourceGrammar -> SourceGrammar canon2canon :: Options -> Ident -> SourceGrammar -> SourceGrammar
canon2canon abs cg0 = canon2canon opts abs cg0 =
(recollect . map cl2cl . repartition abs . purgeGrammar abs) cg0 (recollect . map cl2cl . repartition abs . purgeGrammar abs) cg0
where where
recollect = M.MGrammar . nubBy (\ (i,_) (j,_) -> i==j) . concatMap M.modules recollect = M.MGrammar . nubBy (\ (i,_) (j,_) -> i==j) . concatMap M.modules
@@ -281,7 +281,7 @@ canon2canon abs cg0 =
(c, M.ModMod $ M.replaceJudgements mo $ mapTree f2 (M.jments mo)) (c, M.ModMod $ M.replaceJudgements mo $ mapTree f2 (M.jments mo))
_ -> (c,m) _ -> (c,m)
j2j cg (f,j) = j2j cg (f,j) =
let debug = traceD ("+ " ++ prt f) in let debug = if verbAtLeast opts Verbose then trace ("+ " ++ prt f) else id in
case j of case j of
CncFun x (Yes tr) z -> CncFun x (Yes (debug (t2t tr))) z CncFun x (Yes tr) z -> CncFun x (Yes (debug (t2t tr))) z
CncCat (Yes ty) (Yes x) y -> CncCat (Yes (ty2ty ty)) (Yes (t2t x)) y CncCat (Yes ty) (Yes x) y -> CncCat (Yes (ty2ty ty)) (Yes (t2t x)) y