diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-01 22:56:42 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-01 22:56:42 +0200 |
commit | 128cf82881352cc1e9061db97fe3762315cfd0c9 (patch) | |
tree | 60f0efc4d587a58359b39edba470fd55a0d8c69a /src | |
parent | e2ef3e4de33e15627ce21c7c506650b2f8123a1c (diff) |
removing coloring from .out files
Diffstat (limited to 'src')
-rw-r--r-- | src/LambdaCube/Compiler/DesugaredSource.hs | 2 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Infer.hs | 39 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Pretty.hs | 18 |
3 files changed, 36 insertions, 23 deletions
diff --git a/src/LambdaCube/Compiler/DesugaredSource.hs b/src/LambdaCube/Compiler/DesugaredSource.hs index 33912ae3..7351f4d7 100644 --- a/src/LambdaCube/Compiler/DesugaredSource.hs +++ b/src/LambdaCube/Compiler/DesugaredSource.hs | |||
@@ -447,7 +447,7 @@ data Stmt | |||
447 | pattern Primitive n t = Let n (Just t) (SBuiltin "undefined") | 447 | pattern Primitive n t = Let n (Just t) (SBuiltin "undefined") |
448 | 448 | ||
449 | instance PShow Stmt where | 449 | instance PShow Stmt where |
450 | pShow = \case | 450 | pShow stmt = DResetFreshNames $ case stmt of |
451 | Primitive n t -> shAnn (pShow n) (pShow t) | 451 | Primitive n t -> shAnn (pShow n) (pShow t) |
452 | Let n ty e -> DLet "=" (pShow n) $ maybe (pShow e) (\ty -> shAnn (pShow e) (pShow ty)) ty | 452 | Let n ty e -> DLet "=" (pShow n) $ maybe (pShow e) (\ty -> shAnn (pShow e) (pShow ty)) ty |
453 | Data n ps ty cs -> nest 4 $ "data" <+> shAnn (foldl dApp (DTypeNamespace True $ pShow n) [shAnn (text "_") (pShow t) | (v, t) <- ps]) (pShow ty) <+> "where" <$$> vcat [shAnn (pShow n) $ pShow t | (n, t) <- cs] | 453 | Data n ps ty cs -> nest 4 $ "data" <+> shAnn (foldl dApp (DTypeNamespace True $ pShow n) [shAnn (text "_") (pShow t) | (v, t) <- ps]) (pShow ty) <+> "where" <$$> vcat [shAnn (pShow n) $ pShow t | (n, t) <- cs] |
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs index 61a50814..1b747e69 100644 --- a/src/LambdaCube/Compiler/Infer.hs +++ b/src/LambdaCube/Compiler/Infer.hs | |||
@@ -952,10 +952,10 @@ inferN_ tellTrace = infer where | |||
952 | Parens x -> infer te x | 952 | Parens x -> infer te x |
953 | SAnn x t -> checkN (CheckIType x te) t TType | 953 | SAnn x t -> checkN (CheckIType x te) t TType |
954 | SRHS x -> infer (ELabelEnd te) x | 954 | SRHS x -> infer (ELabelEnd te) x |
955 | SVar sn i -> focus_' te exp (Var i, snd $ varType "C2" i te) | 955 | SVar sn i -> focusTell te exp (Var i, snd $ varType "C2" i te) |
956 | SLit si l -> focus_' te exp (ELit l, litType l) | 956 | SLit si l -> focusTell te exp (ELit l, litType l) |
957 | STyped et -> focus_' te exp et | 957 | STyped et -> focusTell' te exp et |
958 | SGlobal (SIName si s) -> focus_' te exp =<< getDef te si s | 958 | SGlobal (SIName si s) -> focusTell te exp =<< getDef te si s |
959 | SLet le a b -> infer (ELet1 le te b{-in-}) a{-let-} -- infer te SLamV b `SAppV` a) | 959 | SLet le a b -> infer (ELet1 le te b{-in-}) a{-let-} -- infer te SLamV b `SAppV` a) |
960 | SApp_ si h a b -> infer (EApp1 (si `validate` [sourceInfo a, sourceInfo b]) h te b) a | 960 | SApp_ si h a b -> infer (EApp1 (si `validate` [sourceInfo a, sourceInfo b]) h te b) a |
961 | SBind_ si h _ a b -> infer ((if h /= BMeta then CheckType_ (sourceInfo exp) TType else id) $ EBind1 si h te $ (if isPi h then TyType else id) b) a | 961 | SBind_ si h _ a b -> infer ((if h /= BMeta then CheckType_ (sourceInfo exp) TType else id) $ EBind1 si h te $ (if isPi h then TyType else id) b) a |
@@ -984,7 +984,7 @@ inferN_ tellTrace = infer where | |||
984 | | SRHS x <- e = checkN (ELabelEnd te) x t | 984 | | SRHS x <- e = checkN (ELabelEnd te) x t |
985 | | SApp_ si h a b <- e = infer (CheckAppType si h t te b) a | 985 | | SApp_ si h a b <- e = infer (CheckAppType si h t te b) a |
986 | | SLam h a b <- e, Pi h' x y <- t, h == h' = do | 986 | | SLam h a b <- e, Pi h' x y <- t, h == h' = do |
987 | tellType e t | 987 | -- tellType e t |
988 | let same = checkSame te a x | 988 | let same = checkSame te a x |
989 | if same then checkN (EBind2 (BLam h) x te) b y else error $ "checkSame:\n" ++ ppShow a ++ "\nwith\n" ++ showEnvExp te (x, TType) | 989 | if same then checkN (EBind2 (BLam h) x te) b y else error $ "checkSame:\n" ++ ppShow a ++ "\nwith\n" ++ showEnvExp te (x, TType) |
990 | | Pi Hidden a b <- t = do | 990 | | Pi Hidden a b <- t = do |
@@ -1018,7 +1018,8 @@ inferN_ tellTrace = infer where | |||
1018 | hArgs (Pi Hidden _ b) = 1 + hArgs b | 1018 | hArgs (Pi Hidden _ b) = 1 + hArgs b |
1019 | hArgs _ = 0 | 1019 | hArgs _ = 0 |
1020 | 1020 | ||
1021 | focus_' env si eet = tellType si (snd eet) >> focus_ env eet | 1021 | focusTell env si eet = tellType si (snd eet) >> focus_ env eet |
1022 | focusTell' env si eet = focus_ env eet | ||
1022 | 1023 | ||
1023 | focus_ :: Env -> ExpType -> IM m ExpType' | 1024 | focus_ :: Env -> ExpType -> IM m ExpType' |
1024 | focus_ env eet@(e, et) = tellTrace "focus" (showEnvExp env eet) $ case env of | 1025 | focus_ env eet@(e, et) = tellTrace "focus" (showEnvExp env eet) $ case env of |
@@ -1045,10 +1046,10 @@ inferN_ tellTrace = infer where | |||
1045 | | hArgs et < hArgs t, Pi Hidden t1 t2 <- t | 1046 | | hArgs et < hArgs t, Pi Hidden t1 t2 <- t |
1046 | -> focus_ (CheckType_ si t2 $ EBind2 (BLam Hidden) t1 te) eet | 1047 | -> focus_ (CheckType_ si t2 $ EBind2 (BLam Hidden) t1 te) eet |
1047 | | otherwise -> focus_ (EBind2_ si BMeta (cstr TType t et) te) $ up 1 eet | 1048 | | otherwise -> focus_ (EBind2_ si BMeta (cstr TType t et) te) $ up 1 eet |
1048 | EApp2 si h (a, at) te -> focus_' te si (app_ a e, appTy at e) -- h?? | 1049 | EApp2 si h (a, at) te -> focusTell te si (app_ a e, appTy at e) -- h?? |
1049 | EBind1 si h te b -> infer (EBind2_ (sourceInfo b) h e te) b | 1050 | EBind1 si h te b -> infer (EBind2_ (sourceInfo b) h e te) b |
1050 | EBind2_ si (BLam h) a te -> focus_ te $ lamPi h a eet | 1051 | EBind2_ si (BLam h) a te -> focus_ te $ lamPi h a eet |
1051 | EBind2_ si (BPi h) a te -> focus_' te si (Pi h a e, TType) | 1052 | EBind2_ si (BPi h) a te -> focusTell te si (Pi h a e, TType) |
1052 | _ -> focus2 env $ MEnd eet | 1053 | _ -> focus2 env $ MEnd eet |
1053 | 1054 | ||
1054 | focus2 :: Env -> CEnv ExpType -> IM m ExpType' | 1055 | focus2 :: Env -> CEnv ExpType -> IM m ExpType' |
@@ -1065,8 +1066,8 @@ inferN_ tellTrace = infer where | |||
1065 | | CstrT t a b <- tt, Just r <- cst (b, t) a -> r | 1066 | | CstrT t a b <- tt, Just r <- cst (b, t) a -> r |
1066 | | isCstr tt, EBind2 h x te' <- te{-, h /= BMeta todo: remove-}, Just x' <- down 0 tt, x == x' | 1067 | | isCstr tt, EBind2 h x te' <- te{-, h /= BMeta todo: remove-}, Just x' <- down 0 tt, x == x' |
1067 | -> refocus te $ subst 1 (Var 0) eet | 1068 | -> refocus te $ subst 1 (Var 0) eet |
1068 | | EBind2 h x te' <- te, h /= BMeta, Just b' <- down 0 tt | 1069 | | EBind2_ si' h x te' <- te, h /= BMeta, Just b' <- down 0 tt |
1069 | -> refocus (EBind2_ si h (up 1 x) $ EBind2_ si BMeta b' te') $ subst 2 (Var 0) $ up 1 eet | 1070 | -> refocus (EBind2_ si' h (up 1 x) $ EBind2_ si BMeta b' te') $ subst 2 (Var 0) $ up 1 eet |
1070 | | ELet2 le (x, xt) te' <- te, Just b' <- down 0 tt | 1071 | | ELet2 le (x, xt) te' <- te, Just b' <- down 0 tt |
1071 | -> refocus (ELet2 le (up 1 x, up 1 xt) $ EBind2_ si BMeta b' te') $ subst 2 (Var 0) $ up 1 eet | 1072 | -> refocus (ELet2 le (up 1 x, up 1 xt) $ EBind2_ si BMeta b' te') $ subst 2 (Var 0) $ up 1 eet |
1072 | | EBind1 si h te' x <- te -> refocus (EBind1 si h (EBind2_ si BMeta tt_ te') $ up1_ 1 x) eet | 1073 | | EBind1 si h te' x <- te -> refocus (EBind1 si h (EBind2_ si BMeta tt_ te') $ up1_ 1 x) eet |
@@ -1261,7 +1262,7 @@ initEnv = Map.fromList | |||
1261 | -------------------------------------------------------------------------------- infos | 1262 | -------------------------------------------------------------------------------- infos |
1262 | 1263 | ||
1263 | data Info | 1264 | data Info |
1264 | = Info Range String | 1265 | = Info Range Doc |
1265 | | IType SIName Exp | 1266 | | IType SIName Exp |
1266 | | ITrace String String | 1267 | | ITrace String String |
1267 | | IError ErrorMsg | 1268 | | IError ErrorMsg |
@@ -1279,7 +1280,7 @@ instance NFData Info where rnf = rnf . ppShow | |||
1279 | -} | 1280 | -} |
1280 | instance PShow Info where | 1281 | instance PShow Info where |
1281 | pShow = \case | 1282 | pShow = \case |
1282 | Info r s -> shortForm (pShow r) <+> "" <+> text s | 1283 | Info r s -> nest 4 $ shortForm (pShow r) <$$> s |
1283 | IType a b -> shAnn (pShow a) (pShow b) | 1284 | IType a b -> shAnn (pShow a) (pShow b) |
1284 | ITrace i s -> text i <> ": " <+> text s | 1285 | ITrace i s -> text i <> ": " <+> text s |
1285 | IError e -> "!" <> pShow e | 1286 | IError e -> "!" <> pShow e |
@@ -1295,14 +1296,14 @@ mkInfoItem (RangeSI r) i = [Info r i] | |||
1295 | mkInfoItem _ _ = mempty | 1296 | mkInfoItem _ _ = mempty |
1296 | 1297 | ||
1297 | listAllInfos m = h "trace" (listTraceInfos m) | 1298 | listAllInfos m = h "trace" (listTraceInfos m) |
1298 | ++ h "tooltips" [ show (shortForm $ pShow r) ++ " " ++ intercalate " | " is | (r, is) <- listTypeInfos m ] | 1299 | ++ h "tooltips" [ nest 4 $ shortForm (pShow r) <$$> hsep (intersperse "|" is) | (r, is) <- listTypeInfos m ] |
1299 | ++ h "warnings" [ ppShow w | ParseWarning w <- m ] | 1300 | ++ h "warnings" [ pShow w | ParseWarning w <- m ] |
1300 | where | 1301 | where |
1301 | h x [] = [] | 1302 | h x [] = [] |
1302 | h x xs = ("------------ " ++ x) : xs | 1303 | h x xs = ("------------" <+> x) : xs |
1303 | 1304 | ||
1304 | listTraceInfos m = [ppShow i | i <- m, case i of Info{} -> False; ParseWarning{} -> False; _ -> True] | 1305 | listTraceInfos m = [DResetFreshNames $ pShow i | i <- m, case i of Info{} -> False; ParseWarning{} -> False; _ -> True] |
1305 | listTypeInfos m = map (second Set.toList) $ Map.toList $ Map.unionsWith (<>) [Map.singleton r $ Set.singleton i | Info r i <- m] | 1306 | listTypeInfos m = Map.toList $ Map.unionsWith (<>) [Map.singleton r [i] | Info r i <- m] |
1306 | 1307 | ||
1307 | -------------------------------------------------------------------------------- inference for statements | 1308 | -------------------------------------------------------------------------------- inference for statements |
1308 | 1309 | ||
@@ -1346,7 +1347,7 @@ handleStmt = \case | |||
1346 | | c == SGlobal s && take pnum' xs == downToS "a3" (length ctl) pnum' | 1347 | | c == SGlobal s && take pnum' xs == downToS "a3" (length ctl) pnum' |
1347 | = do | 1348 | = do |
1348 | cty <- removeHiddenUnit <$> inferType (UncurryS [(Hidden, x) | (Visible, x) <- ps] ct) | 1349 | cty <- removeHiddenUnit <$> inferType (UncurryS [(Hidden, x) | (Visible, x) <- ps] ct) |
1349 | tellType (sourceInfo cn) cty | 1350 | -- tellType (sourceInfo cn) cty |
1350 | let pars = zipWith (\x -> second $ STyped . flip (,) TType . rUp (1+j) x) [0..] $ drop (length ps) $ fst $ getParams cty | 1351 | let pars = zipWith (\x -> second $ STyped . flip (,) TType . rUp (1+j) x) [0..] $ drop (length ps) $ fst $ getParams cty |
1351 | act = length . fst . getParams $ cty | 1352 | act = length . fst . getParams $ cty |
1352 | acts = map fst . fst . getParams $ cty | 1353 | acts = map fst . fst . getParams $ cty |
@@ -1451,7 +1452,7 @@ joinEnv e1 e2 = do | |||
1451 | 1452 | ||
1452 | downTo n m = map Var [n+m-1, n+m-2..n] | 1453 | downTo n m = map Var [n+m-1, n+m-2..n] |
1453 | 1454 | ||
1454 | tellType si t = tell $ mkInfoItem (sourceInfo si) $ plainShow $ DTypeNamespace True $ mkDoc False (t, TType) | 1455 | tellType si t = tell $ mkInfoItem (sourceInfo si) $ DTypeNamespace True $ mkDoc False (t, TType) |
1455 | 1456 | ||
1456 | 1457 | ||
1457 | -------------------------------------------------------------------------------- pretty print | 1458 | -------------------------------------------------------------------------------- pretty print |
diff --git a/src/LambdaCube/Compiler/Pretty.hs b/src/LambdaCube/Compiler/Pretty.hs index 17b64c15..7aba8f77 100644 --- a/src/LambdaCube/Compiler/Pretty.hs +++ b/src/LambdaCube/Compiler/Pretty.hs | |||
@@ -70,6 +70,7 @@ data Doc | |||
70 | | DFreshName Bool{-used-} Doc | 70 | | DFreshName Bool{-used-} Doc |
71 | | DVar Int | 71 | | DVar Int |
72 | | DUp Int Doc | 72 | | DUp Int Doc |
73 | | DResetFreshNames Doc | ||
73 | 74 | ||
74 | | DExpand Doc Doc | 75 | | DExpand Doc Doc |
75 | 76 | ||
@@ -106,15 +107,21 @@ instance Show Doc where | |||
106 | plainShow :: PShow a => a -> String | 107 | plainShow :: PShow a => a -> String |
107 | plainShow = ($ "") . P.displayS . P.renderPretty 0.6 150 . P.plain . renderDoc . pShow | 108 | plainShow = ($ "") . P.displayS . P.renderPretty 0.6 150 . P.plain . renderDoc . pShow |
108 | 109 | ||
110 | simpleShow :: PShow a => a -> String | ||
111 | simpleShow = ($ "") . P.displayS . P.renderPretty 0.4 200 . P.plain . renderDoc . pShow | ||
112 | |||
109 | renderDoc :: Doc -> P.Doc | 113 | renderDoc :: Doc -> P.Doc |
110 | renderDoc | 114 | renderDoc |
111 | = render | 115 | = render |
112 | . addPar False (Infix (-10)) | 116 | . addPar False (Infix (-10)) |
113 | . flip runReader ((\s n -> '_': n: s) <$> iterate ('\'':) "" <*> ['a'..'z']) | 117 | . flip runReader freeNames |
114 | . flip evalStateT (flip (:) <$> iterate ('\'':) "" <*> ['a'..'z']) | 118 | . flip evalStateT freshNames |
115 | . showVars | 119 | . showVars |
116 | . expand True | 120 | . expand True |
117 | where | 121 | where |
122 | freshNames = flip (:) <$> iterate ('\'':) "" <*> ['a'..'z'] | ||
123 | freeNames = map ('_':) freshNames | ||
124 | |||
118 | noexpand = expand False | 125 | noexpand = expand False |
119 | expand full = \case | 126 | expand full = \case |
120 | DExpand short long -> expand full $ if full then long else short | 127 | DExpand short long -> expand full $ if full then long else short |
@@ -125,7 +132,8 @@ renderDoc | |||
125 | DInfix pr x op y -> DInfix pr (noexpand x) (mapDocAtom (\_ _ -> noexpand) op) (noexpand y) | 132 | DInfix pr x op y -> DInfix pr (noexpand x) (mapDocAtom (\_ _ -> noexpand) op) (noexpand y) |
126 | DPreOp pr op y -> DPreOp pr (mapDocAtom (\_ _ -> noexpand) op) (noexpand y) | 133 | DPreOp pr op y -> DPreOp pr (mapDocAtom (\_ _ -> noexpand) op) (noexpand y) |
127 | DVar i -> DVar i | 134 | DVar i -> DVar i |
128 | DFreshName b x -> DFreshName b $ noexpand x | 135 | DFreshName b x -> (if full then DResetFreshNames else id) $ DFreshName b $ noexpand x |
136 | DResetFreshNames x -> DResetFreshNames $ expand full x | ||
129 | DUp i x -> DUp i $ noexpand x | 137 | DUp i x -> DUp i $ noexpand x |
130 | 138 | ||
131 | showVars = \case | 139 | showVars = \case |
@@ -138,6 +146,10 @@ renderDoc | |||
138 | DVar i -> asks $ text . (!! i) | 146 | DVar i -> asks $ text . (!! i) |
139 | DFreshName True x -> gets head >>= \n -> modify tail >> local (n:) (showVars x) | 147 | DFreshName True x -> gets head >>= \n -> modify tail >> local (n:) (showVars x) |
140 | DFreshName False x -> local ("_":) $ showVars x | 148 | DFreshName False x -> local ("_":) $ showVars x |
149 | DResetFreshNames x -> do | ||
150 | st <- get | ||
151 | put freshNames | ||
152 | local (const freeNames) (showVars x) <* put st | ||
141 | DUp i x -> local (dropIndex i) $ showVars x | 153 | DUp i x -> local (dropIndex i) $ showVars x |
142 | where | 154 | where |
143 | showVarA (SimpleAtom s) = pure $ SimpleAtom s | 155 | showVarA (SimpleAtom s) = pure $ SimpleAtom s |