diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-05-04 16:41:56 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-05-04 16:41:56 +0200 |
commit | d09859323b7213d6b3c3baf485d8389100faf469 (patch) | |
tree | eda20598a3729354cd702e847d648dadfa3acf44 /src/LambdaCube/Compiler/DesugaredSource.hs | |
parent | 6066e1154af07dd27733343199fd51758fed6c52 (diff) |
implement constraint kinds
Diffstat (limited to 'src/LambdaCube/Compiler/DesugaredSource.hs')
-rw-r--r-- | src/LambdaCube/Compiler/DesugaredSource.hs | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/LambdaCube/Compiler/DesugaredSource.hs b/src/LambdaCube/Compiler/DesugaredSource.hs index 8f192c3c..271c678e 100644 --- a/src/LambdaCube/Compiler/DesugaredSource.hs +++ b/src/LambdaCube/Compiler/DesugaredSource.hs | |||
@@ -173,12 +173,10 @@ instance SetSourceInfo SIName where | |||
173 | -- TODO: simplify this | 173 | -- TODO: simplify this |
174 | data FName | 174 | data FName |
175 | = CFName !Int (SData SIName) | 175 | = CFName !Int (SData SIName) |
176 | | FEqCT | FT2 | Fcoe | FparEval | Ft2C | FprimFix | 176 | | FEqCT | FT2 | Fcoe | FparEval | Ft2C | FprimFix | FCW |
177 | | FType | FUnit | FInt | FWord | FNat | FBool | FFloat | FString | FChar | FOrdering | FVecS | FEmpty | FHList | FOutput | 177 | | FType | FConstraint | FUnit | FInt | FWord | FNat | FBool | FFloat | FString | FChar | FOrdering | FVecS | FEmpty | FHList | FOutput |
178 | | FHCons | FHNil | FZero | FSucc | FFalse | FTrue | FLT | FGT | FEQ | FTT | FNil | FCons | 178 | | FHCons | FHNil | FZero | FSucc | FFalse | FTrue | FLT | FGT | FEQ | FTT | FNil | FCons | FCUnit | FCEmpty |
179 | | FSplit | FVecScalar | 179 | | FSplit | FVecScalar |
180 | -- todo: elim | ||
181 | | FEq | FOrd | FNum | FSigned | FComponent | FIntegral | FFloating | ||
182 | deriving (Eq, Ord) | 180 | deriving (Eq, Ord) |
183 | 181 | ||
184 | mkFName' (RangeSI (Range fn p _)) s = fromMaybe (hashPos fn p) $ lookup s $ zipWith (\i (s, _) -> (s, i)) [0..] fntable | 182 | mkFName' (RangeSI (Range fn p _)) s = fromMaybe (hashPos fn p) $ lookup s $ zipWith (\i (s, _) -> (s, i)) [0..] fntable |
@@ -196,6 +194,10 @@ fntable = | |||
196 | , (,) "coe" Fcoe | 194 | , (,) "coe" Fcoe |
197 | , (,) "parEval" FparEval | 195 | , (,) "parEval" FparEval |
198 | , (,) "t2C" Ft2C | 196 | , (,) "t2C" Ft2C |
197 | , (,) "'CW" FCW | ||
198 | , (,) "'Constraint" FConstraint | ||
199 | , (,) "CEmpty" FCEmpty | ||
200 | , (,) "CUnit" FCUnit | ||
199 | , (,) "primFix" FprimFix | 201 | , (,) "primFix" FprimFix |
200 | , (,) "'Unit" FUnit | 202 | , (,) "'Unit" FUnit |
201 | , (,) "'Int" FInt | 203 | , (,) "'Int" FInt |
@@ -209,13 +211,6 @@ fntable = | |||
209 | , (,) "'VecS" FVecS | 211 | , (,) "'VecS" FVecS |
210 | , (,) "'Empty" FEmpty | 212 | , (,) "'Empty" FEmpty |
211 | , (,) "'HList" FHList | 213 | , (,) "'HList" FHList |
212 | , (,) "'Eq" FEq | ||
213 | , (,) "'Ord" FOrd | ||
214 | , (,) "'Num" FNum | ||
215 | , (,) "'Signed" FSigned | ||
216 | , (,) "'Component" FComponent | ||
217 | , (,) "'Integral" FIntegral | ||
218 | , (,) "'Floating" FFloating | ||
219 | , (,) "'Output" FOutput | 214 | , (,) "'Output" FOutput |
220 | , (,) "'Type" FType | 215 | , (,) "'Type" FType |
221 | , (,) "HCons" FHCons | 216 | , (,) "HCons" FHCons |
@@ -317,9 +312,11 @@ pattern ConsName <- SIName _ ":" | |||
317 | pattern SRHS a = SBuiltin "_rhs" `SAppV` a | 312 | pattern SRHS a = SBuiltin "_rhs" `SAppV` a |
318 | pattern Section e = SBuiltin "^section" `SAppV` e | 313 | pattern Section e = SBuiltin "^section" `SAppV` e |
319 | pattern SType = SBuiltin "'Type" | 314 | pattern SType = SBuiltin "'Type" |
315 | pattern SConstraint = SBuiltin "'Constraint" | ||
320 | pattern Parens e = SBuiltin "parens" `SAppV` e | 316 | pattern Parens e = SBuiltin "parens" `SAppV` e |
321 | pattern SAnn a t = SBuiltin "typeAnn" `SAppH` t `SAppV` a | 317 | pattern SAnn a t = SBuiltin "typeAnn" `SAppH` t `SAppV` a |
322 | pattern TyType a = SAnn a SType | 318 | pattern TyType a = SAnn a SType |
319 | pattern SCW a = SBuiltin "'CW" `SAppV` a | ||
323 | 320 | ||
324 | -- builtin heterogenous list | 321 | -- builtin heterogenous list |
325 | pattern HList a = SBuiltin "'HList" `SAppV` a | 322 | pattern HList a = SBuiltin "'HList" `SAppV` a |
@@ -455,8 +452,7 @@ instance (Up a, PShow a) => PShow (SExp' a) where | |||
455 | SGlobal ns -> pShow ns | 452 | SGlobal ns -> pShow ns |
456 | Parens x -> pShow x -- TODO: remove | 453 | Parens x -> pShow x -- TODO: remove |
457 | SAnn a b -> shAnn (pShow a) (pShow b) | 454 | SAnn a b -> shAnn (pShow a) (pShow b) |
458 | TyType a -> text "tyType" `dApp` pShow a | 455 | TyType a -> text "tyType" `DApp` pShow a |
459 | SAppV a b -> pShow a `dApp` pShow b | ||
460 | SApp h a b -> shApp h (pShow a) (pShow b) | 456 | SApp h a b -> shApp h (pShow a) (pShow b) |
461 | Wildcard SType -> text "_" | 457 | Wildcard SType -> text "_" |
462 | Wildcard t -> shAnn (text "_") (pShow t) | 458 | Wildcard t -> shAnn (text "_") (pShow t) |
@@ -472,6 +468,13 @@ shApp Hidden a b = DApp a (DAt b) | |||
472 | 468 | ||
473 | shLam usedVar h a b = shLam_ usedVar h (Just a) b | 469 | shLam usedVar h a b = shLam_ usedVar h (Just a) b |
474 | 470 | ||
471 | shLam_ False (BPi Hidden) (Just (DText "'CW" `DApp` a)) b = DFreshName False $ showContext (DUp 0 a) b | ||
472 | where | ||
473 | showContext x (DFreshName u d) = DFreshName u $ showContext (DUp 0 x) d | ||
474 | showContext x (DParContext xs y) = DParContext (DComma x xs) y | ||
475 | showContext x (DContext xs y) = DParContext (DComma x xs) y | ||
476 | showContext x y = DContext x y | ||
477 | |||
475 | shLam_ usedVar h a b = DFreshName usedVar $ lam (p $ DUp 0 <$> a) b | 478 | shLam_ usedVar h a b = DFreshName usedVar $ lam (p $ DUp 0 <$> a) b |
476 | where | 479 | where |
477 | lam = case h of | 480 | lam = case h of |
@@ -497,6 +500,7 @@ shLam_ usedVar h a b = DFreshName usedVar $ lam (p $ DUp 0 <$> a) b | |||
497 | showForall s x (DForall s' xs y) | s == s' = DForall s (DSep (InfixR 11) x xs) y | 500 | showForall s x (DForall s' xs y) | s == s' = DForall s (DSep (InfixR 11) x xs) y |
498 | showForall s x y = DForall s x y | 501 | showForall s x y = DForall s x y |
499 | 502 | ||
503 | -- TODO: use other sign instead of (=>) | ||
500 | showContext x (DFreshName u d) = DFreshName u $ showContext (DUp 0 x) d | 504 | showContext x (DFreshName u d) = DFreshName u $ showContext (DUp 0 x) d |
501 | showContext x (DParContext xs y) = DParContext (DComma x xs) y | 505 | showContext x (DParContext xs y) = DParContext (DComma x xs) y |
502 | showContext x (DContext xs y) = DParContext (DComma x xs) y | 506 | showContext x (DContext xs y) = DParContext (DComma x xs) y |
@@ -522,7 +526,7 @@ instance PShow Stmt where | |||
522 | pShow stmt = vcat . map DResetFreshNames $ case stmt of | 526 | pShow stmt = vcat . map DResetFreshNames $ case stmt of |
523 | Primitive n t -> pure $ shAnn (pShow n) (pShow t) | 527 | Primitive n t -> pure $ shAnn (pShow n) (pShow t) |
524 | Let n ty e -> [shAnn (pShow n) (pShow t) | Just t <- [ty]] ++ [DLet "=" (pShow n) (pShow e)] | 528 | Let n ty e -> [shAnn (pShow n) (pShow t) | Just t <- [ty]] ++ [DLet "=" (pShow n) (pShow e)] |
525 | Data n ps ty cs -> pure $ nest 2 $ "data" <+> nest 2 (shAnn (foldl dApp (DTypeNamespace True $ pShow n) [shAnn (text "_") (pShow t) | (v, t) <- ps]) (pShow ty)) </> "where" <> nest 2 (hardline <> vcat [shAnn (pShow n) $ pShow $ UncurryS (first (const Hidden) <$> ps) t | (n, t) <- cs]) | 529 | Data n ps ty cs -> pure $ nest 2 $ "data" <+> nest 2 (shAnn (foldl DApp (DTypeNamespace True $ pShow n) [shAnn (text "_") (pShow t) | (v, t) <- ps]) (pShow ty)) </> "where" <> nest 2 (hardline <> vcat [shAnn (pShow n) $ pShow $ UncurryS (first (const Hidden) <$> ps) t | (n, t) <- cs]) |
526 | PrecDef n i -> pure $ pShow i <+> text (sName n) --DOp0 (sName n) i | 530 | PrecDef n i -> pure $ pShow i <+> text (sName n) --DOp0 (sName n) i |
527 | 531 | ||
528 | instance DeBruijnify SIName Stmt where | 532 | instance DeBruijnify SIName Stmt where |