on 2aa7dcd help sign in
elk/src/AST/Declaration.hs
95 lines 1.9 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2module AST.Declaration where
4import Data.Binary
6import qualified AST.Expression.General as General
7import qualified AST.Expression.Source as Source
8import qualified AST.Expression.Valid as Valid
9import qualified AST.Expression.Canonical as Canonical
10import qualified AST.Type as Type
11import qualified Reporting.Annotation as A
14-- DECLARATIONS
16data Declaration' port def tipe expr
17 = Definition def
18 | Datatype String [String] [(String, [tipe])]
19 | TypeAlias String [String] tipe
20 | Port port
21 | Fixity Assoc Int String
24-- INFIX STUFF
26data Assoc = L | N | R
27 deriving (Eq)
30assocToString :: Assoc -> String
31assocToString assoc =
32 case assoc of
33 L -> "left"
34 N -> "non"
35 R -> "right"
38-- DECLARATION PHASES
40type SourceDecl' =
41 Declaration' SourcePort Source.Def Type.Raw Source.Expr
44type SourceDecl =
45 A.Located SourceDecl'
48type ValidDecl =
49 A.Located (Declaration' ValidPort Valid.Def Type.Raw Valid.Expr)
52type CanonicalDecl =
53 A.Located (Declaration' CanonicalPort Canonical.Def Type.Canonical Canonical.Expr)
56-- PORTS
58data SourcePort
59 = PortAnnotation String Type.Raw
60 | PortDefinition String Source.Expr
63data ValidPort
64 = In String Type.Raw
65 | Out String Valid.Expr Type.Raw
68newtype CanonicalPort
69 = CanonicalPort (General.PortImpl Canonical.Expr Type.Canonical)
72validPortName :: ValidPort -> String
73validPortName port =
74 case port of
75 In name _ -> name
76 Out name _ _ -> name
79-- BINARY CONVERSION
81instance Binary Assoc where
82 get =
83 do n <- getWord8
84 return $ case n of
85 0 -> L
86 1 -> N
87 2 -> R
88 _ -> error "Error reading valid associativity from serialized string"
90 put assoc =
91 putWord8 $
92 case assoc of
93 L -> 0
94 N -> 1
95 R -> 2