on e00a3f3 help sign in
elk/src/AST/Effects.hs
101 lines 1.6 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2module AST.Effects
3 ( Effects(..), Raw, Canonical
4 , Info(..)
5 , RawManagerType(..), ManagerType(..)
6 , PortRaw(..), PortCanonical(..), Kind(..)
7 )
8 where
10import Data.Binary
11import Data.Text (Text)
13import qualified AST.Type as Type
14import qualified Elm.Package as Pkg
15import qualified Reporting.Annotation as A
16import qualified Reporting.Region as R
20-- EFFECTS
23data Effects pkg ports
24 = None
25 | Manager pkg Info
26 | Port ports
29type Raw =
30 Effects () [A.Commented PortRaw]
33type Canonical =
34 Effects Pkg.Name [A.Commented PortCanonical]
38-- EFFECT MANAGERS
41data Info =
42 Info
43 { _tag :: R.Region
44 , _init :: R.Region
45 , _onEffects :: R.Region
46 , _onSelfMsg :: R.Region
47 , _managerType :: RawManagerType
48 }
51data RawManagerType
52 = CmdManager (A.Located Text)
53 | SubManager (A.Located Text)
54 | FxManager (A.Located Text) (A.Located Text)
57data ManagerType = Cmds | Subs | Both
61-- FOREIGN EFFECTS
64data PortRaw =
65 PortRaw
66 { _rawName :: Text
67 , _rawType :: Type.Raw
68 }
71data PortCanonical =
72 PortCanonical
73 { _name :: Text
74 , _kind :: Kind
75 , _type :: Type.Canonical
76 }
79data Kind
80 = Outgoing Type.Canonical
81 | Incoming Type.Canonical
85-- BINARY
88instance Binary ManagerType where
89 put managerType =
90 case managerType of
91 Cmds -> putWord8 0
92 Subs -> putWord8 1
93 Both -> putWord8 2
95 get =
96 do word <- getWord8
97 case word of
98 0 -> pure Cmds
99 1 -> pure Subs
100 2 -> pure Both
101 _ -> error "problem getting Effects.ManagerType binary"