on ed26eca help sign in
elk/src/AST/Kernel.hs
74 lines 1.2 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 | Field Text.Text
32 | Debug
33 | Prod
37-- BINARY
40instance Binary Info where
41 put (Info imports chunks) =
42 put imports >> put chunks
44 get =
45 liftM2 Info get get
48instance Binary Chunk where
49 put chunk =
50 case chunk of
51 JS bytes ->
52 putWord8 0 >> put bytes
54 Var home name ->
55 putWord8 1 >> put home >> put name
57 Field field ->
58 putWord8 2 >> put field
60 Debug ->
61 putWord8 3
63 Prod ->
64 putWord8 4
66 get =
67 do word <- getWord8
68 case word of
69 0 -> liftM JS get
70 1 -> liftM2 Var get get
71 2 -> liftM Field get
72 3 -> return Debug
73 4 -> return Prod
74 _ -> error "problem deserializing Parse.Kernel.Chunk"