summaryrefslogtreecommitdiff
path: root/src/runtime/haskell/PGF
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2010-03-24 11:11:55 +0000
committerkrasimir <krasimir@chalmers.se>2010-03-24 11:11:55 +0000
commit68482aa7e9882ab8d65fb5fe261efc0e807f6dfd (patch)
treeb818f5c25002f0be2eefad441e62aa08c959cbe6 /src/runtime/haskell/PGF
parent76d155af0eb6174e479ec6c2023554984c14106f (diff)
now for every category we store, in PGF, the list of functions for it in source-code order. The order matters for the termination of the exhaustive generation with dependent types.
Diffstat (limited to 'src/runtime/haskell/PGF')
-rw-r--r--src/runtime/haskell/PGF/Binary.hs1
-rw-r--r--src/runtime/haskell/PGF/Data.hs10
-rw-r--r--src/runtime/haskell/PGF/Macros.hs14
-rw-r--r--src/runtime/haskell/PGF/Printer.hs4
-rw-r--r--src/runtime/haskell/PGF/TypeCheck.hs4
5 files changed, 14 insertions, 19 deletions
diff --git a/src/runtime/haskell/PGF/Binary.hs b/src/runtime/haskell/PGF/Binary.hs
index d03349fc7..241c9cc99 100644
--- a/src/runtime/haskell/PGF/Binary.hs
+++ b/src/runtime/haskell/PGF/Binary.hs
@@ -44,7 +44,6 @@ instance Binary Abstr where
cats <- get
return (Abstr{ aflags=aflags
, funs=funs, cats=cats
- , catfuns=Map.empty
})
instance Binary Concr where
diff --git a/src/runtime/haskell/PGF/Data.hs b/src/runtime/haskell/PGF/Data.hs
index fe768cd20..b604317fc 100644
--- a/src/runtime/haskell/PGF/Data.hs
+++ b/src/runtime/haskell/PGF/Data.hs
@@ -24,10 +24,12 @@ data PGF = PGF {
}
data Abstr = Abstr {
- aflags :: Map.Map CId Literal, -- value of a flag
- funs :: Map.Map CId (Type,Int,Maybe [Equation]), -- type, arrity and definition of function
- cats :: Map.Map CId [Hypo], -- context of a cat
- catfuns :: Map.Map CId [CId] -- funs to a cat (redundant, for fast lookup)
+ aflags :: Map.Map CId Literal, -- ^ value of a flag
+ funs :: Map.Map CId (Type,Int,Maybe [Equation]), -- ^ type, arrity and definition of function
+ cats :: Map.Map CId ([Hypo],[CId]) -- ^ 1. context of a category
+ -- ^ 2. functions of a category. The order in the list is important,
+ -- this is the order in which the type singatures are given in the source.
+ -- The termination of the exhaustive generation might depend on this.
}
data Concr = Concr {
diff --git a/src/runtime/haskell/PGF/Macros.hs b/src/runtime/haskell/PGF/Macros.hs
index 34f32c386..d7f242c45 100644
--- a/src/runtime/haskell/PGF/Macros.hs
+++ b/src/runtime/haskell/PGF/Macros.hs
@@ -59,7 +59,7 @@ functionsToCat :: PGF -> CId -> [(CId,Type)]
functionsToCat pgf cat =
[(f,ty) | f <- fs, Just (ty,_,_) <- [Map.lookup f $ funs $ abstract pgf]]
where
- fs = lookMap [] cat $ catfuns $ abstract pgf
+ (_,fs) = lookMap ([],[]) cat $ cats $ abstract pgf
missingLins :: PGF -> CId -> [CId]
missingLins pgf lang = [c | c <- fs, not (hasl c)] where
@@ -72,12 +72,11 @@ hasLin pgf lang f = Map.member f $ lproductions $ lookConcr pgf lang
restrictPGF :: (CId -> Bool) -> PGF -> PGF
restrictPGF cond pgf = pgf {
abstract = abstr {
- funs = restrict $ funs $ abstr,
- cats = restrict $ cats $ abstr
+ funs = Map.filterWithKey (\c _ -> cond c) (funs abstr),
+ cats = Map.map (\(hyps,fs) -> (hyps,filter cond fs)) (cats abstr)
}
} ---- restrict concrs also, might be needed
where
- restrict = Map.filterWithKey (\c _ -> cond c)
abstr = abstract pgf
depth :: Expr -> Int
@@ -142,13 +141,8 @@ _B = mkCId "__gfB"
_V = mkCId "__gfV"
updateProductionIndices :: PGF -> PGF
-updateProductionIndices pgf = pgf{ abstract = updateAbstract (abstract pgf)
- , concretes = fmap updateConcrete (concretes pgf)
- }
+updateProductionIndices pgf = pgf{ concretes = fmap updateConcrete (concretes pgf) }
where
- updateAbstract abs =
- abs{catfuns = Map.mapWithKey (\cat _ -> [f | (f, (DTyp _ c _,_,_)) <- Map.toList (funs abs), c==cat]) (cats abs)}
-
updateConcrete cnc =
let prods0 = filterProductions (productions cnc)
p_prods = parseIndex cnc prods0
diff --git a/src/runtime/haskell/PGF/Printer.hs b/src/runtime/haskell/PGF/Printer.hs
index 23bdc718d..1d9928304 100644
--- a/src/runtime/haskell/PGF/Printer.hs
+++ b/src/runtime/haskell/PGF/Printer.hs
@@ -28,8 +28,8 @@ ppAbs name a = text "abstract" <+> ppCId name <+> char '{' $$
ppFlag :: CId -> Literal -> Doc
ppFlag flag value = text "flag" <+> ppCId flag <+> char '=' <+> ppLit value ;
-ppCat :: CId -> [Hypo] -> Doc
-ppCat c hyps = text "cat" <+> ppCId c <+> hsep (snd (mapAccumL (ppHypo 4) [] hyps))
+ppCat :: CId -> ([Hypo],[CId]) -> Doc
+ppCat c (hyps,_) = text "cat" <+> ppCId c <+> hsep (snd (mapAccumL (ppHypo 4) [] hyps))
ppFun :: CId -> (Type,Int,Maybe [Equation]) -> Doc
ppFun f (t,_,Just eqs) = text "fun" <+> ppCId f <+> colon <+> ppType 0 [] t $$
diff --git a/src/runtime/haskell/PGF/TypeCheck.hs b/src/runtime/haskell/PGF/TypeCheck.hs
index 2e34bc31c..3a95fc611 100644
--- a/src/runtime/haskell/PGF/TypeCheck.hs
+++ b/src/runtime/haskell/PGF/TypeCheck.hs
@@ -88,8 +88,8 @@ instance Functor TcM where
lookupCatHyps :: CId -> TcM [Hypo]
lookupCatHyps cat = TcM (\abstr metaid ms -> case Map.lookup cat (cats abstr) of
- Just hyps -> Ok metaid ms hyps
- Nothing -> Fail (UnknownCat cat))
+ Just (hyps,_) -> Ok metaid ms hyps
+ Nothing -> Fail (UnknownCat cat))
lookupFunType :: CId -> TcM TType
lookupFunType fun = TcM (\abstr metaid ms -> case Map.lookup fun (funs abstr) of