summaryrefslogtreecommitdiff
path: root/src/LambdaCube/Compiler/CoreToIR.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/LambdaCube/Compiler/CoreToIR.hs')
-rw-r--r--src/LambdaCube/Compiler/CoreToIR.hs12
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
816tyOf :: ExpTV -> Ty 816tyOf :: ExpTV -> Ty
817tyOf (ExpTV _ t vs) = t .@ vs 817tyOf (ExpTV _ t vs) = t .@ vs
818 818
819expOf (ExpTV x _ _) = x
820
819mapVal f (ExpTV a b c) = ExpTV (f a) b c 821mapVal f (ExpTV a b c) = ExpTV (f a) b c
820 822
821toExp :: ExpType -> ExpTV 823toExp :: ExpType -> ExpTV
@@ -858,17 +860,19 @@ mkApp (ExpTV (Neut (I.App_ a b)) et vs) = Just (ExpTV (Neut a) t vs, head $ chai
858mkApp _ = Nothing 860mkApp _ = Nothing
859 861
860mkFunc r@(ExpTV (I.Func (show -> n) def nt xs) ty vs) | all (supType . tyOf) (r: xs') && n `notElem` ["typeAnn"] && all validChar n 862mkFunc 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
865mkFunc _ = Nothing 869mkFunc _ = Nothing
866 870
867chain vs t@(I.Pi Hidden at y) (a: as) = chain vs (appTy t a) as 871chain vs t@(I.Pi Hidden at y) (a: as) = chain vs (appTy t a) as
868chain vs t xs = chain' vs t xs 872chain vs t xs = map snd $ chain' vs t xs
869 873
870chain' vs t [] = [] 874chain' vs t [] = []
871chain' vs t@(I.Pi b at y) (a: as) = ExpTV a at vs: chain' vs (appTy t a) as 875chain' vs t@(I.Pi b at y) (a: as) = (b, ExpTV a at vs): chain' vs (appTy t a) as
872chain' vs t _ = error $ "chain: " ++ show t 876chain' vs t _ = error $ "chain: " ++ show t
873 877
874mkTVar i (ExpTV t _ vs) = ExpTV (I.Var i) t vs 878mkTVar i (ExpTV t _ vs) = ExpTV (I.Var i) t vs