diff options
Diffstat (limited to 'src/LambdaCube/Compiler/Parser.hs')
-rw-r--r-- | src/LambdaCube/Compiler/Parser.hs | 75 |
1 files changed, 46 insertions, 29 deletions
diff --git a/src/LambdaCube/Compiler/Parser.hs b/src/LambdaCube/Compiler/Parser.hs index 6a27fb56..e4d482a8 100644 --- a/src/LambdaCube/Compiler/Parser.hs +++ b/src/LambdaCube/Compiler/Parser.hs | |||
@@ -13,14 +13,14 @@ module LambdaCube.Compiler.Parser | |||
13 | , sourceInfo, SI(..), debugSI | 13 | , sourceInfo, SI(..), debugSI |
14 | , Module(..), Visibility(..), Binder(..), SExp'(..), Extension(..), Extensions | 14 | , Module(..), Visibility(..), Binder(..), SExp'(..), Extension(..), Extensions |
15 | , pattern SVar, pattern SType, pattern Wildcard, pattern SAppV, pattern SLamV, pattern SAnn | 15 | , pattern SVar, pattern SType, pattern Wildcard, pattern SAppV, pattern SLamV, pattern SAnn |
16 | , pattern SBuiltin, pattern SPi, pattern Primitive, pattern SLabelEnd, pattern SLam | 16 | , pattern SBuiltin, pattern SPi, pattern Primitive, pattern SLabelEnd, pattern SLam, pattern Parens |
17 | , pattern TyType, pattern Wildcard_ | 17 | , pattern TyType, pattern Wildcard_ |
18 | , debug, isPi, varDB, lowerDB, justDB, upDB, cmpDB, MaxDB (..), iterateN, traceD | 18 | , debug, isPi, varDB, lowerDB, justDB, upDB, cmpDB, MaxDB (..), iterateN, traceD |
19 | , parseLC, runDefParser | 19 | , parseLC, runDefParser |
20 | , getParamsS, addParamsS, getApps, apps', downToS, addForalls | 20 | , getParamsS, addParamsS, getApps, apps', downToS, addForalls |
21 | , mkDesugarInfo, joinDesugarInfo | 21 | , mkDesugarInfo, joinDesugarInfo |
22 | , Up (..), up1, up | 22 | , Up (..), up1, up |
23 | , Doc, shLam, shApp, shLet, shLet_, shAtom, shAnn, shVar, epar, showDoc, showDoc_, sExpDoc, shCstr | 23 | , Doc, shLam, shApp, shLet, shLet_, shAtom, shAnn, shVar, epar, showDoc, showDoc_, sExpDoc, shCstr, shTuple |
24 | , mtrace, sortDefs | 24 | , mtrace, sortDefs |
25 | , trSExp', usedS, substSG0, substS | 25 | , trSExp', usedS, substSG0, substS |
26 | , Stmt (..), Export (..), ImportItems (..) | 26 | , Stmt (..), Export (..), ImportItems (..) |
@@ -131,6 +131,7 @@ pattern SLabelEnd a = SBuiltin "labelend" `SAppV` a | |||
131 | pattern SBuiltin s <- SGlobal (_, s) where SBuiltin s = SGlobal (debugSI $ "builtin " ++ s, s) | 131 | pattern SBuiltin s <- SGlobal (_, s) where SBuiltin s = SGlobal (debugSI $ "builtin " ++ s, s) |
132 | 132 | ||
133 | pattern Section e = SBuiltin "^section" `SAppV` e | 133 | pattern Section e = SBuiltin "^section" `SAppV` e |
134 | pattern Parens e = SBuiltin "parens" `SAppV` e | ||
134 | 135 | ||
135 | sApp v a b = SApp (sourceInfo a <> sourceInfo b) v a b | 136 | sApp v a b = SApp (sourceInfo a <> sourceInfo b) v a b |
136 | sBind v x a b = SBind (sourceInfo a <> sourceInfo b) v x a b | 137 | sBind v x a b = SBind (sourceInfo a <> sourceInfo b) v x a b |
@@ -398,25 +399,24 @@ parseTerm prec = setSI' {-TODO: remove, slow-} $ case prec of | |||
398 | 399 | ||
399 | mkProjection = foldl $ \exp field -> SBuiltin "project" `SAppV` field `SAppV` exp | 400 | mkProjection = foldl $ \exp field -> SBuiltin "project" `SAppV` field `SAppV` exp |
400 | 401 | ||
401 | -- Creates: RecordCons @[("x", _), ("y", _), ("z", _)] (1.0, (2.0, (3.0, ()))) | 402 | -- Creates: RecordCons @[("x", _), ("y", _), ("z", _)] (1.0, 2.0, 3.0))) |
402 | mkRecord xs = SBuiltin "RecordCons" `SAppH` names `SAppV` values | 403 | mkRecord xs = SBuiltin "RecordCons" `SAppH` names `SAppV` values |
403 | where | 404 | where |
404 | (names, values) = mkNames *** mkValues $ unzip xs | 405 | (names, values) = mkNames *** mkValues $ unzip xs |
405 | 406 | ||
406 | mkNameTuple (si, v) = SBuiltin "Tuple2" `SAppV` SLit si (LString v) `SAppV` Wildcard SType | 407 | mkNameTuple (si, v) = SBuiltin "RecItem" `SAppV` SLit si (LString v) `SAppV` Wildcard SType |
407 | mkNames = foldr (\n ns -> SBuiltin "Cons" `SAppV` mkNameTuple n `SAppV` ns) | 408 | mkNames = foldr (\n ns -> SBuiltin "Cons" `SAppV` mkNameTuple n `SAppV` ns) |
408 | (SBuiltin "Nil") | 409 | (SBuiltin "Nil") |
409 | 410 | ||
410 | mkValues = foldr (\x xs -> SBuiltin "Tuple2" `SAppV` x `SAppV` xs) | 411 | mkValues = foldr (\x xs -> SBuiltin "HCons" `SAppV` x `SAppV` xs) |
411 | (SBuiltin "Tuple0") | 412 | (SBuiltin "HNil") |
412 | 413 | ||
413 | mkTuple _ [Section e] = e | 414 | mkTuple _ [Section e] = e |
414 | mkTuple _ [x] = x | 415 | mkTuple (Namespace (Just TypeLevel) _) [Parens e] = SBuiltin "'HList" `SAppV` (SBuiltin "Cons" `SAppV` e `SAppV` SBuiltin "Nil") |
415 | mkTuple (Namespace level _) xs = foldl SAppV (SBuiltin (tuple ++ show (length xs))) xs | 416 | mkTuple _ [Parens e] = SBuiltin "HCons" `SAppV` e `SAppV` SBuiltin "HNil" |
416 | where tuple = case level of | 417 | mkTuple _ [x] = Parens x |
417 | Just TypeLevel -> "'Tuple" | 418 | mkTuple (Namespace (Just TypeLevel) _) xs = SBuiltin "'HList" `SAppV` foldr (\x y -> SBuiltin "Cons" `SAppV` x `SAppV` y) (SBuiltin "Nil") xs |
418 | Just ExpLevel -> "Tuple" | 419 | mkTuple _ xs = foldr (\x y -> SBuiltin "HCons" `SAppV` x `SAppV` y) (SBuiltin "HNil") xs |
419 | _ -> error "mkTuple" | ||
420 | 420 | ||
421 | mkList (Namespace (Just TypeLevel) _) [x] = SBuiltin "'List" `SAppV` x | 421 | mkList (Namespace (Just TypeLevel) _) [x] = SBuiltin "'List" `SAppV` x |
422 | mkList (Namespace (Just ExpLevel) _) xs = foldr (\x l -> SBuiltin "Cons" `SAppV` x `SAppV` l) (SBuiltin "Nil") xs | 422 | mkList (Namespace (Just ExpLevel) _) xs = foldr (\x l -> SBuiltin "Cons" `SAppV` x `SAppV` l) (SBuiltin "Nil") xs |
@@ -469,11 +469,11 @@ parseTerm prec = setSI' {-TODO: remove, slow-} $ case prec of | |||
469 | 469 | ||
470 | sNonDepPi h a b = SPi h a $ up1 b | 470 | sNonDepPi h a b = SPi h a $ up1 b |
471 | 471 | ||
472 | getTTuple' (getTTuple -> Just (n, xs)) | n == length xs = xs | 472 | getTTuple' (SBuiltin "'HList" `SAppV` (getTTuple -> Just (n, xs))) | n == length xs = xs |
473 | getTTuple' x = [x] | 473 | getTTuple' x = [x] |
474 | 474 | ||
475 | getTTuple (SAppV (getTTuple -> Just (n, xs)) z) = Just (n, xs ++ [z]{-todo: eff-}) | 475 | getTTuple (SBuiltin "Nil") = Just (0, []) |
476 | getTTuple (SGlobal (si, s@(splitAt 6 -> ("'Tuple", reads -> [(n, "")])))) = Just (n :: Int, []) | 476 | getTTuple (SBuiltin "Cons" `SAppV` x `SAppV` (getTTuple -> Just (n, y))) = Just (n+1, x:y) |
477 | getTTuple _ = Nothing | 477 | getTTuple _ = Nothing |
478 | 478 | ||
479 | patLam :: (SExp -> SExp) -> DesugarInfo -> (Visibility, SExp) -> Pat -> SExp -> SExp | 479 | patLam :: (SExp -> SExp) -> DesugarInfo -> (Visibility, SExp) -> Pat -> SExp -> SExp |
@@ -488,6 +488,8 @@ data Pat | |||
488 | | PatType ParPat SExp | 488 | | PatType ParPat SExp |
489 | deriving Show | 489 | deriving Show |
490 | 490 | ||
491 | pattern PParens p = ViewPat (SBuiltin "parens") (ParPat [p]) | ||
492 | |||
491 | -- parallel patterns like v@(f -> [])@(Just x) | 493 | -- parallel patterns like v@(f -> [])@(Just x) |
492 | newtype ParPat = ParPat [Pat] | 494 | newtype ParPat = ParPat [Pat] |
493 | deriving Show | 495 | deriving Show |
@@ -499,6 +501,7 @@ mapP :: (SExp -> SExp) -> Pat -> Pat | |||
499 | mapP f = \case | 501 | mapP f = \case |
500 | PVar n -> PVar n | 502 | PVar n -> PVar n |
501 | PCon n pp -> PCon n (mapPP f <$> pp) | 503 | PCon n pp -> PCon n (mapPP f <$> pp) |
504 | PParens p -> PParens (mapP f p) | ||
502 | ViewPat e pp -> ViewPat (f e) (mapPP f pp) | 505 | ViewPat e pp -> ViewPat (f e) (mapPP f pp) |
503 | PatType pp e -> PatType (mapPP f pp) (f e) | 506 | PatType pp e -> PatType (mapPP f pp) (f e) |
504 | 507 | ||
@@ -517,6 +520,7 @@ getPPVars = reverse . getPPVars_ | |||
517 | getPVars_ = \case | 520 | getPVars_ = \case |
518 | PVar n -> [n] | 521 | PVar n -> [n] |
519 | PCon _ pp -> foldMap getPPVars_ pp | 522 | PCon _ pp -> foldMap getPPVars_ pp |
523 | PParens p -> getPVars_ p | ||
520 | ViewPat e pp -> getPPVars_ pp | 524 | ViewPat e pp -> getPPVars_ pp |
521 | PatType pp e -> getPPVars_ pp | 525 | PatType pp e -> getPPVars_ pp |
522 | 526 | ||
@@ -577,8 +581,11 @@ parsePat = \case | |||
577 | mkListPat _ [] = PCon (debugSI "mkListPat3", "Nil") [] | 581 | mkListPat _ [] = PCon (debugSI "mkListPat3", "Nil") [] |
578 | 582 | ||
579 | --mkTupPat :: [Pat] -> Pat | 583 | --mkTupPat :: [Pat] -> Pat |
580 | mkTupPat ns [x] = x | 584 | mkTupPat ns [PParens x] = ff [x] |
581 | mkTupPat ns ps = PCon (debugSI "", tick ns $ "Tuple" ++ show (length ps)) (ParPat . (:[]) <$> ps) | 585 | mkTupPat ns [x] = PParens x |
586 | mkTupPat ns ps = ff ps | ||
587 | |||
588 | ff ps = foldr (\a b -> PCon (mempty, "HCons") (ParPat . (:[]) <$> [a, b])) (PCon (mempty, "HNil") []) ps | ||
582 | 589 | ||
583 | patType p (Wildcard SType) = p | 590 | patType p (Wildcard SType) = p |
584 | patType p t = PatType (ParPat [p]) t | 591 | patType p t = PatType (ParPat [p]) t |
@@ -590,6 +597,7 @@ longPattern = parsePat PrecAnn <&> (getPVars &&& id) | |||
590 | 597 | ||
591 | telescopePat = fmap (getPPVars . ParPat . map snd &&& id) $ many $ uncurry f <$> hiddenTerm (parsePat PrecAtom) (parsePat PrecAtom) | 598 | telescopePat = fmap (getPPVars . ParPat . map snd &&& id) $ many $ uncurry f <$> hiddenTerm (parsePat PrecAtom) (parsePat PrecAtom) |
592 | where | 599 | where |
600 | f h (PParens p) = second PParens $ f h p | ||
593 | f h (PatType (ParPat [p]) t) = ((h, t), p) | 601 | f h (PatType (ParPat [p]) t) = ((h, t), p) |
594 | f h p = ((h, Wildcard SType), p) | 602 | f h p = ((h, Wildcard SType), p) |
595 | 603 | ||
@@ -636,8 +644,10 @@ compilePatts ps gu = cp [] ps | |||
636 | ] | 644 | ] |
637 | cp ps' ((p@PVar{}, i): xs) = cp (p: ps') xs | 645 | cp ps' ((p@PVar{}, i): xs) = cp (p: ps') xs |
638 | cp ps' ((p@(PCon (si, n) ps), i): xs) = GuardNode (SVar (si, n) $ i + sum (map (fromMaybe 0 . ff) ps')) n ps $ cp (p: ps') xs | 646 | cp ps' ((p@(PCon (si, n) ps), i): xs) = GuardNode (SVar (si, n) $ i + sum (map (fromMaybe 0 . ff) ps')) n ps $ cp (p: ps') xs |
647 | cp ps' ((PParens p, i): xs) = cp ps' ((p, i): xs) | ||
639 | cp ps' ((p@(ViewPat f (ParPat [PCon (si, n) ps])), i): xs) | 648 | cp ps' ((p@(ViewPat f (ParPat [PCon (si, n) ps])), i): xs) |
640 | = GuardNode (SAppV f $ SVar (si, n) $ i + sum (map (fromMaybe 0 . ff) ps')) n ps $ cp (p: ps') xs | 649 | = GuardNode (SAppV f $ SVar (si, n) $ i + sum (map (fromMaybe 0 . ff) ps')) n ps $ cp (p: ps') xs |
650 | cp _ p = error $ "cp: " ++ show p | ||
641 | 651 | ||
642 | m = length ps | 652 | m = length ps |
643 | 653 | ||
@@ -670,8 +680,8 @@ compileGuardTree ulend lend adts t = (\x -> traceD (" ! :" ++ ppShow x) x) $ g | |||
670 | GuardLeaf e: _ -> lend e | 680 | GuardLeaf e: _ -> lend e |
671 | ts@(GuardNode f s _ _: _) -> case Map.lookup s (snd adts) of | 681 | ts@(GuardNode f s _ _: _) -> case Map.lookup s (snd adts) of |
672 | Nothing -> error $ "Constructor is not defined: " ++ s | 682 | Nothing -> error $ "Constructor is not defined: " ++ s |
673 | Just (Left ((t, inum), cns)) -> | 683 | Just (Left ((casename, inum), cns)) -> |
674 | foldl SAppV (SGlobal (debugSI "compileGuardTree2", caseName t) `SAppV` iterateN (1 + inum) SLamV (Wildcard SType)) | 684 | foldl SAppV (SGlobal (debugSI "compileGuardTree2", casename) `SAppV` iterateN (1 + inum) SLamV (Wildcard SType)) |
675 | [ iterateN n SLamV $ guardTreeToCases $ Alts $ map (filterGuardTree (up n f) cn 0 n . upGT 0 n) ts | 685 | [ iterateN n SLamV $ guardTreeToCases $ Alts $ map (filterGuardTree (up n f) cn 0 n . upGT 0 n) ts |
676 | | (cn, n) <- cns | 686 | | (cn, n) <- cns |
677 | ] | 687 | ] |
@@ -713,6 +723,7 @@ compileGuardTree ulend lend adts t = (\x -> traceD (" ! :" ++ ppShow x) x) $ g | |||
713 | guardNode v [] e = e | 723 | guardNode v [] e = e |
714 | guardNode v [w] e = case w of | 724 | guardNode v [w] e = case w of |
715 | PVar _ -> {-todo guardNode v (subst x v ws) $ -} varGuardNode 0 v e | 725 | PVar _ -> {-todo guardNode v (subst x v ws) $ -} varGuardNode 0 v e |
726 | PParens p -> guardNode v [p] e | ||
716 | ViewPat f (ParPat p) -> guardNode (f `SAppV` v) p {- $ guardNode v ws -} e | 727 | ViewPat f (ParPat p) -> guardNode (f `SAppV` v) p {- $ guardNode v ws -} e |
717 | PCon (_, s) ps' -> GuardNode v s ps' {- $ guardNode v ws -} e | 728 | PCon (_, s) ps' -> GuardNode v s ps' {- $ guardNode v ws -} e |
718 | 729 | ||
@@ -725,7 +736,7 @@ compileCase ge x cs | |||
725 | -------------------------------------------------------------------------------- declaration representation | 736 | -------------------------------------------------------------------------------- declaration representation |
726 | 737 | ||
727 | data Stmt | 738 | data Stmt |
728 | = Let SIName MFixity (Maybe SExp) SExp | 739 | = Let SIName (Maybe SExp) SExp |
729 | | Data SIName [(Visibility, SExp)]{-parameters-} SExp{-type-} Bool{-True:add foralls-} [(SIName, SExp)]{-constructor names and types-} | 740 | | Data SIName [(Visibility, SExp)]{-parameters-} SExp{-type-} Bool{-True:add foralls-} [(SIName, SExp)]{-constructor names and types-} |
730 | | PrecDef SIName Fixity | 741 | | PrecDef SIName Fixity |
731 | 742 | ||
@@ -737,7 +748,7 @@ data Stmt | |||
737 | | FunAlt SIName [((Visibility, SExp), Pat)] (Either [(SExp, SExp)]{-guards-} SExp{-no guards-}) | 748 | | FunAlt SIName [((Visibility, SExp), Pat)] (Either [(SExp, SExp)]{-guards-} SExp{-no guards-}) |
738 | deriving (Show) | 749 | deriving (Show) |
739 | 750 | ||
740 | pattern Primitive n mf t <- Let n mf (Just t) (SBuiltin "undefined") where Primitive n mf t = Let n mf (Just t) $ SBuiltin "undefined" | 751 | pattern Primitive n t <- Let n (Just t) (SBuiltin "undefined") where Primitive n t = Let n (Just t) $ SBuiltin "undefined" |
741 | 752 | ||
742 | -------------------------------------------------------------------------------- declaration parsing | 753 | -------------------------------------------------------------------------------- declaration parsing |
743 | 754 | ||
@@ -864,7 +875,7 @@ parseSomeGuards f = do | |||
864 | mkLets :: DesugarInfo -> [Stmt]{-where block-} -> SExp{-main expression-} -> SExp{-big let with lambdas; replaces global names with de bruijn indices-} | 875 | mkLets :: DesugarInfo -> [Stmt]{-where block-} -> SExp{-main expression-} -> SExp{-big let with lambdas; replaces global names with de bruijn indices-} |
865 | mkLets ds = mkLets' . sortDefs ds where | 876 | mkLets ds = mkLets' . sortDefs ds where |
866 | mkLets' [] e = e | 877 | mkLets' [] e = e |
867 | mkLets' (Let n _ mt x: ds) e | 878 | mkLets' (Let n mt x: ds) e |
868 | = SLet n (maybe id (flip SAnn . addForalls {-todo-}[] []) mt x') (substSG0 n $ mkLets' ds e) | 879 | = SLet n (maybe id (flip SAnn . addForalls {-todo-}[] []) mt x') (substSG0 n $ mkLets' ds e) |
869 | where | 880 | where |
870 | x' = if usedS n x then SBuiltin "primFix" `SAppV` SLamV (substSG0 n x) else x | 881 | x' = if usedS n x then SBuiltin "primFix" `SAppV` SLamV (substSG0 n x) else x |
@@ -894,11 +905,11 @@ sortDefs ds xs = concatMap (desugarMutual ds) $ topSort mempty mempty mempty nod | |||
894 | nodes = zip (zip [0..] xs) $ map (def &&& need) xs | 905 | nodes = zip (zip [0..] xs) $ map (def &&& need) xs |
895 | need = \case | 906 | need = \case |
896 | PrecDef{} -> mempty | 907 | PrecDef{} -> mempty |
897 | Let _ _ mt e -> foldMap freeS' mt <> freeS' e | 908 | Let _ mt e -> foldMap freeS' mt <> freeS' e |
898 | Data _ ps t _ cs -> foldMap (freeS' . snd) ps <> freeS' t <> foldMap (freeS' . snd) cs | 909 | Data _ ps t _ cs -> foldMap (freeS' . snd) ps <> freeS' t <> foldMap (freeS' . snd) cs |
899 | def = \case | 910 | def = \case |
900 | PrecDef{} -> mempty | 911 | PrecDef{} -> mempty |
901 | Let n _ _ _ -> Set.singleton n | 912 | Let n _ _ -> Set.singleton n |
902 | Data n _ _ _ cs -> Set.singleton n <> Set.fromList (map fst cs) | 913 | Data n _ _ _ cs -> Set.singleton n <> Set.fromList (map fst cs) |
903 | freeS' = Set.fromList . freeS | 914 | freeS' = Set.fromList . freeS |
904 | topSort acc@(_:_) defs vs xs | Set.null vs = reverse acc: topSort mempty defs vs xs | 915 | topSort acc@(_:_) defs vs xs | Set.null vs = reverse acc: topSort mempty defs vs xs |
@@ -946,15 +957,15 @@ compileFunAlts compilegt ds xs = dsInfo >>= \ge -> case xs of | |||
946 | -- , let ts = fst $ getParamsS $ up1 t | 957 | -- , let ts = fst $ getParamsS $ up1 t |
947 | , let as = [ FunAlt m p $ Right {- $ SLam Hidden (Wildcard SType) $ up1 -} $ SLet m' e $ SVar mempty 0 | 958 | , let as = [ FunAlt m p $ Right {- $ SLam Hidden (Wildcard SType) $ up1 -} $ SLet m' e $ SVar mempty 0 |
948 | | Instance n' i cstrs alts <- ds, n' == n | 959 | | Instance n' i cstrs alts <- ds, n' == n |
949 | , Let m' ~Nothing ~Nothing e <- alts, m' == m | 960 | , Let m' ~Nothing e <- alts, m' == m |
950 | , let p = zip ((,) Hidden <$> ps) i ++ [((Hidden, Wildcard SType), PVar (mempty, ""))] | 961 | , let p = zip ((,) Hidden <$> ps) i ++ [((Hidden, Wildcard SType), PVar (mempty, ""))] |
951 | -- , let ic = sum $ map varP i | 962 | -- , let ic = sum $ map varP i |
952 | ] | 963 | ] |
953 | ] | 964 | ] |
954 | return $ cd ++ concat cds | 965 | return $ cd ++ concat cds |
955 | [TypeAnn n t] -> return [Primitive n Nothing t | snd n `notElem` [n' | FunAlt (_, n') _ _ <- ds]] | 966 | [TypeAnn n t] -> return [Primitive n t | snd n `notElem` [n' | FunAlt (_, n') _ _ <- ds]] |
956 | tf@[TypeFamily n ps t] -> case [d | d@(FunAlt n' _ _) <- ds, n' == n] of | 967 | tf@[TypeFamily n ps t] -> case [d | d@(FunAlt n' _ _) <- ds, n' == n] of |
957 | [] -> return [Primitive n Nothing $ addParamsS ps t] | 968 | [] -> return [Primitive n $ addParamsS ps t] |
958 | alts -> compileFunAlts compileGuardTrees' [TypeAnn n $ addParamsS ps t] alts | 969 | alts -> compileFunAlts compileGuardTrees' [TypeAnn n $ addParamsS ps t] alts |
959 | [p@PrecDef{}] -> return [p] | 970 | [p@PrecDef{}] -> return [p] |
960 | fs@(FunAlt n vs _: _) -> case map head $ group [length vs | FunAlt _ vs _ <- fs] of | 971 | fs@(FunAlt n vs _: _) -> case map head $ group [length vs | FunAlt _ vs _ <- fs] of |
@@ -963,7 +974,6 @@ compileFunAlts compilegt ds xs = dsInfo >>= \ge -> case xs of | |||
963 | | n `elem` [n' | TypeFamily n' _ _ <- ds] -> return [] | 974 | | n `elem` [n' | TypeFamily n' _ _ <- ds] -> return [] |
964 | | otherwise -> return | 975 | | otherwise -> return |
965 | [ Let n | 976 | [ Let n |
966 | (listToMaybe [t | PrecDef n' t <- ds, n' == n]) | ||
967 | (listToMaybe [t | TypeAnn n' t <- ds, n' == n]) | 977 | (listToMaybe [t | TypeAnn n' t <- ds, n' == n]) |
968 | $ foldr (uncurry SLam . fst) (compilegt ge | 978 | $ foldr (uncurry SLam . fst) (compilegt ge |
969 | [ compilePatts (zip (map snd vs) $ reverse [0.. num - 1]) gsx | 979 | [ compilePatts (zip (map snd vs) $ reverse [0.. num - 1]) gsx |
@@ -984,7 +994,7 @@ mkDesugarInfo :: [Stmt] -> DesugarInfo | |||
984 | mkDesugarInfo ss = | 994 | mkDesugarInfo ss = |
985 | ( Map.fromList $ ("'EqCTt", (Infix, -1)): [(s, f) | PrecDef (_, s) f <- ss] | 995 | ( Map.fromList $ ("'EqCTt", (Infix, -1)): [(s, f) | PrecDef (_, s) f <- ss] |
986 | , Map.fromList $ | 996 | , Map.fromList $ |
987 | [(cn, Left ((t, pars ty), (snd *** pars) <$> cs)) | Data (_, t) ps ty _ cs <- ss, ((_, cn), ct) <- cs] | 997 | [hackHList (cn, Left ((caseName t, pars ty), (snd *** pars) <$> cs)) | Data (_, t) ps ty _ cs <- ss, ((_, cn), ct) <- cs] |
988 | ++ [(t, Right $ pars $ addParamsS ps ty) | Data (_, t) ps ty _ _ <- ss] | 998 | ++ [(t, Right $ pars $ addParamsS ps ty) | Data (_, t) ps ty _ _ <- ss] |
989 | -- ++ [(t, Right $ length xs) | Let (_, t) _ (Just ty) xs _ <- ss] | 999 | -- ++ [(t, Right $ length xs) | Let (_, t) _ (Just ty) xs _ <- ss] |
990 | ++ [("'Type", Right 0)] | 1000 | ++ [("'Type", Right 0)] |
@@ -992,6 +1002,10 @@ mkDesugarInfo ss = | |||
992 | where | 1002 | where |
993 | pars ty = length $ filter ((== Visible) . fst) $ fst $ getParamsS ty -- todo | 1003 | pars ty = length $ filter ((== Visible) . fst) $ fst $ getParamsS ty -- todo |
994 | 1004 | ||
1005 | hackHList ("HCons", _) = ("HCons", Left (("hlistConsCase", 0), [("HCons", 2)])) | ||
1006 | hackHList ("HNil", _) = ("HNil", Left (("hlistNilCase", 0), [("HNil", 0)])) | ||
1007 | hackHList x = x | ||
1008 | |||
995 | joinDesugarInfo (fm, cm) (fm', cm') = (Map.union fm fm', Map.union cm cm') | 1009 | joinDesugarInfo (fm, cm) (fm', cm') = (Map.union fm fm', Map.union cm cm') |
996 | 1010 | ||
997 | 1011 | ||
@@ -1181,6 +1195,9 @@ isAtom' = (<=PrecAtom') . getPrec | |||
1181 | 1195 | ||
1182 | shAtom = PS PrecAtom | 1196 | shAtom = PS PrecAtom |
1183 | shAtom' = PS PrecAtom' | 1197 | shAtom' = PS PrecAtom' |
1198 | shTuple xs = prec PrecAtom $ \_ -> case xs of | ||
1199 | [x] -> "((" ++ str x ++ "))" | ||
1200 | xs -> "(" ++ intercalate ", " (map str xs) ++ ")" | ||
1184 | shAnn _ True x y | str y `elem` ["Type", inGreen "Type"] = x | 1201 | shAnn _ True x y | str y `elem` ["Type", inGreen "Type"] = x |
1185 | shAnn s simp x y | isAtom x && isAtom y = shAtom' $ str x <> s <> str y | 1202 | shAnn s simp x y | isAtom x && isAtom y = shAtom' $ str x <> s <> str y |
1186 | shAnn s simp x y = prec PrecAnn $ lpar x <> " " <> const s <> " " <> rpar y | 1203 | shAnn s simp x y = prec PrecAnn $ lpar x <> " " <> const s <> " " <> rpar y |