on e00a3f3 help sign in
elk/src/AST/Kernel.hs
59 lines 936 B 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
34-- BINARY
37instance Binary Info where
38 put (Info imports chunks) =
39 put imports >> put chunks
41 get =
42 liftM2 Info get get
45instance Binary Chunk where
46 put chunk =
47 case chunk of
48 JS bytes ->
49 putWord8 0 >> put bytes
51 Var home name ->
52 putWord8 1 >> put home >> put name
54 get =
55 do word <- getWord8
56 case word of
57 0 -> liftM JS get
58 1 -> liftM2 Var get get
59 _ -> error "problem deserializing Parse.Kernel.Chunk"