diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-14 01:26:04 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-14 01:26:04 +0200 |
commit | feeac006f966a7e2d621985d9c3eb2c45d2dbdb0 (patch) | |
tree | 2fc9bf313121983c1b6028f2cbab8419902363d4 /src | |
parent | 8d404ca664c695eae97cc9b088f2c98833999ea0 (diff) |
refactoring
Diffstat (limited to 'src')
-rw-r--r-- | src/LambdaCube/Compiler/Core.hs | 37 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Infer.hs | 3 |
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) | |||
148 | pattern TyCaseFun a b c = Neut (TyCaseFun_ a b c) | 148 | pattern TyCaseFun a b c = Neut (TyCaseFun_ a b c) |
149 | pattern Var a = Neut (Var_ a) | 149 | pattern Var a = Neut (Var_ a) |
150 | pattern App a b <- Neut (App_ (Neut -> a) b) | 150 | pattern App a b <- Neut (App_ (Neut -> a) b) |
151 | pattern DFun a t b = Neut (DFunN a t b) | 151 | pattern DFun a b = Neut (DFunN a b) |
152 | 152 | ||
153 | -- unreducable function application | 153 | -- unreducable function application |
154 | pattern UFun a b <- Neut (Fun (FunName (FTag a) _ _ t) b NoRHS) | 154 | pattern UFun a b <- Neut (Fun (FunName (FTag a) _ _ _) b NoRHS) |
155 | 155 | ||
156 | -- saturated delta function application | 156 | -- saturated function application |
157 | pattern DFunN a t xs = DFunN_ (FTag a) t xs | 157 | pattern DFunN a xs <- Fun (FunName (FTag a) _ _ _) xs _ |
158 | where DFunN a xs = Fun (mkFunDef' (FTag a)) xs delta | ||
158 | 159 | ||
159 | pattern DFunN_ a t xs <- Fun (FunName' a t) xs _ | 160 | mkFunDef' a@(FTag f) = mkFunDef a $ funTy f |
160 | where DFunN_ a t xs = Fun (FunName' a t) xs delta | 161 | |
162 | funTy = \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 | ||
162 | conParams (conTypeName -> TyConName _ _ _ _ (CaseFunName _ _ pars)) = pars | 170 | conParams (conTypeName -> TyConName _ _ _ _ (CaseFunName _ _ pars)) = pars |
163 | mkConPars n (snd . getParams . hnf -> TyCon (TyConName _ _ _ _ (CaseFunName _ _ pars)) xs) = take (min n pars) $ reverse xs | 171 | mkConPars 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 | ||
201 | pattern CstrT t a b = Neut (CstrT' t a b) | 209 | pattern CstrT t a b = Neut (CstrT' t a b) |
202 | pattern CstrT' t a b = DFunN F'EqCT (TType :~> Var 0 :~> Var 1 :~> TConstraint) [b, a, t] | 210 | pattern CstrT' t a b = DFunN F'EqCT [b, a, t] |
203 | pattern Coe a b w x = DFun Fcoe (TType :~> TType :~> CW (CstrT TType (Var 1) (Var 0)) :~> Var 2 :~> Var 2) [x,w,b,a] | 211 | pattern Coe a b w x = DFun Fcoe [x,w,b,a] |
204 | pattern ParEval t a b = DFun FparEval (TType :~> Var 0 :~> Var 1 :~> Var 2) [b, a, t] | 212 | pattern ParEval t a b = DFun FparEval [b, a, t] |
205 | pattern T2 a b = DFun F'T2 (TConstraint :~> TConstraint :~> TConstraint) [b, a] | 213 | pattern T2 a b = DFun F'T2 [b, a] |
206 | pattern CW a = DFun F'CW (TConstraint :~> TType) [a] | 214 | pattern CW a = DFun F'CW [a] |
207 | pattern CSplit a b c <- UFun F'Split [c, b, a] | 215 | pattern CSplit a b c <- UFun F'Split [c, b, a] |
208 | 216 | ||
209 | pattern HLit a <- (hnf -> ELit a) | 217 | pattern 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 | ||
457 | pattern FunName' a t <- FunName a _ _ t | ||
458 | where FunName' a t = mkFunDef a t | ||
459 | |||
460 | |||
461 | mkFunDef a@(show -> "primFix") t = fn | 465 | mkFunDef 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? | ||
472 | getFunDef t s f = case show s of | 477 | getFunDef 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 | |||
612 | nonNeut _ = True | 617 | nonNeut _ = True |
613 | 618 | ||
614 | t2C (hnf -> TT) (hnf -> TT) = TT | 619 | t2C (hnf -> TT) (hnf -> TT) = TT |
615 | t2C a b = DFun Ft2C (Unit :~> Unit :~> Unit) [b, a] | 620 | t2C a b = DFun Ft2C [b, a] |
616 | 621 | ||
617 | cw (hnf -> CUnit) = Unit | 622 | cw (hnf -> CUnit) = Unit |
618 | cw (hnf -> CEmpty a) = Empty a | 623 | cw (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__ |