diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2017-09-22 20:43:20 +0100 |
---|---|---|
committer | Csaba Hruska <csaba.hruska@gmail.com> | 2017-09-22 20:43:20 +0100 |
commit | e205a839ce8cf1e0f71b88a7a9c7a793848b8f8e (patch) | |
tree | fe7bb921684f8804e93c3b9ff0de9085f3048ecf /src | |
parent | e8bf0b7bcfb28bddfef1b8110cec848a8c4a4ff4 (diff) |
Exp binary instance
Diffstat (limited to 'src')
-rw-r--r-- | src/LambdaCube/Compiler.hs | 6 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Core.hs | 83 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/DeBruijn.hs | 8 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/DesugaredSource.hs | 58 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/InferMonad.hs | 2 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Pretty.hs | 8 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Utils.hs | 11 |
7 files changed, 161 insertions, 15 deletions
diff --git a/src/LambdaCube/Compiler.hs b/src/LambdaCube/Compiler.hs index a61686ff..4d5213c3 100644 --- a/src/LambdaCube/Compiler.hs +++ b/src/LambdaCube/Compiler.hs | |||
@@ -89,7 +89,7 @@ type ModuleFetcher m = Maybe FilePath -> Either FilePath MName -> m (Either Doc | |||
89 | ioFetch :: MonadIO m => [FilePath] -> ModuleFetcher (MMT m x) | 89 | ioFetch :: MonadIO m => [FilePath] -> ModuleFetcher (MMT m x) |
90 | ioFetch paths' imp n = do | 90 | ioFetch paths' imp n = do |
91 | preludePath <- (</> "lc") <$> liftIO getDataDir | 91 | preludePath <- (</> "lc") <$> liftIO getDataDir |
92 | let paths = map (id &&& id) paths' ++ [(preludePath, "<<installed-prelude-path>>")] | 92 | let paths = map (id &&& id) paths' ++ [(preludePath, preludePath)] |
93 | find ((x, (x', mn)): xs) = liftIO (readFileIfExists x) >>= maybe (find xs) (\src -> return $ Right (x', mn, liftIO src)) | 93 | find ((x, (x', mn)): xs) = liftIO (readFileIfExists x) >>= maybe (find xs) (\src -> return $ Right (x', mn, liftIO src)) |
94 | find [] = return $ Left $ "can't find" <+> either (("lc file" <+>) . text) (("module" <+>) . text) n | 94 | find [] = return $ Left $ "can't find" <+> either (("lc file" <+>) . text) (("module" <+>) . text) n |
95 | <+> "in path" <+> hsep (text . snd <$> paths) | 95 | <+> "in path" <+> hsep (text . snd <$> paths) |
@@ -141,7 +141,7 @@ loadModule ex imp mname_ = do | |||
141 | src <- srcm | 141 | src <- srcm |
142 | fid <- gets nextMId | 142 | fid <- gets nextMId |
143 | modify $ \(Modules nm im ni) -> Modules (Map.insert fname fid nm) im $ ni+1 | 143 | modify $ \(Modules nm im ni) -> Modules (Map.insert fname fid nm) im $ ni+1 |
144 | let fi = FileInfo fid fname mname src | 144 | let fi = FileInfo fid fname mname |
145 | res <- case parseLC fi of | 145 | res <- case parseLC fi of |
146 | Left e -> return $ Left $ text $ show e | 146 | Left e -> return $ Left $ text $ show e |
147 | Right e -> do | 147 | Right e -> do |
@@ -224,7 +224,7 @@ preCompile paths paths' backend mod = do | |||
224 | where | 224 | where |
225 | compile src = runMM fetch $ do | 225 | compile src = runMM fetch $ do |
226 | let pname = "." </> "Prelude.lc" | 226 | let pname = "." </> "Prelude.lc" |
227 | modify $ \(Modules nm im ni) -> Modules (Map.insert pname ni nm) (IM.insert ni (FileInfo ni pname "Prelude" $ fileContent fi, prelude) im) (ni+1) | 227 | modify $ \(Modules nm im ni) -> Modules (Map.insert pname ni nm) (IM.insert ni (FileInfo ni pname "Prelude", prelude) im) (ni+1) |
228 | (snd &&& fst) <$> compilePipeline' ex backend "Main" | 228 | (snd &&& fst) <$> compilePipeline' ex backend "Main" |
229 | where | 229 | where |
230 | fetch imp = \case | 230 | fetch imp = \case |
diff --git a/src/LambdaCube/Compiler/Core.hs b/src/LambdaCube/Compiler/Core.hs index 91056dd9..8e97c6b2 100644 --- a/src/LambdaCube/Compiler/Core.hs +++ b/src/LambdaCube/Compiler/Core.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE DeriveGeneric #-} | ||
1 | {-# LANGUAGE OverloadedStrings #-} | 2 | {-# LANGUAGE OverloadedStrings #-} |
2 | {-# LANGUAGE LambdaCase #-} | 3 | {-# LANGUAGE LambdaCase #-} |
3 | {-# LANGUAGE ViewPatterns #-} | 4 | {-# LANGUAGE ViewPatterns #-} |
@@ -12,6 +13,9 @@ | |||
12 | --{-# OPTIONS_GHC -fno-warn-unused-binds #-} -- TODO: remove | 13 | --{-# OPTIONS_GHC -fno-warn-unused-binds #-} -- TODO: remove |
13 | module LambdaCube.Compiler.Core where | 14 | module LambdaCube.Compiler.Core where |
14 | 15 | ||
16 | import Data.Binary | ||
17 | import GHC.Generics (Generic) | ||
18 | |||
15 | import Data.Monoid | 19 | import Data.Monoid |
16 | import Data.Function | 20 | import Data.Function |
17 | import Data.List | 21 | import Data.List |
@@ -25,14 +29,18 @@ import LambdaCube.Compiler.DesugaredSource | |||
25 | -------------------------------------------------------------------------------- names with infos | 29 | -------------------------------------------------------------------------------- names with infos |
26 | 30 | ||
27 | data ConName = ConName FName Int{-ordinal number, e.g. Zero:0, Succ:1-} Type | 31 | data ConName = ConName FName Int{-ordinal number, e.g. Zero:0, Succ:1-} Type |
32 | deriving Generic | ||
28 | 33 | ||
29 | data TyConName = TyConName FName Int{-num of indices-} Type [(ConName, Type)]{-constructors-} CaseFunName | 34 | data TyConName = TyConName FName Int{-num of indices-} Type [(ConName, Type)]{-constructors-} CaseFunName |
35 | deriving Generic | ||
30 | 36 | ||
31 | data FunName = FunName FName Int{-num of global vars-} FunDef Type | 37 | data FunName = FunName FName Int{-num of global vars-} FunDef Type |
32 | 38 | ||
33 | data CaseFunName = CaseFunName FName Type Int{-num of parameters-} | 39 | data CaseFunName = CaseFunName FName Type Int{-num of parameters-} |
40 | deriving Generic | ||
34 | 41 | ||
35 | data TyCaseFunName = TyCaseFunName FName Type | 42 | data TyCaseFunName = TyCaseFunName FName Type |
43 | deriving Generic | ||
36 | 44 | ||
37 | data FunDef | 45 | data FunDef |
38 | = DeltaDef !Int{-arity-} (FreeVars -> [Exp]{-args in reversed order-} -> Exp) | 46 | = DeltaDef !Int{-arity-} (FreeVars -> [Exp]{-args in reversed order-} -> Exp) |
@@ -67,7 +75,7 @@ instance PShow TyCaseFunName where pShow (TyCaseFunName n _) = text $ MatchName | |||
67 | -------------------------------------------------------------------------------- core expression representation | 75 | -------------------------------------------------------------------------------- core expression representation |
68 | 76 | ||
69 | data Freq = CompileTime | RunTime -- TODO | 77 | data Freq = CompileTime | RunTime -- TODO |
70 | deriving (Eq) | 78 | deriving (Eq, Generic) |
71 | 79 | ||
72 | data Exp | 80 | data Exp |
73 | = ELit Lit | 81 | = ELit Lit |
@@ -80,6 +88,8 @@ data Exp | |||
80 | | RHS Exp{-always in hnf-} | 88 | | RHS Exp{-always in hnf-} |
81 | | Let_ FreeVars ExpType Exp | 89 | | Let_ FreeVars ExpType Exp |
82 | | Up_ FreeVars [Int] Exp | 90 | | Up_ FreeVars [Int] Exp |
91 | | STOP | ||
92 | deriving Generic | ||
83 | 93 | ||
84 | data Neutral | 94 | data Neutral |
85 | = Var_ !Int{-De Bruijn index-} | 95 | = Var_ !Int{-De Bruijn index-} |
@@ -88,13 +98,14 @@ data Neutral | |||
88 | | TyCaseFun__ FreeVars TyCaseFunName [Exp] Neutral | 98 | | TyCaseFun__ FreeVars TyCaseFunName [Exp] Neutral |
89 | | Fun_ FreeVars FunName [Exp]{-given parameters, reversed-} Exp{-unfolded expression, in hnf-} | 99 | | Fun_ FreeVars FunName [Exp]{-given parameters, reversed-} Exp{-unfolded expression, in hnf-} |
90 | | UpN_ FreeVars [Int] Neutral | 100 | | UpN_ FreeVars [Int] Neutral |
101 | deriving Generic | ||
91 | 102 | ||
92 | -------------------------------------------------------------------------------- auxiliary functions and patterns | 103 | -------------------------------------------------------------------------------- auxiliary functions and patterns |
93 | 104 | ||
94 | type Type = Exp | 105 | type Type = Exp |
95 | 106 | ||
96 | data ExpType = ET {expr :: Exp, ty :: Type} | 107 | data ExpType = ET {expr :: Exp, ty :: Type} |
97 | deriving (Eq) | 108 | deriving (Eq, Generic) |
98 | {- | 109 | {- |
99 | pattern ET a b <- ET_ a b | 110 | pattern ET a b <- ET_ a b |
100 | where ET a b = ET_ a (hnf b) | 111 | where ET a b = ET_ a (hnf b) |
@@ -469,6 +480,7 @@ instance MkDoc Neutral where | |||
469 | MT "finElim" [m, z, s, n, ConN "FZero" [i]] -> z `app_` i | 480 | MT "finElim" [m, z, s, n, ConN "FZero" [i]] -> z `app_` i |
470 | -} | 481 | -} |
471 | 482 | ||
483 | mkFunDef :: FName -> Type -> FunName | ||
472 | mkFunDef a@(FTag FprimFix) t = fn | 484 | mkFunDef a@(FTag FprimFix) t = fn |
473 | where | 485 | where |
474 | fn = FunName a 0 (DeltaDef 2 fx) t | 486 | fn = FunName a 0 (DeltaDef 2 fx) t |
@@ -681,3 +693,70 @@ instance NType Lit where | |||
681 | LChar _ -> TChar | 693 | LChar _ -> TChar |
682 | 694 | ||
683 | 695 | ||
696 | closeTyConName (TyConName fname ints type_ cons caseFunName) | ||
697 | -- = TyConName fname ints (closeExp type_) [(closeConName n, closeExp t) | (n,t) <- cons] (closeCaseFunName caseFunName) | ||
698 | = TyConName fname ints STOP [(closeConName n, STOP) | (n,t) <- cons] (closeCaseFunName caseFunName) | ||
699 | |||
700 | closeTyCaseFunName (TyCaseFunName fname type_) | ||
701 | -- = TyCaseFunName fname (closeExp type_) | ||
702 | = TyCaseFunName fname STOP | ||
703 | |||
704 | closeConName (ConName fname ordinal type_) | ||
705 | -- = ConName fname ordinal (closeExp type_) | ||
706 | = ConName fname ordinal STOP | ||
707 | |||
708 | closeCaseFunName (CaseFunName fname type_ int) | ||
709 | -- = CaseFunName fname (closeExp type_) int | ||
710 | = CaseFunName fname STOP int | ||
711 | |||
712 | closeFunName (FunName fname int funDef type_) | ||
713 | -- = FunName fname int (closeFunDef funDef) (closeExp type_) | ||
714 | = FunName fname int (closeFunDef funDef) STOP | ||
715 | |||
716 | closeFunDef = \case | ||
717 | ExpDef exp -> ExpDef STOP | ||
718 | --ExpDef exp -> ExpDef (closeExp exp) | ||
719 | x -> x | ||
720 | |||
721 | closeExp :: Exp -> Exp | ||
722 | closeExp = \case | ||
723 | Lam_ freeVars exp -> Lam_ freeVars $ closeExp exp | ||
724 | Con_ freeVars conName noErasedApplied argsReversed -> Con_ freeVars (closeConName conName) noErasedApplied (map closeExp argsReversed) | ||
725 | TyCon_ freeVars tyConName argsReversed -> TyCon_ freeVars (closeTyConName tyConName) (map closeExp argsReversed) | ||
726 | Pi_ freeVars visibility exp1 exp2 -> Pi_ freeVars visibility (closeExp exp1) (closeExp exp2) | ||
727 | Neut neutral -> Neut $ closeNeutral neutral | ||
728 | RHS whnf -> STOP | ||
729 | Let_ freeVars expType exp -> Let_ freeVars (closeExpType expType) (closeExp exp) | ||
730 | Up_ freeVars ints exp -> Up_ freeVars ints (closeExp exp) | ||
731 | e -> e | ||
732 | |||
733 | closeNeutral :: Neutral -> Neutral | ||
734 | closeNeutral = \case | ||
735 | App__ freeVars neutral exp -> App__ freeVars (closeNeutral neutral) (closeExp exp) | ||
736 | CaseFun__ freeVars caseFunName exps neutral -> CaseFun__ freeVars (closeCaseFunName caseFunName) (map closeExp exps) (closeNeutral neutral) | ||
737 | TyCaseFun__ freeVars tyCaseFunName exps neutral -> TyCaseFun__ freeVars (closeTyCaseFunName tyCaseFunName) (map closeExp exps) (closeNeutral neutral) | ||
738 | Fun_ freeVars funName exps exp -> Fun_ freeVars (closeFunName funName) (map closeExp exps) (closeExp exp) | ||
739 | UpN_ freeVars ints neutral -> UpN_ freeVars ints (closeNeutral neutral) | ||
740 | n -> n | ||
741 | |||
742 | closeExpType :: ExpType -> ExpType | ||
743 | closeExpType (ET e t) = ET (closeExp e) (closeExp t) | ||
744 | |||
745 | instance Binary ExpType | ||
746 | instance Binary Exp | ||
747 | instance Binary Neutral | ||
748 | instance Binary Freq | ||
749 | instance Binary ConName | ||
750 | instance Binary CaseFunName | ||
751 | instance Binary TyConName | ||
752 | instance Binary TyCaseFunName | ||
753 | |||
754 | instance Binary FunName where -- do FunName/FunDef instance together | ||
755 | put (FunName fName int funDef type_) = do | ||
756 | put fName | ||
757 | put type_ | ||
758 | |||
759 | get = do | ||
760 | fName <- get | ||
761 | type_ <- get | ||
762 | pure $ mkFunDef fName type_ | ||
diff --git a/src/LambdaCube/Compiler/DeBruijn.hs b/src/LambdaCube/Compiler/DeBruijn.hs index a1af40db..a0fd8326 100644 --- a/src/LambdaCube/Compiler/DeBruijn.hs +++ b/src/LambdaCube/Compiler/DeBruijn.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE DeriveGeneric #-} | ||
1 | {-# LANGUAGE LambdaCase #-} | 2 | {-# LANGUAGE LambdaCase #-} |
2 | {-# LANGUAGE ViewPatterns #-} | 3 | {-# LANGUAGE ViewPatterns #-} |
3 | {-# LANGUAGE PatternSynonyms #-} | 4 | {-# LANGUAGE PatternSynonyms #-} |
@@ -10,6 +11,9 @@ | |||
10 | {-# LANGUAGE MultiParamTypeClasses #-} | 11 | {-# LANGUAGE MultiParamTypeClasses #-} |
11 | module LambdaCube.Compiler.DeBruijn where | 12 | module LambdaCube.Compiler.DeBruijn where |
12 | 13 | ||
14 | import Data.Binary | ||
15 | import GHC.Generics (Generic) | ||
16 | |||
13 | import Data.Bits | 17 | import Data.Bits |
14 | import Control.Arrow hiding ((<+>)) | 18 | import Control.Arrow hiding ((<+>)) |
15 | 19 | ||
@@ -63,7 +67,9 @@ instance Rearrange Void where | |||
63 | ------------------------------------------------------- set of free variables (implemented with bit vectors) | 67 | ------------------------------------------------------- set of free variables (implemented with bit vectors) |
64 | 68 | ||
65 | newtype FreeVars = FreeVars Integer | 69 | newtype FreeVars = FreeVars Integer |
66 | deriving Eq | 70 | deriving (Eq, Generic) |
71 | |||
72 | instance Binary FreeVars | ||
67 | 73 | ||
68 | instance PShow FreeVars where | 74 | instance PShow FreeVars where |
69 | pShow (FreeVars s) = "FreeVars" `DApp` pShow s | 75 | pShow (FreeVars s) = "FreeVars" `DApp` pShow s |
diff --git a/src/LambdaCube/Compiler/DesugaredSource.hs b/src/LambdaCube/Compiler/DesugaredSource.hs index d355b4b9..8d9a38be 100644 --- a/src/LambdaCube/Compiler/DesugaredSource.hs +++ b/src/LambdaCube/Compiler/DesugaredSource.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE DeriveGeneric #-} | ||
1 | {-# LANGUAGE LambdaCase #-} | 2 | {-# LANGUAGE LambdaCase #-} |
2 | {-# LANGUAGE ViewPatterns #-} | 3 | {-# LANGUAGE ViewPatterns #-} |
3 | {-# LANGUAGE PatternSynonyms #-} | 4 | {-# LANGUAGE PatternSynonyms #-} |
@@ -13,6 +14,13 @@ module LambdaCube.Compiler.DesugaredSource | |||
13 | , Fixity(..) | 14 | , Fixity(..) |
14 | )where | 15 | )where |
15 | 16 | ||
17 | import System.IO.Unsafe | ||
18 | import Text.Printf | ||
19 | import qualified Data.ByteString.Char8 as BS | ||
20 | |||
21 | import Data.Binary | ||
22 | import GHC.Generics (Generic) | ||
23 | |||
16 | import Data.Monoid | 24 | import Data.Monoid |
17 | import Data.Maybe | 25 | import Data.Maybe |
18 | import Data.List | 26 | import Data.List |
@@ -51,7 +59,9 @@ pattern MatchName cs <- 'm':'a':'t':'c':'h':cs where MatchName cs = "match" ++ c | |||
51 | 59 | ||
52 | -- source position without file name | 60 | -- source position without file name |
53 | newtype SPos = SPos_ Int | 61 | newtype SPos = SPos_ Int |
54 | deriving (Eq, Ord) | 62 | deriving (Eq, Ord, Generic) |
63 | |||
64 | instance Binary SPos | ||
55 | 65 | ||
56 | row :: SPos -> Int | 66 | row :: SPos -> Int |
57 | row (SPos_ i) = i `shiftR` 16 | 67 | row (SPos_ i) = i `shiftR` 16 |
@@ -72,8 +82,16 @@ data FileInfo = FileInfo | |||
72 | { fileId :: !Int | 82 | { fileId :: !Int |
73 | , filePath :: FilePath | 83 | , filePath :: FilePath |
74 | , fileModule :: String -- module name | 84 | , fileModule :: String -- module name |
75 | , fileContent :: String | ||
76 | } | 85 | } |
86 | deriving Generic | ||
87 | |||
88 | instance Binary FileInfo | ||
89 | |||
90 | fileContent :: FileInfo -> String | ||
91 | fileContent fi = unsafePerformIO $ do | ||
92 | let fname = filePath fi | ||
93 | BS.putStrLn $ BS.pack $ printf "load source %s" fname | ||
94 | readFile fname | ||
77 | 95 | ||
78 | instance Eq FileInfo where (==) = (==) `on` fileId | 96 | instance Eq FileInfo where (==) = (==) `on` fileId |
79 | instance Ord FileInfo where compare = compare `on` fileId | 97 | instance Ord FileInfo where compare = compare `on` fileId |
@@ -90,7 +108,9 @@ data Range = Range | |||
90 | , rangeStart :: !SPos | 108 | , rangeStart :: !SPos |
91 | , rangeStop :: !SPos | 109 | , rangeStop :: !SPos |
92 | } | 110 | } |
93 | deriving (Eq, Ord) | 111 | deriving (Eq, Ord, Generic) |
112 | |||
113 | instance Binary Range | ||
94 | 114 | ||
95 | instance Show Range where show = ppShow | 115 | instance Show Range where show = ppShow |
96 | instance PShow Range | 116 | instance PShow Range |
@@ -112,6 +132,9 @@ joinRange (Range n b e) (Range n' b' e') = Range n (min b b') (max e e') | |||
112 | data SI | 132 | data SI |
113 | = NoSI (Set.Set String) -- no source info, attached debug info | 133 | = NoSI (Set.Set String) -- no source info, attached debug info |
114 | | RangeSI Range | 134 | | RangeSI Range |
135 | deriving Generic | ||
136 | |||
137 | instance Binary SI | ||
115 | 138 | ||
116 | getRange :: SI -> Maybe Range | 139 | getRange :: SI -> Maybe Range |
117 | getRange (RangeSI r) = Just r | 140 | getRange (RangeSI r) = Just r |
@@ -159,6 +182,9 @@ class SetSourceInfo a where | |||
159 | -------------------------------------------------------------------------------- name with source info | 182 | -------------------------------------------------------------------------------- name with source info |
160 | 183 | ||
161 | data SIName = SIName__ { nameHash :: Int, nameSI :: SI, nameFixity :: Maybe Fixity, sName :: SName } | 184 | data SIName = SIName__ { nameHash :: Int, nameSI :: SI, nameFixity :: Maybe Fixity, sName :: SName } |
185 | deriving Generic | ||
186 | |||
187 | instance Binary SIName | ||
162 | 188 | ||
163 | pattern SIName_ :: SI -> Maybe Fixity -> SName -> SIName | 189 | pattern SIName_ :: SI -> Maybe Fixity -> SName -> SIName |
164 | pattern SIName_ si f n <- SIName__ _ si f n | 190 | pattern SIName_ si f n <- SIName__ _ si f n |
@@ -186,6 +212,9 @@ instance SetSourceInfo SIName where | |||
186 | -------------------------------------------------------------------------------- hashed names | 212 | -------------------------------------------------------------------------------- hashed names |
187 | 213 | ||
188 | newtype FName = FName { fName :: SIName } | 214 | newtype FName = FName { fName :: SIName } |
215 | deriving Generic | ||
216 | |||
217 | instance Binary FName | ||
189 | 218 | ||
190 | instance Eq FName where (==) = (==) `on` nameHash . fName | 219 | instance Eq FName where (==) = (==) `on` nameHash . fName |
191 | instance Ord FName where compare = compare `on` nameHash . fName | 220 | instance Ord FName where compare = compare `on` nameHash . fName |
@@ -228,7 +257,9 @@ data FNameTag | |||
228 | 257 | ||
229 | -- other | 258 | -- other |
230 | | F_rhs | F_section | 259 | | F_rhs | F_section |
231 | deriving (Eq, Ord, Show, Enum, Bounded) | 260 | deriving (Eq, Ord, Show, Enum, Bounded, Generic) |
261 | |||
262 | instance Binary FNameTag | ||
232 | 263 | ||
233 | tagName :: FNameTag -> String | 264 | tagName :: FNameTag -> String |
234 | tagName FCons = ":" | 265 | tagName FCons = ":" |
@@ -267,7 +298,9 @@ data Lit | |||
267 | | LChar Char | 298 | | LChar Char |
268 | | LFloat Double | 299 | | LFloat Double |
269 | | LString String | 300 | | LString String |
270 | deriving (Eq) | 301 | deriving (Eq, Generic) |
302 | |||
303 | instance Binary Lit | ||
271 | 304 | ||
272 | instance PShow Lit where | 305 | instance PShow Lit where |
273 | pShow = \case | 306 | pShow = \case |
@@ -287,7 +320,9 @@ data SExp' a | |||
287 | | SLet_ SI (SData SIName) (SExp' a) (SExp' a) -- let x = e in f --> SLet e f{-x is Var 0-} | 320 | | SLet_ SI (SData SIName) (SExp' a) (SExp' a) -- let x = e in f --> SLet e f{-x is Var 0-} |
288 | | SLHS SIName (SExp' a) | 321 | | SLHS SIName (SExp' a) |
289 | | STyped a | 322 | | STyped a |
290 | deriving (Eq) | 323 | deriving (Eq, Generic) |
324 | |||
325 | instance Binary SExp | ||
291 | 326 | ||
292 | sLHS :: SIName -> SExp' a -> SExp' a | 327 | sLHS :: SIName -> SExp' a -> SExp' a |
293 | sLHS _ (SRHS x) = x | 328 | sLHS _ (SRHS x) = x |
@@ -299,7 +334,9 @@ data Binder | |||
299 | = BPi Visibility | 334 | = BPi Visibility |
300 | | BLam Visibility | 335 | | BLam Visibility |
301 | | BMeta -- a metavariable is like a floating hidden lambda | 336 | | BMeta -- a metavariable is like a floating hidden lambda |
302 | deriving (Eq) | 337 | deriving (Eq, Generic) |
338 | |||
339 | instance Binary Binder | ||
303 | 340 | ||
304 | instance PShow Binder where | 341 | instance PShow Binder where |
305 | pShow = \case | 342 | pShow = \case |
@@ -308,7 +345,9 @@ instance PShow Binder where | |||
308 | BMeta -> "BMeta" | 345 | BMeta -> "BMeta" |
309 | 346 | ||
310 | data Visibility = Hidden | Visible | 347 | data Visibility = Hidden | Visible |
311 | deriving (Eq) | 348 | deriving (Eq, Generic) |
349 | |||
350 | instance Binary Visibility | ||
312 | 351 | ||
313 | instance PShow Visibility where | 352 | instance PShow Visibility where |
314 | pShow = \case | 353 | pShow = \case |
@@ -617,6 +656,9 @@ data Stmt | |||
617 | = StmtLet SIName SExp | 656 | = StmtLet SIName SExp |
618 | | Data SIName [(Visibility, SExp)]{-parameters-} SExp{-type-} [(SIName, SExp)]{-constructor names and types-} | 657 | | Data SIName [(Visibility, SExp)]{-parameters-} SExp{-type-} [(SIName, SExp)]{-constructor names and types-} |
619 | | PrecDef SIName Fixity | 658 | | PrecDef SIName Fixity |
659 | deriving Generic | ||
660 | |||
661 | instance Binary Stmt | ||
620 | 662 | ||
621 | pattern StLet :: SIName -> Maybe (SExp' Void) -> SExp' Void -> Stmt | 663 | pattern StLet :: SIName -> Maybe (SExp' Void) -> SExp' Void -> Stmt |
622 | pattern StLet n mt x <- StmtLet n (getSAnn -> (x, mt)) | 664 | pattern StLet n mt x <- StmtLet n (getSAnn -> (x, mt)) |
diff --git a/src/LambdaCube/Compiler/InferMonad.hs b/src/LambdaCube/Compiler/InferMonad.hs index 1905c839..2499fa5c 100644 --- a/src/LambdaCube/Compiler/InferMonad.hs +++ b/src/LambdaCube/Compiler/InferMonad.hs | |||
@@ -214,3 +214,5 @@ dependentVars ie = cycle mempty | |||
214 | a <-> b = (a --> b) <> (b --> a) | 214 | a <-> b = (a --> b) <> (b --> a) |
215 | 215 | ||
216 | 216 | ||
217 | --closeGlobalEnv :: GlobalEnv -> GlobalEnv | ||
218 | closeGlobalEnv = fmap (\(exp, type_, si) -> (closeExp exp {-, closeExp type_, si)-})) -- HINT: type should be finite | ||
diff --git a/src/LambdaCube/Compiler/Pretty.hs b/src/LambdaCube/Compiler/Pretty.hs index 317c4080..24e540dd 100644 --- a/src/LambdaCube/Compiler/Pretty.hs +++ b/src/LambdaCube/Compiler/Pretty.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE DeriveGeneric #-} | ||
1 | {-# LANGUAGE OverloadedStrings #-} | 2 | {-# LANGUAGE OverloadedStrings #-} |
2 | {-# LANGUAGE NoMonomorphismRestriction #-} | 3 | {-# LANGUAGE NoMonomorphismRestriction #-} |
3 | {-# LANGUAGE LambdaCase #-} | 4 | {-# LANGUAGE LambdaCase #-} |
@@ -13,6 +14,9 @@ module LambdaCube.Compiler.Pretty | |||
13 | ( module LambdaCube.Compiler.Pretty | 14 | ( module LambdaCube.Compiler.Pretty |
14 | ) where | 15 | ) where |
15 | 16 | ||
17 | import Data.Binary (Binary) | ||
18 | import GHC.Generics (Generic) | ||
19 | |||
16 | import Data.Maybe | 20 | import Data.Maybe |
17 | import Data.String | 21 | import Data.String |
18 | import Data.Char | 22 | import Data.Char |
@@ -36,7 +40,9 @@ data Fixity | |||
36 | = Infix !Int | 40 | = Infix !Int |
37 | | InfixL !Int | 41 | | InfixL !Int |
38 | | InfixR !Int | 42 | | InfixR !Int |
39 | deriving (Eq) | 43 | deriving (Eq, Generic) |
44 | |||
45 | instance Binary Fixity | ||
40 | 46 | ||
41 | instance PShow Fixity where | 47 | instance PShow Fixity where |
42 | pShow = \case | 48 | pShow = \case |
diff --git a/src/LambdaCube/Compiler/Utils.hs b/src/LambdaCube/Compiler/Utils.hs index 2a86f80b..3d1dc1ec 100644 --- a/src/LambdaCube/Compiler/Utils.hs +++ b/src/LambdaCube/Compiler/Utils.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE DeriveGeneric #-} | ||
1 | {-# LANGUAGE NoMonomorphismRestriction #-} | 2 | {-# LANGUAGE NoMonomorphismRestriction #-} |
2 | {-# LANGUAGE ScopedTypeVariables #-} | 3 | {-# LANGUAGE ScopedTypeVariables #-} |
3 | {-# LANGUAGE EmptyCase #-} | 4 | {-# LANGUAGE EmptyCase #-} |
@@ -7,6 +8,9 @@ | |||
7 | {-# OPTIONS_GHC -fno-warn-orphans #-} | 8 | {-# OPTIONS_GHC -fno-warn-orphans #-} |
8 | module LambdaCube.Compiler.Utils where | 9 | module LambdaCube.Compiler.Utils where |
9 | 10 | ||
11 | import Data.Binary (Binary(..)) | ||
12 | import GHC.Generics (Generic) | ||
13 | |||
10 | import qualified Data.IntSet as IS | 14 | import qualified Data.IntSet as IS |
11 | import qualified Data.Text as T | 15 | import qualified Data.Text as T |
12 | import qualified Text.Show.Pretty as PP | 16 | import qualified Text.Show.Pretty as PP |
@@ -36,6 +40,10 @@ foldlrev f = foldr (flip f) | |||
36 | 40 | ||
37 | data Void | 41 | data Void |
38 | 42 | ||
43 | instance Binary Void where | ||
44 | get = error "Binary get" | ||
45 | put = error "Binary put" | ||
46 | |||
39 | instance Eq Void where x == y = elimVoid x | 47 | instance Eq Void where x == y = elimVoid x |
40 | 48 | ||
41 | elimVoid :: Void -> a | 49 | elimVoid :: Void -> a |
@@ -45,6 +53,9 @@ elimVoid v = case v of | |||
45 | 53 | ||
46 | -- supplementary data: data with no semantic relevance | 54 | -- supplementary data: data with no semantic relevance |
47 | newtype SData a = SData a | 55 | newtype SData a = SData a |
56 | deriving Generic | ||
57 | |||
58 | instance Binary a => Binary (SData a) | ||
48 | 59 | ||
49 | instance Eq (SData a) where _ == _ = True | 60 | instance Eq (SData a) where _ == _ = True |
50 | instance Ord (SData a) where _ `compare` _ = EQ | 61 | instance Ord (SData a) where _ `compare` _ = EQ |