summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-05-14 01:26:04 +0200
committerPéter Diviánszky <divipp@gmail.com>2016-05-14 01:26:04 +0200
commitfeeac006f966a7e2d621985d9c3eb2c45d2dbdb0 (patch)
tree2fc9bf313121983c1b6028f2cbab8419902363d4 /src
parent8d404ca664c695eae97cc9b088f2c98833999ea0 (diff)
refactoring
Diffstat (limited to 'src')
-rw-r--r--src/LambdaCube/Compiler/Core.hs37
-rw-r--r--src/LambdaCube/Compiler/Infer.hs3
2 files changed, 23 insertions, 17 deletions
diff --git a/src/LambdaCube/Compiler/Core.hs b/src/LambdaCube/Compiler/Core.hs
index 45ebda38..ecc8cf07 100644
--- a/src/LambdaCube/Compiler/Core.hs
+++ b/src/LambdaCube/Compiler/Core.hs
@@ -148,16 +148,24 @@ pattern CaseFun a b c = Neut (CaseFun_ a b c)
148pattern TyCaseFun a b c = Neut (TyCaseFun_ a b c) 148pattern TyCaseFun a b c = Neut (TyCaseFun_ a b c)
149pattern Var a = Neut (Var_ a) 149pattern Var a = Neut (Var_ a)
150pattern App a b <- Neut (App_ (Neut -> a) b) 150pattern App a b <- Neut (App_ (Neut -> a) b)
151pattern DFun a t b = Neut (DFunN a t b) 151pattern DFun a b = Neut (DFunN a b)
152 152
153-- unreducable function application 153-- unreducable function application
154pattern UFun a b <- Neut (Fun (FunName (FTag a) _ _ t) b NoRHS) 154pattern UFun a b <- Neut (Fun (FunName (FTag a) _ _ _) b NoRHS)
155 155
156-- saturated delta function application 156-- saturated function application
157pattern DFunN a t xs = DFunN_ (FTag a) t xs 157pattern DFunN a xs <- Fun (FunName (FTag a) _ _ _) xs _
158 where DFunN a xs = Fun (mkFunDef' (FTag a)) xs delta
158 159
159pattern DFunN_ a t xs <- Fun (FunName' a t) xs _ 160mkFunDef' a@(FTag f) = mkFunDef a $ funTy f
160 where DFunN_ a t xs = Fun (FunName' a t) xs delta 161
162funTy = \case
163 F'EqCT -> TType :~> Var 0 :~> Var 1 :~> TConstraint
164 Fcoe -> TType :~> TType :~> CW (CstrT TType (Var 1) (Var 0)) :~> Var 2 :~> Var 2
165 FparEval -> TType :~> Var 0 :~> Var 1 :~> Var 2
166 F'T2 -> TConstraint :~> TConstraint :~> TConstraint
167 F'CW -> TConstraint :~> TType
168 Ft2C -> Unit :~> Unit :~> Unit
161 169
162conParams (conTypeName -> TyConName _ _ _ _ (CaseFunName _ _ pars)) = pars 170conParams (conTypeName -> TyConName _ _ _ _ (CaseFunName _ _ pars)) = pars
163mkConPars n (snd . getParams . hnf -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) = take (min n pars) $ reverse xs 171mkConPars n (snd . getParams . hnf -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) = take (min n pars) $ reverse xs
@@ -199,11 +207,11 @@ pattern CEmpty s <- ConN FCEmpty (HString s: _)
199 where CEmpty s = tCon FCEmpty 1 (TString :~> TConstraint) [HString s] 207 where CEmpty s = tCon FCEmpty 1 (TString :~> TConstraint) [HString s]
200 208
201pattern CstrT t a b = Neut (CstrT' t a b) 209pattern CstrT t a b = Neut (CstrT' t a b)
202pattern CstrT' t a b = DFunN F'EqCT (TType :~> Var 0 :~> Var 1 :~> TConstraint) [b, a, t] 210pattern CstrT' t a b = DFunN F'EqCT [b, a, t]
203pattern Coe a b w x = DFun Fcoe (TType :~> TType :~> CW (CstrT TType (Var 1) (Var 0)) :~> Var 2 :~> Var 2) [x,w,b,a] 211pattern Coe a b w x = DFun Fcoe [x,w,b,a]
204pattern ParEval t a b = DFun FparEval (TType :~> Var 0 :~> Var 1 :~> Var 2) [b, a, t] 212pattern ParEval t a b = DFun FparEval [b, a, t]
205pattern T2 a b = DFun F'T2 (TConstraint :~> TConstraint :~> TConstraint) [b, a] 213pattern T2 a b = DFun F'T2 [b, a]
206pattern CW a = DFun F'CW (TConstraint :~> TType) [a] 214pattern CW a = DFun F'CW [a]
207pattern CSplit a b c <- UFun F'Split [c, b, a] 215pattern CSplit a b c <- UFun F'Split [c, b, a]
208 216
209pattern HLit a <- (hnf -> ELit a) 217pattern HLit a <- (hnf -> ELit a)
@@ -454,10 +462,6 @@ instance MkDoc Neutral where
454 MT "finElim" [m, z, s, n, ConN "FZero" [i]] -> z `app_` i 462 MT "finElim" [m, z, s, n, ConN "FZero" [i]] -> z `app_` i
455-} 463-}
456 464
457pattern FunName' a t <- FunName a _ _ t
458 where FunName' a t = mkFunDef a t
459
460
461mkFunDef a@(show -> "primFix") t = fn 465mkFunDef a@(show -> "primFix") t = fn
462 where 466 where
463 fn = FunName a 0 (DeltaDef (length $ fst $ getParams t) fx) t 467 fn = FunName a 0 (DeltaDef (length $ fst $ getParams t) fx) t
@@ -469,6 +473,7 @@ mkFunDef a t = fn
469 where 473 where
470 fn = FunName a 0 (maybe NoDef (DeltaDef (length $ fst $ getParams t) . const) $ getFunDef t a $ \xs -> Neut $ Fun fn xs delta) t 474 fn = FunName a 0 (maybe NoDef (DeltaDef (length $ fst $ getParams t) . const) $ getFunDef t a $ \xs -> Neut $ Fun fn xs delta) t
471 475
476-- TODO: don't use show?
472getFunDef t s f = case show s of 477getFunDef t s f = case show s of
473 "'EqCT" -> Just $ \case (b: a: t: _) -> cstr t a b 478 "'EqCT" -> Just $ \case (b: a: t: _) -> cstr t a b
474 "'T2" -> Just $ \case (b: a: _) -> t2 a b 479 "'T2" -> Just $ \case (b: a: _) -> t2 a b
@@ -612,7 +617,7 @@ nonNeut Neut{} = False
612nonNeut _ = True 617nonNeut _ = True
613 618
614t2C (hnf -> TT) (hnf -> TT) = TT 619t2C (hnf -> TT) (hnf -> TT) = TT
615t2C a b = DFun Ft2C (Unit :~> Unit :~> Unit) [b, a] 620t2C a b = DFun Ft2C [b, a]
616 621
617cw (hnf -> CUnit) = Unit 622cw (hnf -> CUnit) = Unit
618cw (hnf -> CEmpty a) = Empty a 623cw (hnf -> CEmpty a) = Empty a
diff --git a/src/LambdaCube/Compiler/Infer.hs b/src/LambdaCube/Compiler/Infer.hs
index 6d26cedd..a03ac8f9 100644
--- a/src/LambdaCube/Compiler/Infer.hs
+++ b/src/LambdaCube/Compiler/Infer.hs
@@ -500,7 +500,8 @@ handleStmt = \case
500 Primitive n t_ -> do 500 Primitive n t_ -> do
501 t <- inferType n $ trSExp' t_ 501 t <- inferType n $ trSExp' t_
502 tellType (sourceInfo n) t 502 tellType (sourceInfo n) t
503 addToEnv n $ flip ET t $ lamify' t $ Neut . DFunN_ (FName n) t 503 let fn = mkFunDef (FName n) t
504 addToEnv n $ flip ET t $ lamify' t $ \xs -> Neut $ Fun fn xs delta
504 StLet n mt t_ -> do 505 StLet n mt t_ -> do
505 let t__ = maybe id (flip SAnn) mt t_ 506 let t__ = maybe id (flip SAnn) mt t_
506 ET x t <- inferTerm n $ trSExp' t__ 507 ET x t <- inferTerm n $ trSExp' t__