on fbff9ce help sign in
elk/src/AST/Kernel.hs
68 lines 1.1 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2module AST.Kernel
3 ( Info(..)
4 , Chunk(..)
5 )
6 where
9import Control.Monad (liftM, liftM2)
10import Data.Binary
11import qualified Data.ByteString as BS
12import qualified Data.Text as Text
14import qualified AST.Module.Name as ModuleName
18-- INFO
21data Info =
22 Info
23 { _imports :: [(ModuleName.Raw, Text.Text)]
24 , _chunks :: [Chunk]
25 }
28data Chunk
29 = JS BS.ByteString
30 | Var ModuleName.Raw Text.Text
31 | Prod Bool
35-- BINARY
38instance Binary Info where
39 put (Info imports chunks) =
40 put imports >> put chunks
42 get =
43 liftM2 Info get get
46instance Binary Chunk where
47 put chunk =
48 case chunk of
49 JS bytes ->
50 putWord8 0 >> put bytes
52 Var home name ->
53 putWord8 1 >> put home >> put name
55 Prod True ->
56 putWord8 2
58 Prod False ->
59 putWord8 3
61 get =
62 do word <- getWord8
63 case word of
64 0 -> liftM JS get
65 1 -> liftM2 Var get get
66 2 -> return (Prod True)
67 3 -> return (Prod False)
68 _ -> error "problem deserializing Parse.Kernel.Chunk"