diff options
Diffstat (limited to 'src/LambdaCube/Compiler/CoreToIR.hs')
-rw-r--r-- | src/LambdaCube/Compiler/CoreToIR.hs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs index 29a2ab39..ac78a6d0 100644 --- a/src/LambdaCube/Compiler/CoreToIR.hs +++ b/src/LambdaCube/Compiler/CoreToIR.hs | |||
@@ -816,6 +816,8 @@ type Ty = ExpTV | |||
816 | tyOf :: ExpTV -> Ty | 816 | tyOf :: ExpTV -> Ty |
817 | tyOf (ExpTV _ t vs) = t .@ vs | 817 | tyOf (ExpTV _ t vs) = t .@ vs |
818 | 818 | ||
819 | expOf (ExpTV x _ _) = x | ||
820 | |||
819 | mapVal f (ExpTV a b c) = ExpTV (f a) b c | 821 | mapVal f (ExpTV a b c) = ExpTV (f a) b c |
820 | 822 | ||
821 | toExp :: ExpType -> ExpTV | 823 | toExp :: ExpType -> ExpTV |
@@ -858,17 +860,19 @@ mkApp (ExpTV (Neut (I.App_ a b)) et vs) = Just (ExpTV (Neut a) t vs, head $ chai | |||
858 | mkApp _ = Nothing | 860 | mkApp _ = Nothing |
859 | 861 | ||
860 | mkFunc r@(ExpTV (I.Func (show -> n) def nt xs) ty vs) | all (supType . tyOf) (r: xs') && n `notElem` ["typeAnn"] && all validChar n | 862 | mkFunc r@(ExpTV (I.Func (show -> n) def nt xs) ty vs) | all (supType . tyOf) (r: xs') && n `notElem` ["typeAnn"] && all validChar n |
861 | = Just (untick n, toExp (def, nt), tyOf r, xs') | 863 | = Just (untick n +++ intercalate "_" (map (filter isAlphaNum . removeEscs . ppShow) hs), toExp (foldl app_ def hs, foldl appTy nt hs), tyOf r, xs') |
862 | where | 864 | where |
863 | xs' = chain vs nt $ reverse xs | 865 | a +++ [] = a |
866 | a +++ b = a ++ "_" ++ b | ||
867 | (map (expOf . snd) -> hs, map snd -> xs') = span ((==Hidden) . fst) $ chain' vs nt $ reverse xs | ||
864 | validChar = isAlphaNum | 868 | validChar = isAlphaNum |
865 | mkFunc _ = Nothing | 869 | mkFunc _ = Nothing |
866 | 870 | ||
867 | chain vs t@(I.Pi Hidden at y) (a: as) = chain vs (appTy t a) as | 871 | chain vs t@(I.Pi Hidden at y) (a: as) = chain vs (appTy t a) as |
868 | chain vs t xs = chain' vs t xs | 872 | chain vs t xs = map snd $ chain' vs t xs |
869 | 873 | ||
870 | chain' vs t [] = [] | 874 | chain' vs t [] = [] |
871 | chain' vs t@(I.Pi b at y) (a: as) = ExpTV a at vs: chain' vs (appTy t a) as | 875 | chain' vs t@(I.Pi b at y) (a: as) = (b, ExpTV a at vs): chain' vs (appTy t a) as |
872 | chain' vs t _ = error $ "chain: " ++ show t | 876 | chain' vs t _ = error $ "chain: " ++ show t |
873 | 877 | ||
874 | mkTVar i (ExpTV t _ vs) = ExpTV (I.Var i) t vs | 878 | mkTVar i (ExpTV t _ vs) = ExpTV (I.Var i) t vs |