on master help sign in
Improve --dumpcases.
4bc8589Matus Tejiscak
src/IRTS/Compiler.hs+23−2
@@ -32,6 +32,7 @@ import Control.Applicative
32import Control.Monad.State
32import Control.Monad.State
33import Data.Maybe
33import Data.Maybe
34import Data.List
34import Data.List
35+import Data.Ord
35import Data.IntSet (IntSet)
36import Data.IntSet (IntSet)
36import qualified Data.IntSet as IS
37import qualified Data.IntSet as IS
37import qualified Data.Map as M
38import qualified Data.Map as M
@@ -117,13 +118,33 @@ mkDecls t used
117 return decls
118 return decls
118
119
119showCaseTrees :: [(Name, LDecl)] -> String
120showCaseTrees :: [(Name, LDecl)] -> String
120−showCaseTrees ds = showSep "\n\n" (map showCT ds)
121+showCaseTrees = showSep "\n\n" . map showCT . sortBy (comparing defnRank)
121 where
122 where
122 showCT (n, LFun _ f args lexp)
123 showCT (n, LFun _ f args lexp)
123− = show n ++ " " ++ showSep " " (map show args) ++ " =\n\t "
124+ = show n ++ " " ++ showSep " " (map show args) ++ " =\n\t"
124 ++ show lexp
125 ++ show lexp
125 showCT (n, LConstructor c t a) = "data " ++ show n ++ " " ++ show a
126 showCT (n, LConstructor c t a) = "data " ++ show n ++ " " ++ show a
126
127
128+ defnRank :: (Name, LDecl) -> String
129+ defnRank (n, LFun _ _ _ _) = "1" ++ nameRank n
130+ defnRank (n, LConstructor _ _ _) = "2" ++ nameRank n
131+
132+ nameRank :: Name -> String
133+ nameRank (UN s) = "1" ++ show s
134+ nameRank (MN i s) = "2" ++ show s ++ show i
135+ nameRank (NS n ns) = "3" ++ concatMap show (reverse ns) ++ nameRank n
136+ nameRank (SN sn) = "4" ++ snRank sn
137+ nameRank n = "5" ++ show n
138+
139+ snRank :: SpecialName -> String
140+ snRank (WhereN i n n') = "1" ++ nameRank n' ++ nameRank n ++ show i
141+ snRank (InstanceN n args) = "2" ++ nameRank n ++ concatMap show args
142+ snRank (ParentN n s) = "3" ++ nameRank n ++ show s
143+ snRank (MethodN n) = "4" ++ nameRank n
144+ snRank (CaseN n) = "5" ++ nameRank n
145+ snRank (ElimN n) = "6" ++ nameRank n
146+ snRank (InstanceCtorN n) = "7" ++ nameRank n
147+
127isCon (TyDecl _ _) = True
148isCon (TyDecl _ _) = True
128isCon _ = False
149isCon _ = False
129
150
src/IRTS/Lang.hs+2−2
@@ -243,9 +243,9 @@ instance Show LExp where
243 where
243 where
244 fmt [] = ""
244 fmt [] = ""
245 fmt [alt]
245 fmt [alt]
246− = "\t" ++ ind ++ " | " ++ showAlt env (ind ++ " ") alt
246+ = "\t" ++ ind ++ "| " ++ showAlt env (ind ++ " ") alt
247 fmt (alt:as)
247 fmt (alt:as)
248− = "\t" ++ ind ++ " | " ++ showAlt env (ind ++ " . ") alt
248+ = "\t" ++ ind ++ "| " ++ showAlt env (ind ++ ". ") alt
249 ++ "\n" ++ fmt as
249 ++ "\n" ++ fmt as
250
250
251 show' env ind (LConst c) = show c
251 show' env ind (LConst c) = show c