summaryrefslogtreecommitdiff
path: root/src/GF/Canon/CanonToGFCC.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2006-09-26 10:23:50 +0000
committeraarne <aarne@cs.chalmers.se>2006-09-26 10:23:50 +0000
commitdeee60f2c2075731be0db1d431114ac1ecf8e483 (patch)
treedc4dca80f901dd7253f5523446faf2f92739fae6 /src/GF/Canon/CanonToGFCC.hs
parentbe2f1ac5c8272837a553dfe484a678813c73fd5b (diff)
improving gfcc generation
Diffstat (limited to 'src/GF/Canon/CanonToGFCC.hs')
-rw-r--r--src/GF/Canon/CanonToGFCC.hs21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/GF/Canon/CanonToGFCC.hs b/src/GF/Canon/CanonToGFCC.hs
index 7735c5db1..8dad8d083 100644
--- a/src/GF/Canon/CanonToGFCC.hs
+++ b/src/GF/Canon/CanonToGFCC.hs
@@ -28,7 +28,7 @@ import GF.Canon.MkGFC
import GF.Canon.CMacros
import qualified GF.Infra.Modules as M
import qualified GF.Infra.Option as O
-import GF.UseGrammar.Linear (unoptimizeCanon)
+import GF.UseGrammar.Linear (expandLinTables, unoptimizeCanon)
import GF.Infra.Ident
import GF.Data.Operations
@@ -203,10 +203,11 @@ term2term cgr env@(labels,untyps,typs) tr = case tr of
in if (any (isStr . trmAss) rs)
then R rs'
else R [Ass (mkLab 0) (valNum tr), Ass (mkLab 1) (R rs')]
- R rs -> valNum tr
P t l -> r2r tr
T i [Cas p t] -> T i [Cas p (t2t t)]
- T ty cs -> V ty [t2t t | Cas _ t <- cs]
+ T _ _ -> case expandLinTables cgr tr of -- to normalize the order of cases
+ Ok (T ty cs) -> V ty [t2t t | Cas _ t <- cs]
+ _ -> K (KS (A.prt tr +++ prtTrace tr "66668"))
V ty ts -> V ty [t2t t | t <- ts]
S t p -> S (t2t t) (t2t p)
_ -> composSafeOp t2t tr
@@ -253,8 +254,18 @@ term2term cgr env@(labels,untyps,typs) tr = case tr of
_ -> composSafeOp (mkBranch x t) tr
mkLab k = L (IC ("_" ++ show k))
- valNum tr = maybe (K (KS (A.prt tr +++ prtTrace tr "66667"))) EInt $
- Map.lookup tr untyps
+ valNum tr = maybe (tryPerm tr) EInt $ Map.lookup tr untyps
+ --- a hack needed because GFCC does not guarantee canonical order of param records
+ where
+ tryPerm tr = case tr of
+ R rs -> case [v | Just v <- [Map.lookup (R rs') untyps | rs' <- permutations rs]] of
+ v:_ -> EInt v
+ _ -> report
+ _ -> report
+ report = K (KS (A.prt tr +++ prtTrace tr "66667"))
+ permutations xx = case xx of
+ [] -> [[]]
+ _ -> [x:xs | x <- xx, xs <- permutations (xx \\ [x])]
isStr tr = case tr of
Par _ _ -> False
EInt _ -> False