@@ -13,63 +13,14 @@ module Idris.Core.Binary where
13import Idris.Core.TT
13import Idris.Core.TT
15import Control.Applicative ((<$>), (<*>))
15import Control.Applicative ((<$>), (<*>))
16−import Control.Monad (liftM2)
17import Data.Binary
16import Data.Binary
18import Data.Binary.Get
17import Data.Binary.Get
19import Data.Binary.Put
18import Data.Binary.Put
21−instance Binary ErrorReportPart where
20+instance Binary ErrorReportPart
22− put (TextPart msg) = do putWord8 0 ; put msg
23− put (NamePart n) = do putWord8 1 ; put n
24− put (TermPart t) = do putWord8 2 ; put t
25− put (SubReport ps) = do putWord8 3 ; put ps
26− put (RawPart r) = do putWord8 4 ; put r
28− get = do i <- getWord8
30− 0 -> fmap TextPart get
31− 1 -> fmap NamePart get
32− 2 -> fmap TermPart get
33− 3 -> fmap SubReport get
34− 4 -> fmap RawPart get
35− _ -> error "Corrupted binary data for ErrorReportPart"
37−instance Binary Provenance where
21+instance Binary Provenance
38− put ExpectedType = putWord8 0
39− put (SourceTerm t) = do putWord8 1
41− put InferredVal = putWord8 2
42− put GivenVal = putWord8 3
43− put (TooManyArgs t) = do putWord8 4
46− get = do i <- getWord8
48− 0 -> return ExpectedType
50− return (SourceTerm x1)
51− 2 -> return InferredVal
54− return (TooManyArgs x1)
55− _ -> error "Corrupted binary data for Provenance"
57−instance Binary UConstraint where
22+instance Binary UConstraint
58− put (ULT x1 x2) = putWord8 0 >> put x1 >> put x2
59− put (ULE x1 x2) = putWord8 1 >> put x1 >> put x2
60− get = do i <- getWord8
62− 0 -> ULT <$> get <*> get
63− 1 -> ULE <$> get <*> get
64− _ -> error "Corrupted binary data for UConstraint"
66−instance Binary ConstraintFC where
23+instance Binary ConstraintFC
67− put (ConstraintFC x1 x2) = putWord8 0 >> put x1 >> put x2
68− get = do i <- getWord8
70− 0 -> liftM2 ConstraintFC get get
71− _ -> error "Corrupted binary data for ConstraintFC"
73instance Binary a => Binary (Err' a) where
24instance Binary a => Binary (Err' a) where
74 put (Msg str) = do putWord8 0
25 put (Msg str) = do putWord8 0
@@ -277,119 +228,10 @@ instance Binary a => Binary (Err' a) where
277 _ -> error "Corrupted binary data for Err'"
228 _ -> error "Corrupted binary data for Err'"
278----- Generated by 'derive'
229----- Generated by 'derive'
280−instance Binary FC where
231+instance Binary FC
283− (FC x1 (x2, x3) (x4, x5)) -> do putWord8 0
285− put (x2 * 65536 + x3)
286− put (x4 * 65536 + x5)
288− FileFC x1 -> do putWord8 2
296− return (FC x1 (x2x3 `div` 65536, x2x3 `mod` 65536) (x4x5 `div` 65536, x4x5 `mod` 65536))
300− _ -> error "Corrupted binary data for FC"
302−instance Binary FC' where
232+instance Binary FC'
303− put (FC' fc) = put fc
306−instance Binary Name where
233+instance Binary Name
309− UN x1 -> do putWord8 0
311− NS x1 x2 -> do putWord8 1
314− MN x1 x2 -> do putWord8 2
317− SN x1 -> do putWord8 3
319− SymRef x1 -> do putWord8 4
336− _ -> error "Corrupted binary data for Name"
338−instance Binary SpecialName where
234+instance Binary SpecialName
341− WhereN x1 x2 x3 -> do putWord8 0
345− ImplementationN x1 x2 -> do putWord8 1
348− ParentN x1 x2 -> do putWord8 2
351− MethodN x1 -> do putWord8 3
353− CaseN x1 x2 -> do putWord8 4; put x1; put x2
354− ElimN x1 -> do putWord8 5; put x1
355− ImplementationCtorN x1 -> do putWord8 6; put x1
356− WithN x1 x2 -> do putWord8 7
359− MetaN x1 x2 -> do putWord8 8
368− return (WhereN x1 x2 x3)
371− return (ImplementationN x1 x2)
374− return (ParentN x1 x2)
379− return (CaseN x1 x2)
383− return (ImplementationCtorN x1)
386− return (WithN x1 x2)
389− return (MetaN x1 x2)
390− _ -> error "Corrupted binary data for SpecialName"
393instance Binary Const where
235instance Binary Const where
395 = case x of
237 = case x of
@@ -453,56 +295,8 @@ instance Binary Const where
453 29 -> return TheWorld
295 29 -> return TheWorld
454 _ -> error "Corrupted binary data for Const"
296 _ -> error "Corrupted binary data for Const"
457−instance Binary Raw where
298+instance Binary Raw
460− Var x1 -> do putWord8 0
462− RBind x1 x2 x3 -> do putWord8 1
466− RApp x1 x2 -> do putWord8 2
470− RConstant x1 -> do putWord8 4
472− RUType x1 -> do putWord8 5
482− return (RBind x1 x2 x3)
488− return (RConstant x1)
491− _ -> error "Corrupted binary data for Raw"
493−instance Binary RigCount where
299+instance Binary RigCount
498− get = do i <- getWord8
503− _ -> error "Corrupted binary data for RigCount"
506instance Binary ImplicitInfo where
300instance Binary ImplicitInfo where
508 = case x of
302 = case x of
@@ -512,124 +306,11 @@ instance Binary ImplicitInfo where
512 x2 <- get
306 x2 <- get
513 return (Impl x1 x2 False)
307 return (Impl x1 x2 False)
515−instance (Binary b) => Binary (Binder b) where
309+instance (Binary b) => Binary (Binder b)
518− Lam x1 x2 -> do putWord8 0
521− Pi x1 x2 x3 x4 -> do putWord8 1
526− Let x1 x2 -> do putWord8 2
529− NLet x1 x2 -> do putWord8 3
532− Hole x1 -> do putWord8 4
534− GHole x1 x2 x3 -> do putWord8 5
538− Guess x1 x2 -> do putWord8 6
541− PVar x1 x2 -> do putWord8 7
544− PVTy x1 -> do putWord8 8
556− return (Pi x1 x2 x3 x4)
568− return (GHole x1 x2 x3)
571− return (Guess x1 x2)
577− _ -> error "Corrupted binary data for Binder"
580−instance Binary Universe where
310+instance Binary Universe
582− UniqueType -> putWord8 0
583− AllTypes -> putWord8 1
584− NullType -> putWord8 2
585− get = do i <- getWord8
587− 0 -> return UniqueType
588− 1 -> return AllTypes
589− 2 -> return NullType
590− _ -> error "Corrupted binary data for Universe"
592−instance Binary NameType where
311+instance Binary NameType
597− DCon x1 x2 x3 -> do putWord8 2
598− put (x1 * 65536 + x2)
600− TCon x1 x2 -> do putWord8 3
601− put (x1 * 65536 + x2)
609− return (DCon (x1x2 `div` 65536) (x1x2 `mod` 65536) x3)
611− return (TCon (x1x2 `div` 65536) (x1x2 `mod` 65536))
612− _ -> error "Corrupted binary data for NameType"
614−-- record concrete levels only, for now
615−instance Binary UExp where
312+instance Binary UExp
617− UVar ns t -> do putWord8 0
620− UVal t -> do putWord8 1
623− get = do i <- getWord8
630− _ -> error "Corrupted binary data for UExp"
632−instance {- (Binary n) => -} Binary (TT Name) where
313+instance Binary (TT Name) where
634 = {-# SCC "putTT" #-}
315 = {-# SCC "putTT" #-}
635 case x of
316 case x of