@@ -2,6 +2,7 @@
22module AST.Declaration where
33
44import Data.Binary
5+import qualified AST.Expression.General as General
56import qualified AST.Expression.Source as Source
67import qualified AST.Expression.Valid as Valid
78import qualified AST.Expression.Canonical as Canonical
@@ -28,11 +29,11 @@ data Assoc = L | N | R
2829-- DECLARATION PHASES
2930
3031type SourceDecl =
31− Declaration' RawPort Source.Def Var.Raw Source.Expr
32+ Declaration' SourcePort Source.Def Var.Raw Source.Expr
3233
3334
3435type ValidDecl =
35− Declaration' (Port Valid.Expr T.RawType) Valid.Def Var.Raw Valid.Expr
36+ Declaration' ValidPort Valid.Def Var.Raw Valid.Expr
3637
3738
3839type CanonicalDecl =
@@ -41,25 +42,25 @@ type CanonicalDecl =
4142
4243-- PORTS
4344
44−data RawPort
45+data SourcePort
4546 = PortAnnotation String T.RawType
4647 | PortDefinition String Source.Expr
4748
4849
49−data Port expr tipe
50− = Inbound String tipe
51− | Outbound String expr tipe
50+data ValidPort
51+ = In String T.RawType
52+ | Out String Valid.Expr T.RawType
5253
5354
54−type CanonicalPort =
55− Port Canonical.Expr (T.PortType Var.Canonical)
55+newtype CanonicalPort
56+ = CanonicalPort (General.PortImpl Canonical.Expr Var.Canonical)
5657
5758
58−getName :: Port expr tipe -> String
59−getName port =
59+validPortName :: ValidPort -> String
60+validPortName port =
6061 case port of
61− Inbound name _ -> name
62− Outbound name _ _ -> name
62+ In name _ -> name
63+ Out name _ _ -> name
6364
6465
6566-- BINARY CONVERSION
@@ -131,24 +132,53 @@ instance (Pretty port, Pretty def, Pretty var, Var.ToString var, Pretty expr) =>
131132 R -> P.text "r"
132133
133134
134−instance Pretty RawPort where
135+instance Pretty SourcePort where
135136 pretty port =
136137 case port of
137138 PortAnnotation name tipe ->
138− P.text "port" <+> P.text name <+> P.colon <+> pretty tipe
139+ prettyPortType name tipe
139140
140141 PortDefinition name expr ->
141− P.text "port" <+> P.text name <+> P.equals <+> pretty expr
142+ prettyPortDef name expr
142143
143144
144−instance (Pretty expr, Pretty tipe) => Pretty (Port expr tipe) where
145+instance Pretty ValidPort where
145146 pretty port =
146147 case port of
147− Inbound name tipe ->
148− P.text "port" <+> P.text name <+> P.colon <+> pretty tipe
149−
150− Outbound name expr tipe ->
151− P.vcat
152− [ P.text "port" <+> P.text name <+> P.colon <+> pretty tipe
153− , P.hang (P.text "port" <+> P.text name <+> P.equals) 4 (pretty expr)
154− ]
148+ In name tipe ->
149+ prettyPortType name tipe
150+
151+ Out name expr tipe ->
152+ prettyPort name expr tipe
153+
154+
155+instance Pretty CanonicalPort where
156+ pretty (CanonicalPort impl) =
157+ case impl of
158+ General.In name tipe ->
159+ prettyPortType name tipe
160+
161+ General.Out name expr tipe ->
162+ prettyPort name expr tipe
163+
164+ General.Task name expr tipe ->
165+ prettyPort name expr tipe
166+
167+
168+
169+prettyPort :: (Pretty expr, Pretty tipe) => String -> expr -> tipe -> P.Doc
170+prettyPort name expr tipe =
171+ P.vcat
172+ [ prettyPortType name tipe
173+ , prettyPortDef name expr
174+ ]
175+
176+
177+prettyPortType :: (Pretty tipe) => String -> tipe -> P.Doc
178+prettyPortType name tipe =
179+ P.text "port" <+> P.text name <+> P.colon <+> pretty tipe
180+
181+
182+prettyPortDef :: (Pretty expr) => String -> expr -> P.Doc
183+prettyPortDef name expr =
184+ P.hang (P.text "port" <+> P.text name <+> P.equals) 4 (pretty expr)