1{-| Binary instances for the core datatypes -}
2module Idris.Core.Binary where
5import Data.Vector.Binary
6import qualified Data.Text as T
10----- Generated by 'derive'
12instance Binary FC where
13 put (FC x1 (x2, x3) (x4, x5))
21 return (FC x1 (x2x3 `div` 65536, x2x3 `mod` 65536) (x4x5 `div` 65536, x4x5 `mod` 65536))
24instance Binary Name where
27 UN x1 -> do putWord8 0
29 NS x1 x2 -> do putWord8 1
32 MN x1 x2 -> do putWord8 2
36 SN x1 -> do putWord8 4
38 SymRef x1 -> do putWord8 5
56 _ -> error "Corrupted binary data for Name"
58instance Binary T.Text where
63instance Binary SpecialName where
66 WhereN x1 x2 x3 -> do putWord8 0
70 InstanceN x1 x2 -> do putWord8 1
73 ParentN x1 x2 -> do putWord8 2
76 MethodN x1 -> do putWord8 3
78 CaseN x1 -> do putWord8 4; put x1
79 ElimN x1 -> do putWord8 5; put x1
80 InstanceCtorN x1 -> do putWord8 6; put x1
81 WithN x1 x2 -> do putWord8 7
90 return (WhereN x1 x2 x3)
93 return (InstanceN x1 x2)
96 return (ParentN x1 x2)
104 return (InstanceCtorN x1)
108 _ -> error "Corrupted binary data for SpecialName"
111instance Binary Const where
114 I x1 -> do putWord8 0
116 BI x1 -> do putWord8 1
118 Fl x1 -> do putWord8 2
120 Ch x1 -> do putWord8 3
122 Str x1 -> do putWord8 4
124 B8 x1 -> putWord8 5 >> put x1
125 B16 x1 -> putWord8 6 >> put x1
126 B32 x1 -> putWord8 7 >> put x1
127 B64 x1 -> putWord8 8 >> put x1
129 (AType (ATInt ITNative)) -> putWord8 9
130 (AType (ATInt ITBig)) -> putWord8 10
131 (AType ATFloat) -> putWord8 11
132 (AType (ATInt ITChar)) -> putWord8 12
133 StrType -> putWord8 13
134 PtrType -> putWord8 14
135 Forgot -> putWord8 15
136 (AType (ATInt (ITFixed ity))) -> putWord8 (fromIntegral (16 + fromEnum ity)) -- 16-19 inclusive
137 (AType (ATInt (ITVec ity count))) -> do
139 putWord8 (fromIntegral . fromEnum $ ity)
140 putWord8 (fromIntegral count)
142 B8V x1 -> putWord8 21 >> put x1
143 B16V x1 -> putWord8 22 >> put x1
144 B32V x1 -> putWord8 23 >> put x1
145 B64V x1 -> putWord8 24 >> put x1
146 BufferType -> putWord8 25
147 ManagedPtrType -> putWord8 26
166 9 -> return (AType (ATInt ITNative))
167 10 -> return (AType (ATInt ITBig))
168 11 -> return (AType ATFloat)
169 12 -> return (AType (ATInt ITChar))
174 16 -> return (AType (ATInt (ITFixed IT8)))
175 17 -> return (AType (ATInt (ITFixed IT16)))
176 18 -> return (AType (ATInt (ITFixed IT32)))
177 19 -> return (AType (ATInt (ITFixed IT64)))
182 return (AType (ATInt (ITVec (toEnum . fromIntegral $ e) (fromIntegral c))))
188 25 -> return BufferType
189 26 -> return ManagedPtrType
191 _ -> error "Corrupted binary data for Const"
194instance Binary Raw where
197 Var x1 -> do putWord8 0
199 RBind x1 x2 x3 -> do putWord8 1
203 RApp x1 x2 -> do putWord8 2
207 RConstant x1 -> do putWord8 4
209 RForce x1 -> do putWord8 5
219 return (RBind x1 x2 x3)
225 return (RConstant x1)
228 _ -> error "Corrupted binary data for Raw"
231instance (Binary b) => Binary (Binder b) where
234 Lam x1 -> do putWord8 0
236 Pi x1 x2 -> do putWord8 1
239 Let x1 x2 -> do putWord8 2
242 NLet x1 x2 -> do putWord8 3
245 Hole x1 -> do putWord8 4
247 GHole x1 x2 -> do putWord8 5
250 Guess x1 x2 -> do putWord8 6
253 PVar x1 -> do putWord8 7
255 PVTy x1 -> do putWord8 8
283 _ -> error "Corrupted binary data for Binder"
286instance Binary Universe where
288 UniqueType -> putWord8 0
289 AllTypes -> putWord8 1
290 NullType -> putWord8 2
291 get = do i <- getWord8
293 0 -> return UniqueType
296 _ -> error "Corrupted binary data for Universe"
298instance Binary NameType where
303 DCon x1 x2 x3 -> do putWord8 2
304 put (x1 * 65536 + x2)
306 TCon x1 x2 -> do putWord8 3
307 put (x1 * 65536 + x2)
315 return (DCon (x1x2 `div` 65536) (x1x2 `mod` 65536) x3)
317 return (TCon (x1x2 `div` 65536) (x1x2 `mod` 65536))
318 _ -> error "Corrupted binary data for NameType"
321instance {- (Binary n) => -} Binary (TT Name) where
323 = {-# SCC "putTT" #-}
325 P x1 x2 x3 -> do putWord8 0
329 V x1 -> if (x1 >= 0 && x1 < 256)
331 putWord8 (toEnum (x1 + 1))
334 Bind x1 x2 x3 -> do putWord8 2
338 App x1 x2 -> do putWord8 3
341 Constant x1 -> do putWord8 4
343 Proj x1 x2 -> do putWord8 5
345 putWord8 (toEnum (x2 + 1))
347 TType x1 -> do putWord8 7
349 Impossible -> putWord8 8
350 UType x1 -> do putWord8 10
358 return (P x1 x2 Erased)
359 1 -> do x1 <- getWord8
360 return (V ((fromEnum x1) - 1))
364 return (Bind x1 x2 x3)
372 return (Proj x1 ((fromEnum x2)-1))
376 8 -> return Impossible
381 _ -> error "Corrupted binary data for TT"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list